diff options
author | Alan Mackenzie <acm@muc.de> | 2016-09-06 11:47:16 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2016-09-06 11:47:16 +0000 |
commit | 96a80239e7711c5f5d1f9cca5e18b6491b352ca5 (patch) | |
tree | 8a02df89429e35b8d566cb3a48db7745c8aacd9b | |
parent | 6acff25280dbb97b5e9ddfd872b33ceb36b0470a (diff) |
New options for handling of literals in c-syntactic-re-search-forward
* lisp/progmodes/cc-engine.el (c-syntactic-re-search-forward): `noerror' can
be given the values `before-literal' and `after-literal', so that when a
search fails, and the `bound' is inside a literal, point is left respectively
before or after that literal.
-rw-r--r-- | lisp/progmodes/cc-engine.el | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 2cad2d0242..d4cb192dbd 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -4278,6 +4278,15 @@ or string literals are ignored. The start point is assumed to be outside any comment, macro or string literal, or else the content of that region is taken as syntactically significant text. +NOERROR, in addition to the values nil, t, and <anything else> +used in `re-search-forward' can also take the values +'before-literal and 'after-literal. In these cases, when BOUND +is also given and is inside a literal, and a search fails, point +will be left, respectively before or after the literal. Be aware +that with 'after-literal, if a string or comment is unclosed at +the end of the buffer, point may be left there, even though it is +inside a literal there. + If PAREN-LEVEL is non-nil, an additional restriction is added to ignore matches in nested paren sexps. The search will also not go outside the current list sexp, which has the effect that if the point @@ -4343,7 +4352,7 @@ comment at the start of cc-engine.el for more info." (setq search-pos (point)) (if (re-search-forward regexp bound noerror) t - ;; Without the following, when PAREN-LEVEL it non-nil, and + ;; Without the following, when PAREN-LEVEL is non-nil, and ;; NOERROR is not nil or t, and the very first search above ;; has just failed, point would end up at BOUND rather than ;; just before the next close paren. @@ -4501,9 +4510,18 @@ comment at the start of cc-engine.el for more info." (match-end 0)) ;; Search failed. Set point as appropriate. - (if (eq noerror t) - (goto-char start) + (cond + ((eq noerror t) + (goto-char start)) + ((not (memq noerror '(before-literal after-literal))) (goto-char bound)) + (t (setq state (parse-partial-sexp state-pos bound nil nil state)) + (when (or (elt state 3) (elt state 4)) + (if (eq noerror 'before-literal) + (goto-char (elt state 8)) + (parse-partial-sexp bound (point-max) nil nil + state 'syntax-table))))) + nil))) (defvar safe-pos-list) ; bound in c-syntactic-skip-backward |