Function: octave-fill-paragraph
octave-fill-paragraph is an interactive and byte-compiled function
defined in octave.el.gz.
Signature
(octave-fill-paragraph &optional ARG)
Documentation
Fill paragraph of Octave code, handling Octave comments.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/octave.el.gz
(defun octave-fill-paragraph (&optional _arg)
"Fill paragraph of Octave code, handling Octave comments."
;; FIXME: difference with generic fill-paragraph:
;; - code lines are only split, never joined.
;; - \n that end comments are never removed.
;; - insert continuation marker when splitting code lines.
(interactive "P")
(save-excursion
(let ((end (progn (forward-paragraph) (copy-marker (point) t)))
(beg (progn
(forward-paragraph -1)
(skip-chars-forward " \t\n")
(beginning-of-line)
(point)))
(cfc (current-fill-column))
comment-prefix)
(goto-char beg)
(while (< (point) end)
(condition-case nil
(indent-according-to-mode)
(error nil))
(move-to-column cfc)
;; First check whether we need to combine non-empty comment lines
(if (and (< (current-column) cfc)
(octave-in-comment-p)
(not (save-excursion
(beginning-of-line)
(looking-at "^\\s-*\\s<+\\s-*$"))))
;; This is a nonempty comment line which does not extend
;; past the fill column. If it is followed by a nonempty
;; comment line with the same comment prefix, try to
;; combine them, and repeat this until either we reach the
;; fill-column or there is nothing more to combine.
(progn
;; Get the comment prefix
(save-excursion
(beginning-of-line)
(while (and (re-search-forward "\\s<+")
(not (octave-in-comment-p))))
(setq comment-prefix (match-string 0)))
;; And keep combining ...
(while (and (< (current-column) cfc)
(save-excursion
(forward-line 1)
(and (looking-at
(concat "^\\s-*"
comment-prefix
"\\S<"))
(not (looking-at
(concat "^\\s-*"
comment-prefix
"\\s-*$"))))))
(delete-char 1)
(re-search-forward comment-prefix)
(delete-region (match-beginning 0) (match-end 0))
(fixup-whitespace)
(move-to-column cfc))))
;; We might also try to combine continued code lines> Perhaps
;; some other time ...
(skip-chars-forward "^ \t\n")
(delete-horizontal-space)
(if (or (< (current-column) cfc)
(and (= (current-column) cfc) (eolp)))
(forward-line 1)
(if (not (eolp)) (insert " "))
(or (funcall normal-auto-fill-function)
(forward-line 1))))
t)))