aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2017-10-04 17:34:27 +0000
committerAlan Mackenzie2017-10-04 17:34:27 +0000
commit4e0b67ed27114fa2cbebca32567089fd8fa78425 (patch)
tree278d6df6528d9ced3b602a43bae83052bbbf5f81
parent0b558b4acb8326c6f26fcde47ca85777716ae831 (diff)
downloademacs-4e0b67ed27114fa2cbebca32567089fd8fa78425.tar.gz
emacs-4e0b67ed27114fa2cbebca32567089fd8fa78425.zip
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. * lisp/progmodes/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. * lisp/progmodes/cc-langs.el (c-cpp-expr-functions-key): New defconst and defvar. * lisp/progmodes/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.
-rw-r--r--lisp/progmodes/cc-engine.el48
-rw-r--r--lisp/progmodes/cc-langs.el5
-rw-r--r--lisp/progmodes/cc-mode.el4
3 files changed, 45 insertions, 12 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 9d65383e258..37928357526 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -132,7 +132,7 @@
132;; 132;;
133;; 'c-not-decl 133;; 'c-not-decl
134;; Put on the brace which introduces a brace list and on the commas 134;; Put on the brace which introduces a brace list and on the commas
135;; which separate the element within it. 135;; which separate the elements within it.
136;; 136;;
137;; 'c-awk-NL-prop 137;; 'c-awk-NL-prop
138;; Used in AWK mode to mark the various kinds of newlines. See 138;; Used in AWK mode to mark the various kinds of newlines. See
@@ -5403,8 +5403,8 @@ comment at the start of cc-engine.el for more info."
5403 (min c-bs-cache-limit pos))) 5403 (min c-bs-cache-limit pos)))
5404 5404
5405(defun c-update-brace-stack (stack from to) 5405(defun c-update-brace-stack (stack from to)
5406 ;; Give a brace-stack which has the value STACK at position FROM, update it 5406 ;; Given a brace-stack which has the value STACK at position FROM, update it
5407 ;; to it's value at position TO, where TO is after (or equal to) FROM. 5407 ;; to its value at position TO, where TO is after (or equal to) FROM.
5408 ;; Return a cons of either TO (if it is outside a literal) and this new 5408 ;; Return a cons of either TO (if it is outside a literal) and this new
5409 ;; value, or of the next position after TO outside a literal and the new 5409 ;; value, or of the next position after TO outside a literal and the new
5410 ;; value. 5410 ;; value.
@@ -5649,11 +5649,13 @@ comment at the start of cc-engine.el for more info."
5649 ;; Call CFD-FUN for each possible spot for a declaration, cast or 5649 ;; Call CFD-FUN for each possible spot for a declaration, cast or
5650 ;; label from the point to CFD-LIMIT. 5650 ;; label from the point to CFD-LIMIT.
5651 ;; 5651 ;;
5652 ;; CFD-FUN is called with point at the start of the spot. It's passed two 5652 ;; CFD-FUN is called with point at the start of the spot. It's passed three
5653 ;; arguments: The first is the end position of the token preceding the spot, 5653 ;; arguments: The first is the end position of the token preceding the spot,
5654 ;; or 0 for the implicit match at bob. The second is a flag that is t when 5654 ;; or 0 for the implicit match at bob. The second is a flag that is t when
5655 ;; the match is inside a macro. Point should be moved forward by at least 5655 ;; the match is inside a macro. The third is a flag that is t when the
5656 ;; one token. 5656 ;; match is at "top level", i.e. outside any brace block, or directly inside
5657 ;; a class or namespace, etc. Point should be moved forward by at least one
5658 ;; token.
5657 ;; 5659 ;;
5658 ;; If CFD-FUN adds `c-decl-end' properties somewhere below the current spot, 5660 ;; If CFD-FUN adds `c-decl-end' properties somewhere below the current spot,
5659 ;; it should return non-nil to ensure that the next search will find them. 5661 ;; it should return non-nil to ensure that the next search will find them.
@@ -6040,6 +6042,8 @@ comment at the start of cc-engine.el for more info."
6040 (setq cfd-macro-end 0) 6042 (setq cfd-macro-end 0)
6041 nil)))) ; end of when condition 6043 nil)))) ; end of when condition
6042 6044
6045 (when (> cfd-macro-end 0)
6046 (setq cfd-top-level nil)) ; In a macro is "never" at top level.
6043 (c-debug-put-decl-spot-faces cfd-match-pos (point)) 6047 (c-debug-put-decl-spot-faces cfd-match-pos (point))
6044 (if (funcall cfd-fun cfd-match-pos (/= cfd-macro-end 0) cfd-top-level) 6048 (if (funcall cfd-fun cfd-match-pos (/= cfd-macro-end 0) cfd-top-level)
6045 (setq cfd-prop-match nil)) 6049 (setq cfd-prop-match nil))
@@ -8577,7 +8581,13 @@ comment at the start of cc-engine.el for more info."
8577 (looking-at c-noise-macro-with-parens-name-re)) 8581 (looking-at c-noise-macro-with-parens-name-re))
8578 (c-forward-noise-clause)) 8582 (c-forward-noise-clause))
8579 8583
8580 ((looking-at c-type-decl-suffix-key) 8584 ((and (looking-at c-type-decl-suffix-key)
8585 ;; We avoid recognizing foo(bar) or foo() at top level as a
8586 ;; construct here in C, since we want to recognize this as a
8587 ;; typeless function declaration.
8588 (not (and (c-major-mode-is 'c-mode)
8589 (eq context 'top)
8590 (eq (char-after) ?\)))))
8581 (if (eq (char-after) ?\)) 8591 (if (eq (char-after) ?\))
8582 (when (> paren-depth 0) 8592 (when (> paren-depth 0)
8583 (setq paren-depth (1- paren-depth)) 8593 (setq paren-depth (1- paren-depth))
@@ -8620,7 +8630,12 @@ comment at the start of cc-engine.el for more info."
8620 (save-excursion 8630 (save-excursion
8621 (goto-char after-paren-pos) 8631 (goto-char after-paren-pos)
8622 (c-forward-syntactic-ws) 8632 (c-forward-syntactic-ws)
8623 (c-forward-type))))) 8633 (or (c-forward-type)
8634 ;; Recognize a top-level typeless
8635 ;; function declaration in C.
8636 (and (c-major-mode-is 'c-mode)
8637 (eq context 'top)
8638 (eq (char-after) ?\))))))))
8624 (setq pos (c-up-list-forward (point))) 8639 (setq pos (c-up-list-forward (point)))
8625 (eq (char-before pos) ?\))) 8640 (eq (char-before pos) ?\)))
8626 (c-fdoc-shift-type-backward) 8641 (c-fdoc-shift-type-backward)
@@ -9037,9 +9052,12 @@ comment at the start of cc-engine.el for more info."
9037 ;; (in at least C++) that anything that can be parsed as a declaration 9052 ;; (in at least C++) that anything that can be parsed as a declaration
9038 ;; is a declaration. Now we're being more defensive and prefer to 9053 ;; is a declaration. Now we're being more defensive and prefer to
9039 ;; highlight things like "foo (bar);" as a declaration only if we're 9054 ;; highlight things like "foo (bar);" as a declaration only if we're
9040 ;; inside an arglist that contains declarations. 9055 ;; inside an arglist that contains declarations. Update (2017-09): We
9041 ;; CASE 19 9056 ;; now recognize a top-level "foo(bar);" as a declaration in C.
9042 (eq context 'decl)))) 9057 ;; CASE 19
9058 (or (eq context 'decl)
9059 (and (c-major-mode-is 'c-mode)
9060 (eq context 'top))))))
9043 9061
9044 ;; The point is now after the type decl expression. 9062 ;; The point is now after the type decl expression.
9045 9063
@@ -9547,6 +9565,7 @@ Note that this function might do hidden buffer changes. See the
9547comment at the start of cc-engine.el for more info." 9565comment at the start of cc-engine.el for more info."
9548 ;; Note to maintainers: this function consumes a great mass of CPU cycles. 9566 ;; Note to maintainers: this function consumes a great mass of CPU cycles.
9549 ;; Its use should thus be minimized as far as possible. 9567 ;; Its use should thus be minimized as far as possible.
9568 ;; Consider instead using `c-bs-at-toplevel-p'.
9550 (let ((paren-state (c-parse-state))) 9569 (let ((paren-state (c-parse-state)))
9551 (or (not (c-most-enclosing-brace paren-state)) 9570 (or (not (c-most-enclosing-brace paren-state))
9552 (c-search-uplist-for-classkey paren-state)))) 9571 (c-search-uplist-for-classkey paren-state))))
@@ -9576,8 +9595,15 @@ comment at the start of cc-engine.el for more info."
9576 (not (and (c-major-mode-is 'objc-mode) 9595 (not (and (c-major-mode-is 'objc-mode)
9577 (c-forward-objc-directive))) 9596 (c-forward-objc-directive)))
9578 9597
9598 ;; Don't confuse #if .... defined(foo) for a function arglist.
9599 (not (and (looking-at c-cpp-expr-functions-key)
9600 (save-excursion
9601 (save-restriction
9602 (widen)
9603 (c-beginning-of-macro lim)))))
9579 (setq id-start 9604 (setq id-start
9580 (car-safe (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))) 9605 (car-safe (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)))
9606 (numberp id-start)
9581 (< id-start beg) 9607 (< id-start beg)
9582 9608
9583 ;; There should not be a '=' or ',' between beg and the 9609 ;; There should not be a '=' or ',' between beg and the
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 7a285f93d34..bcda093678a 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -952,6 +952,11 @@ expression, or nil if there aren't any in the language."
952 '("defined")) 952 '("defined"))
953 pike '("defined" "efun" "constant")) 953 pike '("defined" "efun" "constant"))
954 954
955(c-lang-defconst c-cpp-expr-functions-key
956 ;; Matches a function in a cpp expression.
957 t (c-make-keywords-re t (c-lang-const c-cpp-expr-functions)))
958(c-lang-defvar c-cpp-expr-functions-key (c-lang-const c-cpp-expr-functions-key))
959
955(c-lang-defconst c-assignment-operators 960(c-lang-defconst c-assignment-operators
956 "List of all assignment operators." 961 "List of all assignment operators."
957 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=") 962 t '("=" "*=" "/=" "%=" "+=" "-=" ">>=" "<<=" "&=" "^=" "|=")
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 8867453e85c..b0e5fe47a7c 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1571,6 +1571,8 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
1571 (and (c-beginning-of-macro) 1571 (and (c-beginning-of-macro)
1572 (progn (c-end-of-macro) (point)))))) 1572 (progn (c-end-of-macro) (point))))))
1573 (when (and (c-forward-declarator lim) 1573 (when (and (c-forward-declarator lim)
1574 (or (not (eq (char-after) ?\())
1575 (c-go-list-forward nil lim))
1574 (eq (c-forward-token-2 1 nil lim) 0)) 1576 (eq (c-forward-token-2 1 nil lim) 0))
1575 (c-backward-syntactic-ws) 1577 (c-backward-syntactic-ws)
1576 (point)))))) 1578 (point))))))
@@ -1589,7 +1591,7 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
1589 (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG)) 1591 (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
1590 c-new-END 1592 c-new-END
1591 (or (c-fl-decl-end c-new-END) 1593 (or (c-fl-decl-end c-new-END)
1592 (c-point 'bonl (max (1- c-new-END) (point-min))))))) 1594 (c-point 'bonl c-new-END)))))
1593 1595
1594(defun c-context-expand-fl-region (beg end) 1596(defun c-context-expand-fl-region (beg end)
1595 ;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a 1597 ;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a