diff options
| author | Juri Linkov | 2018-02-21 23:30:18 +0200 |
|---|---|---|
| committer | Juri Linkov | 2018-02-21 23:30:18 +0200 |
| commit | d48e07aaed0baf81baf377a9f2745678c9a5d41b (patch) | |
| tree | 0842337daaf650689714b75a465dc022484e4a6e | |
| parent | 465207221d44e4774b2df3db8fa570de92daf456 (diff) | |
| download | emacs-d48e07aaed0baf81baf377a9f2745678c9a5d41b.tar.gz emacs-d48e07aaed0baf81baf377a9f2745678c9a5d41b.zip | |
* lisp/simple.el (next-error-find-buffer-function): New defcustom.
(next-error-last-buffer): Make variable buffer-local.
(next-error-buffer-on-selected-frame): New function.
(next-error-find-buffer): Use next-error-find-buffer-function
at the first step instead of ad-hoc logic of using one window
on the selected frame.
(next-error, next-error-internal): Set default value of
next-error-last-buffer. Display message with the name of last
next-error buffer.
(next-error-select-buffer): New command.
(Bug#20489)
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/simple.el | 65 |
2 files changed, 60 insertions, 12 deletions
| @@ -203,6 +203,13 @@ styles as configured by the variable 'completion-styles'. | |||
| 203 | These macros are analogue to 'let' and 'let*', but create bindings that | 203 | These macros are analogue to 'let' and 'let*', but create bindings that |
| 204 | are evaluated lazily. | 204 | are evaluated lazily. |
| 205 | 205 | ||
| 206 | ** next-error | ||
| 207 | |||
| 208 | *** New customizable variable next-error-find-buffer-function | ||
| 209 | defines the logic of finding a next-error capable buffer. | ||
| 210 | It has an option to use a single such buffer on selected frame, or | ||
| 211 | by default use the last buffer that navigated to the current buffer. | ||
| 212 | |||
| 206 | ** Eshell | 213 | ** Eshell |
| 207 | 214 | ||
| 208 | --- | 215 | --- |
diff --git a/lisp/simple.el b/lisp/simple.el index 0c54c8f2926..2101cfe8333 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -121,6 +121,7 @@ If non-nil, the value is passed directly to `recenter'." | |||
| 121 | A buffer becomes most recent when its compilation, grep, or | 121 | A buffer becomes most recent when its compilation, grep, or |
| 122 | similar mode is started, or when it is used with \\[next-error] | 122 | similar mode is started, or when it is used with \\[next-error] |
| 123 | or \\[compile-goto-error].") | 123 | or \\[compile-goto-error].") |
| 124 | (make-variable-buffer-local 'next-error-last-buffer) | ||
| 124 | 125 | ||
| 125 | (defvar next-error-function nil | 126 | (defvar next-error-function nil |
| 126 | "Function to use to find the next error in the current buffer. | 127 | "Function to use to find the next error in the current buffer. |
| @@ -169,6 +170,31 @@ rejected, and the function returns nil." | |||
| 169 | (and extra-test-inclusive | 170 | (and extra-test-inclusive |
| 170 | (funcall extra-test-inclusive)))))) | 171 | (funcall extra-test-inclusive)))))) |
| 171 | 172 | ||
| 173 | (defcustom next-error-find-buffer-function nil | ||
| 174 | "Function called to find a `next-error' capable buffer." | ||
| 175 | :type '(choice (const :tag "Single next-error capable buffer on selected frame" | ||
| 176 | next-error-buffer-on-selected-frame) | ||
| 177 | (const :tag "No default" nil) | ||
| 178 | (function :tag "Other function")) | ||
| 179 | :group 'next-error | ||
| 180 | :version "27.1") | ||
| 181 | |||
| 182 | (defun next-error-buffer-on-selected-frame (&optional avoid-current | ||
| 183 | extra-test-inclusive | ||
| 184 | extra-test-exclusive) | ||
| 185 | "Return a single visible next-error buffer on the selected frame." | ||
| 186 | (let ((window-buffers | ||
| 187 | (delete-dups | ||
| 188 | (delq nil (mapcar (lambda (w) | ||
| 189 | (if (next-error-buffer-p | ||
| 190 | (window-buffer w) | ||
| 191 | avoid-current | ||
| 192 | extra-test-inclusive extra-test-exclusive) | ||
| 193 | (window-buffer w))) | ||
| 194 | (window-list)))))) | ||
| 195 | (if (eq (length window-buffers) 1) | ||
| 196 | (car window-buffers)))) | ||
| 197 | |||
| 172 | (defun next-error-find-buffer (&optional avoid-current | 198 | (defun next-error-find-buffer (&optional avoid-current |
| 173 | extra-test-inclusive | 199 | extra-test-inclusive |
| 174 | extra-test-exclusive) | 200 | extra-test-exclusive) |
| @@ -185,18 +211,11 @@ The function EXTRA-TEST-EXCLUSIVE, if non-nil, is called in each buffer | |||
| 185 | that would normally be considered usable. If it returns nil, | 211 | that would normally be considered usable. If it returns nil, |
| 186 | that buffer is rejected." | 212 | that buffer is rejected." |
| 187 | (or | 213 | (or |
| 188 | ;; 1. If one window on the selected frame displays such buffer, return it. | 214 | ;; 1. If a customizable function returns a buffer, use it. |
| 189 | (let ((window-buffers | 215 | (when next-error-find-buffer-function |
| 190 | (delete-dups | 216 | (funcall next-error-find-buffer-function avoid-current |
| 191 | (delq nil (mapcar (lambda (w) | 217 | extra-test-inclusive |
| 192 | (if (next-error-buffer-p | 218 | extra-test-exclusive)) |
| 193 | (window-buffer w) | ||
| 194 | avoid-current | ||
| 195 | extra-test-inclusive extra-test-exclusive) | ||
| 196 | (window-buffer w))) | ||
| 197 | (window-list)))))) | ||
| 198 | (if (eq (length window-buffers) 1) | ||
| 199 | (car window-buffers))) | ||
| 200 | ;; 2. If next-error-last-buffer is an acceptable buffer, use that. | 219 | ;; 2. If next-error-last-buffer is an acceptable buffer, use that. |
| 201 | (if (and next-error-last-buffer | 220 | (if (and next-error-last-buffer |
| 202 | (next-error-buffer-p next-error-last-buffer avoid-current | 221 | (next-error-buffer-p next-error-last-buffer avoid-current |
| @@ -261,11 +280,20 @@ To control which errors are matched, customize the variable | |||
| 261 | (when buffer | 280 | (when buffer |
| 262 | ;; We know here that next-error-function is a valid symbol we can funcall | 281 | ;; We know here that next-error-function is a valid symbol we can funcall |
| 263 | (with-current-buffer buffer | 282 | (with-current-buffer buffer |
| 283 | ;; Allow next-error to be used from the next-error capable buffer. | ||
| 284 | (setq next-error-last-buffer buffer) | ||
| 264 | (funcall next-error-function (prefix-numeric-value arg) reset) | 285 | (funcall next-error-function (prefix-numeric-value arg) reset) |
| 265 | ;; Override possible change of next-error-last-buffer in next-error-function | 286 | ;; Override possible change of next-error-last-buffer in next-error-function |
| 266 | (setq next-error-last-buffer buffer) | 287 | (setq next-error-last-buffer buffer) |
| 288 | (setq-default next-error-last-buffer buffer) | ||
| 267 | (when next-error-recenter | 289 | (when next-error-recenter |
| 268 | (recenter next-error-recenter)) | 290 | (recenter next-error-recenter)) |
| 291 | (message "%s error from %s" | ||
| 292 | (cond (reset "First") | ||
| 293 | ((eq (prefix-numeric-value arg) 0) "Current") | ||
| 294 | ((< (prefix-numeric-value arg) 0) "Previous") | ||
| 295 | (t "Next")) | ||
| 296 | next-error-last-buffer) | ||
| 269 | (run-hooks 'next-error-hook))))) | 297 | (run-hooks 'next-error-hook))))) |
| 270 | 298 | ||
| 271 | (defun next-error-internal () | 299 | (defun next-error-internal () |
| @@ -273,13 +301,26 @@ To control which errors are matched, customize the variable | |||
| 273 | (let ((buffer (current-buffer))) | 301 | (let ((buffer (current-buffer))) |
| 274 | ;; We know here that next-error-function is a valid symbol we can funcall | 302 | ;; We know here that next-error-function is a valid symbol we can funcall |
| 275 | (with-current-buffer buffer | 303 | (with-current-buffer buffer |
| 304 | ;; Allow next-error to be used from the next-error capable buffer. | ||
| 305 | (setq next-error-last-buffer buffer) | ||
| 276 | (funcall next-error-function 0 nil) | 306 | (funcall next-error-function 0 nil) |
| 277 | ;; Override possible change of next-error-last-buffer in next-error-function | 307 | ;; Override possible change of next-error-last-buffer in next-error-function |
| 278 | (setq next-error-last-buffer buffer) | 308 | (setq next-error-last-buffer buffer) |
| 309 | (setq-default next-error-last-buffer buffer) | ||
| 279 | (when next-error-recenter | 310 | (when next-error-recenter |
| 280 | (recenter next-error-recenter)) | 311 | (recenter next-error-recenter)) |
| 312 | (message "Current error from %s" next-error-last-buffer) | ||
| 281 | (run-hooks 'next-error-hook)))) | 313 | (run-hooks 'next-error-hook)))) |
| 282 | 314 | ||
| 315 | (defun next-error-select-buffer (buffer) | ||
| 316 | "Select a `next-error' capable buffer and set it as the last used." | ||
| 317 | (interactive | ||
| 318 | (list (get-buffer | ||
| 319 | (read-buffer "Select next-error buffer: " nil nil | ||
| 320 | (lambda (b) (next-error-buffer-p (cdr b))))))) | ||
| 321 | (setq next-error-last-buffer buffer) | ||
| 322 | (setq-default next-error-last-buffer buffer)) | ||
| 323 | |||
| 283 | (defalias 'goto-next-locus 'next-error) | 324 | (defalias 'goto-next-locus 'next-error) |
| 284 | (defalias 'next-match 'next-error) | 325 | (defalias 'next-match 'next-error) |
| 285 | 326 | ||