;; Emacs <22 + XEmacs
'(default-value 'sentence-end)))
+(defconst c-c++-raw-string-opener-re "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
+;; Matches a C++ raw string opener. Submatch 1 is its identifier.
+
+(defconst c-c++-raw-string-opener-1-re "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
+;; Matches a C++ raw string opener starting after the initial R.
+
+(defmacro c-sub-at-c++-raw-string-opener ()
+ `(save-excursion
+ (and
+ (if (eq (char-after) ?R)
+ (progn (forward-char) t)
+ (eq (char-before) ?R))
+ (looking-at c-c++-raw-string-opener-1-re))))
+
+(defmacro c-at-c++-raw-string-opener (&optional pos)
+ ;; Return non-nil if POS (default point) is either at the start of a C++ raw
+ ;; string opener, or after the introductory R of one. The match data is
+ ;; overwritten. On success the opener's identifier will be (match-string
+ ;; 1). Text properties on any characters are ignored.
+ (if pos
+ `(save-excursion
+ (goto-char ,pos)
+ (c-sub-at-c++-raw-string-opener))
+ `(c-sub-at-c++-raw-string-opener)))
+
;; The following is essentially `save-buffer-state' from lazy-lock.el.
;; It ought to be a standard macro.
(defmacro c-save-buffer-state (varlist &rest body)
(while
(and
(search-forward-regexp
- "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)("
+ c-c++-raw-string-opener-re
(1+ here) 'limit)
(< (point) here)))
(and (eq (point) (1+ here))
(match-beginning 1)
(goto-char (1- (match-beginning 1)))))))
(not (bobp)))))
- (eq (char-before) ?R)
- (looking-at "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)("))
+ (c-at-c++-raw-string-opener))
(setq open-quote-pos (point)
open-paren-pos (match-end 1)
id (match-string-no-properties 1))
(concat "\\(" ; 1
c-anchored-cpp-prefix ; 2
"\\)\\|\\(" ; 3
- "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" ; 4
+ c-c++-raw-string-opener-re ; 4
"\\)")
finish t))
(when (save-excursion
(goto-char (match-end 2)) ; after the "#".
(while (and (< (point) eom)
(c-syntactic-re-search-forward
- "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" eom t))
+ c-c++-raw-string-opener-re eom t))
(c-depropertize-raw-string
(match-string-no-properties 1) ; id
(1+ (match-beginning 0)) ; open quote
(goto-char end)
(setq eoll (c-point 'eoll))
(when (and (null c-old-END-literality)
- (search-forward-regexp "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)("
- eoll t))
+ (search-forward-regexp c-c++-raw-string-opener-re eoll t))
(setq state (c-state-semi-pp-to-literal end))
(when (eq (cadr state) 'string)
(unwind-protect
(while
(and
(setq found
- (search-forward-regexp "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)("
+ (search-forward-regexp c-c++-raw-string-opener-re
c-new-END 'bound))
(<= (match-end 0) beg)))
(when (and found (<= (match-beginning 0) end))
'syntax-table)
'(1)))
(goto-char (1- (cadr c-old-beg-rs)))
- (unless (looking-at "R\"[^ ()\\\n\r\t]\\{0,16\\}(")
+ (unless (looking-at c-c++-raw-string-opener-re)
(c-clear-char-property (1+ (point)) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (1+ (point)))
(if (c-search-forward-char-property 'syntax-table '(15)
(and c-old-beg-rs
(eq (car c-old-beg-rs) 'open-delim)))
(goto-char (cadr c-old-beg-rs))
- (when (looking-at "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
+ (when (looking-at c-c++-raw-string-opener-1-re)
(setq id (match-string-no-properties 1))
(when (re-search-forward (concat ")" id "\"") nil t) ; No bound.
(setq c-new-END (point-max))
(string-start (and (eq (cadr state) 'string)
(car (cddr state))))
(raw-id (and string-start
- (save-excursion
- (goto-char string-start)
- (and (eq (char-before) ?R)
- (looking-at "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
- (match-string-no-properties 1)))))
+ (c-at-c++-raw-string-opener string-start)
+ (match-string-no-properties 1)))
(content-start (and raw-id (point))))
;; We go round the next loop twice per raw string, once for each "end".
(while (< (point) limit)
(memq (char-after) c-string-delims)) ; Ignore an unterminated raw string's (.
;; Opening " on last line of text (without EOL).
(c-clear-char-property (point) 'syntax-table)
- (c-truncate-semi-nonlit-pos-cache (point)))))
+ (c-truncate-semi-nonlit-pos-cache (point))
+ (setq c-new-BEG (min c-new-BEG (point))))))
(t (goto-char end) ; point-max
(when
(c-clear-char-property (point) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point)))))
- (unless (and c-multiline-string-start-char
- (not (c-characterp c-multiline-string-start-char)))
+ (unless
+ (or (and
+ ;; Don't set c-new-BEG/END if we're in a raw string.
+ (eq beg-literal-type 'string)
+ (c-at-c++-raw-string-opener (car beg-limits)))
+ (and c-multiline-string-start-char
+ (not (c-characterp c-multiline-string-start-char))))
(when (and (eq end-literal-type 'string)
(not (eq (char-before (cdr end-limits)) ?\()))
(c-clear-char-property (1- (cdr end-limits)) 'syntax-table)
- (c-truncate-semi-nonlit-pos-cache (1- (cdr end-limits))))
+ (c-truncate-semi-nonlit-pos-cache (1- (cdr end-limits)))
+ (setq c-new-END (max c-new-END (cdr end-limits))))
(when (and (eq beg-literal-type 'string)
(memq (char-after (car beg-limits)) c-string-delims))
(c-clear-char-property (car beg-limits) 'syntax-table)
- (c-truncate-semi-nonlit-pos-cache (car beg-limits))))))
+ (c-truncate-semi-nonlit-pos-cache (car beg-limits))
+ (setq c-new-BEG (min c-new-BEG (car beg-limits)))))))
(defun c-after-change-mark-abnormal-strings (beg end _old-len)
;; Mark any unbalanced strings in the region (c-new-BEG c-new-END) with
(car beg-limits))
(t ; comment
(cdr beg-limits))))
+ ;; Handle one string each time around the next while loop.
(while
(and
(< (point) c-new-END)
(cond
((memq (char-after (match-end 0)) '(?\n ?\r))
(c-put-char-property (1- (point)) 'syntax-table '(15))
- (c-put-char-property (match-end 0) 'syntax-table '(15)))
+ (c-put-char-property (match-end 0) 'syntax-table '(15))
+ (setq c-new-BEG (min c-new-BEG (point))
+ c-new-END (max c-new-END (match-end 0))))
((or (eq (match-end 0) (point-max))
(eq (char-after (match-end 0)) ?\\)) ; \ at EOB
- (c-put-char-property (1- (point)) 'syntax-table '(15))))
+ (c-put-char-property (1- (point)) 'syntax-table '(15))
+ (setq c-new-BEG (min c-new-BEG (point))
+ c-new-END (max c-new-END (match-end 0))) ; Do we need c-new-END?
+ ))
(goto-char (min (1+ (match-end 0)) (point-max))))
(setq s nil)))))