Function: c-after-change-fix-comment-escapes
c-after-change-fix-comment-escapes is a byte-compiled function defined
in cc-mode.el.gz.
Signature
(c-after-change-fix-comment-escapes BEG END OLD-LEN)
Documentation
Apply punctuation syntax-table text properties to C/C++ comment markers.
This is to handle the rare case of two or more backslashes at an end of line in a // comment or the equally rare case of a backslash preceding the terminator of a /* comment, as \*/.
This function is used solely as a member of
c-before-font-lock-functions, where it should appear early in
that variable, and it must be used only together with
c-before-change-fix-comment-escapes.
Note that the function currently only handles comments beginning with // and /*, not more generic line and block comments.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-mode.el.gz
(defun c-after-change-fix-comment-escapes (beg end _old-len)
"Apply punctuation syntax-table text properties to C/C++ comment markers.
This is to handle the rare case of two or more backslashes at an
end of line in a // comment or the equally rare case of a
backslash preceding the terminator of a /* comment, as \\*/.
This function is used solely as a member of
`c-before-font-lock-functions', where it should appear early in
that variable, and it must be used only together with
`c-before-change-fix-comment-escapes'.
Note that the function currently only handles comments beginning
with // and /*, not more generic line and block comments."
(c-save-buffer-state (state)
;; We cannot use `c-full-pp-to-literal' in this function, since the
;; `syntax-table' text properties after point are not yet in a consistent
;; state.
(setq state (c-semi-pp-to-literal beg))
(goto-char (if (memq (cadr state) '(c c++))
(caddr state)
(max (- beg 2) (point-min))))
(while
(re-search-forward "\\\\\\(\\(\\\\\n\\)\\|\\(\\*/\\)\\)"
(min (+ end 2) (point-max)) t)
(setq state (c-semi-pp-to-literal (match-beginning 0)))
(when (cond
((eq (cadr state) 'c)
(match-beginning 3))
((eq (cadr state) 'c++)
(match-beginning 2)))
(c-put-char-property (match-beginning 0) 'syntax-table '(1))
(c-truncate-lit-pos-cache (match-beginning 0))))
(goto-char end)
(setq state (c-semi-pp-to-literal (point)))
(cond
((eq (cadr state) 'c)
(when (search-forward "*/" nil t)
(when (eq (char-before (match-beginning 0)) ?\\)
(c-put-char-property (1- (match-beginning 0)) 'syntax-table '(1))
(c-truncate-lit-pos-cache (1- (match-beginning 0))))))
((eq (cadr state) 'c++)
(while
(progn
(end-of-line)
(and (eq (char-before) ?\\)
(progn
(when (eq (char-before (1- (point))) ?\\)
(c-put-char-property (- (point) 2) 'syntax-table '(1))
(c-truncate-lit-pos-cache (1- (point))))
t)
(not (eobp))))
(forward-char))))))