aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2008-02-19 22:04:34 +0000
committerAlan Mackenzie2008-02-19 22:04:34 +0000
commit88a46e21049ad174ddf98eca63eb3246a5b91946 (patch)
tree7676724772a9d0ae5d8e06d40100ee2d9b27fbb8
parentbc99e713cd4639795fecef3833ca2ad125fadc2b (diff)
downloademacs-88a46e21049ad174ddf98eca63eb3246a5b91946.tar.gz
emacs-88a46e21049ad174ddf98eca63eb3246a5b91946.zip
Set of changes so that "obtrusive" syntactic elements in a C/C++/ObjC
preprocessor line (e.g. an unbalanced string quote or unmatched paren) don't interact syntactically with stuff outside the CPP line. (c-awk-beyond-logical-line, c-awk-old-ByLL): Replace c-awk-end-of-logical-line and c-awk-old-EoLL to solve an off-by-one bug. (c-awk-record-region-clear-NL): Replaces c-awk-before-change, with a bit of refactoring. (c-awk-extend-and-syntax-tablify-region): Takes some of the functionality of c-awk-advise-fl-for-awk-region, which has been refactored away.
-rw-r--r--lisp/progmodes/cc-awk.el122
1 files changed, 58 insertions, 64 deletions
diff --git a/lisp/progmodes/cc-awk.el b/lisp/progmodes/cc-awk.el
index de15d959cbd..8833f279dde 100644
--- a/lisp/progmodes/cc-awk.el
+++ b/lisp/progmodes/cc-awk.el
@@ -53,6 +53,8 @@
53 53
54;; Silence the byte compiler. 54;; Silence the byte compiler.
55(cc-bytecomp-defvar font-lock-mode) ; Checked with boundp before use. 55(cc-bytecomp-defvar font-lock-mode) ; Checked with boundp before use.
56(cc-bytecomp-defvar c-new-BEG)
57(cc-bytecomp-defvar c-new-END)
56 58
57;; Some functions in cc-engine that are used below. There's a cyclic 59;; Some functions in cc-engine that are used below. There's a cyclic
58;; dependency so it can't be required here. (Perhaps some functions 60;; dependency so it can't be required here. (Perhaps some functions
@@ -624,22 +626,25 @@
624 (forward-line -1)) 626 (forward-line -1))
625 (point)) 627 (point))
626 628
627(defun c-awk-end-of-logical-line (&optional pos) 629(defun c-awk-beyond-logical-line (&optional pos)
628;; Go forward to the end of the (apparent) current logical line (or the end of 630;; Return the position just beyond the (apparent) current logical line, or the
629;; the line containing POS), returning the buffer position of that point. I.e., 631;; one containing POS. This is usually the beginning of the next line which
630;; go to the end of the next line which doesn't have an escaped EOL. 632;; doesn't follow an escaped EOL. At EOB, this will be EOB.
633;;
634;; Point is unchanged.
631;; 635;;
632;; This is guaranteed to be "safe" for syntactic analysis, i.e. outwith any 636;; This is guaranteed to be "safe" for syntactic analysis, i.e. outwith any
633;; comment, string or regexp. IT MAY WELL BE that this function should not be 637;; comment, string or regexp. IT MAY WELL BE that this function should not be
634;; executed on a narrowed buffer. 638;; executed on a narrowed buffer.
635;; 639 (save-excursion
636;; This function might do hidden buffer changes. 640 (if pos (goto-char pos))
637 (if pos (goto-char pos)) 641 (end-of-line)
638 (end-of-line) 642 (while (and (< (point) (point-max))
639 (while (and (< (point) (point-max)) 643 (eq (char-before) ?\\))
640 (eq (char-before) ?\\)) 644 (end-of-line 2))
641 (end-of-line 2)) 645 (if (< (point) (point-max))
642 (point)) 646 (1+ (point))
647 (point))))
643 648
644;; ACM, 2002/02/15: The idea of the next function is to put the "Error font" 649;; ACM, 2002/02/15: The idea of the next function is to put the "Error font"
645;; on strings/regexps which are missing their closing delimiter. 650;; on strings/regexps which are missing their closing delimiter.
@@ -712,7 +717,7 @@
712 ;; 717 ;;
713 ;; The result is what ANCHOR-STATE-/DIV (see above) is where point is left. 718 ;; The result is what ANCHOR-STATE-/DIV (see above) is where point is left.
714 ;; 719 ;;
715 ;; This function might do hidden buffer changes. 720 ;; This function does hidden buffer changes.
716 (let ((/point (point))) 721 (let ((/point (point)))
717 (goto-char anchor) 722 (goto-char anchor)
718 ;; Analyse the line to find out what the / is. 723 ;; Analyse the line to find out what the / is.
@@ -780,55 +785,38 @@
780 (c-awk-syntax-tablify-/ anchor anchor-state-/div)))) 785 (c-awk-syntax-tablify-/ anchor anchor-state-/div))))
781 nil)) 786 nil))
782 787
783
784;; ACM, 2002/07/21: Thoughts: We need an AWK Mode after-change function to set 788;; ACM, 2002/07/21: Thoughts: We need an AWK Mode after-change function to set
785;; the syntax-table properties even when font-lock isn't enabled, for the 789;; the syntax-table properties even when font-lock isn't enabled, for the
786;; subsequent use of movement functions, etc. However, it seems that if font 790;; subsequent use of movement functions, etc. However, it seems that if font
787;; lock _is_ enabled, we can always leave it to do the job. 791;; lock _is_ enabled, we can always leave it to do the job.
788(defvar c-awk-old-EOLL 0) 792(defvar c-awk-old-ByLL 0)
789(make-variable-buffer-local 'c-awk-old-EOLL) 793(make-variable-buffer-local 'c-awk-old-Byll)
790;; End of logical line following the region which is about to be changed. Set 794;; Just beyond logical line following the region which is about to be changed.
791;; in c-awk-before-change and used in c-awk-after-change. 795;; Set in c-awk-record-region-clear-NL and used in c-awk-after-change.
792 796
793(defun c-awk-before-change (beg end) 797(defun c-awk-record-region-clear-NL (beg end)
794;; This function is called exclusively from the before-change-functions hook. 798;; This function is called exclusively from the before-change-functions hook.
795;; It does two things: Finds the end of the (logical) line on which END lies, 799;; It does two things: Finds the end of the (logical) line on which END lies,
796;; and clears c-awk-NL-prop text properties from this point onwards. 800;; and clears c-awk-NL-prop text properties from this point onwards. BEG is
801;; ignored.
797;; 802;;
798;; This function might do hidden buffer changes. 803;; On entry, the buffer will have been widened and match-data will have been
799 (save-restriction 804;; saved; point is undefined on both entry and exit; the return value is
800 (save-excursion 805;; ignored.
801 (setq c-awk-old-EOLL (c-awk-end-of-logical-line end)) 806;;
802 (c-save-buffer-state nil 807;; This function does hidden buffer changes.
803 (c-awk-clear-NL-props end (point-max)))))) 808 (c-save-buffer-state ()
809 (setq c-awk-old-ByLL (c-awk-beyond-logical-line end))
810 (c-save-buffer-state nil
811 (c-awk-clear-NL-props end (point-max)))))
804 812
805(defun c-awk-end-of-change-region (beg end old-len) 813(defun c-awk-end-of-change-region (beg end old-len)
806 ;; Find the end of the region which needs to be font-locked after a change. 814 ;; Find the end of the region which needs to be font-locked after a change.
807 ;; This is the end of the logical line on which the change happened, either 815 ;; This is the end of the logical line on which the change happened, either
808 ;; as it was before the change, or as it is now, whichever is later. 816 ;; as it was before the change, or as it is now, whichever is later.
809 ;; N.B. point is left undefined. 817 ;; N.B. point is left undefined.
810 ;; 818 (max (+ (- c-awk-old-ByLL old-len) (- end beg))
811 ;; This function might do hidden buffer changes. 819 (c-awk-beyond-logical-line end)))
812 (max (+ (- c-awk-old-EOLL old-len) (- end beg))
813 (c-awk-end-of-logical-line end)))
814
815(defun c-awk-after-change (beg end old-len)
816;; This function is called exclusively as an after-change function in
817;; AWK Mode. It ensures that the syntax-table properties get set in the
818;; changed region. However, if font-lock is enabled, this function does
819;; nothing, since an enabled font-lock after-change function will always do
820;; this.
821;;
822;; This function might do hidden buffer changes.
823 (unless (and (boundp 'font-lock-mode) font-lock-mode)
824 (save-restriction
825 (save-excursion
826 (save-match-data
827 (setq end (c-awk-end-of-change-region beg end old-len))
828 (c-awk-beginning-of-logical-line beg)
829 (c-save-buffer-state nil ; So that read-only status isn't affected.
830 ; (e.g. when first loading the buffer)
831 (c-awk-set-syntax-table-properties end)))))))
832 820
833;; ACM 2002/5/25. When font-locking is invoked by a buffer change, the region 821;; ACM 2002/5/25. When font-locking is invoked by a buffer change, the region
834;; specified by the font-lock after-change function must be expanded to 822;; specified by the font-lock after-change function must be expanded to
@@ -836,22 +824,28 @@
836;; do this in practice is to use the beginning/end-of-logical-line functions. 824;; do this in practice is to use the beginning/end-of-logical-line functions.
837;; Don't overlook the possibility of the buffer change being the "recapturing" 825;; Don't overlook the possibility of the buffer change being the "recapturing"
838;; of a previously escaped newline. 826;; of a previously escaped newline.
839(defmacro c-awk-advise-fl-for-awk-region (function) 827
840 `(defadvice ,function (before get-awk-region activate) 828;; ACM 2008-02-05:
841;; When font-locking an AWK Mode buffer, make sure that any string/regexp is 829(defun c-awk-extend-and-syntax-tablify-region (beg end old-len)
842;; completely font-locked. 830 ;; Expand the region (BEG END) as needed to (c-new-BEG c-new-END) then put
843 (when (eq major-mode 'awk-mode) 831 ;; `syntax-table' properties on this region.
844 (save-excursion 832 ;;
845 (ad-set-arg 1 (c-awk-end-of-change-region 833 ;; This function is called from an after-change function, BEG END and
846 (ad-get-arg 0) ; beg 834 ;; OLD-LEN being the standard parameters.
847 (ad-get-arg 1) ; end 835 ;;
848 (ad-get-arg 2))) ; old-len 836 ;; Point is undefined both before and after this function call, the buffer
849 (ad-set-arg 0 (c-awk-beginning-of-logical-line (ad-get-arg 0))))))) 837 ;; has been widened, and match-data saved. The return value is ignored.
850 838 ;;
851(c-awk-advise-fl-for-awk-region font-lock-after-change-function) 839 ;; It prepares the buffer for font
852(c-awk-advise-fl-for-awk-region jit-lock-after-change) 840 ;; locking, hence must get called before `font-lock-after-change-function'.
853(c-awk-advise-fl-for-awk-region lazy-lock-defer-rest-after-change) 841 ;;
854(c-awk-advise-fl-for-awk-region lazy-lock-defer-line-after-change) 842 ;; This function is the AWK value of `c-before-font-lock-function'.
843 ;; It does hidden buffer changes.
844 (c-save-buffer-state ()
845 (setq c-new-END (c-awk-end-of-change-region beg end old-len))
846 (setq c-new-BEG (c-awk-beginning-of-logical-line beg))
847 (goto-char c-new-BEG)
848 (c-awk-set-syntax-table-properties c-new-END)))
855 849
856;; Awk regexps written with help from Peter Galbraith 850;; Awk regexps written with help from Peter Galbraith
857;; <galbraith@mixing.qc.dfo.ca>. 851;; <galbraith@mixing.qc.dfo.ca>.