aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2000-11-21 01:11:49 +0000
committerMiles Bader2000-11-21 01:11:49 +0000
commit867092e9acfee14acbd6e2bbe04a35aa1c44f06f (patch)
tree96f2640162b7a3ad1a39c25654d239ad13fb5bf1
parent1a55ec5a9e71f4b6539327508110c703c0365372 (diff)
downloademacs-867092e9acfee14acbd6e2bbe04a35aa1c44f06f.tar.gz
emacs-867092e9acfee14acbd6e2bbe04a35aa1c44f06f.zip
(refill-ignorable-overlay): New variable.
(refill-adjust-ignorable-overlay): New function. (refill-pre-command-function): New function. (refill-mode): Add `refill-pre-command-function' to `pre-command-hook'. Initialize/cleanup `refill-ignorable-overlay'. (refill-post-command-function): Don't reset refill-doit in the case where a self-insertion command doesn't case a refill. Use `refill-fill-paragraph-at', getting position from `refill-doit'. (refill-after-change-function): Set `refill-doit' to END. (refill-fill-paragraph-at): New function, mostly from old refill-fill-paragraph. Use `refill-ignorable-overlay' to fill only the paragraph's tail if possible. Update `refill-ignorable-overlay'. Don't leave point inside the fill-prefix. (refill-fill-paragraph): Use `refill-fill-paragraph-at'.
-rw-r--r--lisp/ChangeLog23
-rw-r--r--lisp/textmodes/refill.el152
2 files changed, 134 insertions, 41 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1bbfe512907..ebbe543adf1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,26 @@
12000-11-21 Miles Bader <miles@gnu.org>
2
3 * textmodes/refill.el (refill-ignorable-overlay): New variable.
4 (refill-adjust-ignorable-overlay): New function.
5 (refill-fill-paragraph-at): Use `refill-ignorable-overlay' to fill
6 only the paragraph's tail if possible.
7 Update `refill-ignorable-overlay'.
8 (refill-mode): Initialize/cleanup `refill-ignorable-overlay'.
9
10 * textmodes/refill.el (refill-fill-paragraph-at): Don't leave
11 point inside the fill-prefix.
12
13 * textmodes/refill.el (refill-post-command-function): Don't reset
14 refill-doit in the case where a self-insertion command doesn't
15 case a refill. Use `refill-fill-paragraph-at', getting position
16 from `refill-doit'.
17 (refill-after-change-function): Set `refill-doit' to END.
18 (refill-fill-paragraph-at): New function, mostly from old
19 refill-fill-paragraph.
20 (refill-fill-paragraph): Use `refill-fill-paragraph-at'.
21 (refill-pre-command-function): New function.
22 (refill-mode): Add it to `pre-command-hook'.
23
12000-11-20 Gerd Moellmann <gerd@gnu.org> 242000-11-20 Gerd Moellmann <gerd@gnu.org>
2 25
3 * textmodes/artist.el (artist-mode): Fix autoload cookie. 26 * textmodes/artist.el (artist-mode): Fix autoload cookie.
diff --git a/lisp/textmodes/refill.el b/lisp/textmodes/refill.el
index 4e9039c87d4..0e15d38ccea 100644
--- a/lisp/textmodes/refill.el
+++ b/lisp/textmodes/refill.el
@@ -56,26 +56,74 @@
56 56
57;;; Code: 57;;; Code:
58 58
59(defun refill-fill-paragraph (arg) 59(defvar refill-ignorable-overlay nil
60 "Like `fill-paragraph' but don't delete whitespace at paragraph end." 60 "Portion of the most recently filled paragraph not needing filling.
61 ;; Should probably use a text property indicating previously-filled 61This is used to optimize refilling.")
62 ;; stuff to avoid filling before the point of change. 62(make-variable-buffer-local 'refill-ignorable-overlay)
63 (let ((before (point))) 63
64(defun refill-adjust-ignorable-overlay (overlay afterp beg end &optional len)
65 "Adjust OVERLAY to not include the about-to-be-modified region."
66 (when (not afterp)
67 (message "adjust: %s-%s" beg end)
68 (save-excursion
69 (goto-char beg)
70 (forward-line -1)
71 (if (<= (point) (overlay-start overlay))
72 ;; Just get OVERLAY out of the way
73 (move-overlay overlay 1 1)
74 ;; Make overlay contain only the region
75 (move-overlay overlay (overlay-start overlay) (point))))))
76
77(defun refill-fill-paragraph-at (pos &optional arg)
78 "Like `fill-paragraph' at POS, but don't delete whitespace at paragraph end."
79 (let (fill-pfx)
64 (save-excursion 80 (save-excursion
81 (goto-char pos)
65 (forward-paragraph) 82 (forward-paragraph)
66 (skip-syntax-backward "-") 83 (skip-syntax-backward "-")
67 (let ((end (point)) 84 (let ((end (point))
68 (beg (progn (backward-paragraph) (point)))) 85 (beg (progn (backward-paragraph) (point)))
69 (goto-char before) 86 (obeg (overlay-start refill-ignorable-overlay))
70 (save-restriction 87 (oend (overlay-end refill-ignorable-overlay)))
71 (if use-hard-newlines 88 (goto-char pos)
72 (fill-region beg end arg) 89 (if (and (>= beg obeg) (< beg oend))
73 (fill-region-as-paragraph beg end arg))))))) 90 ;; Limit filling to the modified tail of the paragraph.
91 (let (;; When adaptive-fill-mode is enabled, the filling
92 ;; functions will attempt to set the fill prefix from
93 ;; the fake paragraph bounds we pass in, so set it
94 ;; ourselves first, using the real paragraph bounds.
95 (fill-prefix
96 (if (and adaptive-fill-mode
97 (or (null fill-prefix) (string= fill-prefix "")))
98 (fill-context-prefix beg end)
99 fill-prefix))
100 ;; Turn off adaptive-fill-mode temporarily
101 (adaptive-fill-mode nil))
102 (message "refill-at %s: %s-%s" pos oend end)
103 (save-restriction
104 (if use-hard-newlines
105 (fill-region oend end arg)
106 (fill-region-as-paragraph oend end arg)))
107 (setq fill-pfx fill-prefix)
108 (move-overlay refill-ignorable-overlay obeg (point)))
109 ;; Fill the whole paragraph
110 (setq fill-pfx
111 (save-restriction
112 (if use-hard-newlines
113 (fill-region beg end arg)
114 (fill-region-as-paragraph beg end arg))))
115 (move-overlay refill-ignorable-overlay beg (point)))))
116 (skip-line-prefix fill-pfx)))
117
118(defun refill-fill-paragraph (arg)
119 "Like `fill-paragraph' but don't delete whitespace at paragraph end."
120 (refill-fill-paragraph-at (point) arg))
74 121
75(defvar refill-doit nil 122(defvar refill-doit nil
76 "Non-nil means that `refill-post-command-function' does its processing. 123 "Non-nil means that `refill-post-command-function' does its processing.
77Set by `refill-after-change-function' in `after-change-functions' and 124Set by `refill-after-change-function' in `after-change-functions' and
78unset by `refill-post-command-function' in `post-command-hook'. This 125unset by `refill-post-command-function' in `post-command-hook', and
126sometimes `refill-pre-command-function' in `pre-command-hook'. This
79ensures refilling is only done once per command that causes a change, 127ensures refilling is only done once per command that causes a change,
80regardless of the number of after-change calls from commands doing 128regardless of the number of after-change calls from commands doing
81complex processing.") 129complex processing.")
@@ -84,39 +132,54 @@ complex processing.")
84(defun refill-after-change-function (beg end len) 132(defun refill-after-change-function (beg end len)
85 "Function for `after-change-functions' which just sets `refill-doit'." 133 "Function for `after-change-functions' which just sets `refill-doit'."
86 (unless undo-in-progress 134 (unless undo-in-progress
87 (setq refill-doit t))) 135 (setq refill-doit end)))
88 136
89(defun refill-post-command-function () 137(defun refill-post-command-function ()
90 "Post-command function to do refilling (conditionally)." 138 "Post-command function to do refilling (conditionally)."
91 (when refill-doit ; there was a change 139 (when refill-doit ; there was a change
92 ;; There's probably scope for more special cases here... 140 ;; There's probably scope for more special cases here...
93 (cond 141 (if (eq this-command 'self-insert-command)
94 ((eq this-command 'self-insert-command) 142 ;; Treat self-insertion commands specially, since they don't
95 ;; Respond to the same characters as auto-fill (other than 143 ;; always reset `refill-doit' -- for self-insertion commands that
96 ;; newline, covered below). 144 ;; *don't* cause a refill, we want to leave it turned on so that
97 (if (aref auto-fill-chars (char-before)) 145 ;; any subsequent non-modification command will cause a refill.
98 (refill-fill-paragraph nil))) 146 (when (aref auto-fill-chars (char-before))
99 ((or (eq this-command 'quoted-insert) 147 ;; Respond to the same characters as auto-fill (other than
100 (eq this-command 'fill-paragraph) 148 ;; newline, covered below).
101 (eq this-command 'fill-region)) 149 (refill-fill-paragraph-at refill-doit)
102 nil) 150 (setq refill-doit nil))
103 ((or (eq this-command 'newline) 151 (cond
104 (eq this-command 'newline-and-indent) 152 ((or (eq this-command 'quoted-insert)
105 (eq this-command 'open-line)) 153 (eq this-command 'fill-paragraph)
106 ;; Don't zap what was just inserted. 154 (eq this-command 'fill-region))
107 (save-excursion 155 nil)
108 (beginning-of-line) ; for newline-and-indent 156 ((or (eq this-command 'newline)
109 (skip-chars-backward "\n") 157 (eq this-command 'newline-and-indent)
110 (save-restriction 158 (eq this-command 'open-line))
111 (narrow-to-region (point-min) (point)) 159 ;; Don't zap what was just inserted.
112 (refill-fill-paragraph nil))) 160 (save-excursion
113 (widen) 161 (beginning-of-line) ; for newline-and-indent
114 (save-excursion 162 (skip-chars-backward "\n")
115 (skip-chars-forward "\n") 163 (save-restriction
116 (save-restriction 164 (narrow-to-region (point-min) (point))
117 (narrow-to-region (line-beginning-position) (point-max)) 165 (refill-fill-paragraph-at refill-doit)))
118 (refill-fill-paragraph nil)))) 166 (widen)
119 (t (refill-fill-paragraph nil))) 167 (save-excursion
168 (skip-chars-forward "\n")
169 (save-restriction
170 (narrow-to-region (line-beginning-position) (point-max))
171 (refill-fill-paragraph-at refill-doit))))
172 (t
173 (refill-fill-paragraph-at refill-doit)))
174 (setq refill-doit nil))))
175
176(defun refill-pre-command-function ()
177 "Pre-command function to do refilling (conditionally)."
178 (when (and refill-doit (not (eq this-command 'self-insert-command)))
179 ;; A previous setting of `refill-doit' didn't result in a refill,
180 ;; because it was a self-insert-command. Since the next command is
181 ;; something else, do the refill now.
182 (refill-fill-paragraph-at refill-doit)
120 (setq refill-doit nil))) 183 (setq refill-doit nil)))
121 184
122(defvar refill-late-fill-paragraph-function nil) 185(defvar refill-late-fill-paragraph-function nil)
@@ -136,13 +199,20 @@ refilling if they would cause auto-filling."
136 (progn 199 (progn
137 (add-hook 'after-change-functions 'refill-after-change-function nil t) 200 (add-hook 'after-change-functions 'refill-after-change-function nil t)
138 (add-hook 'post-command-hook 'refill-post-command-function nil t) 201 (add-hook 'post-command-hook 'refill-post-command-function nil t)
202 (add-hook 'pre-command-hook 'refill-pre-command-function nil t)
139 (set (make-local-variable 'refill-late-fill-paragraph-function) 203 (set (make-local-variable 'refill-late-fill-paragraph-function)
140 fill-paragraph-function) 204 fill-paragraph-function)
141 (set (make-local-variable 'fill-paragraph-function) 205 (set (make-local-variable 'fill-paragraph-function)
142 'refill-fill-paragraph) 206 'refill-fill-paragraph)
207 (setq refill-ignorable-overlay (make-overlay 1 1 nil nil t))
208 (overlay-put refill-ignorable-overlay 'modification-hooks
209 '(refill-adjust-ignorable-overlay))
210 (overlay-put refill-ignorable-overlay 'insert-behind-hooks
211 '(refill-adjust-ignorable-overlay))
143 (auto-fill-mode 0)) 212 (auto-fill-mode 0))
144 (remove-hook 'after-change-functions 'refill-after-change-function t) 213 (remove-hook 'after-change-functions 'refill-after-change-function t)
145 (remove-hook 'post-command-hook 'refill-post-command-function t) 214 (remove-hook 'post-command-hook 'refill-post-command-function t)
215 (delete-overlay refill-ignorable-overlay)
146 (setq fill-paragraph-function refill-late-fill-paragraph-function))) 216 (setq fill-paragraph-function refill-late-fill-paragraph-function)))
147 217
148(provide 'refill) 218(provide 'refill)