Function: comment-normalize-vars
comment-normalize-vars is a byte-compiled function defined in
newcomment.el.gz.
Signature
(comment-normalize-vars &optional NOERROR)
Documentation
Check and set up variables needed by other commenting functions.
All the comment-* commands call this function to set up various
variables, like comment-start, to ensure that the commenting
functions work correctly. Lisp callers of any other comment-*
function should first call this function explicitly.
Source Code
;; Defined in /usr/src/emacs/lisp/newcomment.el.gz
;;;###autoload
(defun comment-normalize-vars (&optional noerror)
"Check and set up variables needed by other commenting functions.
All the `comment-*' commands call this function to set up various
variables, like `comment-start', to ensure that the commenting
functions work correctly. Lisp callers of any other `comment-*'
function should first call this function explicitly."
(unless (and (not comment-start) noerror)
(unless comment-start
(let ((cs (read-string "No comment syntax is defined. Use: ")))
(if (zerop (length cs))
(error "No comment syntax defined")
(setq-local comment-start cs)
(setq-local comment-start-skip cs))))
;; comment-use-syntax
(when (eq comment-use-syntax 'undecided)
(setq-local comment-use-syntax
(let ((st (syntax-table))
(cs comment-start)
(ce (if (string= "" comment-end) "\n" comment-end)))
;; Try to skip over a comment using forward-comment
;; to see if the syntax tables properly recognize it.
(with-temp-buffer
(set-syntax-table st)
(insert cs " hello " ce)
(goto-char (point-min))
(and (forward-comment 1) (eobp))))))
;; comment-padding
(unless comment-padding (setq comment-padding 0))
(when (integerp comment-padding)
(setq comment-padding (make-string comment-padding ? )))
;; comment markers
;;(setq comment-start (comment-string-strip comment-start t nil))
;;(setq comment-end (comment-string-strip comment-end nil t))
;; comment-continue
(unless (or comment-continue (string= comment-end ""))
(setq-local comment-continue
(concat (if (string-match "\\S-\\S-" comment-start) " " "|")
(substring comment-start 1)))
;; Hasn't been necessary yet.
;; (unless (string-match comment-start-skip comment-continue)
;; (kill-local-variable 'comment-continue))
)
;; comment-skip regexps
(unless (and comment-start-skip
;; In case comment-start has changed since last time.
(string-match comment-start-skip comment-start))
(setq-local comment-start-skip
(concat (unless (eq comment-use-syntax t)
;; `syntax-ppss' will detect escaping.
"\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)")
"\\(?:\\s<+\\|"
(regexp-quote (comment-string-strip comment-start t t))
;; Let's not allow any \s- but only [ \t] since \n
;; might be both a comment-end marker and \s-.
"+\\)[ \t]*")))
(unless (and comment-end-skip
;; In case comment-end has changed since last time.
(string-match comment-end-skip
(if (string= "" comment-end) "\n" comment-end)))
(let ((ce (if (string= "" comment-end) "\n"
(comment-string-strip comment-end t t))))
(setq-local comment-end-skip
;; We use [ \t] rather than \s- because we don't want to
;; remove ^L in C mode when uncommenting.
(concat "[ \t]*\\(\\s>" (if comment-quote-nested "" "+")
"\\|" (regexp-quote (substring ce 0 1))
(if (and comment-quote-nested (<= (length ce) 1)) "" "+")
(regexp-quote (substring ce 1))
"\\)"))))))