--- /local/share/src/emacs-cvs/lisp/progmodes/compile.el Wed Apr 7 16:23:31 2004 +++ /home/tzz/emacs/mine/compile.el Wed Apr 7 16:50:40 2004 @@ -945,7 +945,14 @@ (select-window outwin) (goto-char (point-max)))) ;; Make it so the next C-x ` will use this buffer. - (setq compilation-last-buffer outbuf))) + (setq compilation-last-buffer outbuf) + (setq next-error-last-buffer outbuf) + (setq compilation-last-buffer outbuf) + (with-current-buffer outbuf + ;; note that compilation-next-error-function is for interfacing + ;; with the next-error function in simple.el, and it's only + ;; coincidentally named similarly to compilation-next-error + (setq next-error-function 'compilation-next-error-function)))) (defun compilation-set-window-height (window) "Set the height of WINDOW according to `compilation-window-height'." @@ -1247,8 +1254,16 @@ (insert-before-markers string) (run-hooks 'compilation-filter-hook)))))) +;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p (defsubst compilation-buffer-p (buffer) - (local-variable-p 'compilation-locs buffer)) + "Test if BUFFER is a compilation buffer." + (with-current-buffer buffer + (compilation-buffer-internal-p))) + +;;; test if a buffer is a compilation buffer, assuming we're in the buffer +(defsubst compilation-buffer-internal-p () + "Test if inside a compilation buffer." + (local-variable-p 'compilation-locs (current-buffer))) (defmacro compilation-loop (< property-change 1+ error) `(while (,< n 0) @@ -1379,51 +1394,14 @@ ;; Otherwise, look for a compilation buffer and signal an error ;; if there are none. (defun compilation-find-buffer (&optional other-buffer) - (if (and (not other-buffer) - (compilation-buffer-p (current-buffer))) - ;; The current buffer is a compilation buffer. - (current-buffer) - (if (and compilation-last-buffer (buffer-name compilation-last-buffer) - (compilation-buffer-p compilation-last-buffer) - (or (not other-buffer) (not (eq compilation-last-buffer - (current-buffer))))) - compilation-last-buffer - (let ((buffers (buffer-list))) - (while (and buffers (or (not (compilation-buffer-p (car buffers))) - (and other-buffer - (eq (car buffers) (current-buffer))))) - (setq buffers (cdr buffers))) - (if buffers - (car buffers) - (or (and other-buffer - (compilation-buffer-p (current-buffer)) - ;; The current buffer is a compilation buffer. - (progn - (if other-buffer - (message "This is the only compilation buffer.")) - (current-buffer))) - (error "No compilation started!"))))))) + (next-error-find-buffer other-buffer 'compilation-buffer-internal-p)) ;;;###autoload -(defun next-error (&optional n) - "Visit next compilation error message and corresponding source code. -Prefix arg N says how many error messages to move forwards (or -backwards, if negative). - -\\[next-error] normally uses the most recently started compilation or -grep buffer. However, it can operate on any buffer with output from -the \\[compile] and \\[grep] commands, or, more generally, on any -buffer in Compilation mode or with Compilation Minor mode enabled. To -specify use of a particular buffer for error messages, type -\\[next-error] in that buffer. - -Once \\[next-error] has chosen the buffer for error messages, -it stays with that buffer until you use it in some other buffer which -uses Compilation mode or Compilation Minor mode. - -See variable `compilation-error-regexp-alist' for customization ideas." +(defun compilation-next-error-function (argp &optional reset) (interactive "p") (set-buffer (setq compilation-last-buffer (compilation-find-buffer))) + (when reset + (setq compilation-current-error nil)) (let* ((columns compilation-error-screen-columns) ; buffer's local value (last 1) (loc (compilation-next-error (or n 1) nil @@ -1463,27 +1441,6 @@ (setcdr (nthcdr 2 col) `(,(point-marker))))))))) (compilation-goto-locus marker (nth 3 loc) (nth 3 end-loc)) (setcdr (nthcdr 3 loc) t))) ; Set this one as visited. - -;;;###autoload (define-key ctl-x-map "`" 'next-error) - -(defun previous-error (n) - "Visit previous compilation error message and corresponding source code. -Prefix arg N says how many error messages to move backwards (or -forwards, if negative). - -This operates on the output from the \\[compile] and \\[grep] commands." - (interactive "p") - (next-error (- n))) - -(defun first-error (n) - "Restart at the first error. -Visit corresponding source code. -With prefix arg N, visit the source code of the Nth error. -This operates on the output from the \\[compile] command." - (interactive "p") - (set-buffer (setq compilation-last-buffer (compilation-find-buffer))) - (setq compilation-current-error nil) - (next-error n)) (defcustom compilation-context-lines next-screen-context-lines "*Display this many lines of leading context before message." --- /local/share/src/emacs-cvs/lisp/replace.el Sat Mar 13 03:22:41 2004 +++ /home/tzz/emacs/mine/replace.el Wed Apr 7 16:49:24 2004 @@ -614,6 +614,21 @@ "Move to the Nth (default 1) previous match in an Occur mode buffer." (interactive "p") (occur-find-match n #'previous-single-property-change "No earlier matches")) + +(defun occur-next-error (&optional argp reset) + "Move to the Nth (default 1) next match in an Occur mode buffer. +Compatibility function for \\[next-error] invocations." + (interactive "p") + (when reset + (occur-find-match 0 #'next-single-property-change "No first match")) + (occur-find-match + (prefix-numeric-value argp) + (if (> 0 (prefix-numeric-value argp)) + #'previous-single-property-change + #'next-single-property-change) + "No more matches") + (occur-mode-goto-occurrence)) + (defcustom list-matching-lines-default-context-lines 0 "*Default number of context lines included around `list-matching-lines' matches. @@ -800,7 +815,10 @@ (setq occur-revert-arguments (list regexp nlines bufs) buffer-read-only t) (if (> count 0) - (display-buffer occur-buf) + (progn + (display-buffer occur-buf) + (setq next-error-last-buffer occur-buf) + (setq next-error-function 'occur-next-error)) (kill-buffer occur-buf))) (run-hooks 'occur-hook)))) @@ -916,7 +934,7 @@ (goto-char headerpt) (let ((beg (point)) end) - (insert (format "%d matches for \"%s\" in buffer: %s\n" + (insert (format "%d lines matching \"%s\" in buffer: %s\n" matches regexp (buffer-name buf))) (setq end (point)) (add-text-properties beg end --- /local/share/src/emacs-cvs/lisp/simple.el Fri Mar 26 03:23:15 2004 +++ /home/tzz/emacs/mine/simple.el Wed Apr 7 16:55:23 2004 @@ -66,6 +66,118 @@ (setq list (cdr list))) (switch-to-buffer found))) +;;; next-error support framework +(defvar next-error-last-buffer nil + "The most recent next-error buffer. +A buffer becomes most recent when its compilation, grep, or +similar mode is started, or when it is used with \\[next-error] +or \\[compile-goto-error].") + +(defvar next-error-function nil + "The next-error vehicle for other modes. +This variable can be bound to a function by a mode. It is +buffer-local by default. Together with +`next-error-last-buffer', this variable lets modes hook into +\\[next-error].") + +(make-variable-buffer-local 'next-error-function) + +(defsubst next-error-buffer-p (buffer &optional extra-test) + "Test if BUFFER is a next-error capable buffer." + (with-current-buffer buffer + (or (and extra-test (funcall extra-test)) + next-error-function))) + +;; Return a next-error capable buffer. +;; If the current buffer is such, return it. +;; If next-error-last-buffer is set to a live buffer, use that. +;; Otherwise, look for a next-error capable buffer and signal an error +;; if there are none. +(defun next-error-find-buffer (&optional other-buffer extra-test) + (if (and (not other-buffer) + (next-error-buffer-p (current-buffer) extra-test)) + ;; The current buffer is a next-error capable buffer. + (current-buffer) + (if (and next-error-last-buffer (buffer-name next-error-last-buffer) + (next-error-buffer-p next-error-last-buffer extra-test) + (or (not other-buffer) (not (eq next-error-last-buffer + (current-buffer))))) + next-error-last-buffer + (let ((buffers (buffer-list))) + (while (and buffers (or (not (next-error-buffer-p (car buffers) extra-test)) + (and other-buffer + (eq (car buffers) (current-buffer))))) + (setq buffers (cdr buffers))) + (if buffers + (car buffers) + (or (and other-buffer + (next-error-buffer-p (current-buffer) extra-test) + ;; The current buffer is a next-error capable buffer. + (progn + (if other-buffer + (message "This is the only next-error capable buffer.")) + (current-buffer))) + (error "No next-error capable buffer found!"))))))) + +(defun next-error (argp &optional reset) + "Visit next next-error message and corresponding source code. + +If all the error messages parsed so far have been processed already, +the message buffer is checked for new ones. + +A prefix ARGP specifies how many error messages to move; +negative means move back to previous error messages. +Just \\[universal-argument] as a prefix means reparse the error message buffer +and start at the first error. + +The RESET argument specifies that we should restart from the beginning + +\\[next-error] normally uses the most recently started +compilation, grep, or occur buffer. It can also operate on any +buffer with output from the \\[compile], \\[grep] commands, or, +more generally, on any buffer in Compilation mode or with +Compilation Minor mode enabled, or any buffer in which +`next-error-function' is bound to an appropriate +function. To specify use of a particular buffer for error +messages, type \\[next-error] in that buffer. + +Once \\[next-error] has chosen the buffer for error messages, +it stays with that buffer until you use it in some other buffer which +uses Compilation mode or Compilation Minor mode. + +See variables `compilation-parse-errors-function' and +\`compilation-error-regexp-alist' for customization ideas." + (interactive "P") + (when (setq next-error-last-buffer (next-error-find-buffer)) + ;; we know here that next-error-function is a valid symbol we can funcall + (with-current-buffer next-error-last-buffer + (funcall next-error-function argp reset)))) + +(defalias 'goto-next-locus 'next-error) +(defalias 'next-match 'next-error) + +(define-key ctl-x-map "`" 'next-error) + +(defun previous-error (n) + "Visit previous next-error message and corresponding source code. + +Prefix arg N says how many error messages to move backwards (or +forwards, if negative). + +This operates on the output from the \\[compile] and \\[grep] commands." + (interactive "p") + (next-error (- n))) + +(defun first-error (n) + "Restart at the first error. +Visit corresponding source code. +With prefix arg N, visit the source code of the Nth error. +This operates on the output from the \\[compile] command, for instance." + (interactive "p") + (next-error n t)) + +;;; + (defun fundamental-mode () "Major mode not specialized for anything in particular. Other major modes are defined by comparison with this one."