commit/cc-mode: acm: Fix @examples in cc-mode.info,
where lines were getting glued together.
6 years, 11 months
Bitbucket
1 new commit in cc-mode:
https://bitbucket.org/xemacs/cc-mode/commits/9d8620fddb42/
Changeset: 9d8620fddb42
User: acm
Date: 2018-01-30 17:58:51+00:00
Summary: Fix @examples in cc-mode.info, where lines were getting glued together.
This happened because of false @c's in macro lines.
* cc-mode.texi (Line-up Functions): Remove the unneeded @c from macros
sssTBasicOffset, sssTsssTBasicOffset, and hereFn.
Affected #: 1 file
diff -r a3392363b1dddb36ce09f6676a4323bcda3418ee -r 9d8620fddb42529768dabcd93d50e191bda75a42 cc-mode.texi
--- a/cc-mode.texi
+++ b/cc-mode.texi
@@ -5637,15 +5637,15 @@
@end ifinfo
@macro sssTBasicOffset
-<--> @i{c-basic-offset}@c
+<--> @i{c-basic-offset}
@end macro
@macro sssTsssTBasicOffset
-<--><--> @i{c-basic-offset}@c
+<--><--> @i{c-basic-offset}
@end macro
@macro hereFn{func}
-<- @i{\func\}@c
+<- @i{\func\}
@end macro
@c The TeX backend seems to insert extra spaces around the argument. :P
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.
commit/cc-mode: acm: Fix some errors in c-display-defun-name when the
type is "struct {..}", etc.
6 years, 11 months
Bitbucket
1 new commit in cc-mode:
https://bitbucket.org/xemacs/cc-mode/commits/a3392363b1dd/
Changeset: a3392363b1dd
User: acm
Date: 2018-01-28 17:25:48+00:00
Summary: Fix some errors in c-display-defun-name when the type is "struct {..}", etc.
Also fix some errors with c-display-defun-name when there are nested classes.
* cc-cmds.el (c-in-function-trailer-p): Deal with a struct {..} being merely
the type of a function.
(c-where-wrt-brace-construct): Deal with a struct {..} being merely the type
of a function. Rearrange the order of some Lisp forms. Insert a check for
c-protection-key ("private", etc.) alongside the checking for a label.
(c-defun-name-1): New function extracted form c-defun-name, which works within
the existing restriction. Don't regard 'at-function-end as being within the
defun any more. Recognize "struct", etc., with the new
c-defun-type-name-decl-key rather than c-type-prefix-key. Make the
recognition of a normal function more accurate.
(c-defun-name): Part left after extracting the above function. It now just
widens and calls c-defun-name-1.
(c-declaration-limits-1): New function extracted from c-declaration-limits,
which works within the existing restriction. Move LIM back one block to
account for the possibility of struct {..} as a function type. Check we're
not inside a declaration without braces.
(c-declaration-limits): Part left after extracting the above function. It now
just narrows to an enclosing decl block and calls c-declaration-limits-1.
(c-defun-name-and-limits): New function which identifies the name and limits
of the most nested enclosing declaration or macro.
(c-display-defun-name): Use c-defun-name-and-limits rather than two separate
functions (which didn't always agree on which function).
* cc-engine.el (c-beginning-of-statement-1): If we have struct {..} as the
type of a function, go back over this, too.
* cc-langs.el (c-defun-type-name-decl-kwds, c-defun-type-name-decl-key): New
lang const/var.
Affected #: 3 files
diff -r 1b5c372f3b60eea55165c6d04738f98905cd5a11 -r a3392363b1dddb36ce09f6676a4323bcda3418ee cc-cmds.el
--- a/cc-cmds.el
+++ b/cc-cmds.el
@@ -1364,6 +1364,16 @@
(not (eq (char-before) ?_))
(c-syntactic-re-search-forward "[;=\(\[{]" eo-block t t t)
(eq (char-before) ?\{)
+ ;; Exclude the entire "struct {...}" being the type of a
+ ;; function being declared.
+ (not
+ (and
+ (c-go-up-list-forward)
+ (eq (char-before) ?})
+ (progn (c-forward-syntactic-ws)
+ (c-syntactic-re-search-forward
+ "[;=([{]" nil t t t))
+ (eq (char-before) ?\()))
bod)))))
(defun c-where-wrt-brace-construct ()
@@ -1401,7 +1411,11 @@
((and (not least-enclosing)
(consp paren-state)
(consp (car paren-state))
- (eq start (cdar paren-state)))
+ (eq start (cdar paren-state))
+ (not
+ (progn
+ (c-forward-syntactic-ws)
+ (looking-at c-symbol-start))))
'at-function-end)
(t
;; Find the start of the current declaration. NOTE: If we're in the
@@ -1416,6 +1430,18 @@
(not (c-looking-at-non-alphnumspace)))
(forward-char))
(setq kluge-start (point))
+ ;; First approximation as to whether the current "header" we're in is
+ ;; one followed by braces.
+ (setq brace-decl-p
+ (save-excursion
+ (and (c-syntactic-re-search-forward "[;{]" nil t t)
+ (or (eq (char-before) ?\{)
+ (and c-recognize-knr-p
+ ;; Might have stopped on the
+ ;; ';' in a K&R argdecl. In
+ ;; that case the declaration
+ ;; should contain a block.
+ (c-in-knr-argdecl))))))
(setq decl-result
(car (c-beginning-of-decl-1
;; NOTE: If we're in a K&R region, this might be the start
@@ -1426,17 +1452,9 @@
(c-safe-position least-enclosing paren-state)))))
;; Has the declaration we've gone back to got braces?
- (or (eq decl-result 'label)
- (setq brace-decl-p
- (save-excursion
- (and (c-syntactic-re-search-forward "[;{]" nil t t)
- (or (eq (char-before) ?\{)
- (and c-recognize-knr-p
- ;; Might have stopped on the
- ;; ';' in a K&R argdecl. In
- ;; that case the declaration
- ;; should contain a block.
- (c-in-knr-argdecl)))))))
+ (if (or (eq decl-result 'label)
+ (looking-at c-protection-key))
+ (setq brace-decl-p nil))
(cond
((or (eq decl-result 'label) ; e.g. "private:" or invalid syntax.
@@ -1772,94 +1790,246 @@
(c-keep-region-active)
(= arg 0))))
+(defun c-defun-name-1 ()
+ "Return the name of the current defun, at the current narrowing,
+or NIL if there isn't one. \"Defun\" here means a function, or
+other top level construct with a brace block."
+ (c-save-buffer-state
+ (beginning-of-defun-function end-of-defun-function
+ where pos decl name-start name-end case-fold-search)
+
+ (save-excursion
+ ;; Move back out of any macro/comment/string we happen to be in.
+ (c-beginning-of-macro)
+ (setq pos (c-literal-start))
+ (if pos (goto-char pos))
+
+ (setq where (c-where-wrt-brace-construct))
+
+ ;; Move to the beginning of the current defun, if any, if we're not
+ ;; already there.
+ (if (memq where '(outwith-function at-function-end))
+ nil
+ (unless (eq where 'at-header)
+ (c-backward-to-nth-BOF-{ 1 where)
+ (c-beginning-of-decl-1))
+ (when (looking-at c-typedef-key)
+ (goto-char (match-end 0))
+ (c-forward-syntactic-ws))
+
+ ;; Pick out the defun name, according to the type of defun.
+ (cond
+ ;; struct, union, enum, or similar:
+ ((save-excursion
+ (and
+ (looking-at c-defun-type-name-decl-key)
+ (consp (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))
+ (or (not (or (eq (char-after) ?{)
+ (and c-recognize-knr-p
+ (c-in-knr-argdecl))))
+ (progn (c-backward-syntactic-ws)
+ (not (eq (char-before) ?\)))))))
+ (let ((key-pos (point)))
+ (c-forward-over-token-and-ws) ; over "struct ".
+ (cond
+ ((looking-at c-symbol-key) ; "struct foo { ..."
+ (buffer-substring-no-properties key-pos (match-end 0)))
+ ((eq (char-after) ?{) ; "struct { ... } foo"
+ (when (c-go-list-forward)
+ (c-forward-syntactic-ws)
+ (when (looking-at c-symbol-key) ; a bit bogus - there might
+ ; be several identifiers.
+ (match-string-no-properties 0)))))))
+
+ ((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs!
+ ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory
+ ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK
+ (down-list 1)
+ (c-forward-syntactic-ws)
+ (when (eq (char-after) ?\")
+ (forward-sexp 1)
+ (c-forward-token-2)) ; over the comma and following WS.
+ (buffer-substring-no-properties
+ (point)
+ (progn
+ (c-forward-token-2)
+ (c-backward-syntactic-ws)
+ (point))))
+
+ (t
+ ;; Normal function or initializer.
+ (when
+ (and
+ (consp
+ (setq decl
+ (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)))
+ (setq name-start (car decl))
+ (progn (if (and (looking-at c-after-suffixed-type-decl-key)
+ (match-beginning 1))
+ (c-forward-keyword-clause 1))
+ t)
+ (or (eq (char-after) ?{)
+ (and c-recognize-knr-p
+ (c-in-knr-argdecl)))
+ (goto-char name-start)
+ (c-forward-name)
+ (eq (char-after) ?\())
+ (c-backward-syntactic-ws)
+ (when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ;
+ (c-backward-token-2)
+ (c-backward-syntactic-ws))
+ (setq name-end (point))
+ (c-back-over-compound-identifier)
+ (and (looking-at c-symbol-start)
+ (buffer-substring-no-properties (point) name-end)))))))))
+
(defun c-defun-name ()
"Return the name of the current defun, or NIL if there isn't one.
\"Defun\" here means a function, or other top level construct
-with a brace block."
- (c-save-buffer-state
- (beginning-of-defun-function end-of-defun-function
- where pos name-end case-fold-search)
-
+with a brace block, at the outermost level of nesting."
+ (c-save-buffer-state ()
(save-restriction
(widen)
- (save-excursion
- ;; Move back out of any macro/comment/string we happen to be in.
- (c-beginning-of-macro)
- (setq pos (c-literal-start))
- (if pos (goto-char pos))
-
- (setq where (c-where-wrt-brace-construct))
-
- ;; Move to the beginning of the current defun, if any, if we're not
- ;; already there.
- (if (eq where 'outwith-function)
- nil
- (unless (eq where 'at-header)
- (c-backward-to-nth-BOF-{ 1 where)
- (c-beginning-of-decl-1))
- (when (looking-at c-typedef-key)
- (goto-char (match-end 0))
- (c-forward-syntactic-ws))
-
- ;; Pick out the defun name, according to the type of defun.
- (cond
- ;; struct, union, enum, or similar:
- ((save-excursion
- (and
- (looking-at c-type-prefix-key)
- (consp (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))
- (or (not (or (eq (char-after) ?{)
- (and c-recognize-knr-p
- (c-in-knr-argdecl))))
- (progn (c-backward-syntactic-ws)
- (not (eq (char-before) ?\)))))))
- (let ((key-pos (point)))
- (c-forward-over-token-and-ws) ; over "struct ".
- (cond
- ((looking-at c-symbol-key) ; "struct foo { ..."
- (buffer-substring-no-properties key-pos (match-end 0)))
- ((eq (char-after) ?{) ; "struct { ... } foo"
- (when (c-go-list-forward)
- (c-forward-syntactic-ws)
- (when (looking-at c-symbol-key) ; a bit bogus - there might
- ; be several identifiers.
- (match-string-no-properties 0)))))))
-
- ((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs!
- ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory
- ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK
- (down-list 1)
- (c-forward-syntactic-ws)
- (when (eq (char-after) ?\")
- (forward-sexp 1)
- (c-forward-token-2)) ; over the comma and following WS.
- (buffer-substring-no-properties
- (point)
- (progn
- (c-forward-token-2)
- (c-backward-syntactic-ws)
- (point))))
-
- (t
- ;; Normal function or initializer.
- (when
- (and
- (consp (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))
- (or (eq (char-after) ?{)
- (and c-recognize-knr-p
- (c-in-knr-argdecl)))
+ (c-defun-name-1))))
+
+(defun c-declaration-limits-1 (near)
+ ;; Return a cons of the beginning and end position of the current
+ ;; declaration or macro in the current narrowing. If there is no current
+ ;; declaration or macro, return nil, unless NEAR is non-nil, in which case
+ ;; the closest following one is chosen instead (if there is any). The end
+ ;; position is at the next line, providing there is one before the
+ ;; declaration.
+ ;;
+ ;; This function might do hidden buffer changes.
+ (save-excursion
+ (let ((start (point))
+ (paren-state (c-parse-state))
+ lim pos end-pos where)
+ (or
+ ;; Note: Some code duplication in `c-beginning-of-defun' and
+ ;; `c-end-of-defun'.
+ (catch 'exit
+ (unless (c-safe
+ (goto-char (c-least-enclosing-brace paren-state))
+ ;; If we moved to the outermost enclosing paren
+ ;; then we can use c-safe-position to set the
+ ;; limit. Can't do that otherwise since the
+ ;; earlier paren pair on paren-state might very
+ ;; well be part of the declaration we should go
+ ;; to.
+ (setq lim (c-safe-position (point) paren-state))
+ ;; We might have a struct foo {...} as the type of the
+ ;; function, so set LIM back one further block.
+ (if (eq (char-before lim) ?})
+ (setq lim
+ (or
+ (save-excursion
+ (and
+ (c-go-list-backward lim)
+ (let ((paren-state-1 (c-parse-state)))
+ (c-safe-position
+ (point) paren-state-1))))
+ (point-min))))
+ t)
+ ;; At top level. Make sure we aren't inside a literal.
+ (setq pos (c-literal-start
+ (c-safe-position (point) paren-state)))
+ (if pos (goto-char pos)))
+
+ (when (c-beginning-of-macro)
+ (throw 'exit
+ (cons (point)
+ (save-excursion
+ (c-end-of-macro)
+ (forward-line 1)
+ (point)))))
+
+ (setq pos (point))
+ (setq where (and (not (save-excursion (c-beginning-of-macro)))
+ (c-where-wrt-brace-construct)))
+ (when (and (not (eq where 'at-header))
+ (or (and near
+ (memq where
+ '(at-function-end outwith-function))
+ ;; Check we're not inside a declaration without
+ ;; braces.
+ (save-excursion
+ (memq (car (c-beginning-of-decl-1 lim))
+ '(previous label))))
+ (eq (car (c-beginning-of-decl-1 lim)) 'previous)
+ (= pos (point))))
+ ;; We moved back over the previous defun. Skip to the next
+ ;; one. Not using c-forward-syntactic-ws here since we
+ ;; should not skip a macro. We can also be directly after
+ ;; the block in a `c-opt-block-decls-with-vars-key'
+ ;; declaration, but then we won't move significantly far
+ ;; here.
+ (goto-char pos)
+ (c-forward-comments)
+
+ (when (and near (c-beginning-of-macro))
+ (throw 'exit
+ (cons (point)
+ (save-excursion
+ (c-end-of-macro)
+ (forward-line 1)
+ (point))))))
+
+ (if (eobp) (throw 'exit nil))
+
+ ;; Check if `c-beginning-of-decl-1' put us after the block in a
+ ;; declaration that doesn't end there. We're searching back and
+ ;; forth over the block here, which can be expensive.
+ (setq pos (point))
+ (if (and c-opt-block-decls-with-vars-key
+ (progn
+ (c-backward-syntactic-ws)
+ (eq (char-before) ?}))
+ (eq (car (c-beginning-of-decl-1))
+ 'previous)
+ (save-excursion
+ (c-end-of-decl-1)
+ (and (> (point) pos)
+ (setq end-pos (point)))))
+ nil
+ (goto-char pos))
+
+ (if (or (and (not near) (> (point) start))
+ (not (eq (c-where-wrt-brace-construct) 'at-header)))
+ nil
+
+ ;; Try to be line oriented; position the limits at the
+ ;; closest preceding boi, and after the next newline, that
+ ;; isn't inside a comment, but if we hit a neighboring
+ ;; declaration then we instead use the exact declaration
+ ;; limit in that direction.
+ (cons (progn
+ (setq pos (point))
+ (while (and (/= (point) (c-point 'boi))
+ (c-backward-single-comment)))
+ (if (/= (point) (c-point 'boi))
+ pos
+ (point)))
(progn
- (c-backward-syntactic-ws)
- (eq (char-before) ?\)))
- (c-go-list-backward))
- (c-backward-syntactic-ws)
- (when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ;
- (c-backward-token-2)
- (c-backward-syntactic-ws))
- (setq name-end (point))
- (c-back-over-compound-identifier)
- (and (looking-at c-symbol-start)
- (buffer-substring-no-properties (point) name-end))))))))))
+ (if end-pos
+ (goto-char end-pos)
+ (c-end-of-decl-1))
+ (setq pos (point))
+ (while (and (not (bolp))
+ (not (looking-at "\\s *$"))
+ (c-forward-single-comment)))
+ (cond ((bolp)
+ (point))
+ ((looking-at "\\s *$")
+ (forward-line 1)
+ (point))
+ (t
+ pos))))))
+ (and (not near)
+ (goto-char (point-min))
+ (c-forward-decl-or-cast-1 -1 nil nil)
+ (eq (char-after) ?\{)
+ (cons (point-min) (point-max)))))))
(defun c-declaration-limits (near)
;; Return a cons of the beginning and end positions of the current
@@ -1870,135 +2040,48 @@
;; declaration.
;;
;; This function might do hidden buffer changes.
- (save-excursion
- (save-restriction
- (let ((start (point))
- (paren-state (c-parse-state))
- lim pos end-pos where)
- ;; Narrow enclosing brace blocks out, as required by the values of
- ;; `c-defun-tactic', `near', and the position of point.
- (when (eq c-defun-tactic 'go-outward)
- (let ((bounds
- (save-restriction
- (if (and (not (save-excursion (c-beginning-of-macro)))
- (save-restriction
- (c-narrow-to-most-enclosing-decl-block)
- (memq (c-where-wrt-brace-construct)
- '(at-function-end outwith-function)))
- (not near))
- (c-narrow-to-most-enclosing-decl-block nil 2)
- (c-narrow-to-most-enclosing-decl-block))
- (cons (point-min) (point-max)))))
- (narrow-to-region (car bounds) (cdr bounds))))
- (setq paren-state (c-parse-state))
-
- (or
- ;; Note: Some code duplication in `c-beginning-of-defun' and
- ;; `c-end-of-defun'.
- (catch 'exit
- (unless (c-safe
- (goto-char (c-least-enclosing-brace paren-state))
- ;; If we moved to the outermost enclosing paren
- ;; then we can use c-safe-position to set the
- ;; limit. Can't do that otherwise since the
- ;; earlier paren pair on paren-state might very
- ;; well be part of the declaration we should go
- ;; to.
- (setq lim (c-safe-position (point) paren-state))
- t)
- ;; At top level. Make sure we aren't inside a literal.
- (setq pos (c-literal-start
- (c-safe-position (point) paren-state)))
- (if pos (goto-char pos)))
-
- (when (c-beginning-of-macro)
- (throw 'exit
- (cons (point)
- (save-excursion
- (c-end-of-macro)
- (forward-line 1)
- (point)))))
-
- (setq pos (point))
- (setq where (and (not (save-excursion (c-beginning-of-macro)))
- (c-where-wrt-brace-construct)))
- (when (and (not (eq where 'at-header))
- (or (and near
- (memq where
- '(at-function-end outwith-function)))
- (eq (car (c-beginning-of-decl-1 lim)) 'previous)
- (= pos (point))))
- ;; We moved back over the previous defun. Skip to the next
- ;; one. Not using c-forward-syntactic-ws here since we
- ;; should not skip a macro. We can also be directly after
- ;; the block in a `c-opt-block-decls-with-vars-key'
- ;; declaration, but then we won't move significantly far
- ;; here.
- (goto-char pos)
- (c-forward-comments)
-
- (when (and near (c-beginning-of-macro))
- (throw 'exit
- (cons (point)
- (save-excursion
- (c-end-of-macro)
- (forward-line 1)
- (point))))))
-
- (if (eobp) (throw 'exit nil))
-
- ;; Check if `c-beginning-of-decl-1' put us after the block in a
- ;; declaration that doesn't end there. We're searching back and
- ;; forth over the block here, which can be expensive.
- (setq pos (point))
- (if (and c-opt-block-decls-with-vars-key
- (progn
- (c-backward-syntactic-ws)
- (eq (char-before) ?}))
- (eq (car (c-beginning-of-decl-1))
- 'previous)
- (save-excursion
- (c-end-of-decl-1)
- (and (> (point) pos)
- (setq end-pos (point)))))
- nil
- (goto-char pos))
-
- (if (and (not near) (> (point) start))
- nil
-
- ;; Try to be line oriented; position the limits at the
- ;; closest preceding boi, and after the next newline, that
- ;; isn't inside a comment, but if we hit a neighboring
- ;; declaration then we instead use the exact declaration
- ;; limit in that direction.
- (cons (progn
- (setq pos (point))
- (while (and (/= (point) (c-point 'boi))
- (c-backward-single-comment)))
- (if (/= (point) (c-point 'boi))
- pos
- (point)))
- (progn
- (if end-pos
- (goto-char end-pos)
- (c-end-of-decl-1))
- (setq pos (point))
- (while (and (not (bolp))
- (not (looking-at "\\s *$"))
- (c-forward-single-comment)))
- (cond ((bolp)
- (point))
- ((looking-at "\\s *$")
- (forward-line 1)
- (point))
- (t
- pos))))))
- (and (not near)
- (goto-char (point-min))
- (c-forward-decl-or-cast-1 -1 nil nil)
- (eq (char-after) ?\{)
- (cons (point-min) (point-max))))))))
+ (save-restriction
+ ;; Narrow enclosing brace blocks out, as required by the values of
+ ;; `c-defun-tactic', `near', and the position of point.
+ (when (eq c-defun-tactic 'go-outward)
+ (let ((bounds
+ (save-restriction
+ (if (and (not (save-excursion (c-beginning-of-macro)))
+ (save-restriction
+ (c-narrow-to-most-enclosing-decl-block)
+ (memq (c-where-wrt-brace-construct)
+ '(at-function-end outwith-function)))
+ (not near))
+ (c-narrow-to-most-enclosing-decl-block nil 2)
+ (c-narrow-to-most-enclosing-decl-block))
+ (cons (point-min) (point-max)))))
+ (narrow-to-region (car bounds) (cdr bounds))))
+ (c-declaration-limits-1 near)))
+
+(defun c-defun-name-and-limits (near)
+ ;; Return a cons of the name and limits (itself a cons) of the current
+ ;; top-level declaration or macro, or nil of there is none.
+ ;;
+ ;; If `c-defun-tactic' is 'go-outward, we return the name and limits of the
+ ;; most tightly enclosing declaration or macro. Otherwise, we return that
+ ;; at the file level.
+ (save-restriction
+ (widen)
+ (if (eq c-defun-tactic 'go-outward)
+ (c-save-buffer-state ((paren-state (c-parse-state))
+ (orig-point-min (point-min))
+ (orig-point-max (point-max))
+ lim name where limits fdoc)
+ (setq lim (c-widen-to-enclosing-decl-scope
+ paren-state orig-point-min orig-point-max))
+ (and lim (setq lim (1- lim)))
+ (c-while-widening-to-decl-block (not (setq name (c-defun-name-1))))
+ (when name
+ (setq limits (c-declaration-limits-1 near))
+ (cons name limits)))
+ (c-save-buffer-state ((name (c-defun-name))
+ (limits (c-declaration-limits near)))
+ (and name limits (cons name limits))))))
(defun c-display-defun-name (&optional arg)
"Display the name of the current CC mode defun and the position in it.
@@ -2006,12 +2089,13 @@
(interactive "P")
(save-restriction
(widen)
- (c-save-buffer-state ((name (c-defun-name))
- (limits (c-declaration-limits t))
+ (c-save-buffer-state ((name-and-limits (c-defun-name-and-limits nil))
+ (name (car name-and-limits))
+ (limits (cdr name-and-limits))
(point-bol (c-point 'bol)))
(when name
(message "%s. Line %s/%s." name
- (1+ (count-lines (car limits) point-bol))
+ (1+ (count-lines (car limits) (max point-bol (car limits))))
(count-lines (car limits) (cdr limits)))
(if arg (kill-new name))
(sit-for 3 t)))))
@@ -4188,7 +4272,7 @@
; (or (<= (- (cdr c-lit-limits) 2) (point))
; 2010-10-17 Construct removed.
; (or (< (- (cdr c-lit-limits) 2) (point))
- (and
+ (and
(search-forward-regexp
(concat "\\=[ \t]*\\(" c-current-comment-prefix "\\)")
(- (cdr c-lit-limits) 2) t)
diff -r 1b5c372f3b60eea55165c6d04738f98905cd5a11 -r a3392363b1dddb36ce09f6676a4323bcda3418ee cc-engine.el
--- a/cc-engine.el
+++ b/cc-engine.el
@@ -1128,7 +1128,16 @@
(not (c-looking-at-inexpr-block lim nil t))
(save-excursion
(c-backward-token-2 1 t nil)
- (not (looking-at "=\\([^=]\\|$\\)"))))
+ (not (looking-at "=\\([^=]\\|$\\)")))
+ (or
+ (not c-opt-block-decls-with-vars-key)
+ (save-excursion
+ (c-backward-token-2 1 t nil)
+ (if (and (looking-at c-symbol-start)
+ (not (looking-at c-keywords-regexp)))
+ (c-backward-token-2 1 t nil))
+ (not (looking-at
+ c-opt-block-decls-with-vars-key)))))
(save-excursion
(c-forward-sexp) (point)))
;; Just gone back over some paren block?
diff -r 1b5c372f3b60eea55165c6d04738f98905cd5a11 -r a3392363b1dddb36ce09f6676a4323bcda3418ee cc-langs.el
--- a/cc-langs.el
+++ b/cc-langs.el
@@ -2090,6 +2090,18 @@
"Alist associating keywords in c-other-decl-block-decl-kwds with
their matching \"in\" syntactic symbols.")
+(c-lang-defconst c-defun-type-name-decl-kwds
+ "Keywords introducing a named block, where the name is a \"defun\"
+ name."
+ t (append (c-lang-const c-class-decl-kwds)
+ (c-lang-const c-brace-list-decl-kwds)))
+
+(c-lang-defconst c-defun-type-name-decl-key
+ ;; Regexp matching a keyword in `c-defun-name-decl-kwds'.
+ t (c-make-keywords-re t (c-lang-const c-defun-type-name-decl-kwds)))
+(c-lang-defvar c-defun-type-name-decl-key
+ (c-lang-const c-defun-type-name-decl-key))
+
(c-lang-defconst c-typedef-decl-kwds
"Keywords introducing declarations where the identifier(s) being
declared are types.
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.
commit/cc-mode: acm: Handle C99 Compound Literals in return
statements and argument lists.
6 years, 11 months
Bitbucket
1 new commit in cc-mode:
https://bitbucket.org/xemacs/cc-mode/commits/1b5c372f3b60/
Changeset: 1b5c372f3b60
User: acm
Date: 2018-01-21 18:05:41+00:00
Summary: Handle C99 Compound Literals in return statements and argument lists.
* cc-engine.el (c-looking-at-or-maybe-in-bracelist): Recognize a brace list
when preceded by "return" or inside parentheses, either immediately after the
"(" or following a comma.
(c-looking-at-inexpr-block): Test c-has-compound-literals rather than hard
coded C++ Mode.
(c-guess-basic-syntax, CASE 7B): Test additionally for not being just inside a
parenthesis or being at a Java "new" keyword. CASE 9: Remove the simple
minded test on the contents of a block to determine a brace list.
* cc-langs.el (c-has-compound-literals): New lang const and lang var.
Affected #: 2 files
diff -r 47ceda16abc59b73d2bed96eb6eb93499eacc9f7 -r 1b5c372f3b60eea55165c6d04738f98905cd5a11 cc-engine.el
--- a/cc-engine.el
+++ b/cc-engine.el
@@ -10534,6 +10534,17 @@
((and class-key
(looking-at class-key))
(setq braceassignp nil))
+ ((and c-has-compound-literals
+ (looking-at c-return-key))
+ (setq braceassignp t)
+ nil)
+ ((and c-has-compound-literals
+ (eq (char-after) ?,))
+ (save-excursion
+ (when (and (c-go-up-list-backward nil lim)
+ (eq (char-after) ?\())
+ (setq braceassignp t)
+ nil)))
((eq (char-after) ?=)
;; We've seen a =, but must check earlier tokens so
;; that it isn't something that should be ignored.
@@ -10572,9 +10583,14 @@
))))
nil)
(t t))))))
- (if (and (eq braceassignp 'dontknow)
- (/= (c-backward-token-2 1 t lim) 0))
- (setq braceassignp nil)))
+ (when (and (eq braceassignp 'dontknow)
+ (/= (c-backward-token-2 1 t lim) 0))
+ (if (save-excursion
+ (and c-has-compound-literals
+ (eq (c-backward-token-2 1 nil lim) 0)
+ (eq (char-after) ?\()))
+ (setq braceassignp t)
+ (setq braceassignp nil))))
(cond
(braceassignp
@@ -10939,7 +10955,7 @@
(c-on-identifier)))
(and c-special-brace-lists
(c-looking-at-special-brace-list))
- (and (c-major-mode-is 'c++-mode)
+ (and c-has-compound-literals
(save-excursion
(goto-char block-follows)
(not (c-looking-at-statement-block)))))
@@ -12449,6 +12465,11 @@
;; in-expression block or brace list. C.f. cases 4, 16A
;; and 17E.
((and (eq char-after-ip ?{)
+ (or (not (eq (char-after containing-sexp) ?\())
+ (save-excursion
+ (and c-opt-inexpr-brace-list-key
+ (eq (c-beginning-of-statement-1 lim t nil t) 'same)
+ (looking-at c-opt-inexpr-brace-list-key))))
(progn
(setq placeholder (c-inside-bracelist-p (point)
paren-state
@@ -12575,11 +12596,7 @@
(save-excursion
(goto-char containing-sexp)
(c-looking-at-special-brace-list)))
- (c-inside-bracelist-p containing-sexp paren-state t)
- (save-excursion
- (goto-char containing-sexp)
- (and (eq (char-after) ?{)
- (not (c-looking-at-statement-block)))))))
+ (c-inside-bracelist-p containing-sexp paren-state t))))
(cond
;; CASE 9A: In the middle of a special brace list opener.
diff -r 47ceda16abc59b73d2bed96eb6eb93499eacc9f7 -r 1b5c372f3b60eea55165c6d04738f98905cd5a11 cc-langs.el
--- a/cc-langs.el
+++ b/cc-langs.el
@@ -600,6 +600,12 @@
c++ t)
(c-lang-defvar c-has-quoted-numbers (c-lang-const c-has-quoted-numbers))
+(c-lang-defconst c-has-compound-literals
+ "Whether literal initializers {...} are used other than in initializations."
+ t nil
+ (c c++) t)
+(c-lang-defvar c-has-compound-literals (c-lang-const c-has-compound-literals))
+
(c-lang-defconst c-modified-constant
"Regexp that matches a \"modified\" constant literal such as \"L'a'\",
a \"long character\". In particular, this recognizes forms of constant
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.
commit/cc-mode: acm: C++ Mode: Fontify correctly uniform
initialisation with inner parentheses.
6 years, 11 months
Bitbucket
1 new commit in cc-mode:
https://bitbucket.org/xemacs/cc-mode/commits/47ceda16abc5/
Changeset: 47ceda16abc5
User: acm
Date: 2018-01-16 21:39:59+00:00
Summary: C++ Mode: Fontify correctly uniform initialisation with inner parentheses.
E.g.: someStruct x ( (nullptr != y) ? 3 : 4 )
Also fontify declarations of function pointers correctly.
* cc-engine.el (c-forward-decl-or-cast-1): While testing for a typeless
declaration, additionally test the variable `got-prefix' to recognize a
function pointer in parentheses. Allow c-fdoc-shift-type-backward to be
invoked when we have nested parens.
Affected #: 1 file
diff -r d8e0dfbe0ba20868860033443d02de5ddd248e33 -r 47ceda16abc59b73d2bed96eb6eb93499eacc9f7 cc-engine.el
--- a/cc-engine.el
+++ b/cc-engine.el
@@ -8614,6 +8614,7 @@
;; construct here in C, since we want to recognize this as a
;; typeless function declaration.
(not (and (c-major-mode-is 'c-mode)
+ (not got-prefix)
(or (eq context 'top) make-top)
(eq (char-after) ?\)))))
(if (eq (char-after) ?\))
@@ -8643,31 +8644,39 @@
;; (con|de)structors in C++ and `c-typeless-decl-kwds'
;; style declarations. That isn't applicable in an
;; arglist context, though.
- (when (and (= paren-depth 1)
- (not got-prefix-before-parens)
- (not (eq at-type t))
- (or backup-at-type
- maybe-typeless
- backup-maybe-typeless
- (when c-recognize-typeless-decls
- (and (memq context '(nil top))
- ;; Deal with C++11's "copy-initialization"
- ;; where we have <type>(<constant>), by
- ;; contraasting with a typeless
- ;; <name>(<type><parameter>, ...).
- (save-excursion
- (goto-char after-paren-pos)
- (c-forward-syntactic-ws)
- (or (c-forward-type)
- ;; Recognize a top-level typeless
- ;; function declaration in C.
- (and (c-major-mode-is 'c-mode)
- (or (eq context 'top) make-top)
- (eq (char-after) ?\))))))))
- (setq pos (c-up-list-forward (point)))
- (eq (char-before pos) ?\)))
+ (when (and (> paren-depth 0)
+ (not got-prefix-before-parens)
+ (not (eq at-type t))
+ (or backup-at-type
+ maybe-typeless
+ backup-maybe-typeless
+ (when c-recognize-typeless-decls
+ (and (memq context '(nil top))
+ ;; Deal with C++11's "copy-initialization"
+ ;; where we have <type>(<constant>), by
+ ;; contraasting with a typeless
+ ;; <name>(<type><parameter>, ...).
+ (save-excursion
+ (goto-char after-paren-pos)
+ (c-forward-syntactic-ws)
+ (or (c-forward-type)
+ ;; Recognize a top-level typeless
+ ;; function declaration in C.
+ (and (c-major-mode-is 'c-mode)
+ (or (eq context 'top) make-top)
+ (eq (char-after) ?\))))))))
+ (let ((pd paren-depth))
+ (setq pos (point))
+ (catch 'pd
+ (while (> pd 0)
+ (setq pos (c-up-list-forward pos))
+ (when (or (null pos)
+ (not (eq (char-before pos) ?\))))
+ (throw 'pd nil))
+ (goto-char pos)
+ (setq pd (1- pd)))
+ t)))
(c-fdoc-shift-type-backward)
- (goto-char pos)
t)))
(c-forward-syntactic-ws))
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.