emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

font-lock-multiline for cc-awk.


From: Stefan Monnier
Subject: font-lock-multiline for cc-awk.
Date: Tue, 25 Apr 2006 16:10:33 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

AFAICT the patch below converts cc-awk to use font-lock-multiline instead of
an after-change-function.


        Stefan


--- cc-awk.el   06 Mar 2006 14:26:48 -0500      1.9
+++ cc-awk.el   25 Apr 2006 16:08:37 -0400      
@@ -677,7 +677,13 @@
     (goto-char (1+ beg))
     (or (eobp)
         (while (search-forward "\"" end t)
-          (c-put-char-property (1- (point)) 'syntax-table '(1))))))
+          (c-put-char-property (1- (point)) 'syntax-table '(1)))))
+  ;; Make sure that this element will be properly refontified next time
+  ;; around even if it spans several lines.
+  (save-excursion
+    (goto-char beg)
+    (if (search-forward "\n" end t)
+        (put-text-property beg end 'font-lock-multiline t))))
 
 (defun c-awk-syntax-tablify-string ()
   ;; Point is at the opening " or _" of a string.  Set the syntax-table
@@ -759,10 +765,12 @@
 ;; (iv) Inside a comment, all syntax-table properties are cleared.
 ;;
 ;; This function does hidden buffer changes.
-  (let (anchor
-       (anchor-state-/div nil)) ; t means a following / would be a div sign.
     (c-awk-beginning-of-logical-line) ; ACM 2002/7/21.  This is probably 
redundant.
+  ;; Redundant if called from font-lock.  --Stef
     (c-clear-char-properties (point) lim 'syntax-table)
+  (let (anchor
+       (anchor-state-/div nil)
+        (linebeg (point))) ; t means a following / would be a div sign.
     ;; Once round the next loop for each string, regexp, or div sign
     (while (progn
              ;; Skip any "harmless" lines before the next tricky one.
@@ -776,83 +784,19 @@
       (setq anchor-state-/div
             (if (looking-at "_?\"")
                 (c-awk-syntax-tablify-string)
+              (if (save-excursion (re-search-backward "\n" linebeg t))
+                  ;; Whether / is interpreted as a div or not depends on all
+                  ;; the text between linebeg and point, so if something is
+                  ;; changed there, even if it's on another line, we need to
+                  ;; refontify this piece of text.
+                  ;; Note that jit-lock-contextually also takes care of
+                  ;; that, so this is only necessary if we want it to work
+                  ;; without jit-lock-contextually or if we want to avoid
+                  ;; the jit-lock-context-time delay.
+                  (put-text-property linebeg (point) 'font-lock-multiline t))
               (c-awk-syntax-tablify-/ anchor anchor-state-/div))))
     nil))
 
-
-;; ACM, 2002/07/21: Thoughts: We need an AWK Mode after-change function to set
-;; the syntax-table properties even when font-lock isn't enabled, for the
-;; subsequent use of movement functions, etc.  However, it seems that if font
-;; lock _is_ enabled, we can always leave it to do the job.
-(defvar c-awk-old-EOLL 0)
-(make-variable-buffer-local 'c-awk-old-EOLL)
-;; End of logical line following the region which is about to be changed.  Set
-;; in c-awk-before-change and used in c-awk-after-change.
-
-(defun c-awk-before-change (beg end)
-;; This function is called exclusively from the before-change-functions hook.
-;; It does two things: Finds the end of the (logical) line on which END lies,
-;; and clears c-awk-NL-prop text properties from this point onwards.
-;;
-;; This function might do hidden buffer changes.
-  (save-restriction
-    (save-excursion
-      (setq c-awk-old-EOLL (c-awk-end-of-logical-line end))
-      (c-save-buffer-state nil
-       (c-awk-clear-NL-props end (point-max))))))
-
-(defun c-awk-end-of-change-region (beg end old-len)
-  ;; Find the end of the region which needs to be font-locked after a change.
-  ;; This is the end of the logical line on which the change happened, either
-  ;; as it was before the change, or as it is now, whichever is later.
-  ;; N.B. point is left undefined.
-  ;;
-  ;; This function might do hidden buffer changes.
-  (max (+ (- c-awk-old-EOLL old-len) (- end beg))
-       (c-awk-end-of-logical-line end)))
-
-(defun c-awk-after-change (beg end old-len)
-;; This function is called exclusively as an after-change function in
-;; AWK Mode.  It ensures that the syntax-table properties get set in the
-;; changed region.  However, if font-lock is enabled, this function does
-;; nothing, since an enabled font-lock after-change function will always do
-;; this.
-;;
-;; This function might do hidden buffer changes.
-  (unless (and (boundp 'font-lock-mode) font-lock-mode)
-    (save-restriction
-      (save-excursion
-       (save-match-data
-         (setq end (c-awk-end-of-change-region beg end old-len))
-         (c-awk-beginning-of-logical-line beg)
-         (c-save-buffer-state nil  ; So that read-only status isn't affected.
-                                        ; (e.g. when first loading the buffer)
-           (c-awk-set-syntax-table-properties end)))))))
-
-;; ACM 2002/5/25.  When font-locking is invoked by a buffer change, the region
-;; specified by the font-lock after-change function must be expanded to
-;; include ALL of any string or regexp within the region.  The simplest way to
-;; do this in practice is to use the beginning/end-of-logical-line functions.
-;; Don't overlook the possibility of the buffer change being the "recapturing"
-;; of a previously escaped newline.
-(defmacro c-awk-advise-fl-for-awk-region (function)
-  `(defadvice ,function (before get-awk-region activate)
-;; When font-locking an AWK Mode buffer, make sure that any string/regexp is
-;; completely font-locked.
-  (when (eq major-mode 'awk-mode)
-    (save-excursion
-      (ad-set-arg 1 (c-awk-end-of-change-region
-                     (ad-get-arg 0)     ; beg
-                     (ad-get-arg 1)     ; end
-                     (ad-get-arg 2)))   ; old-len
-      (ad-set-arg 0 (c-awk-beginning-of-logical-line (ad-get-arg 0)))))))
-
-(c-awk-advise-fl-for-awk-region font-lock-after-change-function)
-(c-awk-advise-fl-for-awk-region jit-lock-after-change)
-(c-awk-advise-fl-for-awk-region lazy-lock-defer-rest-after-change)
-(c-awk-advise-fl-for-awk-region lazy-lock-defer-line-after-change)
-
-
 ;; ACM 2002/9/29.  Movement functions, e.g. for C-M-a and C-M-e
 
 ;; The following three regexps differ from those earlier on in cc-awk.el in
@@ -1011,5 +955,5 @@
 
 (cc-provide 'cc-awk)                   ; Changed from 'awk-mode, ACM 2002/5/21
 
-;;; arch-tag: c4836289-3aa4-4a59-9934-9ccc2bacccf3
+;; arch-tag: c4836289-3aa4-4a59-9934-9ccc2bacccf3
 ;;; awk-mode.el ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]