Function: comment-valid-prefix-p
comment-valid-prefix-p is a byte-compiled function defined in
newcomment.el.gz.
Signature
(comment-valid-prefix-p PREFIX COMPOS)
Documentation
Check that the adaptive fill prefix is consistent with the context.
PREFIX is the prefix (presumably guessed by adaptive-fill-mode).
COMPOS is the position of the beginning of the comment we're in, or nil
if we're not inside a comment.
Source Code
;; Defined in /usr/src/emacs/lisp/newcomment.el.gz
(defun comment-valid-prefix-p (prefix compos)
"Check that the adaptive fill prefix is consistent with the context.
PREFIX is the prefix (presumably guessed by `adaptive-fill-mode').
COMPOS is the position of the beginning of the comment we're in, or nil
if we're not inside a comment."
;; This consistency checking is mostly needed to workaround the limitation
;; of auto-fill-mode whose paragraph-determination doesn't pay attention
;; to comment boundaries.
(if (null compos)
;; We're not inside a comment: the prefix shouldn't match
;; a comment-starter.
(not (and comment-start comment-start-skip
(string-match comment-start-skip prefix)))
(or
;; Accept any prefix if the current comment is not EOL-terminated.
(save-excursion (goto-char compos) (comment-forward) (not (bolp)))
;; Accept any prefix that starts with the same comment-start marker
;; as the current one.
(when (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
prefix)
(let ((prefix-com (comment-string-strip (match-string 0 prefix) nil t)))
(string-match "\\`[ \t]*" prefix-com)
(let* ((prefix-space (match-string 0 prefix-com))
(prefix-indent (string-width prefix-space))
(prefix-comstart (substring prefix-com (match-end 0))))
(save-excursion
(goto-char compos)
;; The comstart marker is the same.
(and (looking-at (regexp-quote prefix-comstart))
;; The indentation as well.
(or (= prefix-indent
(- (current-column) (current-left-margin)))
;; Check the indentation in two different ways, just
;; to try and avoid most of the potential funny cases.
(equal prefix-space
(buffer-substring (point)
(progn (move-to-left-margin)
(point)))))))))))))