emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r105598: Fix - typing on a C++ inher-


From: Alan Mackenzie
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r105598: Fix - typing on a C++ inher-intro or inher-cont line should preserve the
Date: Sun, 28 Aug 2011 11:42:33 +0000
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105598
committer: Alan Mackenzie <address@hidden>
branch nick: trunk
timestamp: Sun 2011-08-28 11:42:33 +0000
message:
  Fix - typing on a C++ inher-intro or inher-cont line should preserve the
  fontification of the inherited class names.  Analogously for namespace
  names and Java import, extends, etc.
  
  (cc-fonts.el): (c-make-font-lock-BO-decl-search-function): New function.
  (c-basic-matchers-after - "Fontify the clauses after various keywords"):
  Extract the three keyword lists for the 3 erroneous constructs from the
  list of four, and use the new function above in place of an old one.
modified:
  lisp/ChangeLog
  lisp/progmodes/cc-fonts.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-08-28 06:07:14 +0000
+++ b/lisp/ChangeLog    2011-08-28 11:42:33 +0000
@@ -1,3 +1,12 @@
+2011-08-28  Alan Mackenzie  <address@hidden>
+
+       * progmodes/cc-fonts.el
+       (c-make-font-lock-BO-decl-search-function): New function.
+       (c-basic-matchers-after - "Fontify the clauses after various
+       keywords"): Extract the three keyword lists for the 3 erroneous
+       constructs from the list of four, and use the new function above
+       in place of an old one.
+
 2011-08-28  Deniz Dogan  <address@hidden>
 
        * net/rcirc.el (rcirc-insert-prev-input)

=== modified file 'lisp/progmodes/cc-fonts.el'
--- a/lisp/progmodes/cc-fonts.el        2011-08-20 22:02:25 +0000
+++ b/lisp/progmodes/cc-fonts.el        2011-08-28 11:42:33 +0000
@@ -398,6 +398,59 @@
 
        nil)))
 
+  (defun c-make-font-lock-BO-decl-search-function (regexp &rest highlights)
+    ;; This function makes a byte compiled function that first moves back
+    ;; to the beginning of the current declaration (if any), then searches
+    ;; forward for matcher elements (as in `font-lock-keywords') and
+    ;; fontifies them.
+    ;;
+    ;; The motivation for moving back to the declaration start is to
+    ;; establish a context for the current text when, e.g., a character
+    ;; is typed on a C++ inheritance continuation line, or a jit-lock
+    ;; chunk starts there.
+    ;; 
+    ;; The new function works much like a matcher element in
+    ;; `font-lock-keywords'.  It cuts out a little bit of the overhead
+    ;; compared to a real matcher.  The main reason is however to pass the
+    ;; real search limit to the anchored matcher(s), since most (if not
+    ;; all) font-lock implementations arbitrarily limit anchored matchers
+    ;; to the same line, and also to insulate against various other
+    ;; irritating differences between the different (X)Emacs font-lock
+    ;; packages.
+    ;;
+    ;; REGEXP is the matcher, which must be a regexp.  Only matches
+    ;; where the beginning is outside any comment or string literal are
+    ;; significant.
+    ;;
+    ;; HIGHLIGHTS is a list of highlight specs, just like in
+    ;; `font-lock-keywords', with these limitations: The face is always
+    ;; overridden (no big disadvantage, since hits in comments etc are
+    ;; filtered anyway), there is no "laxmatch", and an anchored matcher
+    ;; is always a form which must do all the fontification directly.
+    ;; `limit' is a variable bound to the real limit in the context of
+    ;; the anchored matcher forms.
+    ;;
+    ;; This function does not do any hidden buffer changes, but the
+    ;; generated functions will.  (They are however used in places
+    ;; covered by the font-lock context.)
+
+    ;; Note: Replace `byte-compile' with `eval' to debug the generated
+    ;; lambda more easily.
+    (byte-compile
+     `(lambda (limit)
+       (let ( ;; The font-lock package in Emacs is known to clobber
+             ;; `parse-sexp-lookup-properties' (when it exists).
+             (parse-sexp-lookup-properties
+              (cc-eval-when-compile
+                (boundp 'parse-sexp-lookup-properties))))
+         (goto-char
+          (let ((here (point)))
+            (if (eq (car (c-beginning-of-decl-1)) 'same)
+                (point)
+              here)))
+         ,(c-make-font-lock-search-form regexp highlights))
+       nil)))
+
   (defun c-make-font-lock-context-search-function (normal &rest state-stanzas)
     ;; This function makes a byte compiled function that works much like
     ;; a matcher element in `font-lock-keywords', with the following
@@ -1828,24 +1881,32 @@
                          c-label-face-name nil t))))))
 
       ;; Fontify the clauses after various keywords.
-      ,@(when (or (c-lang-const c-type-list-kwds)
-                 (c-lang-const c-ref-list-kwds)
-                 (c-lang-const c-colon-type-list-kwds)
-                 (c-lang-const c-paren-type-kwds))
-         `((,(c-make-font-lock-search-function
-              (concat "\\<\\("
-                      (c-make-keywords-re nil
-                        (append (c-lang-const c-type-list-kwds)
-                                (c-lang-const c-ref-list-kwds)
-                                (c-lang-const c-colon-type-list-kwds)
-                                (c-lang-const c-paren-type-kwds)))
-                      "\\)\\>")
-              '((c-fontify-types-and-refs ((c-promote-possible-types t))
-                  (c-forward-keyword-clause 1)
-                  (if (> (point) limit) (goto-char limit))))))))
-
-      ,@(when (c-major-mode-is 'java-mode)
-         `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face))))
+       ,@(when (or (c-lang-const c-type-list-kwds)
+                   (c-lang-const c-ref-list-kwds)
+                   (c-lang-const c-colon-type-list-kwds))
+           `((,(c-make-font-lock-BO-decl-search-function
+                (concat "\\<\\("
+                        (c-make-keywords-re nil
+                          (append (c-lang-const c-type-list-kwds)
+                                  (c-lang-const c-ref-list-kwds)
+                                  (c-lang-const c-colon-type-list-kwds)))
+                        "\\)\\>")
+                '((c-fontify-types-and-refs ((c-promote-possible-types t))
+                    (c-forward-keyword-clause 1)
+                    (if (> (point) limit) (goto-char limit))))))))
+
+       ,@(when (c-lang-const c-paren-type-kwds)
+           `((,(c-make-font-lock-search-function
+                (concat "\\<\\("
+                        (c-make-keywords-re nil
+                          (c-lang-const c-paren-type-kwds))
+                        "\\)\\>")
+                '((c-fontify-types-and-refs ((c-promote-possible-types t))
+                    (c-forward-keyword-clause 1)
+                    (if (> (point) limit) (goto-char limit))))))))
+
+       ,@(when (c-major-mode-is 'java-mode)
+           `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face))))
       ))
 
 (c-lang-defconst c-matchers-1


reply via email to

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