1 new commit in cc-mode:
https://bitbucket.org/xemacs/cc-mode/commits/e8b41be48ec5/
Changeset: e8b41be48ec5
User: acm
Date: 2017-10-22 13:55:40+00:00
Summary: Refactor c-forward-token-2 with new function c-forward-over-token-and-ws.
Use the new function directly in several places where c-forward-token-2
wouldn't move over the last token in the buffer. This caused an infinite loop
in c-restore-<>-properties.
* cc-engine.el (c-forward-over-token-and-ws): New function, extracted from
c-forward-token-2.
(c-forward-token-2): Refactor, calling the new function.
(c-restore-<>-properties): Fix infinite loop.
(c-forward-<>-arglist-recur, c-in-knr-argdecl)
(c-looking-at-or-maybe-in-bracelist): Call the new function directly in place
of c-forward-token-2.
* cc-cmds.el (c-defun-name) Call the new function directly in place of
c-forward-token-2.
* cc-fonts.el (c-font-lock-enclosing-decls): Call the new function directly in
place of c-forward-token-2.
Affected #: 3 files
diff -r 57b32f709a4f3f80c78071d67fec82b4cc629878 -r
e8b41be48ec5204df18d51eca0924527e82d8ee1 cc-cmds.el
--- a/cc-cmds.el
+++ b/cc-cmds.el
@@ -1807,7 +1807,7 @@
;; struct, union, enum, or similar:
((looking-at c-type-prefix-key)
(let ((key-pos (point)))
- (c-forward-token-2 1) ; over "struct ".
+ (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)))
diff -r 57b32f709a4f3f80c78071d67fec82b4cc629878 -r
e8b41be48ec5204df18d51eca0924527e82d8ee1 cc-engine.el
--- a/cc-engine.el
+++ b/cc-engine.el
@@ -4305,6 +4305,47 @@
"\\w\\|\\s_\\|\\s\"\\|\\s|"
"\\w\\|\\s_\\|\\s\""))
+(defun c-forward-over-token-and-ws (&optional balanced)
+ "Move forward over a token and any following whitespace
+Return t if we moved, nil otherwise (i.e. we were at EOB, or a
+non-token or BALANCED is non-nil and we can't move). If we
+are at syntactic whitespace, move over this in place of a token.
+
+If BALANCED is non-nil move over any balanced parens we are at, and never move
+out of an enclosing paren.
+
+This function differs from `c-forward-token-2' in that it will move forward
+over the final token in a buffer, up to EOB."
+ (let ((jump-syntax (if balanced
+ c-jump-syntax-balanced
+ c-jump-syntax-unbalanced))
+ (here (point)))
+ (when
+ (condition-case nil
+ (cond
+ ((/= (point)
+ (progn (c-forward-syntactic-ws) (point)))
+ ;; If we're at whitespace, count this as the token.
+ t)
+ ((eobp) nil)
+ ((looking-at jump-syntax)
+ (goto-char (scan-sexps (point) 1))
+ t)
+ ((looking-at c-nonsymbol-token-regexp)
+ (goto-char (match-end 0))
+ t)
+ ((save-restriction
+ (widen)
+ (looking-at c-nonsymbol-token-regexp))
+ nil)
+ (t
+ (forward-char)
+ t))
+ (error (goto-char here)
+ nil))
+ (c-forward-syntactic-ws)
+ t)))
+
(defun c-forward-token-2 (&optional count balanced limit)
"Move forward by tokens.
A token is defined as all symbols and identifiers which aren't
@@ -4334,15 +4375,11 @@
(if (< count 0)
(- (c-backward-token-2 (- count) balanced limit))
- (let ((jump-syntax (if balanced
- c-jump-syntax-balanced
- c-jump-syntax-unbalanced))
- (last (point))
- (prev (point)))
-
- (if (zerop count)
- ;; If count is zero we should jump if in the middle of a token.
- (c-end-of-current-token))
+ (let ((here (point))
+ (last (point)))
+ (when (zerop count)
+ ;; If count is zero we should jump if in the middle of a token.
+ (c-end-of-current-token))
(save-restriction
(if limit (narrow-to-region (point-min) limit))
@@ -4356,43 +4393,15 @@
;; Moved out of bounds. Make sure the returned count isn't zero.
(progn
(if (zerop count) (setq count 1))
- (goto-char last))
-
- ;; Use `condition-case' to avoid having the limit tests
- ;; inside the loop.
- (condition-case nil
- (while (and
- (> count 0)
- (progn
- (setq last (point))
- (cond ((looking-at jump-syntax)
- (goto-char (scan-sexps (point) 1))
- t)
- ((looking-at c-nonsymbol-token-regexp)
- (goto-char (match-end 0))
- t)
- ;; `c-nonsymbol-token-regexp' above should always
- ;; match if there are correct tokens. Try to
- ;; widen to see if the limit was set in the
- ;; middle of one, else fall back to treating
- ;; the offending thing as a one character token.
- ((and limit
- (save-restriction
- (widen)
- (looking-at c-nonsymbol-token-regexp)))
- nil)
- (t
- (forward-char)
- t))))
- (c-forward-syntactic-ws)
- (setq prev last
- count (1- count)))
- (error (goto-char last)))
-
- (when (eobp)
- (goto-char prev)
- (setq count (1+ count)))))
-
+ (goto-char here))
+ (while (and
+ (> count 0)
+ (c-forward-over-token-and-ws balanced)
+ (not (eobp)))
+ (setq last (point)
+ count (1- count)))
+ (if (eobp)
+ (goto-char last))))
count)))
(defun c-backward-token-2 (&optional count balanced limit)
@@ -6437,7 +6446,8 @@
(not (eq (c-get-char-property (point) 'c-type)
'c-decl-arg-start)))))))
(or (c-forward-<>-arglist nil)
- (c-forward-token-2)))))
+ (c-forward-over-token-and-ws)
+ (goto-char c-new-END)))))
;; Functions to handle C++ raw strings.
@@ -7153,7 +7163,7 @@
(let ((c-promote-possible-types t)
(c-record-found-types t))
(c-forward-type))
- (c-forward-token-2))))
+ (c-forward-over-token-and-ws))))
(c-forward-syntactic-ws)
@@ -9731,8 +9741,8 @@
;; identifiers?
(progn
(goto-char before-lparen)
- (c-forward-token-2) ; to first token inside parens
(and
+ (c-forward-over-token-and-ws) ; to first token inside parens
(setq id-start (c-on-identifier)) ; Must be at least one.
(catch 'id-list
(while
@@ -9744,7 +9754,7 @@
ids)
(c-forward-syntactic-ws)
(eq (char-after) ?\,))
- (c-forward-token-2)
+ (c-forward-over-token-and-ws)
(unless (setq id-start (c-on-identifier))
(throw 'id-list nil)))
(eq (char-after) ?\)))))
@@ -10534,10 +10544,10 @@
((and after-type-id-pos
(save-excursion
(when (eq (char-after) ?\;)
- (c-forward-token-2 1 t))
+ (c-forward-over-token-and-ws t))
(setq bufpos (point))
(when (looking-at c-opt-<>-sexp-key)
- (c-forward-token-2)
+ (c-forward-over-token-and-ws)
(when (and (eq (char-after) ?<)
(c-get-char-property (point) 'syntax-table))
(c-go-list-forward nil after-type-id-pos)
diff -r 57b32f709a4f3f80c78071d67fec82b4cc629878 -r
e8b41be48ec5204df18d51eca0924527e82d8ee1 cc-fonts.el
--- a/cc-fonts.el
+++ b/cc-fonts.el
@@ -1730,7 +1730,7 @@
(c-syntactic-skip-backward "^;{}" decl-search-lim)
(c-forward-syntactic-ws)
(setq in-typedef (looking-at c-typedef-key))
- (if in-typedef (c-forward-token-2))
+ (if in-typedef (c-forward-over-token-and-ws))
(when (and c-opt-block-decls-with-vars-key
(looking-at c-opt-block-decls-with-vars-key))
(goto-char ps-elt)
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.