diff options
| author | Alan Mackenzie | 2011-08-28 11:42:33 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2011-08-28 11:42:33 +0000 |
| commit | ef8cdf8c2abe4c25f9f71fd7ccb409a61d18aa90 (patch) | |
| tree | f1ea5b0a1d2df0e9cf926a82a09d089c54eb8dec | |
| parent | d6b9407c0c01fa68694f304b1422a790a805bfb2 (diff) | |
| download | emacs-ef8cdf8c2abe4c25f9f71fd7ccb409a61d18aa90.tar.gz emacs-ef8cdf8c2abe4c25f9f71fd7ccb409a61d18aa90.zip | |
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.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 97 |
2 files changed, 88 insertions, 18 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3840e299cb1..39ac42fe6b0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2011-08-28 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | * progmodes/cc-fonts.el | ||
| 4 | (c-make-font-lock-BO-decl-search-function): New function. | ||
| 5 | (c-basic-matchers-after - "Fontify the clauses after various | ||
| 6 | keywords"): Extract the three keyword lists for the 3 erroneous | ||
| 7 | constructs from the list of four, and use the new function above | ||
| 8 | in place of an old one. | ||
| 9 | |||
| 1 | 2011-08-28 Deniz Dogan <deniz@dogan.se> | 10 | 2011-08-28 Deniz Dogan <deniz@dogan.se> |
| 2 | 11 | ||
| 3 | * net/rcirc.el (rcirc-insert-prev-input) | 12 | * net/rcirc.el (rcirc-insert-prev-input) |
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 3d5dc30d823..bca95c97e8b 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -398,6 +398,59 @@ | |||
| 398 | 398 | ||
| 399 | nil))) | 399 | nil))) |
| 400 | 400 | ||
| 401 | (defun c-make-font-lock-BO-decl-search-function (regexp &rest highlights) | ||
| 402 | ;; This function makes a byte compiled function that first moves back | ||
| 403 | ;; to the beginning of the current declaration (if any), then searches | ||
| 404 | ;; forward for matcher elements (as in `font-lock-keywords') and | ||
| 405 | ;; fontifies them. | ||
| 406 | ;; | ||
| 407 | ;; The motivation for moving back to the declaration start is to | ||
| 408 | ;; establish a context for the current text when, e.g., a character | ||
| 409 | ;; is typed on a C++ inheritance continuation line, or a jit-lock | ||
| 410 | ;; chunk starts there. | ||
| 411 | ;; | ||
| 412 | ;; The new function works much like a matcher element in | ||
| 413 | ;; `font-lock-keywords'. It cuts out a little bit of the overhead | ||
| 414 | ;; compared to a real matcher. The main reason is however to pass the | ||
| 415 | ;; real search limit to the anchored matcher(s), since most (if not | ||
| 416 | ;; all) font-lock implementations arbitrarily limit anchored matchers | ||
| 417 | ;; to the same line, and also to insulate against various other | ||
| 418 | ;; irritating differences between the different (X)Emacs font-lock | ||
| 419 | ;; packages. | ||
| 420 | ;; | ||
| 421 | ;; REGEXP is the matcher, which must be a regexp. Only matches | ||
| 422 | ;; where the beginning is outside any comment or string literal are | ||
| 423 | ;; significant. | ||
| 424 | ;; | ||
| 425 | ;; HIGHLIGHTS is a list of highlight specs, just like in | ||
| 426 | ;; `font-lock-keywords', with these limitations: The face is always | ||
| 427 | ;; overridden (no big disadvantage, since hits in comments etc are | ||
| 428 | ;; filtered anyway), there is no "laxmatch", and an anchored matcher | ||
| 429 | ;; is always a form which must do all the fontification directly. | ||
| 430 | ;; `limit' is a variable bound to the real limit in the context of | ||
| 431 | ;; the anchored matcher forms. | ||
| 432 | ;; | ||
| 433 | ;; This function does not do any hidden buffer changes, but the | ||
| 434 | ;; generated functions will. (They are however used in places | ||
| 435 | ;; covered by the font-lock context.) | ||
| 436 | |||
| 437 | ;; Note: Replace `byte-compile' with `eval' to debug the generated | ||
| 438 | ;; lambda more easily. | ||
| 439 | (byte-compile | ||
| 440 | `(lambda (limit) | ||
| 441 | (let ( ;; The font-lock package in Emacs is known to clobber | ||
| 442 | ;; `parse-sexp-lookup-properties' (when it exists). | ||
| 443 | (parse-sexp-lookup-properties | ||
| 444 | (cc-eval-when-compile | ||
| 445 | (boundp 'parse-sexp-lookup-properties)))) | ||
| 446 | (goto-char | ||
| 447 | (let ((here (point))) | ||
| 448 | (if (eq (car (c-beginning-of-decl-1)) 'same) | ||
| 449 | (point) | ||
| 450 | here))) | ||
| 451 | ,(c-make-font-lock-search-form regexp highlights)) | ||
| 452 | nil))) | ||
| 453 | |||
| 401 | (defun c-make-font-lock-context-search-function (normal &rest state-stanzas) | 454 | (defun c-make-font-lock-context-search-function (normal &rest state-stanzas) |
| 402 | ;; This function makes a byte compiled function that works much like | 455 | ;; This function makes a byte compiled function that works much like |
| 403 | ;; a matcher element in `font-lock-keywords', with the following | 456 | ;; a matcher element in `font-lock-keywords', with the following |
| @@ -1828,24 +1881,32 @@ higher." | |||
| 1828 | c-label-face-name nil t)))))) | 1881 | c-label-face-name nil t)))))) |
| 1829 | 1882 | ||
| 1830 | ;; Fontify the clauses after various keywords. | 1883 | ;; Fontify the clauses after various keywords. |
| 1831 | ,@(when (or (c-lang-const c-type-list-kwds) | 1884 | ,@(when (or (c-lang-const c-type-list-kwds) |
| 1832 | (c-lang-const c-ref-list-kwds) | 1885 | (c-lang-const c-ref-list-kwds) |
| 1833 | (c-lang-const c-colon-type-list-kwds) | 1886 | (c-lang-const c-colon-type-list-kwds)) |
| 1834 | (c-lang-const c-paren-type-kwds)) | 1887 | `((,(c-make-font-lock-BO-decl-search-function |
| 1835 | `((,(c-make-font-lock-search-function | 1888 | (concat "\\<\\(" |
| 1836 | (concat "\\<\\(" | 1889 | (c-make-keywords-re nil |
| 1837 | (c-make-keywords-re nil | 1890 | (append (c-lang-const c-type-list-kwds) |
| 1838 | (append (c-lang-const c-type-list-kwds) | 1891 | (c-lang-const c-ref-list-kwds) |
| 1839 | (c-lang-const c-ref-list-kwds) | 1892 | (c-lang-const c-colon-type-list-kwds))) |
| 1840 | (c-lang-const c-colon-type-list-kwds) | 1893 | "\\)\\>") |
| 1841 | (c-lang-const c-paren-type-kwds))) | 1894 | '((c-fontify-types-and-refs ((c-promote-possible-types t)) |
| 1842 | "\\)\\>") | 1895 | (c-forward-keyword-clause 1) |
| 1843 | '((c-fontify-types-and-refs ((c-promote-possible-types t)) | 1896 | (if (> (point) limit) (goto-char limit)))))))) |
| 1844 | (c-forward-keyword-clause 1) | 1897 | |
| 1845 | (if (> (point) limit) (goto-char limit)))))))) | 1898 | ,@(when (c-lang-const c-paren-type-kwds) |
| 1846 | 1899 | `((,(c-make-font-lock-search-function | |
| 1847 | ,@(when (c-major-mode-is 'java-mode) | 1900 | (concat "\\<\\(" |
| 1848 | `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face)))) | 1901 | (c-make-keywords-re nil |
| 1902 | (c-lang-const c-paren-type-kwds)) | ||
| 1903 | "\\)\\>") | ||
| 1904 | '((c-fontify-types-and-refs ((c-promote-possible-types t)) | ||
| 1905 | (c-forward-keyword-clause 1) | ||
| 1906 | (if (> (point) limit) (goto-char limit)))))))) | ||
| 1907 | |||
| 1908 | ,@(when (c-major-mode-is 'java-mode) | ||
| 1909 | `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face)))) | ||
| 1849 | )) | 1910 | )) |
| 1850 | 1911 | ||
| 1851 | (c-lang-defconst c-matchers-1 | 1912 | (c-lang-defconst c-matchers-1 |