aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2017-10-22 14:18:20 +0000
committerAlan Mackenzie2017-10-22 14:18:20 +0000
commitb7c4aa951c8b12629742df9d20d6374c3d2a8ba8 (patch)
treea3b86aa4e129b208ca796325f996c2e0e8a17563
parent3aee7be62eaf8caef6f2fab31bee79674b3abbb7 (diff)
downloademacs-b7c4aa951c8b12629742df9d20d6374c3d2a8ba8.tar.gz
emacs-b7c4aa951c8b12629742df9d20d6374c3d2a8ba8.zip
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. * lisp/progmodes/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. * lisp/progmodes/cc-cmds.el (c-defun-name) Call the new function directly in place of c-forward-token-2. * lisp/progmodes/cc-fonts.el (c-font-lock-enclosing-decls): Call the new function directly in place of c-forward-token-2.
-rw-r--r--lisp/progmodes/cc-cmds.el2
-rw-r--r--lisp/progmodes/cc-engine.el114
-rw-r--r--lisp/progmodes/cc-fonts.el2
3 files changed, 64 insertions, 54 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 5c8bbebf31b..ca64b544200 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1852,7 +1852,7 @@ with a brace block."
1852 ;; struct, union, enum, or similar: 1852 ;; struct, union, enum, or similar:
1853 ((looking-at c-type-prefix-key) 1853 ((looking-at c-type-prefix-key)
1854 (let ((key-pos (point))) 1854 (let ((key-pos (point)))
1855 (c-forward-token-2 1) ; over "struct ". 1855 (c-forward-over-token-and-ws) ; over "struct ".
1856 (cond 1856 (cond
1857 ((looking-at c-symbol-key) ; "struct foo { ..." 1857 ((looking-at c-symbol-key) ; "struct foo { ..."
1858 (buffer-substring-no-properties key-pos (match-end 0))) 1858 (buffer-substring-no-properties key-pos (match-end 0)))
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 37928357526..c506294c5a0 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -4297,6 +4297,47 @@ comment at the start of cc-engine.el for more info."
4297 "\\w\\|\\s_\\|\\s\"\\|\\s|" 4297 "\\w\\|\\s_\\|\\s\"\\|\\s|"
4298 "\\w\\|\\s_\\|\\s\"")) 4298 "\\w\\|\\s_\\|\\s\""))
4299 4299
4300(defun c-forward-over-token-and-ws (&optional balanced)
4301 "Move forward over a token and any following whitespace
4302Return t if we moved, nil otherwise (i.e. we were at EOB, or a
4303non-token or BALANCED is non-nil and we can't move). If we
4304are at syntactic whitespace, move over this in place of a token.
4305
4306If BALANCED is non-nil move over any balanced parens we are at, and never move
4307out of an enclosing paren.
4308
4309This function differs from `c-forward-token-2' in that it will move forward
4310over the final token in a buffer, up to EOB."
4311 (let ((jump-syntax (if balanced
4312 c-jump-syntax-balanced
4313 c-jump-syntax-unbalanced))
4314 (here (point)))
4315 (when
4316 (condition-case nil
4317 (cond
4318 ((/= (point)
4319 (progn (c-forward-syntactic-ws) (point)))
4320 ;; If we're at whitespace, count this as the token.
4321 t)
4322 ((eobp) nil)
4323 ((looking-at jump-syntax)
4324 (goto-char (scan-sexps (point) 1))
4325 t)
4326 ((looking-at c-nonsymbol-token-regexp)
4327 (goto-char (match-end 0))
4328 t)
4329 ((save-restriction
4330 (widen)
4331 (looking-at c-nonsymbol-token-regexp))
4332 nil)
4333 (t
4334 (forward-char)
4335 t))
4336 (error (goto-char here)
4337 nil))
4338 (c-forward-syntactic-ws)
4339 t)))
4340
4300(defun c-forward-token-2 (&optional count balanced limit) 4341(defun c-forward-token-2 (&optional count balanced limit)
4301 "Move forward by tokens. 4342 "Move forward by tokens.
4302A token is defined as all symbols and identifiers which aren't 4343A token is defined as all symbols and identifiers which aren't
@@ -4326,15 +4367,11 @@ comment at the start of cc-engine.el for more info."
4326 (if (< count 0) 4367 (if (< count 0)
4327 (- (c-backward-token-2 (- count) balanced limit)) 4368 (- (c-backward-token-2 (- count) balanced limit))
4328 4369
4329 (let ((jump-syntax (if balanced 4370 (let ((here (point))
4330 c-jump-syntax-balanced 4371 (last (point)))
4331 c-jump-syntax-unbalanced)) 4372 (when (zerop count)
4332 (last (point)) 4373 ;; If count is zero we should jump if in the middle of a token.
4333 (prev (point))) 4374 (c-end-of-current-token))
4334
4335 (if (zerop count)
4336 ;; If count is zero we should jump if in the middle of a token.
4337 (c-end-of-current-token))
4338 4375
4339 (save-restriction 4376 (save-restriction
4340 (if limit (narrow-to-region (point-min) limit)) 4377 (if limit (narrow-to-region (point-min) limit))
@@ -4348,43 +4385,15 @@ comment at the start of cc-engine.el for more info."
4348 ;; Moved out of bounds. Make sure the returned count isn't zero. 4385 ;; Moved out of bounds. Make sure the returned count isn't zero.
4349 (progn 4386 (progn
4350 (if (zerop count) (setq count 1)) 4387 (if (zerop count) (setq count 1))
4351 (goto-char last)) 4388 (goto-char here))
4352 4389 (while (and
4353 ;; Use `condition-case' to avoid having the limit tests 4390 (> count 0)
4354 ;; inside the loop. 4391 (c-forward-over-token-and-ws balanced)
4355 (condition-case nil 4392 (not (eobp)))
4356 (while (and 4393 (setq last (point)
4357 (> count 0) 4394 count (1- count)))
4358 (progn 4395 (if (eobp)
4359 (setq last (point)) 4396 (goto-char last))))
4360 (cond ((looking-at jump-syntax)
4361 (goto-char (scan-sexps (point) 1))
4362 t)
4363 ((looking-at c-nonsymbol-token-regexp)
4364 (goto-char (match-end 0))
4365 t)
4366 ;; `c-nonsymbol-token-regexp' above should always
4367 ;; match if there are correct tokens. Try to
4368 ;; widen to see if the limit was set in the
4369 ;; middle of one, else fall back to treating
4370 ;; the offending thing as a one character token.
4371 ((and limit
4372 (save-restriction
4373 (widen)
4374 (looking-at c-nonsymbol-token-regexp)))
4375 nil)
4376 (t
4377 (forward-char)
4378 t))))
4379 (c-forward-syntactic-ws)
4380 (setq prev last
4381 count (1- count)))
4382 (error (goto-char last)))
4383
4384 (when (eobp)
4385 (goto-char prev)
4386 (setq count (1+ count)))))
4387
4388 count))) 4397 count)))
4389 4398
4390(defun c-backward-token-2 (&optional count balanced limit) 4399(defun c-backward-token-2 (&optional count balanced limit)
@@ -6424,7 +6433,8 @@ comment at the start of cc-engine.el for more info."
6424 (not (eq (c-get-char-property (point) 'c-type) 6433 (not (eq (c-get-char-property (point) 'c-type)
6425 'c-decl-arg-start))))))) 6434 'c-decl-arg-start)))))))
6426 (or (c-forward-<>-arglist nil) 6435 (or (c-forward-<>-arglist nil)
6427 (c-forward-token-2))))) 6436 (c-forward-over-token-and-ws)
6437 (goto-char c-new-END)))))
6428 6438
6429 6439
6430;; Functions to handle C++ raw strings. 6440;; Functions to handle C++ raw strings.
@@ -7142,7 +7152,7 @@ comment at the start of cc-engine.el for more info."
7142 (let ((c-promote-possible-types t) 7152 (let ((c-promote-possible-types t)
7143 (c-record-found-types t)) 7153 (c-record-found-types t))
7144 (c-forward-type)) 7154 (c-forward-type))
7145 (c-forward-token-2)))) 7155 (c-forward-over-token-and-ws))))
7146 7156
7147 (c-forward-syntactic-ws) 7157 (c-forward-syntactic-ws)
7148 7158
@@ -9722,8 +9732,8 @@ comment at the start of cc-engine.el for more info."
9722 ;; identifiers? 9732 ;; identifiers?
9723 (progn 9733 (progn
9724 (goto-char before-lparen) 9734 (goto-char before-lparen)
9725 (c-forward-token-2) ; to first token inside parens
9726 (and 9735 (and
9736 (c-forward-over-token-and-ws) ; to first token inside parens
9727 (setq id-start (c-on-identifier)) ; Must be at least one. 9737 (setq id-start (c-on-identifier)) ; Must be at least one.
9728 (catch 'id-list 9738 (catch 'id-list
9729 (while 9739 (while
@@ -9735,7 +9745,7 @@ comment at the start of cc-engine.el for more info."
9735 ids) 9745 ids)
9736 (c-forward-syntactic-ws) 9746 (c-forward-syntactic-ws)
9737 (eq (char-after) ?\,)) 9747 (eq (char-after) ?\,))
9738 (c-forward-token-2) 9748 (c-forward-over-token-and-ws)
9739 (unless (setq id-start (c-on-identifier)) 9749 (unless (setq id-start (c-on-identifier))
9740 (throw 'id-list nil))) 9750 (throw 'id-list nil)))
9741 (eq (char-after) ?\))))) 9751 (eq (char-after) ?\)))))
@@ -10525,10 +10535,10 @@ comment at the start of cc-engine.el for more info."
10525 ((and after-type-id-pos 10535 ((and after-type-id-pos
10526 (save-excursion 10536 (save-excursion
10527 (when (eq (char-after) ?\;) 10537 (when (eq (char-after) ?\;)
10528 (c-forward-token-2 1 t)) 10538 (c-forward-over-token-and-ws t))
10529 (setq bufpos (point)) 10539 (setq bufpos (point))
10530 (when (looking-at c-opt-<>-sexp-key) 10540 (when (looking-at c-opt-<>-sexp-key)
10531 (c-forward-token-2) 10541 (c-forward-over-token-and-ws)
10532 (when (and (eq (char-after) ?<) 10542 (when (and (eq (char-after) ?<)
10533 (c-get-char-property (point) 'syntax-table)) 10543 (c-get-char-property (point) 'syntax-table))
10534 (c-go-list-forward nil after-type-id-pos) 10544 (c-go-list-forward nil after-type-id-pos)
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 02b685d240d..acdb1ad1334 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1730,7 +1730,7 @@ casts and declarations are fontified. Used on level 2 and higher."
1730 (c-syntactic-skip-backward "^;{}" decl-search-lim) 1730 (c-syntactic-skip-backward "^;{}" decl-search-lim)
1731 (c-forward-syntactic-ws) 1731 (c-forward-syntactic-ws)
1732 (setq in-typedef (looking-at c-typedef-key)) 1732 (setq in-typedef (looking-at c-typedef-key))
1733 (if in-typedef (c-forward-token-2)) 1733 (if in-typedef (c-forward-over-token-and-ws))
1734 (when (and c-opt-block-decls-with-vars-key 1734 (when (and c-opt-block-decls-with-vars-key
1735 (looking-at c-opt-block-decls-with-vars-key)) 1735 (looking-at c-opt-block-decls-with-vars-key))
1736 (goto-char ps-elt) 1736 (goto-char ps-elt)