Function: cpp-highlight-buffer
cpp-highlight-buffer is an autoloaded, interactive and byte-compiled
function defined in cpp.el.gz.
Signature
(cpp-highlight-buffer ARG)
Documentation
Highlight C code according to preprocessor conditionals.
This command pops up a buffer which you should edit to specify what kind of highlighting to use, and the criteria for highlighting. A prefix arg suppresses display of that buffer.
Probably introduced at or before Emacs version 19.29.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cpp.el.gz
;;;###autoload
(defun cpp-highlight-buffer (arg)
"Highlight C code according to preprocessor conditionals.
This command pops up a buffer which you should edit to specify
what kind of highlighting to use, and the criteria for highlighting.
A prefix arg suppresses display of that buffer."
(interactive "P")
(unless (or (eq t buffer-invisibility-spec)
(memq 'cpp buffer-invisibility-spec))
(add-to-invisibility-spec 'cpp))
(setq cpp-parse-symbols nil)
(cpp-parse-reset)
(if (null cpp-edit-list)
(cpp-edit-load))
(let ((reporter
(and cpp-message-min-time-interval
(make-progress-reporter "Parsing..." (point-min) (point-max)
nil nil cpp-message-min-time-interval)))
cpp-state-stack)
(save-excursion
(goto-char (point-min))
(while (re-search-forward cpp-parse-regexp nil t)
(when reporter (progress-reporter-update reporter (point)))
(let ((match (buffer-substring (match-beginning 0) (match-end 0))))
(cond ((or (string-equal match "'")
(string-equal match "\""))
(goto-char (match-beginning 0))
(condition-case nil
(forward-sexp)
(error (cpp-parse-error
"Unterminated string or character"))))
((string-equal match "/*")
(or (search-forward "*/" nil t)
(error "Unterminated comment")))
((string-equal match "//")
(skip-chars-forward "^\n\r"))
(t
(end-of-line 1)
(let ((from (match-beginning 1))
(to (1+ (point)))
(type (buffer-substring (match-beginning 2)
(match-end 2)))
(expr (buffer-substring (match-end 1) (point))))
(cond ((string-equal type "ifdef")
(cpp-parse-open t expr from to))
((string-equal type "ifndef")
(cpp-parse-open nil expr from to))
((string-equal type "if")
(cpp-parse-open t expr from to))
((string-equal type "elif")
(let (cpp-known-face cpp-unknown-face)
(cpp-parse-close from to))
(cpp-parse-open t expr from to))
((string-equal type "else")
(or cpp-state-stack
(cpp-parse-error "Top level #else"))
(let ((entry (list (not (nth 0 (car cpp-state-stack)))
(nth 1 (car cpp-state-stack))
from to)))
(cpp-parse-close from to)
(setq cpp-state-stack (cons entry cpp-state-stack))))
((string-equal type "endif")
(cpp-parse-close from to))
(t
(cpp-parse-error "Parser error"))))))))
(when reporter (progress-reporter-done reporter)))
(if cpp-state-stack
(save-excursion
(goto-char (nth 3 (car cpp-state-stack)))
(cpp-parse-error "Unclosed conditional"))))
(or arg
(null cpp-parse-symbols)
(cpp-parse-edit)))