Function: c-ts-common--adaptive-fill-prefix
c-ts-common--adaptive-fill-prefix is a byte-compiled function defined
in c-ts-common.el.gz.
Signature
(c-ts-common--adaptive-fill-prefix)
Documentation
Returns the appropriate fill-prefix for this paragraph.
This function should be called at BOL. Used by
adaptive-fill-function.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/c-ts-common.el.gz
(defun c-ts-common--adaptive-fill-prefix ()
"Returns the appropriate fill-prefix for this paragraph.
This function should be called at BOL. Used by
`adaptive-fill-function'."
(cond
;; (1)
;; If current line is /* and next line is * -> prefix is *.
;; Eg:
;; /* xxx => /* xxx
;; * xxx xxx * xxx
;; * xxx
;; If current line is /* and next line isn't * or doesn't exist ->
;; prefix is whitespace.
;; Eg:
;; /* xxx xxx */ => /* xxx
;; xxx */
((and (looking-at (rx (* (syntax whitespace))
"/*"
(* "*")
(* (syntax whitespace))))
(let ((whitespaces (make-string (length (match-string 0)) ?\s)))
(save-excursion
(if (and (eq (forward-line) 0)
(looking-at (rx (* (syntax whitespace))
"*"
(* (syntax whitespace)))))
(match-string 0)
whitespaces)))))
;; (2)
;; Current line: //, ///, ////...
;; Prefix: same.
((looking-at (rx (* (syntax whitespace))
"//"
(* "/")
(* (syntax whitespace))))
(match-string 0))
;; (3)
;; Current line: *, |, -
;; Prefix: same.
;; Adaptive fill looks at the first and second line of a paragraph,
;; only when both lines return the same prefix does it use that
;; prefix for the following lines. If the first lines matches branch
;; (1) and returns * as prefix, and the second line matches this
;; branch (3), and returns * as prefix, then the whole paragraph will
;; use * as prefix.
((looking-at (rx (* (syntax whitespace))
(or "*" "|" "-")
(* (syntax whitespace))))
(match-string 0))
;; Other: let `adaptive-fill-regexp' and
;; `adaptive-fill-first-line-regexp' decide.
(t nil)))