aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2004-12-27 16:34:43 +0000
committerRichard M. Stallman2004-12-27 16:34:43 +0000
commite967cd114c37474fc7f91c358e4b06fb7ce653d8 (patch)
treecad34c804b9037503fadf2bf5bf407a250deb7cd
parentf6e4371206111ca0a06fb85b27307d4e87639cf3 (diff)
downloademacs-e967cd114c37474fc7f91c358e4b06fb7ce653d8.tar.gz
emacs-e967cd114c37474fc7f91c358e4b06fb7ce653d8.zip
(next-error-buffer-p): New arg AVOID-CURRENT.
Test that the buffer is live, and maybe reject current buffer too. Rewrite for clarity. (next-error-find-buffer): Rewrite for clarity. (undo-list-saved): New variable (buffer-local). (undo): Set and test it. (next-matching-history-element): Use same `interactive' form as previous-matching-history-element.
-rw-r--r--lisp/simple.el128
1 files changed, 82 insertions, 46 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 9f1bde393ee..008d52eabc1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -124,70 +124,87 @@ to navigate in it.")
124(make-variable-buffer-local 'next-error-function) 124(make-variable-buffer-local 'next-error-function)
125 125
126(defsubst next-error-buffer-p (buffer 126(defsubst next-error-buffer-p (buffer
127 &optional 127 &optional avoid-current
128 extra-test-inclusive 128 extra-test-inclusive
129 extra-test-exclusive) 129 extra-test-exclusive)
130 "Test if BUFFER is a next-error capable buffer. 130 "Test if BUFFER is a next-error capable buffer.
131EXTRA-TEST-INCLUSIVE is called to allow extra buffers. 131
132EXTRA-TEST-EXCLUSIVE is called to disallow buffers." 132If AVOID-CURRENT is non-nil, treat the current buffer
133 (with-current-buffer buffer 133as an absolute last resort only.
134 (or (and extra-test-inclusive (funcall extra-test-inclusive)) 134
135 (and (if extra-test-exclusive (funcall extra-test-exclusive) t) 135The function EXTRA-TEST-INCLUSIVE, if non-nil, is called in each buffer
136 next-error-function)))) 136that normally would not qualify. If it returns t, the buffer
137 137in question is treated as usable.
138(defun next-error-find-buffer (&optional other-buffer 138
139The function EXTRA-TEST-EXCLUSIVE, if non-nil is called in each buffer
140that would normally be considered usable. if it returns nil,
141that buffer is rejected."
142 (and (buffer-name buffer) ;First make sure it's live.
143 (not (and avoid-current (eq buffer (current-buffer))))
144 (with-current-buffer buffer
145 (if next-error-function ; This is the normal test.
146 ;; Optionally reject some buffers.
147 (if extra-test-exclusive
148 (funcall extra-test-exclusive)
149 t)
150 ;; Optionally accept some other buffers.
151 (and extra-test-inclusive
152 (funcall extra-test-inclusive))))))
153
154(defun next-error-find-buffer (&optional avoid-current
139 extra-test-inclusive 155 extra-test-inclusive
140 extra-test-exclusive) 156 extra-test-exclusive)
141 "Return a next-error capable buffer. 157 "Return a next-error capable buffer.
142OTHER-BUFFER will disallow the current buffer. 158If AVOID-CURRENT is non-nil, treat the current buffer
143EXTRA-TEST-INCLUSIVE is called to allow extra buffers. 159as an absolute last resort only.
144EXTRA-TEST-EXCLUSIVE is called to disallow buffers." 160
161The function EXTRA-TEST-INCLUSIVE, if non-nil, is called in each buffers
162that normally would not qualify. If it returns t, the buffer
163in question is treated as usable.
164
165The function EXTRA-TEST-EXCLUSIVE, if non-nil is called in each buffer
166that would normally be considered usable. If it returns nil,
167that buffer is rejected."
145 (or 168 (or
146 ;; 1. If one window on the selected frame displays such buffer, return it. 169 ;; 1. If one window on the selected frame displays such buffer, return it.
147 (let ((window-buffers 170 (let ((window-buffers
148 (delete-dups 171 (delete-dups
149 (delq nil (mapcar (lambda (w) 172 (delq nil (mapcar (lambda (w)
150 (if (next-error-buffer-p 173 (if (next-error-buffer-p
151 (window-buffer w) 174 (window-buffer w)
175 avoid-current
152 extra-test-inclusive extra-test-exclusive) 176 extra-test-inclusive extra-test-exclusive)
153 (window-buffer w))) 177 (window-buffer w)))
154 (window-list)))))) 178 (window-list))))))
155 (if other-buffer
156 (setq window-buffers (delq (current-buffer) window-buffers)))
157 (if (eq (length window-buffers) 1) 179 (if (eq (length window-buffers) 1)
158 (car window-buffers))) 180 (car window-buffers)))
159 ;; 2. If next-error-last-buffer is set to a live buffer, use that. 181 ;; 2. If next-error-last-buffer is an acceptable buffer, use that.
160 (if (and next-error-last-buffer 182 (if (and next-error-last-buffer
161 (buffer-name next-error-last-buffer) 183 (next-error-buffer-p next-error-last-buffer avoid-current
162 (next-error-buffer-p next-error-last-buffer
163 extra-test-inclusive extra-test-exclusive)
164 (or (not other-buffer)
165 (not (eq next-error-last-buffer (current-buffer)))))
166 next-error-last-buffer)
167 ;; 3. If the current buffer is a next-error capable buffer, return it.
168 (if (and (not other-buffer)
169 (next-error-buffer-p (current-buffer)
170 extra-test-inclusive extra-test-exclusive)) 184 extra-test-inclusive extra-test-exclusive))
185 next-error-last-buffer)
186 ;; 3. If the current buffer is acceptable, choose it.
187 (if (next-error-buffer-p (current-buffer) avoid-current
188 extra-test-inclusive extra-test-exclusive)
171 (current-buffer)) 189 (current-buffer))
172 ;; 4. Look for a next-error capable buffer in a buffer list. 190 ;; 4. Look for any acceptable buffer.
173 (let ((buffers (buffer-list))) 191 (let ((buffers (buffer-list)))
174 (while (and buffers 192 (while (and buffers
175 (or (not (next-error-buffer-p 193 (not (next-error-buffer-p
176 (car buffers) 194 (car buffers) avoid-current
177 extra-test-inclusive extra-test-exclusive)) 195 extra-test-inclusive extra-test-exclusive)))
178 (and other-buffer (eq (car buffers) (current-buffer)))))
179 (setq buffers (cdr buffers))) 196 (setq buffers (cdr buffers)))
180 (if buffers 197 (car buffers))
181 (car buffers) 198 ;; 5. Use the current buffer as a last resort if it qualifies,
182 (or (and other-buffer 199 ;; even despite AVOID-CURRENT.
183 (next-error-buffer-p (current-buffer) 200 (and avoid-current
184 extra-test-inclusive extra-test-exclusive) 201 (next-error-buffer-p (current-buffer) nil
185 ;; The current buffer is a next-error capable buffer. 202 extra-test-inclusive extra-test-exclusive)
186 (progn 203 (progn
187 (if other-buffer 204 (message "This is the only next-error capable buffer")
188 (message "This is the only next-error capable buffer")) 205 (current-buffer)))
189 (current-buffer))) 206 ;; 6. Give up.
190 (error "No next-error capable buffer found")))))) 207 (error "No next-error capable buffer found")))
191 208
192(defun next-error (&optional arg reset) 209(defun next-error (&optional arg reset)
193 "Visit next next-error message and corresponding source code. 210 "Visit next next-error message and corresponding source code.
@@ -1113,11 +1130,13 @@ makes the search case-sensitive."
1113 nil 1130 nil
1114 minibuffer-local-map 1131 minibuffer-local-map
1115 nil 1132 nil
1116 'minibuffer-history-search-history))) 1133 'minibuffer-history-search-history
1134 (car minibuffer-history-search-history))))
1117 ;; Use the last regexp specified, by default, if input is empty. 1135 ;; Use the last regexp specified, by default, if input is empty.
1118 (list (if (string= regexp "") 1136 (list (if (string= regexp "")
1119 (setcar minibuffer-history-search-history 1137 (if minibuffer-history-search-history
1120 (nth 1 minibuffer-history-search-history)) 1138 (car minibuffer-history-search-history)
1139 (error "No previous history search regexp"))
1121 regexp) 1140 regexp)
1122 (prefix-numeric-value current-prefix-arg)))) 1141 (prefix-numeric-value current-prefix-arg))))
1123 (previous-matching-history-element regexp (- n))) 1142 (previous-matching-history-element regexp (- n)))
@@ -1215,6 +1234,10 @@ Return 0 if current buffer is not a mini-buffer."
1215(defvar undo-no-redo nil 1234(defvar undo-no-redo nil
1216 "If t, `undo' doesn't go through redo entries.") 1235 "If t, `undo' doesn't go through redo entries.")
1217 1236
1237(defvar undo-list-saved nil
1238 "The value of `buffer-undo-list' saved by the last undo command.")
1239(make-variable-buffer-local 'undo-list-saved)
1240
1218(defun undo (&optional arg) 1241(defun undo (&optional arg)
1219 "Undo some previous changes. 1242 "Undo some previous changes.
1220Repeat this command to undo more changes. 1243Repeat this command to undo more changes.
@@ -1237,7 +1260,10 @@ as an argument limits undo to changes within the current region."
1237 ;; So set `this-command' to something other than `undo'. 1260 ;; So set `this-command' to something other than `undo'.
1238 (setq this-command 'undo-start) 1261 (setq this-command 'undo-start)
1239 1262
1240 (unless (eq last-command 'undo) 1263 (unless (and (eq last-command 'undo)
1264 ;; If something (a timer or filter?) changed the buffer
1265 ;; since the previous command, don't continue the undo seq.
1266 (eq undo-list-saved buffer-undo-list))
1241 (setq undo-in-region 1267 (setq undo-in-region
1242 (if transient-mark-mode mark-active (and arg (not (numberp arg))))) 1268 (if transient-mark-mode mark-active (and arg (not (numberp arg)))))
1243 (if undo-in-region 1269 (if undo-in-region
@@ -1289,10 +1315,20 @@ as an argument limits undo to changes within the current region."
1289 (setq tail (cdr tail))) 1315 (setq tail (cdr tail)))
1290 (setq tail nil))) 1316 (setq tail nil)))
1291 (setq prev tail tail (cdr tail)))) 1317 (setq prev tail tail (cdr tail))))
1292 1318 ;; Record what the current undo list says,
1319 ;; so the next command can tell if the buffer was modified in between.
1320 (setq undo-list-saved buffer-undo-list)
1293 (and modified (not (buffer-modified-p)) 1321 (and modified (not (buffer-modified-p))
1294 (delete-auto-save-file-if-necessary recent-save)))) 1322 (delete-auto-save-file-if-necessary recent-save))))
1295 1323
1324(defun buffer-disable-undo (&optional buffer)
1325 "Make BUFFER stop keeping undo information.
1326No argument or nil as argument means do this for the current buffer."
1327 (interactive)
1328 (with-current-buffer (get-buffer buffer)
1329 (setq buffer-undo-list t
1330 undo-list-saved nil)))
1331
1296(defun undo-only (&optional arg) 1332(defun undo-only (&optional arg)
1297 "Undo some previous changes. 1333 "Undo some previous changes.
1298Repeat this command to undo more changes. 1334Repeat this command to undo more changes.