Commit bf2c1571 authored by Alan Mackenzie's avatar Alan Mackenzie

CC Mode: Fontify declarators properly when, e.g., a jit-lock chunk begins

inside a declaration.  Changed cc-engine.el, cc-langs.el, cc-fonts.el.
parent 8f8eda06
2011-07-18 Alan Mackenzie <acm@muc.de>
Fontify declarators properly when, e.g., a jit-lock chunk begins
inside a declaration.
* progmodes/cc-langs.el (c-symbol-chars): Correct a typo.
* progmodes/cc-fonts.el (c-font-lock-enclosing-decls): New
function.
(c-complex-decl-matchers): Insert reference to
c-font-lock-enclosing-decls.
* progmodes/cc-engine.el (c-backward-single-comment):
(c-backward-comments): Bind open-paren-in-column-0-is-defun-start
to nil around calls to (forward-comment -1).
2011-07-17 Lars Magne Ingebrigtsen <larsi@gnus.org>
* image.el (put-image): Doc typo fix.
......
......@@ -1301,12 +1301,13 @@ This function does not do any hidden buffer changes."
;; same line.
(re-search-forward "\\=\\s *[\n\r]" start t)
(if (if (forward-comment -1)
(if (if (let (open-paren-in-column-0-is-defun-start) (forward-comment -1))
(if (eolp)
;; If forward-comment above succeeded and we're at eol
;; then the newline we moved over above didn't end a
;; line comment, so we give it another go.
(forward-comment -1)
(let (open-paren-in-column-0-is-defun-start)
(forward-comment -1))
t))
;; Emacs <= 20 and XEmacs move back over the closer of a
......@@ -1333,7 +1334,8 @@ comment at the start of cc-engine.el for more info."
;; return t when moving backwards at bob.
(not (bobp))
(if (forward-comment -1)
(if (let (open-paren-in-column-0-is-defun-start)
(forward-comment -1))
(if (looking-at "\\*/")
;; Emacs <= 20 and XEmacs move back over the
;; closer of a block comment that lacks an opener.
......
......@@ -1346,6 +1346,50 @@ casts and declarations are fontified. Used on level 2 and higher."
(c-font-lock-declarators limit t nil)))
nil)
(defun c-font-lock-enclosing-decls (limit)
;; Fontify the declarators of (nested) declarations we're in the middle of.
;; This is mainly for when a jit-lock etc. chunk starts inside the brace
;; block of a struct/union/class, etc.
;;
;; This function will be called from font-lock for a region bounded by POINT
;; and LIMIT, as though it were to identify a keyword for
;; font-lock-keyword-face. It always returns NIL to inhibit this and
;; prevent a repeat invocation. See elisp/lispref page "Search-based
;; Fontification".
(let* ((paren-state (c-parse-state))
(start (point))
decl-context bo-decl in-typedef type-type ps-elt)
;; First, are we actually in a "local" declaration?
(setq decl-context (c-beginning-of-decl-1)
bo-decl (point)
in-typedef (looking-at c-typedef-key))
(if in-typedef (c-forward-token-2))
(when (and (eq (car decl-context) 'same)
(< bo-decl start))
;; Are we genuinely at a type?
(setq type-type (c-forward-type t))
(if (and type-type
(or (not (eq type-type 'maybe))
(looking-at c-symbol-key)))
(c-font-lock-declarators limit t in-typedef)))
;; Secondly, are we in any nested struct/union/class/etc. braces?
(while paren-state
(setq ps-elt (car paren-state)
paren-state (cdr paren-state))
(when (and (atom ps-elt)
(eq (char-after ps-elt) ?\{))
(goto-char ps-elt)
(setq decl-context (c-beginning-of-decl-1)
in-typedef (looking-at c-typedef-key))
(if in-typedef (c-forward-token-2))
(when (looking-at c-opt-block-decls-with-vars-key)
(goto-char ps-elt)
(when (c-safe (c-forward-sexp))
(c-forward-syntactic-ws)
(c-font-lock-declarators limit t in-typedef)))))))
(c-lang-defconst c-simple-decl-matchers
"Simple font lock matchers for types and declarations. These are used
on level 2 only and so aren't combined with `c-complex-decl-matchers'."
......@@ -1452,6 +1496,9 @@ on level 2 only and so aren't combined with `c-complex-decl-matchers'."
;; Fontify all declarations, casts and normal labels.
c-font-lock-declarations
;; Fontify declarators when POINT is within their declaration.
c-font-lock-enclosing-decls
;; Fontify angle bracket arglists like templates in C++.
,@(when (c-lang-const c-recognize-<>-arglists)
`(c-font-lock-<>-arglists))
......
......@@ -523,7 +523,7 @@ operator at the top level."
(c-lang-defconst c-symbol-chars
"Set of characters that can be part of a symbol.
This is on the form that fits inside [ ] in a regexp."
This is of the form that fits inside [ ] in a regexp."
;; Pike note: With the backquote identifiers this would include most
;; operator chars too, but they are handled with other means instead.
t (concat c-alnum "_$")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment