annotate lisp/fill.el @ 4882:eab9498ecc0e

merge most of rest of redisplay-x.c and redisplay-gtk.c into redisplay-xlike-inc.c -------------------- ChangeLog entries follow: -------------------- src/ChangeLog addition: 2010-01-18 Ben Wing <ben@xemacs.org> * redisplay-gtk.c: * redisplay-gtk.c (gtk_bevel_area): * redisplay-x.c: * redisplay-x.c (THIS_IS_X): * redisplay-xlike-inc.c: * redisplay-xlike-inc.c (XLIKE_text_width_single_run): * redisplay-xlike-inc.c (XLIKE_text_width): * redisplay-xlike-inc.c (XLIKE_output_display_block): * redisplay-xlike-inc.c (XLIKE_get_gc): * redisplay-xlike-inc.c (XLIKE_output_string): * redisplay-xlike-inc.c (XLIKE_OUTPUT_XLIKE_PIXMAP): * redisplay-xlike-inc.c (XLIKE_output_pixmap): * redisplay-xlike-inc.c (XLIKE_output_vertical_divider): * redisplay-xlike-inc.c (XLIKE_output_blank): * redisplay-xlike-inc.c (XLIKE_output_horizontal_line): * redisplay-xlike-inc.c (XLIKE_clear_region): * redisplay-xlike-inc.c (XLIKE_output_eol_cursor): * redisplay-xlike-inc.c (XLIKE_clear_frame_window): * redisplay-xlike-inc.c (XLIKE_clear_frame): * redisplay-xlike-inc.c (XLIKE_flash): * redisplay-xlike-inc.c (console_type_create_redisplay_XLIKE): Move lots more code into redisplay-xlike-inc.c. Use macros to isolate the code that differs among X vs. GTK, to reduce the need for ifdefs in the middle of the code. Now, redisplay-x.c and redisplay-gtk.c only contain a few functions whose implementation is completely different from one to the other, or which are not present at all in one of them. GTK code not currently tested, but it has bitrotted somewhat any. Doing this will help keep it less bitrotty. * depend: Regenerate.
author Ben Wing <ben@xemacs.org>
date Mon, 18 Jan 2010 08:44:49 -0600
parents 6f72d9a709c3
children 308d34e9f07d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; fill.el --- fill commands for XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 1997 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Keywords: wp, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.34.
2510
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
26 ;;; NOTE: Merging past 19.34 is currently impossible. Later versions
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
27 ;;; contain FSF's own Kinsoku processing, conflicting with the current code
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
28 ;;; and depending on various features of their Mule implementation that
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
29 ;;; do not currently exist.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; All the commands for filling text. These are documented in the XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; Reference Manual.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; 97/3/14 Jareth Hein (jhod@po.iijnet.or.jp) added functions for kinsoku (asian text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; line break processing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; 97/06/11 Steve Baur (steve@xemacs.org) converted broken
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;; following-char/preceding-char calls to char-after/char-before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 (defgroup fill nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 "Indenting and filling text."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 :group 'editing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 (defcustom fill-individual-varying-indent nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 Non-nil means changing indent doesn't end a paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 That mode can handle paragraphs with extra indentation on the first line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 but it requires separator lines between paragraphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 A value of nil means that any change in indentation starts a new paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 (defcustom sentence-end-double-space t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 "*Non-nil means a single space does not end a sentence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 This variable applies only to filling, not motion commands. To
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 change the behavior of motion commands, see `sentence-end'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (defcustom colon-double-space nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 "*Non-nil means put two spaces after a colon when filling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (defvar fill-paragraph-function nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 "Mode-specific function to fill a paragraph, or nil if there is none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 If the function returns nil, then `fill-paragraph' does its normal work.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (defun set-fill-prefix ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 "Set the fill prefix to the current line up to point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 Filling expects lines to start with the fill prefix and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 reinserts the fill prefix in each resulting line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (setq fill-prefix (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (save-excursion (move-to-left-margin) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (if (equal fill-prefix "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (setq fill-prefix nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (if fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 (message "fill-prefix: \"%s\"" fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (message "fill-prefix cancelled")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (defcustom adaptive-fill-mode t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 "*Non-nil means determine a paragraph's fill prefix from its text."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 ;; #### - this is still weak. Yeah, there's filladapt, but this should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 ;; still be better... --Stig
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
95 (defcustom adaptive-fill-regexp "[ \t]*\\([#;>*]+ +\\)?"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 "*Regexp to match text at start of line that constitutes indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 If Adaptive Fill mode is enabled, whatever text matches this pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 on the second line of a paragraph is used as the standard indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 for the paragraph. If the paragraph has just one line, the indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 is taken from that line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 :type 'regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (defcustom adaptive-fill-function nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 "*Function to call to choose a fill prefix for a paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 This function is used when `adaptive-fill-regexp' does not match."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
110 ;; Added for kinsoku processing. Use this instead of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ;; (skip-chars-backward "^ \t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ;; (skip-chars-backward "^ \n" linebeg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 (defun fill-move-backward-to-break-point (regexp &optional lim)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (let ((opoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ;; 93.8.23 by kawamoto@ics.es.osaka-u.ac.jp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ;; case of first 'word' being longer than fill-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 (if (not (re-search-backward regexp lim 'move))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ;; we have skipped backward SPC or WAN (word-across-newline). So move point forward again.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 (forward-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 (if (< opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 (forward-char -1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;; Added for kinsoku processing. Use instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 ;; (re-search-forward "[ \t]" opoint t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 ;; (skip-chars-forward "^ \n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 ;; (skip-chars-forward "^ \n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 (defun fill-move-forward-to-break-point (regexp &optional lim)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (let ((opoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 (if (not (re-search-forward regexp lim 'move))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (if (< (point) opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (forward-char))))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
135 (if (featurep 'mule) (declare-fboundp (kinsoku-process-extend))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (defun fill-end-of-sentence-p ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (skip-chars-backward " ]})\"'")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (memq (char-before (point)) '(?. ?? ?!))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (defun current-fill-column ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 "Return the fill-column to use for this line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 The fill-column to use for a buffer is stored in the variable `fill-column',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 but can be locally modified by the `right-margin' text property, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 subtracted from `fill-column'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 The fill column to use for a line is the first column at which the column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 number equals or exceeds the local fill-column - right-margin difference."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (if fill-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (let* ((here (progn (beginning-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (here-col 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (eol (progn (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 margin fill-col change col)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 ;; Look separately at each region of line with a different right-margin.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (while (and (setq margin (get-text-property here 'right-margin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 fill-col (- fill-column (or margin 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 change (text-property-not-all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 here eol 'right-margin margin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (progn (goto-char (1- change))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (setq col (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (< col fill-col)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (setq here change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 here-col col))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (max here-col fill-col)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
168 (defun canonically-space-region (start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 "Remove extra spaces between words in region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 Leave one space between words, two at end of sentences or after colons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 \(depending on values of `sentence-end-double-space' and `colon-double-space').
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 Remove indentation from each line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (interactive "r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 ;;;### 97/3/14 jhod: Do I have to add anything here for kinsoku?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (save-excursion
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
176 (goto-char start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ;; XEmacs - (ENE/stig from fa-extras.el): Skip the start of a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (and comment-start-skip
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (looking-at comment-start-skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (goto-char (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 ;; Nuke tabs; they get screwed up in a fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 ;; This is quick, but loses when a tab follows the end of a sentence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ;; Actually, it is difficult to tell that from "Mr.\tSmith".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 ;; Blame the typist.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
185 (subst-char-in-region start end ?\t ?\ )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (while (and (< (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (re-search-forward " *" end t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (delete-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (+ (match-beginning 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 ;; Determine number of spaces to leave:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 (skip-chars-backward " ]})\"'")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (cond ((and sentence-end-double-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (memq (char-before (point)) '(?. ?? ?!))) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 ((and colon-double-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (eq (char-before (point)) ?:)) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ((char-equal (char-before (point)) ?\n) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (t 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 ;; Make sure sentences ending at end of line get an extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 ;; loses on split abbrevs ("Mr.\nSmith")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
202 (goto-char start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (while (and (< (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (re-search-forward "[.?!][])}\"']*$" end t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 ;; We insert before markers in case a caller such as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 ;; do-auto-fill has done a save-excursion with point at the end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;; of the line and wants it to stay at the end of the line.
2510
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
208 (insert-before-markers-and-inherit ? ))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 ;; XEmacs -- added DONT-SKIP-FIRST. Port of older code changes by Stig.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 ;; #### probably this junk is broken -- do-auto-fill doesn't actually use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 ;; it. If so, it should be removed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (defun fill-context-prefix (from to &optional first-line-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 dont-skip-first)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 "Compute a fill prefix from the text between FROM and TO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 first line, insist it must match FIRST-LINE-REGEXP."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (if (eolp) (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 ;; Move to the second line unless there is just one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (let ((firstline (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 ;; Non-nil if we are on the second line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 at-second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (if (not dont-skip-first)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (cond ((>= (point) to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (goto-char firstline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 ((/= (point) from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (setq at-second t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (move-to-left-margin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (let ((start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ; jhod: no longer used?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ;(eol (save-excursion (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (setq result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (if (or dont-skip-first (not (looking-at paragraph-start)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (buffer-substring-no-properties start (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (adaptive-fill-function (funcall adaptive-fill-function)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (and result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (or at-second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (null first-line-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (string-match first-line-regexp result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 result)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 ;; XEmacs (stig) - this is pulled out of fill-region-as-paragraph so that it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;; can also be called from do-auto-fill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 ;; #### But it's not used there. Chuck pulled it out because it broke things.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (defun maybe-adapt-fill-prefix (&optional from to dont-skip-first)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (if (and adaptive-fill-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (or (null fill-prefix) (string= fill-prefix "")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (setq fill-prefix (fill-context-prefix from to nil dont-skip-first))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (defun fill-region-as-paragraph (from to &optional justify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 nosqueeze squeeze-after)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 "Fill the region as one paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 It removes any paragraph breaks in the region and extra newlines at the end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 indents and fills lines between the margins given by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 `current-left-margin' and `current-fill-column' functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 It leaves point at the beginning of the line following the paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 Normally performs justification according to the `current-justification'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 function, but with a prefix arg, does full justification instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 From a program, optional third arg JUSTIFY can specify any type of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 justification. Fourth arg NOSQUEEZE non-nil means not to make spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 means don't canonicalize spaces before that position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 If `sentence-end-double-space' is non-nil, then period followed by one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 space does not end a sentence, so don't break a line there."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 ;; XEmacs addition:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (barf-if-buffer-read-only nil (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (list (region-beginning) (region-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (if current-prefix-arg 'full))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 ;; Arrange for undoing the fill to restore point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (setq buffer-undo-list (cons (point) buffer-undo-list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 ;; Make sure "to" is the endpoint.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (goto-char (min from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (setq to (max from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 ;; Ignore blank lines at beginning of region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (skip-chars-forward " \t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (let ((from-plus-indent (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (oneleft nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (setq from (point))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
299
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 ;; Delete all but one soft newline at end of region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 ;; And leave TO before that one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (goto-char to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (while (and (> (point) from) (eq ?\n (char-after (1- (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (if (and oneleft
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (not (and use-hard-newlines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (get-text-property (1- (point)) 'hard))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (delete-backward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (backward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (setq oneleft t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (setq to (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 ;; If there was no newline, and there is text in the paragraph, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 ;; create a newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (if (and (not oneleft) (> to from-plus-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (newline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (goto-char from-plus-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (if (not (> to (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 nil ; There is no paragraph, only whitespace: exit now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (or justify (setq justify (current-justification)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 ;; Don't let Adaptive Fill mode alter the fill prefix permanently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (let ((fill-prefix fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;; Figure out how this paragraph is indented, if desired.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 ;; XEmacs: move some code here to a separate function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (maybe-adapt-fill-prefix from to t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (narrow-to-region (point) to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (if (not justify) ; filling disabled: just check indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (if (and (not (eolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (< (current-indentation) (current-left-margin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (indent-to-left-margin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (if use-hard-newlines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (remove-text-properties from (point-max) '(hard nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 ;; Make sure first line is indented (at least) to left margin...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (if (or (memq justify '(right center))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (< (current-indentation) (current-left-margin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (indent-to-left-margin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 ;; Delete the fill prefix from every line except the first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 ;; The first line may not even have a fill prefix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (let ((fpre (and fill-prefix (not (equal fill-prefix ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (concat "[ \t]*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (regexp-quote fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 "[ \t]*"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (and fpre
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (if (>= (+ (current-left-margin) (length fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (current-fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (error "fill-prefix too long for specified width"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (if (looking-at fpre)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (delete-region (point) (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (if (looking-at fpre)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (goto-char (match-end 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (setq from (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 ;; Remove indentation from lines other than the first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (beginning-of-line 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (indent-region (point) (point-max) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 ;; FROM, and point, are now before the text to fill,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 ;; but after any fill prefix on the first line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 ;; Make sure sentences ending at end of line get an extra space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 ;; loses on split abbrevs ("Mr.\nSmith")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (while (re-search-forward "[.?!][])}\"']*$" nil t)
2510
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
382 (or (eobp) (insert-and-inherit ?\ ?\ )))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 ;; Then change all newlines to spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 ;;; 97/3/14 jhod: Kinsoku change
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
387 ;; Spacing is not necessary for characters of no word-separator.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 ;; The regexp word-across-newline is used for this check.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (defvar word-across-newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (if (not (and (featurep 'mule)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (stringp word-across-newline)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (subst-char-in-region from (point-max) ?\n ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 ;; WAN +NL+WAN --> WAN + WAN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 ;; not(WAN)+NL+WAN --> not(WAN) + WAN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ;; WAN +NL+not(WAN) --> WAN + not(WAN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 ;; SPC +NL+not(WAN) --> SPC + not(WAN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 ;; not(WAN)+NL+not(WAN) --> not(WAN) + SPC + not(WAN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 ;; Insert SPC only when point is between nonWAN. Insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 ;; before deleting to preserve marker if possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (if (or (prog2 ; check following char.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (forward-char) ; skip newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (or (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (looking-at word-across-newline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (forward-char -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (prog2 ; check previous char.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (or (eq (char-after (point)) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (looking-at word-across-newline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (forward-char)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (insert ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (delete-char 1) ; delete newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 ;; end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (goto-char from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (if (and nosqueeze (not (eq justify 'full)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (canonically-space-region (or squeeze-after (point)) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (delete-horizontal-space)
2510
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
427 (insert-and-inherit " "))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 ;; This is the actual filling loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (let ((prefixcol 0) linebeg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (re-break-point (if (featurep 'mule)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 (concat "[ \n\t]\\|" word-across-newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 ".\\|." word-across-newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 "[ \n\t]")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (setq linebeg (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (move-to-column (1+ (current-fill-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (or nosqueeze (delete-horizontal-space))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 ;; Move back to start of word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 ;(skip-chars-backward "^ \n" linebeg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (fill-move-backward-to-break-point re-break-point linebeg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 ;; end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 ;; Don't break after a period followed by just one space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 ;; Move back to the previous place to break.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 ;; The reason is that if a period ends up at the end of a line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 ;; further fills will assume it ends a sentence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 ;; If we now know it does not end a sentence,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 ;; avoid putting it at the end of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 (if sentence-end-double-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (while (and (> (point) (+ linebeg 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (eq (char-before (point)) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (not (eq (char-after (point)) ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (eq (char-after (- (point) 2)) ?\.))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (forward-char -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 ;(skip-chars-backward "^ \n" linebeg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (fill-move-backward-to-break-point re-break-point linebeg)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
461 (if (featurep 'mule) (declare-fboundp (kinsoku-process)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 ;end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 ;; If the left margin and fill prefix by themselves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 ;; pass the fill-column. or if they are zero
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 ;; but we have no room for even one word,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 ;; keep at least one word anyway.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 ;; This handles ALL BUT the first line of the paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (if (if (zerop prefixcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (skip-chars-backward " \t" linebeg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (bolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 (>= prefixcol (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 ;; Ok, skip at least one word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 ;; Meanwhile, don't stop at a period followed by one space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 (let ((first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (move-to-column prefixcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 (while (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 (or first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 sentence-end-double-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (save-excursion (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (and (looking-at "\\. ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (not (looking-at "\\. ")))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 ;; 94/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 ;(skip-chars-forward "^ \n\t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (fill-move-forward-to-break-point re-break-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 ;; end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (setq first nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 ;; Normally, move back over the single space between the words.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (if (eq (char-before (point)) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (forward-char -1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 ;; If the left margin and fill prefix by themselves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 ;; pass the fill-column, keep at least one word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 ;; This handles the first line of the paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 (if (and (zerop prefixcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (let ((fill-point (point)) nchars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 (move-to-left-margin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (setq nchars (- fill-point (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 (or (< nchars 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 (and fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (< nchars (length fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (string= (buffer-substring (point) fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (substring fill-prefix 0 nchars)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 ;; Ok, skip at least one word. But
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 ;; don't stop at a period followed by just one space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 (let ((first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (while (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (or first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 sentence-end-double-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (save-excursion (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 (and (looking-at "\\. ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (not (looking-at "\\. ")))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 ;(skip-chars-forward "^ \t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 (fill-move-forward-to-break-point re-break-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 ;; end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 (setq first nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 ;; Check again to see if we got to the end of the paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 (if (save-excursion (skip-chars-forward " \t") (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (or nosqueeze (delete-horizontal-space))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 ;; Replace whitespace here with one newline, then indent to left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 ;; margin.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 ;; 97/3/14 jhod: More kinsoku stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 (if (featurep 'mule)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 ;; WAN means chars which match word-across-newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 ;; (0) | SPC + SPC* <EOB> --> NL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 ;; (1) WAN | SPC + SPC* --> WAN + SPC + NL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 ;; (2) | SPC + SPC* + WAN --> SPC + NL + WAN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 ;; (3) '.' | SPC + nonSPC --> '.' + SPC + NL + nonSPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 ;; (4) '.' | SPC + SPC --> '.' + NL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 ;; (5) | SPC* --> NL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (let ((start (point)) ; 92.6.30 by K.Handa
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (ch (char-after (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (if (and (= ch ? )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (progn ; not case (0) -- 92.6.30 by K.Handa
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (not (eobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (progn ; case (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (looking-at word-across-newline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (progn ; case (2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (looking-at word-across-newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 ;; never leave space after the end of sentence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 (not (fill-end-of-sentence-p))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 (progn ; case (3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 (goto-char (1+ start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (not (eq (char-after (point)) ? ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (fill-end-of-sentence-p)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 ;; We should keep one SPACE before NEWLINE. (1),(2),(3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (goto-char (1+ start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 ;; We should delete all SPACES around break point. (4),(5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (goto-char start))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 ;; end of patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (insert ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 ;; Give newline the properties of the space(s) it replaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (set-text-properties (1- (point)) (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (text-properties-at (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 (indent-to-left-margin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 ;; Insert the fill prefix after indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 ;; Set prefixcol so whitespace in the prefix won't get lost.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (and fill-prefix (not (equal fill-prefix ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (progn
2510
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
575 (insert-and-inherit fill-prefix)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (setq prefixcol (current-column))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 ;; Justify the line just ended, if desired.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (if justify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 (if (save-excursion (skip-chars-forward " \t") (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 (delete-horizontal-space)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 (justify-current-line justify t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (forward-line -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 (justify-current-line justify nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (forward-line 1))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 ;; Leave point after final newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (goto-char (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (forward-char 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (defun fill-paragraph (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 "Fill paragraph at or after point. Prefix arg means justify as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 If `sentence-end-double-space' is non-nil, then period followed by one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 space does not end a sentence, so don't break a line there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 If `fill-paragraph-function' is non-nil, we call it (passing our
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 argument to it), and if it returns non-nil, we simply return its value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (interactive (list (if current-prefix-arg 'full)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (or (and fill-paragraph-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (let ((function fill-paragraph-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 fill-paragraph-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (funcall function arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (let ((before (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (forward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (or (bolp) (newline 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 (let ((end (point))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
607 (start (progn (backward-paragraph) (point))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 (goto-char before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (if use-hard-newlines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 ;; Can't use fill-region-as-paragraph, since this paragraph may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 ;; still contain hard newlines. See fill-region.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
612 (fill-region start end arg)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
613 (fill-region-as-paragraph start end arg)))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (defun fill-region (from to &optional justify nosqueeze to-eop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 "Fill each of the paragraphs in the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 Prefix arg (non-nil third arg, if called from program) means justify as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 Noninteractively, fourth arg NOSQUEEZE non-nil means to leave
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 whitespace other than line breaks untouched, and fifth arg TO-EOP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 non-nil means to keep filling to the end of the paragraph (or next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 hard newline, if `use-hard-newlines' is on).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 If `sentence-end-double-space' is non-nil, then period followed by one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 space does not end a sentence, so don't break a line there."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 ;; XEmacs addition:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (barf-if-buffer-read-only nil (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 (list (region-beginning) (region-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (if current-prefix-arg 'full))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
632 (let (end start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (goto-char (max from to))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 (if to-eop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 (progn (skip-chars-backward "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (forward-paragraph)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 (setq end (point))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
639 (goto-char (setq start (min from to)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (narrow-to-region (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (let ((initial (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 ;; If using hard newlines, break at every one for filling
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
646 ;; purposes rather than using paragraph breaks.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (if use-hard-newlines
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
648 (progn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 (while (and (setq end (text-property-any (point) (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 'hard t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 (not (eq ?\n (char-after end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 (not (= end (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (goto-char (1+ end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 (setq end (if end (min (point-max) (1+ end)) (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (goto-char initial))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 (forward-paragraph 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (forward-paragraph -1))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
659 (if (< (point) start)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
660 (goto-char start))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (if (>= (point) initial)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (fill-region-as-paragraph (point) end justify nosqueeze)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 (goto-char end)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (defun fill-paragraph-or-region (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 "Fill the current region, if it's active; otherwise, fill the paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 See `fill-paragraph' and `fill-region' for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (if (region-active-p)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
670 (call-interactively 'fill-region)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
671 (call-interactively 'fill-paragraph)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
673
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (defconst default-justification 'left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 "*Method of justifying text not otherwise specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 Possible values are `left', `right', `full', `center', or `none'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 The requested kind of justification is done whenever lines are filled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 The `justification' text-property can locally override this variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 This variable automatically becomes buffer-local when set in any fashion.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 (make-variable-buffer-local 'default-justification)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 (defun current-justification ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 "How should we justify this line?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 This returns the value of the text-property `justification',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 or the variable `default-justification' if there is no text-property.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 However, it returns nil rather than `none' to mean \"don't justify\"."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
687 (let ((j (or (get-text-property
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 ;; Make sure we're looking at paragraph body.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
689 (save-excursion (skip-chars-forward " \t")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 (if (and (eobp) (not (bobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 (1- (point)) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 'justification)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 default-justification)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 (if (eq 'none j)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 j)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 (defun set-justification (begin end value &optional whole-par)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 "Set the region's justification style.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 The kind of justification to use is prompted for.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 If the mark is not active, this command operates on the current paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 If the mark is active, the region is used. However, if the beginning and end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 of the region are not at paragraph breaks, they are moved to the beginning and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 end of the paragraphs they are in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 If `use-hard-newlines' is true, all hard newlines are taken to be paragraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 breaks.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 When calling from a program, operates just on region between BEGIN and END,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 extended to include entire paragraphs as in the interactive command."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 ;; XEmacs change (was mark-active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 (interactive (list (if (region-active-p) (region-beginning) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (if (region-active-p) (region-end) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 (let ((s (completing-read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 "Set justification to: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 '(("left") ("right") ("full")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 ("center") ("none"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 (if (equal s "") (error ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 (intern s))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 (if whole-par
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 (let ((paragraph-start (if use-hard-newlines "." paragraph-start))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
726 (paragraph-ignore-fill-prefix (if use-hard-newlines t
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 paragraph-ignore-fill-prefix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 (goto-char begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 (while (and (bolp) (not (eobp))) (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 (backward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 (setq begin (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (skip-chars-backward " \t\n" begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 (forward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 (setq end (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (narrow-to-region (point-min) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 (unjustify-region begin (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (put-text-property begin (point-max) 'justification value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 (fill-region begin (point-max) nil t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 (defun set-justification-none (b e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 "Disable automatic filling for paragraphs in the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 If the mark is not active, this applies to the current paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 ;; XEmacs change (was mark-active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 (interactive (list (if (region-active-p) (region-beginning) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 (if (region-active-p) (region-end) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 (set-justification b e 'none t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 (defun set-justification-left (b e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 "Make paragraphs in the region left-justified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 This is usually the default, but see the variable `default-justification'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 If the mark is not active, this applies to the current paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 ;; XEmacs change (was mark-active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (interactive (list (if (region-active-p) (region-beginning) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (if (region-active-p) (region-end) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 (set-justification b e 'left t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 (defun set-justification-right (b e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 "Make paragraphs in the region right-justified:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 Flush at the right margin and ragged on the left.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 If the mark is not active, this applies to the current paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 ;; XEmacs change (was mark-active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 (interactive (list (if (region-active-p) (region-beginning) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 (if (region-active-p) (region-end) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (set-justification b e 'right t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (defun set-justification-full (b e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 "Make paragraphs in the region fully justified:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 This makes lines flush on both margins by inserting spaces between words.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 If the mark is not active, this applies to the current paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 ;; XEmacs change (was mark-active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 (interactive (list (if (region-active-p) (region-beginning) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 (if (region-active-p) (region-end) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 (set-justification b e 'full t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 (defun set-justification-center (b e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 "Make paragraphs in the region centered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 If the mark is not active, this applies to the current paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 ;; XEmacs change (was mark-active)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 (interactive (list (if (region-active-p) (region-beginning) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 (if (region-active-p) (region-end) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (set-justification b e 'center t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 ;; 97/3/14 jhod: This functions are added for Kinsoku support
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 (defun find-space-insertable-point ()
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
787 "Search backward for a permissible point for inserting justification spaces."
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 502
diff changeset
788 (if-boundp 'space-insertable
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 502
diff changeset
789 (if (re-search-backward space-insertable nil t)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (progn (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 (search-backward " " nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 ;; A line has up to six parts:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 ;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
797 ;; >>> hello.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 ;; [Indent-1][FP][ Indent-2 ][text][trailing whitespace][newline]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 ;; "Indent-1" is the left-margin indentation; normally it ends at column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 ;; given by the `current-left-margin' function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 ;; "FP" is the fill-prefix. It can be any string, including whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 ;; "Indent-2" is added to justify a line if the `current-justification' is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 ;; `center' or `right'. In `left' and `full' justification regions, any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 ;; whitespace there is part of the line's text, and should not be changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 ;; Trailing whitespace is not counted as part of the line length when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 ;; center- or right-justifying.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 ;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
809 ;; All parts of the line are optional, although the final newline can
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 ;; only be missing on the last line of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 (defun justify-current-line (&optional how eop nosqueeze)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 "Do some kind of justification on this line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 Normally does full justification: adds spaces to the line to make it end at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 the column given by `current-fill-column'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 Optional first argument HOW specifies alternate type of justification:
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
817 it can be `left', `right', `full', `center', or `none'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 If HOW is t, will justify however the `current-justification' function says to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 If HOW is nil or missing, full justification is done by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 Second arg EOP non-nil means that this is the last line of the paragraph, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 it will not be stretched by full justification.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 otherwise it is made canonical."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (if (eq t how) (setq how (or (current-justification) 'none))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (if (null how) (setq how 'full)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (or (memq how '(none left right center))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (setq how 'full))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 (or (memq how '(none left)) ; No action required for these.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 (let ((fc (current-fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 (pos (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 fp-end ; point at end of fill prefix
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
833 start ; point at beginning of line's text
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 end ; point at end of line's text
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
835 indent ; column of `start'
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 endcol ; column of `end'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 ncols) ; new indent point or offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 ;; Check if this is the last line of the paragraph.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
840 (if (and use-hard-newlines (null eop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 (get-text-property (point) 'hard))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 (setq eop t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 ;; Quick exit if it appears to be properly justified already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 ;; or there is no text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 (if (or (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 (and (memq how '(full right))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (= (current-column) fc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 ;; Skip over fill-prefix.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
854 (if (and fill-prefix
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (not (string-equal fill-prefix ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 (equal fill-prefix
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
857 (buffer-substring
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 (point) (min (point-max) (+ (length fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 (point))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (forward-char (length fill-prefix))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
861 (if (and adaptive-fill-mode
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 (looking-at adaptive-fill-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (goto-char (match-end 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (setq fp-end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 ;; This is beginning of the line's text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (setq indent (current-column))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
868 (setq start (point))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 (setq endcol (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 ;; HOW can't be null or left--we would have exited already
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
873 (cond ((eq 'right how)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (setq ncols (- fc endcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (if (< ncols 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 ;; Need to remove some indentation
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
877 (delete-region
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 (progn (goto-char fp-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 (if (< (current-column) (+ indent ncols))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 (move-to-column (+ indent ncols) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 (progn (move-to-column indent) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 ;; Need to add some
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
884 (goto-char start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (indent-to (+ indent ncols))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 ;; If point was at beginning of text, keep it there.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
887 (if (= start pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (move-marker pos (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 ((eq 'center how)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 ;; Figure out how much indentation is needed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (setq ncols (+ (current-left-margin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 (/ (- fc (current-left-margin) ;avail. space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (- endcol indent)) ;text width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 2)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (if (< ncols indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 ;; Have too much indentation - remove some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 (delete-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 (progn (goto-char fp-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 (if (< (current-column) ncols)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (move-to-column ncols t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (progn (move-to-column indent) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 ;; Have too little - add some
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
905 (goto-char start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (indent-to ncols)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 ;; If point was at beginning of text, keep it there.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
908 (if (= start pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 (move-marker pos (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 ((eq 'full how)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 ;; Insert extra spaces between words to justify line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 (save-restriction
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
914 (narrow-to-region start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (or nosqueeze
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
916 (canonically-space-region start end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (setq ncols (- fc endcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 ;; Ncols is number of additional spaces needed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 (if (> ncols 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (if (and (not eop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (find-space-insertable-point)) ;(search-backward " " nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (while (> ncols 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (let ((nmove (+ 3 (random 3))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 (while (> nmove 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (or (find-space-insertable-point) ;(search-backward " " nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (find-space-insertable-point))) ;(search-backward " ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (skip-chars-backward " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (setq nmove (1- nmove))))
2510
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
933 (insert-and-inherit " ")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (skip-chars-backward " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (setq ncols (1- ncols)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 (t (error "Unknown justification value"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (goto-char pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 (move-marker pos nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (defun unjustify-current-line ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 "Remove justification whitespace from current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 If the line is centered or right-justified, this function removes any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 indentation past the left margin. If the line is full-justified, it removes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 extra spaces between words. It does nothing in other justification modes."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 (let ((justify (current-justification)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (cond ((eq 'left justify) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 ((eq nil justify) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 ((eq 'full justify) ; full justify: remove extra spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (beginning-of-line-text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 (canonically-space-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 (point) (save-excursion (end-of-line) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 ((memq justify '(center right))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 (move-to-left-margin nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 ;; Position ourselves after any fill-prefix.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
957 (if (and fill-prefix
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 (not (string-equal fill-prefix ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (equal fill-prefix
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
960 (buffer-substring
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 (point) (min (point-max) (+ (length fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (point))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (forward-char (length fill-prefix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (delete-region (point) (progn (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 (point))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 (defun unjustify-region (&optional begin end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 "Remove justification whitespace from region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 For centered or right-justified regions, this function removes any indentation
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
970 past the left margin from each line. For full-justified lines, it removes
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 extra spaces between words. It does nothing in other justification modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 Arguments BEGIN and END are optional; default is the whole buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (if end (narrow-to-region (point-min) end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 (goto-char (or begin (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (unjustify-current-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (forward-line 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (defun fill-nonuniform-paragraphs (min max &optional justifyp mailp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 "Fill paragraphs within the region, allowing varying indentation within each.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 This command divides the region into \"paragraphs\",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 only at paragraph-separator lines, then fills each paragraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 using as the fill prefix the smallest indentation of any line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 in the paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 When calling from a program, pass range to fill as first two arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 JUSTIFY to justify paragraphs (prefix arg),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 MAIL-FLAG for a mail message, i. e. don't fill header lines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (interactive (list (region-beginning) (region-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (if current-prefix-arg 'full)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 (let ((fill-individual-varying-indent t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 (fill-individual-paragraphs min max justifyp mailp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 (defun fill-individual-paragraphs (min max &optional justify mailp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 "Fill paragraphs of uniform indentation within the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 This command divides the region into \"paragraphs\",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 treating every change in indentation level as a paragraph boundary,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 then fills each paragraph using its indentation level as the fill prefix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 When calling from a program, pass range to fill as first two arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 JUSTIFY to justify paragraphs (prefix arg),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 MAIL-FLAG for a mail message, i. e. don't fill header lines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (interactive (list (region-beginning) (region-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (if current-prefix-arg 'full)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (goto-char min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 (narrow-to-region (point) max)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1017 (if mailp
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 (while (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (or (looking-at "[ \t]*[^ \t\n]+:")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (looking-at "[ \t]*$")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 (if (looking-at "[ \t]*[^ \t\n]+:")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (search-forward "\n\n" nil 'move)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 (forward-line 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 (narrow-to-region (point) max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 ;; Loop over paragraphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (while (progn (skip-chars-forward " \t\n") (not (eobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 (move-to-left-margin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (let ((start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 fill-prefix fill-prefix-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 ;; Find end of paragraph, and compute the smallest fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 ;; that fits all the lines in this paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 ;; Update the fill-prefix on the first line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 ;; and whenever the prefix good so far is too long.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (if (not (and fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (looking-at fill-prefix-regexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (setq fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 (if (and adaptive-fill-mode adaptive-fill-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (looking-at adaptive-fill-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (match-string 0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1041 (buffer-substring
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (save-excursion (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 fill-prefix-regexp (regexp-quote fill-prefix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (if (bolp)
2510
6f72d9a709c3 [xemacs-hg @ 2005-01-26 09:56:05 by ben]
ben
parents: 776
diff changeset
1048 ;; If forward-line went past a newline,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 ;; move further to the left margin.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (move-to-left-margin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 ;; Now stop the loop if end of paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (if fill-individual-varying-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 ;; If this line is a separator line, with or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 ;; without prefix, end the paragraph.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 440
diff changeset
1056 (and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (not (looking-at paragraph-separate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (not (and (looking-at fill-prefix-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 (forward-char (length fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (looking-at paragraph-separate))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 ;; If this line has more or less indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 ;; than the fill prefix wants, end the paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (and (looking-at fill-prefix-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (forward-char (length fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 (or (looking-at paragraph-separate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (looking-at paragraph-start))))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 ;; Fill this paragraph, but don't add a newline at the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (let ((had-newline (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 (fill-region-as-paragraph start (point) justify)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 (or had-newline (delete-char -1))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 ;;; fill.el ends here