Function: LaTeX-fill-region-as-para-do
LaTeX-fill-region-as-para-do is an interactive and byte-compiled
function defined in latex.el.
Signature
(LaTeX-fill-region-as-para-do FROM TO &optional JUSTIFY NOSQUEEZE SQUEEZE-AFTER)
Documentation
Fill the region defined by FROM and TO as one paragraph.
It removes any paragraph breaks in the region and extra newlines at the end,
indents and fills lines between the margins given by the
current-left-margin and current-fill-column functions.
(In most cases, the variable fill-column controls the width.)
It leaves point at the beginning of the line following the paragraph.
Normally performs justification according to the current-justification
function, but with a prefix arg, does full justification instead.
From a program, optional third arg JUSTIFY can specify any type of justification. Fourth arg NOSQUEEZE non-nil means not to make spaces between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil, means don't canonicalize spaces before that position.
Return the fill-prefix used for filling.
If sentence-end-double-space is non-nil, then period followed by one
space does not end a sentence, so don't break a line there.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
;; The content of `LaTeX-fill-region-as-para-do' was copied from the
;; function `fill-region-as-paragraph' in `fill.el' (CVS Emacs,
;; January 2004) and adapted to the needs of AUCTeX.
(defun LaTeX-fill-region-as-para-do (from to &optional justify
nosqueeze squeeze-after)
"Fill the region defined by FROM and TO as one paragraph.
It removes any paragraph breaks in the region and extra newlines at the end,
indents and fills lines between the margins given by the
`current-left-margin' and `current-fill-column' functions.
\(In most cases, the variable `fill-column' controls the width.)
It leaves point at the beginning of the line following the paragraph.
Normally performs justification according to the `current-justification'
function, but with a prefix arg, does full justification instead.
From a program, optional third arg JUSTIFY can specify any type of
justification. Fourth arg NOSQUEEZE non-nil means not to make spaces
between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
means don't canonicalize spaces before that position.
Return the `fill-prefix' used for filling.
If `sentence-end-double-space' is non-nil, then period followed by one
space does not end a sentence, so don't break a line there."
(declare (modes LaTeX-mode))
(interactive (progn
(barf-if-buffer-read-only)
(list (region-beginning) (region-end)
(if current-prefix-arg 'full))))
(unless (memq justify '(t nil none full center left right))
(setq justify 'full))
;; Make sure "to" is the endpoint.
(goto-char (min from to))
(setq to (max from to))
;; Ignore blank lines at beginning of region.
(skip-chars-forward " \t\n")
(let ((from-plus-indent (point))
(oneleft nil))
(beginning-of-line)
(setq from (point))
;; Delete all but one soft newline at end of region.
;; And leave TO before that one.
(goto-char to)
(while (and (> (point) from) (eq ?\n (char-after (1- (point)))))
(if (and oneleft
(not (and use-hard-newlines
(get-text-property (1- (point)) 'hard))))
(delete-char -1)
(backward-char 1)
(setq oneleft t)))
(setq to (copy-marker (point) t))
(goto-char from-plus-indent))
(if (not (> to (point)))
;; There is no paragraph, only whitespace: exit now.
(progn
(set-marker to nil)
nil)
(or justify (setq justify (current-justification)))
;; Don't let Adaptive Fill mode alter the fill prefix permanently.
(let ((fill-prefix fill-prefix))
;; Figure out how this paragraph is indented, if desired.
(when (and adaptive-fill-mode
(or (null fill-prefix) (string= fill-prefix "")))
(setq fill-prefix (fill-context-prefix from to))
;; Ignore a white-space only fill-prefix
;; if we indent-according-to-mode.
(when (and fill-prefix fill-indent-according-to-mode
(string-match "\\`[ \t]*\\'" fill-prefix))
(setq fill-prefix nil)))
(goto-char from)
(beginning-of-line)
(if (not justify) ; filling disabled: just check indentation
(progn
(goto-char from)
(while (< (point) to)
(if (and (not (eolp))
(< (LaTeX-current-indentation) (current-left-margin)))
(fill-indent-to-left-margin))
(forward-line 1)))
(when use-hard-newlines
(remove-text-properties from to '(hard nil)))
;; Make sure first line is indented (at least) to left margin...
(indent-according-to-mode)
;; Delete the fill-prefix from every line.
(fill-delete-prefix from to fill-prefix)
(setq from (point))
;; FROM, and point, are now before the text to fill,
;; but after any fill prefix on the first line.
(fill-delete-newlines from to justify nosqueeze squeeze-after)
;; This is the actual FILLING LOOP.
(goto-char from)
(let* (linebeg
(code-comment-start (save-excursion
(LaTeX-back-to-indentation)
(TeX-search-forward-comment-start
(line-end-position))))
(end-marker (save-excursion
(goto-char (or code-comment-start to))
(point-marker)))
(LaTeX-current-environment (LaTeX-current-environment)))
;; Fill until point is greater than the end point. If there
;; is a code comment, use the code comment's start as a
;; limit.
(while (and (< (point) (marker-position end-marker))
(or (not code-comment-start)
(and code-comment-start
(> (- (marker-position end-marker)
(line-beginning-position))
fill-column))))
(setq linebeg (point))
(move-to-column (current-fill-column))
(if (when (< (point) (marker-position end-marker))
;; Find the position where we'll break the line.
(forward-char 1) ; Use an immediately following
; space, if any.
(LaTeX-fill-move-to-break-point linebeg)
;; Check again to see if we got to the end of
;; the paragraph.
(skip-chars-forward " \t")
(< (point) (marker-position end-marker)))
;; Found a place to cut.
(progn
(LaTeX-fill-newline)
(when justify
;; Justify the line just ended, if desired.
(save-excursion
(forward-line -1)
(justify-current-line justify nil t))))
(goto-char end-marker)
;; Justify this last line, if desired.
(if justify (justify-current-line justify t t))))
;; Fill a code comment if necessary. (Enable this code if
;; you want the comment part in lines with code comments to
;; be filled. Originally it was disabled because the
;; indentation code indented the lines following the line
;; with the code comment to the column of the comment
;; starters. That means, it would have looked like this:
;; | code code code % comment
;; | % comment
;; | code code code
;; This now (2005-07-29) is not the case anymore. But as
;; filling code comments like this would split a single
;; paragraph into two separate ones, we still leave it
;; disabled. I leave the code here in case it is useful for
;; somebody.
;; (when (and code-comment-start
;; (> (- (line-end-position) (line-beginning-position))
;; fill-column))
;; (LaTeX-fill-code-comment justify))
;; The following is an alternative strategy to minimize the
;; occurence of overfull lines with code comments. A line
;; will be broken before the last non-comment word if the
;; code comment does not fit into the line.
(when (and LaTeX-fill-break-before-code-comments
code-comment-start
(> (- (line-end-position) (line-beginning-position))
fill-column))
(beginning-of-line)
(goto-char end-marker)
(while (not (looking-at TeX-comment-start-regexp)) (forward-char))
(skip-chars-backward " \t")
(skip-chars-backward "^ \t\n")
(unless (or (bolp)
;; Comment starters and whitespace.
(TeX-looking-at-backward
(concat "^\\([ \t]*" TeX-comment-start-regexp "+\\)*"
"[ \t]*")
(line-beginning-position)))
(LaTeX-fill-newline)))
(set-marker end-marker nil)))
;; Leave point after final newline.
(goto-char to)
(unless (eobp) (forward-char 1))
(set-marker to nil)
;; Return the fill-prefix we used
fill-prefix)))