1992-05-30 23:54:21 +00:00
|
|
|
|
;;; fill.el --- fill commands for Emacs
|
|
|
|
|
|
1997-06-17 21:46:40 +00:00
|
|
|
|
;; Copyright (C) 1985, 86, 92, 94, 95, 96, 1997 Free Software Foundation, Inc.
|
1990-07-27 04:20:16 +00:00
|
|
|
|
|
1992-07-22 04:22:42 +00:00
|
|
|
|
;; Keywords: wp
|
|
|
|
|
|
1990-07-27 04:20:16 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
1990-07-27 04:20:16 +00:00
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
1990-07-27 04:20:16 +00:00
|
|
|
|
|
1993-03-22 03:27:18 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; All the commands for filling text. These are documented in the Emacs
|
|
|
|
|
;; manual.
|
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;;; Code:
|
1990-07-27 04:20:16 +00:00
|
|
|
|
|
1997-05-05 15:00:53 +00:00
|
|
|
|
(defcustom fill-individual-varying-indent nil
|
1992-05-10 18:15:10 +00:00
|
|
|
|
"*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
|
|
|
|
|
Non-nil means changing indent doesn't end a paragraph.
|
|
|
|
|
That mode can handle paragraphs with extra indentation on the first line,
|
|
|
|
|
but it requires separator lines between paragraphs.
|
1997-05-05 15:00:53 +00:00
|
|
|
|
A value of nil means that any change in indentation starts a new paragraph."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'fill)
|
1994-02-04 04:45:52 +00:00
|
|
|
|
|
1997-05-05 15:00:53 +00:00
|
|
|
|
(defcustom sentence-end-double-space t
|
|
|
|
|
"*Non-nil means a single space does not end a sentence."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'fill)
|
1992-05-10 18:15:10 +00:00
|
|
|
|
|
1997-05-05 15:00:53 +00:00
|
|
|
|
(defcustom colon-double-space nil
|
|
|
|
|
"*Non-nil means put two spaces after a colon when filling."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'fill)
|
1995-08-02 18:36:20 +00:00
|
|
|
|
|
1995-02-02 09:50:23 +00:00
|
|
|
|
(defvar fill-paragraph-function nil
|
1995-12-24 23:30:18 +00:00
|
|
|
|
"Mode-specific function to fill a paragraph, or nil if there is none.
|
|
|
|
|
If the function returns nil, then `fill-paragraph' does its normal work.")
|
1995-02-02 09:50:23 +00:00
|
|
|
|
|
1997-05-17 02:01:42 +00:00
|
|
|
|
(defvar enable-kinsoku t
|
|
|
|
|
"*Non-nil means enable `kinsoku' processing on filling paragraph.
|
|
|
|
|
`Kinsoku' processing is to prohibit specific characters to be placed
|
|
|
|
|
at beginning or end of line. See the documentation of kinsoku for
|
|
|
|
|
more detail.")
|
1997-02-20 05:33:51 +00:00
|
|
|
|
|
1990-07-27 04:20:16 +00:00
|
|
|
|
(defun set-fill-prefix ()
|
1994-02-04 04:45:52 +00:00
|
|
|
|
"Set the fill prefix to the current line up to point.
|
1991-03-20 04:10:45 +00:00
|
|
|
|
Filling expects lines to start with the fill prefix and
|
|
|
|
|
reinserts the fill prefix in each resulting line."
|
1990-07-27 04:20:16 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(setq fill-prefix (buffer-substring
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(save-excursion (move-to-left-margin) (point))
|
1990-07-27 04:20:16 +00:00
|
|
|
|
(point)))
|
|
|
|
|
(if (equal fill-prefix "")
|
|
|
|
|
(setq fill-prefix nil))
|
|
|
|
|
(if fill-prefix
|
|
|
|
|
(message "fill-prefix: \"%s\"" fill-prefix)
|
|
|
|
|
(message "fill-prefix cancelled")))
|
|
|
|
|
|
1997-05-05 15:00:53 +00:00
|
|
|
|
(defcustom adaptive-fill-mode t
|
|
|
|
|
"*Non-nil means determine a paragraph's fill prefix from its text."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'fill)
|
1991-03-20 04:10:45 +00:00
|
|
|
|
|
1997-06-11 06:51:29 +00:00
|
|
|
|
(defcustom adaptive-fill-regexp "[ \t]*\\([-|#;>*]+ *\\|(?[0-9]+[.)] *\\)*"
|
1991-03-20 04:10:45 +00:00
|
|
|
|
"*Regexp to match text at start of line that constitutes indentation.
|
1997-06-11 06:51:29 +00:00
|
|
|
|
If Adaptive Fill mode is enabled, a prefix matching this pattern
|
|
|
|
|
on the first and second lines of a paragraph is used as the
|
|
|
|
|
standard indentation for the whole paragraph.
|
|
|
|
|
|
|
|
|
|
If the paragraph has just one line, the indentation is taken from that
|
|
|
|
|
line, but in that case `adaptive-fill-first-line-regexp' also plays
|
|
|
|
|
a role."
|
|
|
|
|
:type 'regexp
|
|
|
|
|
:group 'fill)
|
|
|
|
|
|
|
|
|
|
(defcustom adaptive-fill-first-line-regexp "\\`[ \t]*$`//'"
|
|
|
|
|
"*Regexp specifying whether to set fill prefix from a one-line paragraph.
|
|
|
|
|
When a paragraph has just one line, then after `adaptive-fill-regexp'
|
|
|
|
|
finds the prefix at the beginning of the line, if it doesn't
|
|
|
|
|
match this regexp, it is replaced with whitespace.
|
|
|
|
|
|
|
|
|
|
By default, this regexp matches sequences of just spaces and tabs.
|
|
|
|
|
|
|
|
|
|
However, we never use a prefix from a one-line paragraph
|
|
|
|
|
if it would act as a paragraph-starter on the second line."
|
1997-05-05 15:00:53 +00:00
|
|
|
|
:type 'regexp
|
|
|
|
|
:group 'fill)
|
1991-03-20 04:10:45 +00:00
|
|
|
|
|
1997-05-05 15:00:53 +00:00
|
|
|
|
(defcustom adaptive-fill-function nil
|
1995-08-02 18:36:20 +00:00
|
|
|
|
"*Function to call to choose a fill prefix for a paragraph.
|
1997-05-05 15:00:53 +00:00
|
|
|
|
This function is used when `adaptive-fill-regexp' does not match."
|
|
|
|
|
:type 'function
|
|
|
|
|
:group 'fill)
|
1995-08-02 18:36:20 +00:00
|
|
|
|
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(defun current-fill-column ()
|
|
|
|
|
"Return the fill-column to use for this line.
|
|
|
|
|
The fill-column to use for a buffer is stored in the variable `fill-column',
|
|
|
|
|
but can be locally modified by the `right-margin' text property, which is
|
|
|
|
|
subtracted from `fill-column'.
|
|
|
|
|
|
|
|
|
|
The fill column to use for a line is the first column at which the column
|
|
|
|
|
number equals or exceeds the local fill-column - right-margin difference."
|
|
|
|
|
(save-excursion
|
1995-06-29 03:21:26 +00:00
|
|
|
|
(if fill-column
|
|
|
|
|
(let* ((here (progn (beginning-of-line) (point)))
|
|
|
|
|
(here-col 0)
|
|
|
|
|
(eol (progn (end-of-line) (point)))
|
|
|
|
|
margin fill-col change col)
|
|
|
|
|
;; Look separately at each region of line with a different right-margin.
|
|
|
|
|
(while (and (setq margin (get-text-property here 'right-margin)
|
|
|
|
|
fill-col (- fill-column (or margin 0))
|
|
|
|
|
change (text-property-not-all
|
|
|
|
|
here eol 'right-margin margin))
|
|
|
|
|
(progn (goto-char (1- change))
|
|
|
|
|
(setq col (current-column))
|
|
|
|
|
(< col fill-col)))
|
|
|
|
|
(setq here change
|
|
|
|
|
here-col col))
|
|
|
|
|
(max here-col fill-col)))))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(defun canonically-space-region (beg end)
|
|
|
|
|
"Remove extra spaces between words in region.
|
1996-02-21 21:20:28 +00:00
|
|
|
|
Leave one space between words, two at end of sentences or after colons
|
|
|
|
|
(depending on values of `sentence-end-double-space' and `colon-double-space').
|
1995-07-17 22:50:30 +00:00
|
|
|
|
Remove indentation from each line."
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(interactive "r")
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
;; Nuke tabs; they get screwed up in a fill.
|
|
|
|
|
;; This is quick, but loses when a tab follows the end of a sentence.
|
|
|
|
|
;; Actually, it is difficult to tell that from "Mr.\tSmith".
|
|
|
|
|
;; Blame the typist.
|
|
|
|
|
(subst-char-in-region beg end ?\t ?\ )
|
|
|
|
|
(while (and (< (point) end)
|
|
|
|
|
(re-search-forward " *" end t))
|
|
|
|
|
(delete-region
|
|
|
|
|
(+ (match-beginning 0)
|
|
|
|
|
;; Determine number of spaces to leave:
|
|
|
|
|
(save-excursion
|
|
|
|
|
(skip-chars-backward " ]})\"'")
|
|
|
|
|
(cond ((and sentence-end-double-space
|
|
|
|
|
(memq (preceding-char) '(?. ?? ?!))) 2)
|
1995-08-02 18:36:20 +00:00
|
|
|
|
((and colon-double-space
|
|
|
|
|
(= (preceding-char) ?:)) 2)
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
((char-equal (preceding-char) ?\n) 0)
|
|
|
|
|
(t 1))))
|
|
|
|
|
(match-end 0)))
|
|
|
|
|
;; Make sure sentences ending at end of line get an extra space.
|
|
|
|
|
;; loses on split abbrevs ("Mr.\nSmith")
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(while (and (< (point) end)
|
|
|
|
|
(re-search-forward "[.?!][])}\"']*$" end t))
|
1996-02-21 21:20:28 +00:00
|
|
|
|
;; We insert before markers in case a caller such as
|
|
|
|
|
;; do-auto-fill has done a save-excursion with point at the end
|
|
|
|
|
;; of the line and wants it to stay at the end of the line.
|
|
|
|
|
(insert-before-markers-and-inherit ? ))))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
1995-11-18 16:42:57 +00:00
|
|
|
|
(defun fill-context-prefix (from to &optional first-line-regexp)
|
1995-11-10 17:13:56 +00:00
|
|
|
|
"Compute a fill prefix from the text between FROM and TO.
|
1997-06-11 06:51:29 +00:00
|
|
|
|
This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'
|
|
|
|
|
and `adaptive-fill-first-line-regexp'. `paragraph-start' also plays a role;
|
|
|
|
|
we reject a prefix based on a one-line paragraph if that prefix would
|
|
|
|
|
act as a paragraph-separator."
|
|
|
|
|
(or first-line-regexp
|
|
|
|
|
(setq first-line-regexp adaptive-fill-first-line-regexp))
|
1995-11-10 17:13:56 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char from)
|
|
|
|
|
(if (eolp) (forward-line 1))
|
|
|
|
|
;; Move to the second line unless there is just one.
|
1995-11-18 16:42:57 +00:00
|
|
|
|
(let ((firstline (point))
|
1997-06-17 21:46:40 +00:00
|
|
|
|
first-line-prefix
|
1995-11-18 16:42:57 +00:00
|
|
|
|
;; Non-nil if we are on the second line.
|
|
|
|
|
at-second
|
1997-06-17 21:46:40 +00:00
|
|
|
|
second-line-prefix
|
|
|
|
|
start)
|
|
|
|
|
(move-to-left-margin)
|
|
|
|
|
(setq start (point))
|
|
|
|
|
(setq first-line-prefix
|
|
|
|
|
(cond ((looking-at paragraph-start) nil)
|
|
|
|
|
((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
|
|
|
|
|
(buffer-substring-no-properties start (match-end 0)))
|
|
|
|
|
(adaptive-fill-function (funcall adaptive-fill-function))))
|
1995-11-10 17:13:56 +00:00
|
|
|
|
(forward-line 1)
|
|
|
|
|
(if (>= (point) to)
|
1995-11-18 16:42:57 +00:00
|
|
|
|
(goto-char firstline)
|
1997-06-17 21:46:40 +00:00
|
|
|
|
(setq at-second t)
|
|
|
|
|
(move-to-left-margin)
|
|
|
|
|
(setq start (point))
|
|
|
|
|
(setq second-line-prefix
|
|
|
|
|
(cond ((looking-at paragraph-start) nil)
|
|
|
|
|
((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
|
|
|
|
|
(buffer-substring-no-properties start (match-end 0)))
|
|
|
|
|
(adaptive-fill-function (funcall adaptive-fill-function)))))
|
|
|
|
|
(if at-second
|
|
|
|
|
;; If we get a fill prefix from the second line,
|
|
|
|
|
;; make sure it or something compatible is on the first line too.
|
|
|
|
|
(and second-line-prefix
|
|
|
|
|
(if (or (string-match (regexp-quote second-line-prefix)
|
|
|
|
|
first-line-prefix)
|
|
|
|
|
(and (string-match "[ \t]" second-line-prefix)
|
|
|
|
|
(>= (string-width first-line-prefix)
|
|
|
|
|
(string-width second-line-prefix))))
|
|
|
|
|
second-line-prefix))
|
|
|
|
|
;; If we get a fill prefix from a one-line paragraph,
|
|
|
|
|
;; maybe change it to whitespace,
|
|
|
|
|
;; and check that it isn't a paragraph starter.
|
|
|
|
|
(if first-line-prefix
|
|
|
|
|
(let ((result
|
|
|
|
|
;; If first-line-prefix comes from the first line,
|
|
|
|
|
;; see if it seems reasonable to use for all lines.
|
|
|
|
|
;; If not, replace it with whitespace.
|
|
|
|
|
(if (or (and first-line-regexp
|
|
|
|
|
(string-match first-line-regexp
|
|
|
|
|
first-line-prefix))
|
|
|
|
|
(and comment-start-skip
|
|
|
|
|
(string-match comment-start-skip
|
|
|
|
|
first-line-prefix)))
|
|
|
|
|
first-line-prefix
|
|
|
|
|
(make-string (string-width first-line-prefix) ?\ ))))
|
|
|
|
|
;; But either way, reject it if it indicates the start
|
|
|
|
|
;; of a paragraph when text follows it.
|
|
|
|
|
(if (not (eq 0 (string-match paragraph-start
|
|
|
|
|
(concat result "a"))))
|
1997-06-17 21:47:30 +00:00
|
|
|
|
result)))))))
|
1995-11-10 17:13:56 +00:00
|
|
|
|
|
1996-02-21 21:20:28 +00:00
|
|
|
|
(defun fill-region-as-paragraph (from to &optional justify
|
|
|
|
|
nosqueeze squeeze-after)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
"Fill the region as one paragraph.
|
1995-11-17 23:32:15 +00:00
|
|
|
|
It removes any paragraph breaks in the region and extra newlines at the end,
|
1995-02-23 18:22:04 +00:00
|
|
|
|
indents and fills lines between the margins given by the
|
|
|
|
|
`current-left-margin' and `current-fill-column' functions.
|
1995-11-17 23:32:15 +00:00
|
|
|
|
It leaves point at the beginning of the line following the paragraph.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
1995-02-23 18:22:04 +00:00
|
|
|
|
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
|
1996-02-21 21:20:28 +00:00
|
|
|
|
justification. Fourth arg NOSQUEEZE non-nil means not to make spaces
|
1996-02-22 02:57:50 +00:00
|
|
|
|
between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
|
1996-02-21 21:20:28 +00:00
|
|
|
|
means don't canonicalize spaces before that position.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
1994-02-04 04:45:52 +00:00
|
|
|
|
If `sentence-end-double-space' is non-nil, then period followed by one
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
space does not end a sentence, so don't break a line there."
|
1995-04-10 08:02:39 +00:00
|
|
|
|
(interactive (list (region-beginning) (region-end)
|
|
|
|
|
(if current-prefix-arg 'full)))
|
1992-10-04 04:10:02 +00:00
|
|
|
|
;; Arrange for undoing the fill to restore point.
|
|
|
|
|
(if (and buffer-undo-list (not (eq buffer-undo-list t)))
|
|
|
|
|
(setq buffer-undo-list (cons (point) buffer-undo-list)))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
|
1995-11-17 23:32:15 +00:00
|
|
|
|
;; Make sure "to" is the endpoint.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(goto-char (min from to))
|
|
|
|
|
(setq to (max from to))
|
1995-11-17 23:32:15 +00:00
|
|
|
|
;; Ignore blank lines at beginning of region.
|
|
|
|
|
(skip-chars-forward " \t\n")
|
1995-02-23 18:22:04 +00:00
|
|
|
|
|
1995-11-17 23:32:15 +00:00
|
|
|
|
(let ((from-plus-indent (point))
|
|
|
|
|
(oneleft nil))
|
|
|
|
|
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(setq from (point))
|
|
|
|
|
|
|
|
|
|
;; Delete all but one soft newline at end of region.
|
1996-01-09 23:18:07 +00:00
|
|
|
|
;; And leave TO before that one.
|
1995-11-17 23:32:15 +00:00
|
|
|
|
(goto-char to)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(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-backward-char 1)
|
|
|
|
|
(backward-char 1)
|
|
|
|
|
(setq oneleft t)))
|
1995-11-17 23:32:15 +00:00
|
|
|
|
(setq to (point))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
|
1995-11-17 23:32:15 +00:00
|
|
|
|
;; If there was no newline, and there is text in the paragraph, then
|
|
|
|
|
;; create a newline.
|
|
|
|
|
(if (and (not oneleft) (> to from-plus-indent))
|
|
|
|
|
(newline))
|
|
|
|
|
(goto-char from-plus-indent))
|
|
|
|
|
|
|
|
|
|
(if (not (> to (point)))
|
|
|
|
|
nil ; There is no paragraph, only whitespace: exit now.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
|
|
|
|
|
(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.
|
|
|
|
|
(if (and adaptive-fill-mode
|
|
|
|
|
(or (null fill-prefix) (string= fill-prefix "")))
|
1995-11-10 17:13:56 +00:00
|
|
|
|
(setq fill-prefix (fill-context-prefix from to)))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(save-restriction
|
|
|
|
|
(goto-char from)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(narrow-to-region (point) to)
|
|
|
|
|
|
|
|
|
|
(if (not justify) ; filling disabled: just check indentation
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char from)
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(if (and (not (eolp))
|
|
|
|
|
(< (current-indentation) (current-left-margin)))
|
|
|
|
|
(indent-to-left-margin))
|
|
|
|
|
(forward-line 1)))
|
|
|
|
|
|
|
|
|
|
(if use-hard-newlines
|
|
|
|
|
(remove-text-properties from (point-max) '(hard nil)))
|
|
|
|
|
;; Make sure first line is indented (at least) to left margin...
|
|
|
|
|
(if (or (memq justify '(right center))
|
|
|
|
|
(< (current-indentation) (current-left-margin)))
|
|
|
|
|
(indent-to-left-margin))
|
|
|
|
|
;; Delete the fill prefix from every line except the first.
|
|
|
|
|
;; The first line may not even have a fill prefix.
|
|
|
|
|
(goto-char from)
|
|
|
|
|
(let ((fpre (and fill-prefix (not (equal fill-prefix ""))
|
|
|
|
|
(concat "[ \t]*"
|
|
|
|
|
(regexp-quote fill-prefix)
|
|
|
|
|
"[ \t]*"))))
|
|
|
|
|
(and fpre
|
|
|
|
|
(progn
|
|
|
|
|
(if (>= (+ (current-left-margin) (length fill-prefix))
|
|
|
|
|
(current-fill-column))
|
|
|
|
|
(error "fill-prefix too long for specified width"))
|
|
|
|
|
(goto-char from)
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(if (looking-at fpre)
|
|
|
|
|
(delete-region (point) (match-end 0)))
|
|
|
|
|
(forward-line 1))
|
|
|
|
|
(goto-char from)
|
1996-02-21 21:20:28 +00:00
|
|
|
|
(if (looking-at fpre)
|
|
|
|
|
(goto-char (match-end 0)))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(setq from (point)))))
|
1995-04-02 00:11:19 +00:00
|
|
|
|
;; Remove indentation from lines other than the first.
|
|
|
|
|
(beginning-of-line 2)
|
|
|
|
|
(indent-region (point) (point-max) 0)
|
|
|
|
|
(goto-char from)
|
|
|
|
|
|
|
|
|
|
;; FROM, and point, are now before the text to fill,
|
1995-02-23 18:22:04 +00:00
|
|
|
|
;; but after any fill prefix on the first line.
|
|
|
|
|
|
|
|
|
|
;; Make sure sentences ending at end of line get an extra space.
|
|
|
|
|
;; loses on split abbrevs ("Mr.\nSmith")
|
|
|
|
|
(while (re-search-forward "[.?!][])}\"']*$" nil t)
|
1995-11-10 17:13:56 +00:00
|
|
|
|
(or (eobp) (insert-and-inherit ?\ )))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(goto-char from)
|
1997-02-20 05:33:51 +00:00
|
|
|
|
;; The character category `|' means that we can break a line
|
|
|
|
|
;; at the character. Since we don't need a space between
|
|
|
|
|
;; them, delete all newlines between them ...
|
|
|
|
|
(while (re-search-forward "\\c|\n\\|\n\\c|" nil t)
|
|
|
|
|
(if (bolp)
|
|
|
|
|
(delete-char -1)
|
|
|
|
|
(if (= (char-before (match-beginning 0)) ?\ )
|
|
|
|
|
;; ... except when there is end of sentence. The
|
|
|
|
|
;; variable `sentence-end-double-space' is handled
|
|
|
|
|
;; properly later.
|
|
|
|
|
nil
|
|
|
|
|
(delete-region (match-beginning 0) (1+ (match-beginning 0))))))
|
|
|
|
|
(goto-char from)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
;; Then change all newlines to spaces.
|
|
|
|
|
(subst-char-in-region from (point-max) ?\n ?\ )
|
|
|
|
|
(if (and nosqueeze (not (eq justify 'full)))
|
|
|
|
|
nil
|
1996-02-21 21:20:28 +00:00
|
|
|
|
(canonically-space-region (or squeeze-after (point)) (point-max))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(delete-horizontal-space)
|
|
|
|
|
(insert-and-inherit " "))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
|
|
|
|
|
;; This is the actual filling loop.
|
|
|
|
|
(let ((prefixcol 0) linebeg)
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(setq linebeg (point))
|
|
|
|
|
(move-to-column (1+ (current-fill-column)))
|
|
|
|
|
(if (eobp)
|
|
|
|
|
(or nosqueeze (delete-horizontal-space))
|
1997-02-20 05:33:51 +00:00
|
|
|
|
;; Move back to the point where we can break the line
|
|
|
|
|
;; at. We break the line between word or after/before
|
|
|
|
|
;; the character which has character category `|'. We
|
|
|
|
|
;; search space, \c| followed by a character, or \c|
|
|
|
|
|
;; following a character. If not found, place
|
|
|
|
|
;; the point at linebeg.
|
|
|
|
|
(if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0)
|
|
|
|
|
;; In case of space, we place the point at next to
|
|
|
|
|
;; the point where the break occurs acutually,
|
|
|
|
|
;; because we don't want to change the following
|
|
|
|
|
;; logic of original Emacs. In case of \c|, the
|
|
|
|
|
;; point is at the place where the break occurs.
|
|
|
|
|
(forward-char 1))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
;; Don't break after a period followed by just one space.
|
|
|
|
|
;; Move back to the previous place to break.
|
|
|
|
|
;; The reason is that if a period ends up at the end of a line,
|
|
|
|
|
;; further fills will assume it ends a sentence.
|
|
|
|
|
;; If we now know it does not end a sentence,
|
|
|
|
|
;; avoid putting it at the end of the line.
|
|
|
|
|
(if sentence-end-double-space
|
|
|
|
|
(while (and (> (point) (+ linebeg 2))
|
|
|
|
|
(eq (preceding-char) ?\ )
|
|
|
|
|
(not (eq (following-char) ?\ ))
|
|
|
|
|
(eq (char-after (- (point) 2)) ?\.))
|
|
|
|
|
(forward-char -2)
|
1997-02-20 05:33:51 +00:00
|
|
|
|
(if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0)
|
|
|
|
|
(forward-char 1))))
|
1995-11-15 01:30:28 +00:00
|
|
|
|
;; If the left margin and fill prefix by themselves
|
1996-03-19 20:05:11 +00:00
|
|
|
|
;; pass the fill-column. or if they are zero
|
|
|
|
|
;; but we have no room for even one word,
|
1997-02-20 05:33:51 +00:00
|
|
|
|
;; keep at least one word or a character which has
|
|
|
|
|
;; category `|'anyway .
|
1995-11-15 01:30:28 +00:00
|
|
|
|
;; This handles ALL BUT the first line of the paragraph.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(if (if (zerop prefixcol)
|
|
|
|
|
(save-excursion
|
1995-11-17 23:32:15 +00:00
|
|
|
|
(skip-chars-backward " \t" linebeg)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(bolp))
|
|
|
|
|
(>= prefixcol (current-column)))
|
1997-02-20 05:33:51 +00:00
|
|
|
|
;; Ok, skip at least one word or one \c| character.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
;; Meanwhile, don't stop at a period followed by one space.
|
|
|
|
|
(let ((first t))
|
|
|
|
|
(move-to-column prefixcol)
|
|
|
|
|
(while (and (not (eobp))
|
|
|
|
|
(or first
|
|
|
|
|
(and (not (bobp))
|
|
|
|
|
sentence-end-double-space
|
|
|
|
|
(save-excursion (forward-char -1)
|
|
|
|
|
(and (looking-at "\\. ")
|
|
|
|
|
(not (looking-at "\\. ")))))))
|
1995-11-17 23:32:15 +00:00
|
|
|
|
(skip-chars-forward " \t")
|
1997-02-20 05:33:51 +00:00
|
|
|
|
;; Skip one \c| character or one word.
|
|
|
|
|
(if (looking-at "$\\|\\c|\\|[^ \t\n]+")
|
|
|
|
|
(goto-char (match-end 0)))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(setq first nil)))
|
|
|
|
|
;; Normally, move back over the single space between the words.
|
1997-02-20 05:33:51 +00:00
|
|
|
|
(if (= (preceding-char) ?\ ) (forward-char -1))
|
|
|
|
|
;; Do KINSOKU processing.
|
1997-05-17 02:01:42 +00:00
|
|
|
|
(if (and enable-multibyte-characters enable-kinsoku)
|
|
|
|
|
(kinsoku linebeg)))
|
1997-02-20 05:33:51 +00:00
|
|
|
|
|
1995-11-15 01:30:28 +00:00
|
|
|
|
;; If the left margin and fill prefix by themselves
|
|
|
|
|
;; pass the fill-column, keep at least one word.
|
|
|
|
|
;; This handles the first line of the paragraph.
|
|
|
|
|
(if (and (zerop prefixcol)
|
|
|
|
|
(let ((fill-point (point)) nchars)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(move-to-left-margin)
|
|
|
|
|
(setq nchars (- fill-point (point)))
|
|
|
|
|
(or (< nchars 0)
|
|
|
|
|
(and fill-prefix
|
|
|
|
|
(< nchars (length fill-prefix))
|
|
|
|
|
(string= (buffer-substring (point) fill-point)
|
|
|
|
|
(substring fill-prefix 0 nchars)))))))
|
|
|
|
|
;; Ok, skip at least one word. But
|
|
|
|
|
;; don't stop at a period followed by just one space.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(let ((first t))
|
|
|
|
|
(while (and (not (eobp))
|
|
|
|
|
(or first
|
|
|
|
|
(and (not (bobp))
|
|
|
|
|
sentence-end-double-space
|
|
|
|
|
(save-excursion (forward-char -1)
|
|
|
|
|
(and (looking-at "\\. ")
|
|
|
|
|
(not (looking-at "\\. ")))))))
|
1995-11-17 23:32:15 +00:00
|
|
|
|
(skip-chars-forward " \t")
|
1997-02-20 05:33:51 +00:00
|
|
|
|
;; Skip one \c| character or one word.
|
|
|
|
|
(if (looking-at "$\\|\\c|\\|[^ \t\n]+")
|
|
|
|
|
(goto-char (match-end 0)))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(setq first nil))))
|
1996-01-09 23:18:07 +00:00
|
|
|
|
;; Check again to see if we got to the end of the paragraph.
|
1996-03-19 20:05:11 +00:00
|
|
|
|
(if (save-excursion (skip-chars-forward " \t") (eobp))
|
1996-01-09 23:18:07 +00:00
|
|
|
|
(or nosqueeze (delete-horizontal-space))
|
|
|
|
|
;; Replace whitespace here with one newline, then indent to left
|
|
|
|
|
;; margin.
|
|
|
|
|
(skip-chars-backward " \t")
|
1997-02-20 05:33:51 +00:00
|
|
|
|
(if (and (= (following-char) ?\ )
|
|
|
|
|
(or (aref (char-category-set (preceding-char)) ?|)
|
|
|
|
|
(looking-at "[ \t]+\\c|")))
|
|
|
|
|
;; We need one space at end of line so that
|
|
|
|
|
;; further filling won't delete it. NOTE: We
|
|
|
|
|
;; intentionally leave this one space to
|
|
|
|
|
;; distingush the case that user wants to put
|
|
|
|
|
;; space between \c| characters.
|
|
|
|
|
(forward-char 1))
|
1996-01-09 23:18:07 +00:00
|
|
|
|
(insert ?\n)
|
|
|
|
|
;; Give newline the properties of the space(s) it replaces
|
|
|
|
|
(set-text-properties (1- (point)) (point)
|
|
|
|
|
(text-properties-at (point)))
|
|
|
|
|
(indent-to-left-margin)
|
|
|
|
|
;; Insert the fill prefix after indentation.
|
|
|
|
|
;; Set prefixcol so whitespace in the prefix won't get lost.
|
|
|
|
|
(and fill-prefix (not (equal fill-prefix ""))
|
|
|
|
|
(progn
|
|
|
|
|
(insert-and-inherit fill-prefix)
|
|
|
|
|
(setq prefixcol (current-column))))))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
;; Justify the line just ended, if desired.
|
|
|
|
|
(if justify
|
|
|
|
|
(if (eobp)
|
1995-04-10 08:02:39 +00:00
|
|
|
|
(justify-current-line justify t t)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(forward-line -1)
|
1995-04-10 08:02:39 +00:00
|
|
|
|
(justify-current-line justify nil t)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(forward-line 1))))))
|
|
|
|
|
;; Leave point after final newline.
|
|
|
|
|
(goto-char (point-max)))
|
|
|
|
|
(forward-char 1))))
|
1990-07-27 04:20:16 +00:00
|
|
|
|
|
|
|
|
|
(defun fill-paragraph (arg)
|
1994-02-04 04:45:52 +00:00
|
|
|
|
"Fill paragraph at or after point. Prefix arg means justify as well.
|
|
|
|
|
If `sentence-end-double-space' is non-nil, then period followed by one
|
1995-02-02 09:50:23 +00:00
|
|
|
|
space does not end a sentence, so don't break a line there.
|
|
|
|
|
|
|
|
|
|
If `fill-paragraph-function' is non-nil, we call it (passing our
|
|
|
|
|
argument to it), and if it returns non-nil, we simply return its value."
|
1995-04-14 18:33:44 +00:00
|
|
|
|
(interactive (list (if current-prefix-arg 'full)))
|
1995-02-02 09:50:23 +00:00
|
|
|
|
(or (and fill-paragraph-function
|
1995-02-02 19:28:31 +00:00
|
|
|
|
(let ((function fill-paragraph-function)
|
|
|
|
|
fill-paragraph-function)
|
|
|
|
|
(funcall function arg)))
|
1995-02-02 09:50:23 +00:00
|
|
|
|
(let ((before (point)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-paragraph)
|
|
|
|
|
(or (bolp) (newline 1))
|
|
|
|
|
(let ((end (point))
|
|
|
|
|
(beg (progn (backward-paragraph) (point))))
|
|
|
|
|
(goto-char before)
|
|
|
|
|
(if use-hard-newlines
|
|
|
|
|
;; Can't use fill-region-as-paragraph, since this paragraph may
|
|
|
|
|
;; still contain hard newlines. See fill-region.
|
|
|
|
|
(fill-region beg end arg)
|
|
|
|
|
(fill-region-as-paragraph beg end arg)))))))
|
1990-07-27 04:20:16 +00:00
|
|
|
|
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(defun fill-region (from to &optional justify nosqueeze to-eop)
|
1990-07-27 04:20:16 +00:00
|
|
|
|
"Fill each of the paragraphs in the region.
|
1994-02-04 04:45:52 +00:00
|
|
|
|
Prefix arg (non-nil third arg, if called from program) means justify as well.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
Noninteractively, fourth arg NOSQUEEZE non-nil means to leave
|
|
|
|
|
whitespace other than line breaks untouched, and fifth arg TO-EOP
|
|
|
|
|
non-nil means to keep filling to the end of the paragraph (or next
|
|
|
|
|
hard newline, if `use-hard-newlines' is on).
|
|
|
|
|
|
1994-02-04 04:45:52 +00:00
|
|
|
|
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."
|
1995-04-14 18:33:44 +00:00
|
|
|
|
(interactive (list (region-beginning) (region-end)
|
|
|
|
|
(if current-prefix-arg 'full)))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(let (end beg)
|
1994-12-04 19:49:21 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(goto-char (max from to))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(if to-eop
|
|
|
|
|
(progn (skip-chars-backward "\n")
|
|
|
|
|
(forward-paragraph)))
|
1994-12-04 19:49:21 +00:00
|
|
|
|
(setq end (point))
|
|
|
|
|
(goto-char (setq beg (min from to)))
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(narrow-to-region (point) end)
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(let ((initial (point))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
end)
|
|
|
|
|
;; If using hard newlines, break at every one for filling
|
|
|
|
|
;; purposes rather than using paragraph breaks.
|
|
|
|
|
(if use-hard-newlines
|
|
|
|
|
(progn
|
|
|
|
|
(while (and (setq end (text-property-any (point) (point-max)
|
|
|
|
|
'hard t))
|
|
|
|
|
(not (= ?\n (char-after end)))
|
|
|
|
|
(not (= end (point-max))))
|
|
|
|
|
(goto-char (1+ end)))
|
1995-04-07 23:44:45 +00:00
|
|
|
|
(setq end (if end (min (point-max) (1+ end)) (point-max)))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(goto-char initial))
|
|
|
|
|
(forward-paragraph 1)
|
|
|
|
|
(setq end (point))
|
|
|
|
|
(forward-paragraph -1))
|
1994-12-04 19:49:21 +00:00
|
|
|
|
(if (< (point) beg)
|
|
|
|
|
(goto-char beg))
|
|
|
|
|
(if (>= (point) initial)
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(fill-region-as-paragraph (point) end justify nosqueeze)
|
1994-12-04 19:49:21 +00:00
|
|
|
|
(goto-char end)))))))
|
1990-07-27 04:20:16 +00:00
|
|
|
|
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
1997-05-05 15:00:53 +00:00
|
|
|
|
(defcustom default-justification 'left
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
"*Method of justifying text not otherwise specified.
|
|
|
|
|
Possible values are `left', `right', `full', `center', or `none'.
|
|
|
|
|
The requested kind of justification is done whenever lines are filled.
|
|
|
|
|
The `justification' text-property can locally override this variable.
|
1997-05-05 15:00:53 +00:00
|
|
|
|
This variable automatically becomes buffer-local when set in any fashion."
|
|
|
|
|
:type '(choice (const left)
|
|
|
|
|
(const right)
|
|
|
|
|
(const full)
|
|
|
|
|
(const center)
|
|
|
|
|
(const none))
|
|
|
|
|
:group 'fill)
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(make-variable-buffer-local 'default-justification)
|
|
|
|
|
|
1995-01-19 04:27:15 +00:00
|
|
|
|
(defun current-justification ()
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
"How should we justify this line?
|
|
|
|
|
This returns the value of the text-property `justification',
|
|
|
|
|
or the variable `default-justification' if there is no text-property.
|
|
|
|
|
However, it returns nil rather than `none' to mean \"don't justify\"."
|
|
|
|
|
(let ((j (or (get-text-property
|
|
|
|
|
;; Make sure we're looking at paragraph body.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(save-excursion (skip-chars-forward " \t")
|
|
|
|
|
(if (and (eobp) (not (bobp)))
|
|
|
|
|
(1- (point)) (point)))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
'justification)
|
|
|
|
|
default-justification)))
|
|
|
|
|
(if (eq 'none j)
|
|
|
|
|
nil
|
|
|
|
|
j)))
|
|
|
|
|
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(defun set-justification (begin end value &optional whole-par)
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
"Set the region's justification style.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
The kind of justification to use is prompted for.
|
|
|
|
|
If the mark is not active, this command operates on the current paragraph.
|
|
|
|
|
If the mark is active, the region is used. However, if the beginning and end
|
|
|
|
|
of the region are not at paragraph breaks, they are moved to the beginning and
|
|
|
|
|
end of the paragraphs they are in.
|
|
|
|
|
If `use-hard-newlines' is true, all hard newlines are taken to be paragraph
|
|
|
|
|
breaks.
|
|
|
|
|
|
|
|
|
|
When calling from a program, operates just on region between BEGIN and END,
|
|
|
|
|
unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are
|
|
|
|
|
extended to include entire paragraphs as in the interactive command."
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(interactive (list (if mark-active (region-beginning) (point))
|
|
|
|
|
(if mark-active (region-end) (point))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(let ((s (completing-read
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
"Set justification to: "
|
1995-02-23 18:22:04 +00:00
|
|
|
|
'(("left") ("right") ("full")
|
|
|
|
|
("center") ("none"))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
nil t)))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(if (equal s "") (error ""))
|
|
|
|
|
(intern s))
|
|
|
|
|
t))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(if whole-par
|
|
|
|
|
(let ((paragraph-start (if use-hard-newlines "." paragraph-start))
|
|
|
|
|
(paragraph-ignore-fill-prefix (if use-hard-newlines t
|
|
|
|
|
paragraph-ignore-fill-prefix)))
|
|
|
|
|
(goto-char begin)
|
|
|
|
|
(while (and (bolp) (not (eobp))) (forward-char 1))
|
|
|
|
|
(backward-paragraph)
|
|
|
|
|
(setq begin (point))
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(skip-chars-backward " \t\n" begin)
|
|
|
|
|
(forward-paragraph)
|
|
|
|
|
(setq end (point))))
|
|
|
|
|
|
|
|
|
|
(narrow-to-region (point-min) end)
|
|
|
|
|
(unjustify-region begin (point-max))
|
|
|
|
|
(put-text-property begin (point-max) 'justification value)
|
|
|
|
|
(fill-region begin (point-max) nil t))))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(defun set-justification-none (b e)
|
|
|
|
|
"Disable automatic filling for paragraphs in the region.
|
|
|
|
|
If the mark is not active, this applies to the current paragraph."
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(interactive (list (if mark-active (region-beginning) (point))
|
|
|
|
|
(if mark-active (region-end) (point))))
|
|
|
|
|
(set-justification b e 'none t))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(defun set-justification-left (b e)
|
|
|
|
|
"Make paragraphs in the region left-justified.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
This is usually the default, but see the variable `default-justification'.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
If the mark is not active, this applies to the current paragraph."
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(interactive (list (if mark-active (region-beginning) (point))
|
|
|
|
|
(if mark-active (region-end) (point))))
|
|
|
|
|
(set-justification b e 'left t))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(defun set-justification-right (b e)
|
|
|
|
|
"Make paragraphs in the region right-justified:
|
|
|
|
|
Flush at the right margin and ragged on the left.
|
|
|
|
|
If the mark is not active, this applies to the current paragraph."
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(interactive (list (if mark-active (region-beginning) (point))
|
|
|
|
|
(if mark-active (region-end) (point))))
|
|
|
|
|
(set-justification b e 'right t))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(defun set-justification-full (b e)
|
|
|
|
|
"Make paragraphs in the region fully justified:
|
1995-02-23 18:22:04 +00:00
|
|
|
|
This makes lines flush on both margins by inserting spaces between words.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
If the mark is not active, this applies to the current paragraph."
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(interactive (list (if mark-active (region-beginning) (point))
|
|
|
|
|
(if mark-active (region-end) (point))))
|
|
|
|
|
(set-justification b e 'full t))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(defun set-justification-center (b e)
|
|
|
|
|
"Make paragraphs in the region centered.
|
|
|
|
|
If the mark is not active, this applies to the current paragraph."
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(interactive (list (if mark-active (region-beginning) (point))
|
|
|
|
|
(if mark-active (region-end) (point))))
|
|
|
|
|
(set-justification b e 'center t))
|
|
|
|
|
|
|
|
|
|
;; A line has up to six parts:
|
|
|
|
|
;;
|
|
|
|
|
;; >>> hello.
|
|
|
|
|
;; [Indent-1][FP][ Indent-2 ][text][trailing whitespace][newline]
|
|
|
|
|
;;
|
|
|
|
|
;; "Indent-1" is the left-margin indentation; normally it ends at column
|
|
|
|
|
;; given by the `current-left-margin' function.
|
|
|
|
|
;; "FP" is the fill-prefix. It can be any string, including whitespace.
|
|
|
|
|
;; "Indent-2" is added to justify a line if the `current-justification' is
|
|
|
|
|
;; `center' or `right'. In `left' and `full' justification regions, any
|
|
|
|
|
;; whitespace there is part of the line's text, and should not be changed.
|
|
|
|
|
;; Trailing whitespace is not counted as part of the line length when
|
|
|
|
|
;; center- or right-justifying.
|
|
|
|
|
;;
|
|
|
|
|
;; All parts of the line are optional, although the final newline can
|
|
|
|
|
;; only be missing on the last line of the buffer.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
(defun justify-current-line (&optional how eop nosqueeze)
|
1995-02-23 18:22:04 +00:00
|
|
|
|
"Do some kind of justification on this line.
|
|
|
|
|
Normally does full justification: adds spaces to the line to make it end at
|
|
|
|
|
the column given by `current-fill-column'.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
Optional first argument HOW specifies alternate type of justification:
|
|
|
|
|
it can be `left', `right', `full', `center', or `none'.
|
1995-02-23 18:22:04 +00:00
|
|
|
|
If HOW is t, will justify however the `current-justification' function says to.
|
|
|
|
|
If HOW is nil or missing, full justification is done by default.
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
Second arg EOP non-nil means that this is the last line of the paragraph, so
|
|
|
|
|
it will not be stretched by full justification.
|
|
|
|
|
Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged,
|
|
|
|
|
otherwise it is made canonical."
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(interactive)
|
1995-11-10 17:13:56 +00:00
|
|
|
|
(if (eq t how) (setq how (or (current-justification) 'none))
|
|
|
|
|
(if (null how) (setq how 'full)
|
|
|
|
|
(or (memq how '(none left right center))
|
|
|
|
|
(setq how 'full))))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(or (memq how '(none left)) ; No action required for these.
|
|
|
|
|
(let ((fc (current-fill-column))
|
|
|
|
|
(pos (point-marker))
|
|
|
|
|
fp-end ; point at end of fill prefix
|
|
|
|
|
beg ; point at beginning of line's text
|
|
|
|
|
end ; point at end of line's text
|
|
|
|
|
indent ; column of `beg'
|
|
|
|
|
endcol ; column of `end'
|
|
|
|
|
ncols) ; new indent point or offset
|
|
|
|
|
(end-of-line)
|
|
|
|
|
;; Check if this is the last line of the paragraph.
|
|
|
|
|
(if (and use-hard-newlines (null eop)
|
|
|
|
|
(get-text-property (point) 'hard))
|
|
|
|
|
(setq eop t))
|
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
;; Quick exit if it appears to be properly justified already
|
|
|
|
|
;; or there is no text.
|
|
|
|
|
(if (or (bolp)
|
|
|
|
|
(and (memq how '(full right))
|
|
|
|
|
(= (current-column) fc)))
|
|
|
|
|
nil
|
|
|
|
|
(setq end (point))
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
;; Skip over fill-prefix.
|
|
|
|
|
(if (and fill-prefix
|
|
|
|
|
(not (string-equal fill-prefix ""))
|
|
|
|
|
(equal fill-prefix
|
|
|
|
|
(buffer-substring
|
|
|
|
|
(point) (min (point-max) (+ (length fill-prefix)
|
|
|
|
|
(point))))))
|
|
|
|
|
(forward-char (length fill-prefix))
|
|
|
|
|
(if (and adaptive-fill-mode
|
|
|
|
|
(looking-at adaptive-fill-regexp))
|
|
|
|
|
(goto-char (match-end 0))))
|
|
|
|
|
(setq fp-end (point))
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
;; This is beginning of the line's text.
|
|
|
|
|
(setq indent (current-column))
|
|
|
|
|
(setq beg (point))
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(setq endcol (current-column))
|
|
|
|
|
|
|
|
|
|
;; HOW can't be null or left--we would have exited already
|
|
|
|
|
(cond ((eq 'right how)
|
|
|
|
|
(setq ncols (- fc endcol))
|
|
|
|
|
(if (< ncols 0)
|
|
|
|
|
;; Need to remove some indentation
|
|
|
|
|
(delete-region
|
|
|
|
|
(progn (goto-char fp-end)
|
|
|
|
|
(if (< (current-column) (+ indent ncols))
|
|
|
|
|
(move-to-column (+ indent ncols) t))
|
|
|
|
|
(point))
|
|
|
|
|
(progn (move-to-column indent) (point)))
|
|
|
|
|
;; Need to add some
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(indent-to (+ indent ncols))
|
|
|
|
|
;; If point was at beginning of text, keep it there.
|
|
|
|
|
(if (= beg pos)
|
|
|
|
|
(move-marker pos (point)))))
|
|
|
|
|
|
|
|
|
|
((eq 'center how)
|
|
|
|
|
;; Figure out how much indentation is needed
|
|
|
|
|
(setq ncols (+ (current-left-margin)
|
|
|
|
|
(/ (- fc (current-left-margin) ;avail. space
|
|
|
|
|
(- endcol indent)) ;text width
|
|
|
|
|
2)))
|
|
|
|
|
(if (< ncols indent)
|
|
|
|
|
;; Have too much indentation - remove some
|
|
|
|
|
(delete-region
|
|
|
|
|
(progn (goto-char fp-end)
|
|
|
|
|
(if (< (current-column) ncols)
|
|
|
|
|
(move-to-column ncols t))
|
|
|
|
|
(point))
|
|
|
|
|
(progn (move-to-column indent) (point)))
|
|
|
|
|
;; Have too little - add some
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(indent-to ncols)
|
|
|
|
|
;; If point was at beginning of text, keep it there.
|
|
|
|
|
(if (= beg pos)
|
|
|
|
|
(move-marker pos (point)))))
|
|
|
|
|
|
|
|
|
|
((eq 'full how)
|
|
|
|
|
;; Insert extra spaces between words to justify line
|
|
|
|
|
(save-restriction
|
1995-01-25 00:05:59 +00:00
|
|
|
|
(narrow-to-region beg end)
|
|
|
|
|
(or nosqueeze
|
|
|
|
|
(canonically-space-region beg end))
|
|
|
|
|
(goto-char (point-max))
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(setq ncols (- fc endcol))
|
|
|
|
|
;; Ncols is number of additional spaces needed
|
|
|
|
|
(if (> ncols 0)
|
|
|
|
|
(if (and (not eop)
|
|
|
|
|
(search-backward " " nil t))
|
|
|
|
|
(while (> ncols 0)
|
|
|
|
|
(let ((nmove (+ 3 (random 3))))
|
|
|
|
|
(while (> nmove 0)
|
|
|
|
|
(or (search-backward " " nil t)
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(search-backward " ")))
|
|
|
|
|
(skip-chars-backward " ")
|
|
|
|
|
(setq nmove (1- nmove))))
|
|
|
|
|
(insert-and-inherit " ")
|
|
|
|
|
(skip-chars-backward " ")
|
|
|
|
|
(setq ncols (1- ncols)))))))
|
|
|
|
|
(t (error "Unknown justification value"))))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(move-marker pos nil)))
|
1993-03-11 07:05:23 +00:00
|
|
|
|
nil)
|
1994-09-23 20:46:35 +00:00
|
|
|
|
|
1995-02-23 18:22:04 +00:00
|
|
|
|
(defun unjustify-current-line ()
|
|
|
|
|
"Remove justification whitespace from current line.
|
|
|
|
|
If the line is centered or right-justified, this function removes any
|
1996-01-04 23:35:23 +00:00
|
|
|
|
indentation past the left margin. If the line is full-justified, it removes
|
1995-02-23 18:22:04 +00:00
|
|
|
|
extra spaces between words. It does nothing in other justification modes."
|
|
|
|
|
(let ((justify (current-justification)))
|
|
|
|
|
(cond ((eq 'left justify) nil)
|
|
|
|
|
((eq nil justify) nil)
|
|
|
|
|
((eq 'full justify) ; full justify: remove extra spaces
|
|
|
|
|
(beginning-of-line-text)
|
|
|
|
|
(canonically-space-region
|
|
|
|
|
(point) (save-excursion (end-of-line) (point))))
|
|
|
|
|
((memq justify '(center right))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(move-to-left-margin nil t)
|
|
|
|
|
;; Position ourselves after any fill-prefix.
|
|
|
|
|
(if (and fill-prefix
|
|
|
|
|
(not (string-equal fill-prefix ""))
|
|
|
|
|
(equal fill-prefix
|
|
|
|
|
(buffer-substring
|
|
|
|
|
(point) (min (point-max) (+ (length fill-prefix)
|
|
|
|
|
(point))))))
|
|
|
|
|
(forward-char (length fill-prefix)))
|
|
|
|
|
(delete-region (point) (progn (skip-chars-forward " \t")
|
|
|
|
|
(point))))))))
|
|
|
|
|
|
|
|
|
|
(defun unjustify-region (&optional begin end)
|
|
|
|
|
"Remove justification whitespace from region.
|
|
|
|
|
For centered or right-justified regions, this function removes any indentation
|
1996-01-04 23:35:23 +00:00
|
|
|
|
past the left margin from each line. For full-justified lines, it removes
|
1995-02-23 18:22:04 +00:00
|
|
|
|
extra spaces between words. It does nothing in other justification modes.
|
|
|
|
|
Arguments BEGIN and END are optional; default is the whole buffer."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(if end (narrow-to-region (point-min) end))
|
|
|
|
|
(goto-char (or begin (point-min)))
|
|
|
|
|
(while (not (eobp))
|
|
|
|
|
(unjustify-current-line)
|
|
|
|
|
(forward-line 1)))))
|
|
|
|
|
|
1990-07-27 04:20:16 +00:00
|
|
|
|
|
1993-04-11 04:02:23 +00:00
|
|
|
|
(defun fill-nonuniform-paragraphs (min max &optional justifyp mailp)
|
|
|
|
|
"Fill paragraphs within the region, allowing varying indentation within each.
|
|
|
|
|
This command divides the region into \"paragraphs\",
|
|
|
|
|
only at paragraph-separator lines, then fills each paragraph
|
|
|
|
|
using as the fill prefix the smallest indentation of any line
|
|
|
|
|
in the paragraph.
|
|
|
|
|
|
|
|
|
|
When calling from a program, pass range to fill as first two arguments.
|
1992-05-10 18:15:10 +00:00
|
|
|
|
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
|
|
|
|
|
JUSTIFY to justify paragraphs (prefix arg),
|
1993-04-11 04:02:23 +00:00
|
|
|
|
MAIL-FLAG for a mail message, i. e. don't fill header lines."
|
1995-04-14 18:33:44 +00:00
|
|
|
|
(interactive (list (region-beginning) (region-end)
|
|
|
|
|
(if current-prefix-arg 'full)))
|
1993-04-11 04:02:23 +00:00
|
|
|
|
(let ((fill-individual-varying-indent t))
|
|
|
|
|
(fill-individual-paragraphs min max justifyp mailp)))
|
|
|
|
|
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(defun fill-individual-paragraphs (min max &optional justify mailp)
|
1993-04-11 04:02:23 +00:00
|
|
|
|
"Fill paragraphs of uniform indentation within the region.
|
|
|
|
|
This command divides the region into \"paragraphs\",
|
|
|
|
|
treating every change in indentation level as a paragraph boundary,
|
|
|
|
|
then fills each paragraph using its indentation level as the fill prefix.
|
1992-05-10 18:15:10 +00:00
|
|
|
|
|
|
|
|
|
When calling from a program, pass range to fill as first two arguments.
|
|
|
|
|
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
|
|
|
|
|
JUSTIFY to justify paragraphs (prefix arg),
|
1990-07-27 04:20:16 +00:00
|
|
|
|
MAIL-FLAG for a mail message, i. e. don't fill header lines."
|
1995-04-14 18:33:44 +00:00
|
|
|
|
(interactive (list (region-beginning) (region-end)
|
|
|
|
|
(if current-prefix-arg 'full)))
|
1991-12-21 09:14:03 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char min)
|
|
|
|
|
(beginning-of-line)
|
1994-10-26 09:32:04 +00:00
|
|
|
|
(narrow-to-region (point) max)
|
1991-12-21 09:14:03 +00:00
|
|
|
|
(if mailp
|
1994-10-26 09:32:04 +00:00
|
|
|
|
(while (and (not (eobp))
|
1995-11-10 17:13:56 +00:00
|
|
|
|
(or (looking-at "[ \t]*[^ \t\n]+:")
|
1994-10-26 09:32:04 +00:00
|
|
|
|
(looking-at "[ \t]*$")))
|
1995-11-10 17:13:56 +00:00
|
|
|
|
(if (looking-at "[ \t]*[^ \t\n]+:")
|
1993-11-12 23:35:39 +00:00
|
|
|
|
(search-forward "\n\n" nil 'move)
|
|
|
|
|
(forward-line 1))))
|
1991-12-21 09:14:03 +00:00
|
|
|
|
(narrow-to-region (point) max)
|
|
|
|
|
;; Loop over paragraphs.
|
|
|
|
|
(while (progn (skip-chars-forward " \t\n") (not (eobp)))
|
1995-11-11 05:30:49 +00:00
|
|
|
|
(move-to-left-margin)
|
1991-12-21 09:14:03 +00:00
|
|
|
|
(let ((start (point))
|
|
|
|
|
fill-prefix fill-prefix-regexp)
|
|
|
|
|
;; Find end of paragraph, and compute the smallest fill-prefix
|
|
|
|
|
;; that fits all the lines in this paragraph.
|
|
|
|
|
(while (progn
|
|
|
|
|
;; Update the fill-prefix on the first line
|
|
|
|
|
;; and whenever the prefix good so far is too long.
|
|
|
|
|
(if (not (and fill-prefix
|
|
|
|
|
(looking-at fill-prefix-regexp)))
|
|
|
|
|
(setq fill-prefix
|
1995-07-17 22:50:30 +00:00
|
|
|
|
(if (and adaptive-fill-mode adaptive-fill-regexp
|
1995-11-11 05:30:49 +00:00
|
|
|
|
(looking-at adaptive-fill-regexp))
|
|
|
|
|
(match-string 0)
|
|
|
|
|
(buffer-substring
|
|
|
|
|
(point)
|
|
|
|
|
(save-excursion (skip-chars-forward " \t")
|
|
|
|
|
(point))))
|
|
|
|
|
fill-prefix-regexp (regexp-quote fill-prefix)))
|
1995-11-14 23:28:24 +00:00
|
|
|
|
(forward-line 1)
|
1996-05-31 04:17:02 +00:00
|
|
|
|
(if (bolp)
|
|
|
|
|
;; If forward-line went past a newline,
|
|
|
|
|
;; move further to the left margin.
|
|
|
|
|
(move-to-left-margin))
|
1991-12-21 09:14:03 +00:00
|
|
|
|
;; Now stop the loop if end of paragraph.
|
|
|
|
|
(and (not (eobp))
|
1992-05-10 18:15:10 +00:00
|
|
|
|
(if fill-individual-varying-indent
|
|
|
|
|
;; If this line is a separator line, with or
|
|
|
|
|
;; without prefix, end the paragraph.
|
|
|
|
|
(and
|
1995-11-14 23:28:24 +00:00
|
|
|
|
(not (looking-at paragraph-separate))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(not (and (looking-at fill-prefix-regexp)
|
|
|
|
|
(progn (forward-char (length fill-prefix))
|
1992-05-10 18:15:10 +00:00
|
|
|
|
(looking-at paragraph-separate))))))
|
|
|
|
|
;; If this line has more or less indent
|
|
|
|
|
;; than the fill prefix wants, end the paragraph.
|
|
|
|
|
(and (looking-at fill-prefix-regexp)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(not (progn (forward-char (length fill-prefix))
|
|
|
|
|
(or (looking-at paragraph-separate)
|
|
|
|
|
(looking-at paragraph-start))))))))))
|
1991-12-21 09:14:03 +00:00
|
|
|
|
;; Fill this paragraph, but don't add a newline at the end.
|
|
|
|
|
(let ((had-newline (bolp)))
|
(set-justification): New function.
(set-justification-{none,left,right,full,center}): New functions.
(fill-region-as-paragraph, fill-region, justify-current-line): New
arg NOSQUEEZE defeats normal removal of extra whitespace.
(fill-region-as-paragraph, fill-region)
(fill-nonuniform-paragraphs, fill-individual-paragraphs):
Arg JUSTIFY-FLAG (JUSTIFYP) renamed to JUSTIFY.
(fill-region-as-paragraph): Obey left-margin; fill-prefix starts
after left-margin. Disable filling if JUSTIFY == none, but indent to
margin anyway.
Adaptive-fill removes text-props from fill-prefixes it finds.
Adaptive-fill no longer has to notice left-margin: std fill does that.
Use fill-column and canonically-space-region functions.
(canonically-space-region): New fn split from fill-region-as-paragraph.
(fill-region): New args NOSQUEEZE (as above) and TO-EOP.
(default-justification): New variable.
(current-left-margin, fill-column, justification): New functions.
(fill-paragraph): Use fill-region-as-paragraph when possible.
(justify-current-line): New arguments; different kinds of
justification handled. Uses left-margin and fill-column functions.
1995-01-19 04:20:52 +00:00
|
|
|
|
(fill-region-as-paragraph start (point) justify)
|
1992-05-10 18:15:10 +00:00
|
|
|
|
(or had-newline (delete-char -1))))))))
|
1992-05-30 23:54:21 +00:00
|
|
|
|
|
1992-06-30 13:54:21 +00:00
|
|
|
|
;;; fill.el ends here
|