diff options
| -rw-r--r-- | lisp/simple.el | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 6287090312c..494a9884100 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -66,6 +66,137 @@ | |||
| 66 | (setq list (cdr list))) | 66 | (setq list (cdr list))) |
| 67 | (switch-to-buffer found))) | 67 | (switch-to-buffer found))) |
| 68 | 68 | ||
| 69 | ;;; next-error support framework | ||
| 70 | (defvar next-error-last-buffer nil | ||
| 71 | "The most recent next-error buffer. | ||
| 72 | A buffer becomes most recent when its compilation, grep, or | ||
| 73 | similar mode is started, or when it is used with \\[next-error] | ||
| 74 | or \\[compile-goto-error].") | ||
| 75 | |||
| 76 | (defvar next-error-function nil | ||
| 77 | "The next-error vehicle for other modes. | ||
| 78 | This variable can be bound to a function by a mode. It is | ||
| 79 | buffer-local by default. Together with | ||
| 80 | `next-error-last-buffer', this variable lets modes hook into | ||
| 81 | \\[next-error].") | ||
| 82 | |||
| 83 | (make-variable-buffer-local 'next-error-function) | ||
| 84 | |||
| 85 | (defsubst next-error-buffer-p (buffer &optional extra-test) | ||
| 86 | "Test if BUFFER is a next-error capable buffer." | ||
| 87 | (with-current-buffer buffer | ||
| 88 | (or (and extra-test (funcall extra-test)) | ||
| 89 | next-error-function))) | ||
| 90 | |||
| 91 | ;; Return a next-error capable buffer. | ||
| 92 | ;; If the current buffer is such, return it. | ||
| 93 | ;; If next-error-last-buffer is set to a live buffer, use that. | ||
| 94 | ;; Otherwise, look for a next-error capable buffer and signal an error | ||
| 95 | ;; if there are none. | ||
| 96 | (defun next-error-find-buffer (&optional other-buffer extra-test) | ||
| 97 | (if (and (not other-buffer) | ||
| 98 | (next-error-buffer-p (current-buffer) extra-test)) | ||
| 99 | ;; The current buffer is a next-error capable buffer. | ||
| 100 | (current-buffer) | ||
| 101 | (if (and next-error-last-buffer (buffer-name next-error-last-buffer) | ||
| 102 | (next-error-buffer-p next-error-last-buffer extra-test) | ||
| 103 | (or (not other-buffer) (not (eq next-error-last-buffer | ||
| 104 | (current-buffer))))) | ||
| 105 | next-error-last-buffer | ||
| 106 | (let ((buffers (buffer-list))) | ||
| 107 | (while (and buffers (or (not (next-error-buffer-p (car buffers) extra-test)) | ||
| 108 | (and other-buffer | ||
| 109 | (eq (car buffers) (current-buffer))))) | ||
| 110 | (setq buffers (cdr buffers))) | ||
| 111 | (if buffers | ||
| 112 | (car buffers) | ||
| 113 | (or (and other-buffer | ||
| 114 | (next-error-buffer-p (current-buffer) extra-test) | ||
| 115 | ;; The current buffer is a next-error capable buffer. | ||
| 116 | (progn | ||
| 117 | (if other-buffer | ||
| 118 | (message "This is the only next-error capable buffer.")) | ||
| 119 | (current-buffer))) | ||
| 120 | (error "No next-error capable buffer found!"))))))) | ||
| 121 | |||
| 122 | (defun next-error (argp &optional reset) | ||
| 123 | "Visit next next-error message and corresponding source code. | ||
| 124 | |||
| 125 | If all the error messages parsed so far have been processed already, | ||
| 126 | the message buffer is checked for new ones. | ||
| 127 | |||
| 128 | A prefix ARGP specifies how many error messages to move; | ||
| 129 | negative means move back to previous error messages. | ||
| 130 | Just \\[universal-argument] as a prefix means reparse the error message buffer | ||
| 131 | and start at the first error. | ||
| 132 | |||
| 133 | The RESET argument specifies that we should restart from the beginning | ||
| 134 | |||
| 135 | \\[next-error] normally uses the most recently started | ||
| 136 | compilation, grep, or occur buffer. It can also operate on any | ||
| 137 | buffer with output from the \\[compile], \\[grep] commands, or, | ||
| 138 | more generally, on any buffer in Compilation mode or with | ||
| 139 | Compilation Minor mode enabled, or any buffer in which | ||
| 140 | `next-error-function' is bound to an appropriate | ||
| 141 | function. To specify use of a particular buffer for error | ||
| 142 | messages, type \\[next-error] in that buffer. | ||
| 143 | |||
| 144 | Once \\[next-error] has chosen the buffer for error messages, | ||
| 145 | it stays with that buffer until you use it in some other buffer which | ||
| 146 | uses Compilation mode or Compilation Minor mode. | ||
| 147 | |||
| 148 | See variables `compilation-parse-errors-function' and | ||
| 149 | \`compilation-error-regexp-alist' for customization ideas." | ||
| 150 | (interactive "P") | ||
| 151 | (when (setq next-error-last-buffer (next-error-find-buffer)) | ||
| 152 | ;; we know here that next-error-function is a valid symbol we can funcall | ||
| 153 | (with-current-buffer next-error-last-buffer | ||
| 154 | (funcall next-error-function argp reset)))) | ||
| 155 | |||
| 156 | (defalias 'goto-next-locus 'next-error) | ||
| 157 | (defalias 'next-match 'next-error) | ||
| 158 | |||
| 159 | (define-key ctl-x-map "`" 'next-error) | ||
| 160 | |||
| 161 | (defun previous-error (n) | ||
| 162 | "Visit previous next-error message and corresponding source code. | ||
| 163 | |||
| 164 | Prefix arg N says how many error messages to move backwards (or | ||
| 165 | forwards, if negative). | ||
| 166 | |||
| 167 | This operates on the output from the \\[compile] and \\[grep] commands." | ||
| 168 | (interactive "p") | ||
| 169 | (next-error (- n))) | ||
| 170 | |||
| 171 | (defun first-error (n) | ||
| 172 | "Restart at the first error. | ||
| 173 | Visit corresponding source code. | ||
| 174 | With prefix arg N, visit the source code of the Nth error. | ||
| 175 | This operates on the output from the \\[compile] command, for instance." | ||
| 176 | (interactive "p") | ||
| 177 | (next-error n t)) | ||
| 178 | |||
| 179 | (defun next-error-no-select (n) | ||
| 180 | "Move point to the next error in the next-error buffer and highlight match. | ||
| 181 | Prefix arg N says how many error messages to move forwards (or | ||
| 182 | backwards, if negative). | ||
| 183 | Finds and highlights the source line like \\[next-error], but does not | ||
| 184 | select the source buffer." | ||
| 185 | (interactive "p") | ||
| 186 | (next-error n) | ||
| 187 | (pop-to-buffer next-error-last-buffer)) | ||
| 188 | |||
| 189 | (defun previous-error-no-select (n) | ||
| 190 | "Move point to the previous error in the next-error buffer and highlight match. | ||
| 191 | Prefix arg N says how many error messages to move backwards (or | ||
| 192 | forwards, if negative). | ||
| 193 | Finds and highlights the source line like \\[previous-error], but does not | ||
| 194 | select the source buffer." | ||
| 195 | (interactive "p") | ||
| 196 | (next-error-no-select (- n))) | ||
| 197 | |||
| 198 | ;;; | ||
| 199 | |||
| 69 | (defun fundamental-mode () | 200 | (defun fundamental-mode () |
| 70 | "Major mode not specialized for anything in particular. | 201 | "Major mode not specialized for anything in particular. |
| 71 | Other major modes are defined by comparison with this one." | 202 | Other major modes are defined by comparison with this one." |