1 new commit in cc-mode:
https://bitbucket.org/xemacs/cc-mode/commits/57b32f709a4f/
Changeset: 57b32f709a4f
User: acm
Date: 2017-10-04 16:58:54+00:00
Summary: Fontify untyped function declarations in C Mode correctly.
Also correct two bugs where deleting WS at a BOL could leave an untyped
function declaration unfontified.
* cc-engine.el (c-find-decl-spots): Don't set the flag "top-level" when
we're
in a macro.
(c-forward-decl-or-cast-1): Recognize top-level "foo(bar)" or "foo()"
in C
Mode as a implicitly typed function declaration.
(c-just-after-func-arglist-p): Don't get confused by "defined (foo)" inside
a
macro. It's not a function plus arglist.
* cc-langs.el (c-cpp-expr-functions-key): New defconst and defvar.
* cc-mode.el (c-fl-decl-end): After c-forward-declarator, move over any
following parenthesis expression (i.e. parameter list).
(c-change-expand-fl-region): When c-new-END is at a BOL, include that line in
the returned region, to cope with deletions at column 0.
Affected #: 3 files
diff -r e39b785df77e0a0f89c55aa73e042cc6cc499028 -r
57b32f709a4f3f80c78071d67fec82b4cc629878 cc-engine.el
--- a/cc-engine.el
+++ b/cc-engine.el
@@ -134,7 +134,7 @@
;;
;; 'c-not-decl
;; Put on the brace which introduces a brace list and on the commas
-;; which separate the element within it.
+;; which separate the elements within it.
;;
;; 'c-awk-NL-prop
;; Used in AWK mode to mark the various kinds of newlines. See
@@ -5413,8 +5413,8 @@
(min c-bs-cache-limit pos)))
(defun c-update-brace-stack (stack from to)
- ;; Give a brace-stack which has the value STACK at position FROM, update it
- ;; to it's value at position TO, where TO is after (or equal to) FROM.
+ ;; Given a brace-stack which has the value STACK at position FROM, update it
+ ;; to its value at position TO, where TO is after (or equal to) FROM.
;; Return a cons of either TO (if it is outside a literal) and this new
;; value, or of the next position after TO outside a literal and the new
;; value.
@@ -5659,11 +5659,13 @@
;; Call CFD-FUN for each possible spot for a declaration, cast or
;; label from the point to CFD-LIMIT.
;;
- ;; CFD-FUN is called with point at the start of the spot. It's passed two
+ ;; CFD-FUN is called with point at the start of the spot. It's passed three
;; arguments: The first is the end position of the token preceding the spot,
;; or 0 for the implicit match at bob. The second is a flag that is t when
- ;; the match is inside a macro. Point should be moved forward by at least
- ;; one token.
+ ;; the match is inside a macro. The third is a flag that is t when the
+ ;; match is at "top level", i.e. outside any brace block, or directly inside
+ ;; a class or namespace, etc. Point should be moved forward by at least one
+ ;; token.
;;
;; If CFD-FUN adds `c-decl-end' properties somewhere below the current spot,
;; it should return non-nil to ensure that the next search will find them.
@@ -6059,6 +6061,8 @@
(setq cfd-macro-end 0)
nil)))) ; end of when condition
+ (when (> cfd-macro-end 0)
+ (setq cfd-top-level nil)) ; In a macro is "never" at top level.
(c-debug-put-decl-spot-faces cfd-match-pos (point))
(if (funcall cfd-fun cfd-match-pos (/= cfd-macro-end 0) cfd-top-level)
(setq cfd-prop-match nil))
@@ -8586,7 +8590,13 @@
(looking-at c-noise-macro-with-parens-name-re))
(c-forward-noise-clause))
- ((looking-at c-type-decl-suffix-key)
+ ((and (looking-at c-type-decl-suffix-key)
+ ;; We avoid recognizing foo(bar) or foo() at top level as a
+ ;; construct here in C, since we want to recognize this as a
+ ;; typeless function declaration.
+ (not (and (c-major-mode-is 'c-mode)
+ (eq context 'top)
+ (eq (char-after) ?\)))))
(if (eq (char-after) ?\))
(when (> paren-depth 0)
(setq paren-depth (1- paren-depth))
@@ -8629,7 +8639,12 @@
(save-excursion
(goto-char after-paren-pos)
(c-forward-syntactic-ws)
- (c-forward-type)))))
+ (or (c-forward-type)
+ ;; Recognize a top-level typeless
+ ;; function declaration in C.
+ (and (c-major-mode-is 'c-mode)
+ (eq context 'top)
+ (eq (char-after) ?\))))))))
(setq pos (c-up-list-forward (point)))
(eq (char-before pos) ?\)))
(c-fdoc-shift-type-backward)
@@ -9046,9 +9061,12 @@
;; (in at least C++) that anything that can be parsed as a declaration
;; is a declaration. Now we're being more defensive and prefer to
;; highlight things like "foo (bar);" as a declaration only if we're
- ;; inside an arglist that contains declarations.
+ ;; inside an arglist that contains declarations. Update (2017-09): We
+ ;; now recognize a top-level "foo(bar);" as a declaration in C.
;; CASE 19
- (eq context 'decl))))
+ (or (eq context 'decl)
+ (and (c-major-mode-is 'c-mode)
+ (eq context 'top))))))
;; The point is now after the type decl expression.
@@ -9556,6 +9574,7 @@
comment at the start of cc-engine.el for more info."
;; Note to maintainers: this function consumes a great mass of CPU cycles.
;; It's use should thus be minimised as far as possible.
+ ;; Consider instead using `c-bs-at-toplevel-p'.
(let ((paren-state (c-parse-state)))
(or (not (c-most-enclosing-brace paren-state))
(c-search-uplist-for-classkey paren-state))))
@@ -9585,8 +9604,15 @@
(not (and (c-major-mode-is 'objc-mode)
(c-forward-objc-directive)))
+ ;; Don't confuse #if .... defined(foo) for a function arglist.
+ (not (and (looking-at c-cpp-expr-functions-key)
+ (save-excursion
+ (save-restriction
+ (widen)
+ (c-beginning-of-macro lim)))))
(setq id-start
(car-safe (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)))
+ (numberp id-start)
(< id-start beg)
;; There should not be a '=' or ',' between beg and the
diff -r e39b785df77e0a0f89c55aa73e042cc6cc499028 -r
57b32f709a4f3f80c78071d67fec82b4cc629878 cc-langs.el
--- a/cc-langs.el
+++ b/cc-langs.el
@@ -935,6 +935,11 @@
'("defined"))
pike '("defined" "efun" "constant"))
+(c-lang-defconst c-cpp-expr-functions-key
+ ;; Matches a function in a cpp expression.
+ t (c-make-keywords-re t (c-lang-const c-cpp-expr-functions)))
+(c-lang-defvar c-cpp-expr-functions-key (c-lang-const c-cpp-expr-functions-key))
+
(c-lang-defconst c-assignment-operators
"List of all assignment operators."
t '("=" "*=" "/=" "%=" "+="
"-=" ">>=" "<<=" "&="
"^=" "|=")
diff -r e39b785df77e0a0f89c55aa73e042cc6cc499028 -r
57b32f709a4f3f80c78071d67fec82b4cc629878 cc-mode.el
--- a/cc-mode.el
+++ b/cc-mode.el
@@ -1551,6 +1551,8 @@
(and (c-beginning-of-macro)
(progn (c-end-of-macro) (point))))))
(when (and (c-forward-declarator lim)
+ (or (not (eq (char-after) ?\())
+ (c-go-list-forward nil lim))
(eq (c-forward-token-2 1 nil lim) 0))
(c-backward-syntactic-ws)
(point))))))
@@ -1569,7 +1571,7 @@
(or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
c-new-END
(or (c-fl-decl-end c-new-END)
- (c-point 'bonl (max (1- c-new-END) (point-min)))))))
+ (c-point 'bonl c-new-END)))))
(defun c-context-expand-fl-region (beg end)
;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a
Repository URL:
https://bitbucket.org/xemacs/cc-mode/
--
This is a commit notification from
bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.