;; element is a list (HERE STATE END)), where HERE is the buffer position the
;; function was called for, STATE is the `parse-partial-sexp' state there, and
;; END is the end of the literal enclosing HERE, if any, or nil otherwise.
+;; N.B. END will be nil if the literal ends at EOB without a delimiter.
(defun c-full-trim-near-cache ()
;; Remove stale entries in `c-full-lit-near-cache', i.e. those whose END
;; (STATE) otherwise,
;; where STATE is the parsing state at HERE, TYPE is the type of the literal
;; enclosing HERE, (one of 'string, 'c, 'c++) and (BEG . END) is the
- ;; boundaries of that literal (including the delimiters).
+ ;; boundaries of that literal (including the delimiters), with END being nil
+ ;; if there is no end delimiter (i.e. the literal ends at EOB).
;;
;; Unless NOT-IN-DELIMITER is non-nil, when TO is inside a two-character
;; comment opener, this is recognized as being in a comment literal.
(base (car elt))
(near-base base)
(s (cadr elt))
+ s1
(end (car (cddr elt)))
far-base-and-state far-base far-s ty start)
(if (or
(t 'c)))
(setq start (nth 8 s))
(unless end
- (parse-partial-sexp here (point-max)
- nil ; TARGETDEPTH
- nil ; STOPBEFORE
- s ; OLDSTATE
- 'syntax-table) ; stop at end of literal
- (setq end (point)))
+ (setq s1 (parse-partial-sexp here (point-max)
+ nil ; TARGETDEPTH
+ nil ; STOPBEFORE
+ s ; OLDSTATE
+ 'syntax-table)); stop at EO literal
+ (unless (or (nth 3 s1) ; still in a string
+ (and (nth 4 s1)
+ (not (eq (nth 7 s1) 'syntax-table)))) ; still
+ ; in a
+ ; comment
+ (setq end (point))))
(unless (eq near-base here)
(c-full-put-near-cache-entry here s end))
(list s ty (cons start end)))
s
'syntax-table)
(point)))))
- (let ((pp-to-lit (c-full-pp-to-literal pos not-in-delimiter)))
- (car (cddr pp-to-lit))))))
+ (let* ((pp-to-lit (c-full-pp-to-literal pos not-in-delimiter))
+ (limits (car (cddr pp-to-lit))))
+ (if (and limits (null (cdr limits)))
+ (cons (car limits) (point-max))
+ limits)))))
(cond
(lit-limits)
(or (not (nth 3 s))
(not (memq (char-before) c-string-delims))))))
;; We're at the start of a string.
- (memq (char-before) c-string-delims)))
+ (and (memq (char-before) c-string-delims)
+ (not (nth 4 s))))) ; Check we're actually out of the
+ ; comment. not stuck at EOB
(unless (and (c-major-mode-is 'c++-mode)
(c-maybe-re-mark-raw-string))
(if (c-unescaped-nls-in-string-p (1- (point)))