CC Mode: Fix bug in whitespace scanning functions
c-forward-sws and c-backward-sws were scanning over spaces and linefeeds marked with the string-fence syntax-table text property. Fix this by (i) removing the WS text properties c-in-sws and c-is-sws from characters when setting the string-fence on them; (ii) checking the syntax of "space" characters when scanning over them. * lisp/progmodes/cc-defs.el (c-skip-ws-chars-forward) c-skip-ws-chars-backward, c-put-string-fence): New macros. * lisp/progmodes/cc-awk.el (c-awk-set-string-regexp-syntax-table-properties): Use c-put-string-fence. * lisp/progmodes/cc-engine.el (c-beginning-of-statement-1): Correct the determination of macro-start. (c-forward-sws, c-backward-sws): Replace skip-chars-forward by c-skip-ws-chars-forward and skip-chars-backward by c-skip-ws-chars-backward. (c-unmark-<>-around-region, c-after-change-unmark-ml-strings) (c-propertize-ml-string-opener): Use c-put-string-fence. * lisp/progmodes/cc-mode.el (c-put-syn-tab): Use c-put-string-fence when appropriate.
This commit is contained in:
parent
309554edb4
commit
688c893b18
4 changed files with 86 additions and 43 deletions
|
|
@ -754,14 +754,14 @@
|
|||
(if (eq (char-after beg) ?_) (setq beg (1+ beg)))
|
||||
|
||||
;; First put the properties on the delimiters.
|
||||
(cond ((eq end (point-max)) ; string/regexp terminated by EOB
|
||||
(c-put-char-property beg 'syntax-table '(15))) ; (15) = "string fence"
|
||||
((/= (char-after beg) (char-after end)) ; missing end delimiter
|
||||
(c-put-char-property beg 'syntax-table '(15))
|
||||
(c-put-char-property end 'syntax-table '(15)))
|
||||
((eq (char-after beg) ?/) ; Properly bracketed regexp
|
||||
(c-put-char-property beg 'syntax-table '(7)) ; (7) = "string"
|
||||
(c-put-char-property end 'syntax-table '(7)))
|
||||
(cond ((eq end (point-max)) ; string/regexp terminated by EOB
|
||||
(c-put-string-fence beg))
|
||||
((/= (char-after beg) (char-after end)) ; missing end delimiter
|
||||
(c-put-string-fence beg)
|
||||
(c-put-string-fence end))
|
||||
((eq (char-after beg) ?/) ; Properly bracketed regexp
|
||||
(c-put-char-property beg 'syntax-table '(7)) ; (7) = "string"
|
||||
(c-put-char-property end 'syntax-table '(7)))
|
||||
(t)) ; Properly bracketed string: Nothing to do.
|
||||
;; Now change the properties of any escaped "s in the string to punctuation.
|
||||
(save-excursion
|
||||
|
|
|
|||
|
|
@ -733,9 +733,10 @@ various buffer change hooks."
|
|||
|
||||
(defmacro c-forward-syntactic-ws (&optional limit)
|
||||
"Forward skip over syntactic whitespace.
|
||||
Syntactic whitespace is defined as whitespace characters, comments,
|
||||
and preprocessor directives. However if point starts inside a comment
|
||||
or preprocessor directive, the content of it is not treated as
|
||||
Syntactic whitespace is defined as whitespace characters with
|
||||
whitespace (or comment-end) syntax, comments, and preprocessor
|
||||
directives. However if point starts inside a comment or
|
||||
preprocessor directive, the content of it is not treated as
|
||||
whitespace.
|
||||
|
||||
LIMIT sets an upper limit of the forward movement, if specified. If
|
||||
|
|
@ -755,9 +756,10 @@ comment at the start of cc-engine.el for more info."
|
|||
|
||||
(defmacro c-backward-syntactic-ws (&optional limit)
|
||||
"Backward skip over syntactic whitespace.
|
||||
Syntactic whitespace is defined as whitespace characters, comments,
|
||||
and preprocessor directives. However if point starts inside a comment
|
||||
or preprocessor directive, the content of it is not treated as
|
||||
Syntactic whitespace is defined as whitespace characters with
|
||||
whitespace (or comment-end) syntax, comments, and preprocessor
|
||||
directives. However if point starts inside a comment or
|
||||
preprocessor directive, the content of it is not treated as
|
||||
whitespace.
|
||||
|
||||
LIMIT sets a lower limit of the backward movement, if specified. If
|
||||
|
|
@ -1102,6 +1104,38 @@ continuations."
|
|||
(eq (char-before) ?\\)))
|
||||
(backward-char))))
|
||||
|
||||
(defmacro c-skip-ws-chars-forward (string &optional lim)
|
||||
;; Move point forward, stopping before a char which isn't in STRING, or a
|
||||
;; char whose syntax isn't whitespace or comment-end, or at pos LIM.
|
||||
;; Note that \n usually has comment-end syntax.
|
||||
;;
|
||||
;; Returns the distance traveled, either zero or positive.
|
||||
(declare (debug t))
|
||||
`(let ((-lim- ,lim)
|
||||
(here (point))
|
||||
count)
|
||||
(setq count (skip-chars-forward ,string -lim-))
|
||||
(when (> count 0)
|
||||
(goto-char here)
|
||||
(setq count (skip-syntax-forward " >" (+ here count))))
|
||||
count))
|
||||
|
||||
(defmacro c-skip-ws-chars-backward (string &optional lim)
|
||||
;; Move point backward, stopping after a char which isn't in STRING, or a
|
||||
;; char whose syntax isn't whitespace or comment-end, or at pos LIM. Note
|
||||
;; that \n usually has comment-end syntax.
|
||||
;;
|
||||
;; Returns the distance traveled, either zero or negative.
|
||||
(declare (debug t))
|
||||
`(let ((-lim- ,lim)
|
||||
(here (point))
|
||||
count)
|
||||
(setq count (skip-chars-backward ,string -lim-))
|
||||
(when (< count 0)
|
||||
(goto-char here)
|
||||
(setq count (skip-syntax-backward " >" (+ here count))))
|
||||
count))
|
||||
|
||||
(eval-and-compile
|
||||
(defvar c-langs-are-parametric nil))
|
||||
|
||||
|
|
@ -1208,6 +1242,17 @@ MODE is either a mode symbol or a list of mode symbols."
|
|||
`((setq c-syntax-table-hwm (min c-syntax-table-hwm -pos-))))
|
||||
(put-text-property -pos- (1+ -pos-) ',property ,value))))
|
||||
|
||||
(defmacro c-put-string-fence (pos)
|
||||
;; Put the string-fence syntax-table text property at POS.
|
||||
;; Since the character there cannot then count as syntactic whitespace,
|
||||
;; clear the properties `c-is-sws' and `c-in-sws' (see functions
|
||||
;; `c-forward-sws' and `c-backward-sws' in cc-engine.el for details).
|
||||
(declare (debug t))
|
||||
`(let ((-pos- ,pos))
|
||||
(c-put-char-property -pos- 'syntax-table '(15))
|
||||
(c-clear-char-property -pos- 'c-is-sws)
|
||||
(c-clear-char-property -pos- 'c-in-sws)))
|
||||
|
||||
(eval-and-compile
|
||||
;; Constant to decide at compilation time whether to use category
|
||||
;; properties. Currently (2010-03) they're available only on GNU
|
||||
|
|
|
|||
|
|
@ -976,10 +976,10 @@ comment at the start of cc-engine.el for more info."
|
|||
(point-min)))
|
||||
(widen)
|
||||
|
||||
(if (save-excursion
|
||||
(and (c-beginning-of-macro)
|
||||
(/= (point) start)))
|
||||
(setq macro-start (point)))
|
||||
(save-excursion
|
||||
(if (and (c-beginning-of-macro)
|
||||
(/= (point) start))
|
||||
(setq macro-start (point))))
|
||||
|
||||
;; Try to skip back over unary operator characters, to register
|
||||
;; that we've moved.
|
||||
|
|
@ -2130,7 +2130,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; Skip simple ws and do a quick check on the following character to see
|
||||
;; if it's anything that can't start syntactic ws, so we can bail out
|
||||
;; early in the majority of cases when there just are a few ws chars.
|
||||
(skip-chars-forward " \t\n\r\f\v")
|
||||
(c-skip-ws-chars-forward " \t\n\r\f\v")
|
||||
(when (or (looking-at c-syntactic-ws-start)
|
||||
(and c-opt-cpp-prefix
|
||||
(looking-at c-noise-macro-name-re))
|
||||
|
|
@ -2180,7 +2180,7 @@ comment at the start of cc-engine.el for more info."
|
|||
rung-pos (point) (point-max))
|
||||
|
||||
(setq rung-pos (point))
|
||||
(and (> (skip-chars-forward " \t\n\r\f\v") 0)
|
||||
(and (> (c-skip-ws-chars-forward " \t\n\r\f\v") 0)
|
||||
(not (eobp))))
|
||||
|
||||
;; We'll loop here if there is simple ws after the last rung.
|
||||
|
|
@ -2246,7 +2246,7 @@ comment at the start of cc-engine.el for more info."
|
|||
(and c-opt-cpp-prefix
|
||||
(looking-at c-opt-cpp-start)
|
||||
(setq macro-start (point))
|
||||
(progn (skip-chars-backward " \t")
|
||||
(progn (c-skip-ws-chars-backward " \t")
|
||||
(bolp))
|
||||
(or (bobp)
|
||||
(progn (backward-char)
|
||||
|
|
@ -2286,7 +2286,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; We've searched over a piece of non-white syntactic ws. See if this
|
||||
;; can be cached.
|
||||
(setq next-rung-pos (point))
|
||||
(skip-chars-forward " \t\n\r\f\v")
|
||||
(c-skip-ws-chars-forward " \t\n\r\f\v")
|
||||
(setq rung-end-pos (min (1+ (point)) (point-max)))
|
||||
|
||||
(if (or
|
||||
|
|
@ -2383,7 +2383,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; bail out early in the majority of cases when there just are a few ws
|
||||
;; chars. Newlines are complicated in the backward direction, so we can't
|
||||
;; skip over them.
|
||||
(skip-chars-backward " \t\f")
|
||||
(c-skip-ws-chars-backward " \t\f")
|
||||
(when (and (not (bobp))
|
||||
(save-excursion
|
||||
(or (and
|
||||
|
|
@ -2411,7 +2411,7 @@ comment at the start of cc-engine.el for more info."
|
|||
(setq simple-ws-beg (or attr-end ; After attribute.
|
||||
(match-end 1) ; Noise macro, etc.
|
||||
(match-end 0))) ; c-syntactic-ws-end
|
||||
(skip-chars-backward " \t\n\r\f\v")
|
||||
(c-skip-ws-chars-backward " \t\n\r\f\v")
|
||||
(if (setq rung-is-marked (text-property-any
|
||||
(point) (min (1+ rung-pos) (point-max))
|
||||
'c-is-sws t))
|
||||
|
|
@ -2448,10 +2448,10 @@ comment at the start of cc-engine.el for more info."
|
|||
(point) rung-pos (point-min))
|
||||
|
||||
(setq rung-pos (point))
|
||||
(if (and (< (min (skip-chars-backward " \t\f\v")
|
||||
(if (and (< (min (c-skip-ws-chars-backward " \t\f\v")
|
||||
(progn
|
||||
(setq simple-ws-beg (point))
|
||||
(skip-chars-backward " \t\n\r\f\v")))
|
||||
(c-skip-ws-chars-backward " \t\n\r\f\v")))
|
||||
0)
|
||||
(setq rung-is-marked
|
||||
(text-property-any (point) rung-pos
|
||||
|
|
@ -2531,7 +2531,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; the macro, and then `simple-ws-beg' must be kept on the
|
||||
;; same side of those comments.
|
||||
(goto-char simple-ws-beg)
|
||||
(skip-chars-backward " \t\n\r\f\v")
|
||||
(c-skip-ws-chars-backward " \t\n\r\f\v")
|
||||
(if (eq (char-before) ?\\)
|
||||
(forward-char))
|
||||
(forward-line 1)
|
||||
|
|
@ -2544,7 +2544,7 @@ comment at the start of cc-engine.el for more info."
|
|||
t)))
|
||||
|
||||
((/= (save-excursion
|
||||
(skip-chars-forward " \t\n\r\f\v" simple-ws-beg)
|
||||
(c-skip-ws-chars-forward " \t\n\r\f\v" simple-ws-beg)
|
||||
(setq next-rung-pos (point)))
|
||||
simple-ws-beg)
|
||||
;; Skipped over comments. Must put point at the end of
|
||||
|
|
@ -2581,7 +2581,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; We've searched over a piece of non-white syntactic ws. See if this
|
||||
;; can be cached.
|
||||
(setq next-rung-pos (point))
|
||||
(skip-chars-backward " \t\f\v")
|
||||
(c-skip-ws-chars-backward " \t\f\v")
|
||||
|
||||
(if (or
|
||||
;; Cache if we started either from a marked rung or from a
|
||||
|
|
@ -2591,7 +2591,7 @@ comment at the start of cc-engine.el for more info."
|
|||
|
||||
;; Cache if there's a marked rung in the encountered simple ws.
|
||||
(save-excursion
|
||||
(skip-chars-backward " \t\n\r\f\v")
|
||||
(c-skip-ws-chars-backward " \t\n\r\f\v")
|
||||
(text-property-any (point) (min (1+ next-rung-pos) (point-max))
|
||||
'c-is-sws t)))
|
||||
|
||||
|
|
@ -7202,10 +7202,8 @@ comment at the start of cc-engine.el for more info."
|
|||
(progn
|
||||
(c-clear-char-property (1- beg-literal-end)
|
||||
'syntax-table)
|
||||
(c-put-char-property (1- end-literal-end)
|
||||
'syntax-table '(15)))
|
||||
(c-put-char-property (1- beg-literal-end)
|
||||
'syntax-table '(15))
|
||||
(c-put-string-fence (1- end-literal-end)))
|
||||
(c-put-string-fence (1- beg-literal-end))
|
||||
(c-clear-char-property (1- end-literal-end)
|
||||
'syntax-table)))
|
||||
|
||||
|
|
@ -7284,10 +7282,8 @@ comment at the start of cc-engine.el for more info."
|
|||
(progn
|
||||
(c-clear-char-property (1- beg-literal-end)
|
||||
'syntax-table)
|
||||
(c-put-char-property (1- end-literal-end)
|
||||
'syntax-table '(15)))
|
||||
(c-put-char-property (1- beg-literal-end)
|
||||
'syntax-table '(15))
|
||||
(c-put-string-fence (1- end-literal-end)))
|
||||
(c-put-string-fence (1- beg-literal-end))
|
||||
(c-clear-char-property (1- end-literal-end)
|
||||
'syntax-table)))))
|
||||
;; Extend the fontification region, if needed.
|
||||
|
|
@ -7946,7 +7942,7 @@ multi-line strings (but not C++, for example)."
|
|||
(insert (nth 3 (car state))))
|
||||
((eq (nth 3 (car state)) t)
|
||||
(insert ?\")
|
||||
(c-put-char-property end 'syntax-table '(15))))
|
||||
(c-put-string-fence end)))
|
||||
(c-truncate-lit-pos-cache end)
|
||||
;; ....ensure c-new-END extends right to the end of the about
|
||||
;; to be un-stringed raw string....
|
||||
|
|
@ -8191,7 +8187,7 @@ multi-line strings (but not C++, for example)."
|
|||
(goto-char (cadr end-delim))
|
||||
t)
|
||||
(c-put-char-property (cddr delim) 'syntax-table '(1))
|
||||
(c-put-char-property (1- (cadr delim)) 'syntax-table '(15))
|
||||
(c-put-string-fence (1- (cadr delim)))
|
||||
(c-truncate-lit-pos-cache (1- (cddr delim)))
|
||||
(when bound
|
||||
;; In a CPP construct, we try to apply a generic-string
|
||||
|
|
@ -8221,10 +8217,10 @@ multi-line strings (but not C++, for example)."
|
|||
(cadr delim) t))
|
||||
(if (match-beginning 10)
|
||||
(progn
|
||||
(c-put-char-property (match-beginning 10) 'syntax-table '(15))
|
||||
(c-put-string-fence (match-beginning 10))
|
||||
(c-truncate-lit-pos-cache (match-beginning 10)))
|
||||
(c-put-char-property (match-beginning 5) 'syntax-table '(1))
|
||||
(c-put-char-property (1+ (match-beginning 5)) 'syntax-table '(15))
|
||||
(c-put-string-fence (1+ (match-beginning 5)))
|
||||
(c-truncate-lit-pos-cache (match-beginning 5))))
|
||||
(goto-char bound))
|
||||
nil))
|
||||
|
|
|
|||
|
|
@ -1279,7 +1279,9 @@ Note that the style variables are always made local to the buffer."
|
|||
;; VALUE (which should not be nil).
|
||||
;; `(let ((-pos- ,pos)
|
||||
;; (-value- ,value))
|
||||
(c-put-char-property pos 'syntax-table value)
|
||||
(if (equal value '(15))
|
||||
(c-put-string-fence pos)
|
||||
(c-put-char-property pos 'syntax-table value))
|
||||
(c-put-char-property pos 'c-fl-syn-tab value)
|
||||
(cond
|
||||
((null c-min-syn-tab-mkr)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue