From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: Add M-x occur to the menu-bar Date: Tue, 24 Feb 2004 12:23:59 -0500 Organization: =?koi8-r?q?=F4=C5=CF=C4=CF=D2=20=FA=CC=C1=D4=C1=CE=CF=D7?= @ Cienfuegos Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <4nn078jsr4.fsf@collins.bwh.harvard.edu> References: <3F69E6FF.9050702@yahoo.com> <4n8yjto16h.fsf@collins.bwh.harvard.edu> <4nisixjibl.fsf@collins.bwh.harvard.edu> <20040127230323.GB5407@fencepost> <4n7jzc919v.fsf@collins.bwh.harvard.edu> <4nn085i7nl.fsf@collins.bwh.harvard.edu> <4noese37h0.fsf@collins.bwh.harvard.edu> <4nbrodxwqm.fsf@collins.bwh.harvard.edu> <4n8yjcccvj.fsf@collins.bwh.harvard.edu> <4nwu6sp7ni.fsf@collins.bwh.harvard.edu> Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Avgls-0007mo-00 for ; Tue, 24 Feb 2004 18:55:04 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1Avglr-00058v-00 for ; Tue, 24 Feb 2004 18:55:04 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1Avgku-00057d-Po for emacs-devel@quimby.gnus.org; Tue, 24 Feb 2004 12:54:04 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1AvgjG-00054o-Jh for emacs-devel@gnu.org; Tue, 24 Feb 2004 12:52:22 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1AvgLV-0006n0-QN for emacs-devel@gnu.org; Tue, 24 Feb 2004 12:28:21 -0500 Original-Received: from [134.174.9.41] (helo=clifford.bwh.harvard.edu) by monty-python.gnu.org with esmtp (Exim 4.30) id 1AvgJf-0006II-Bh for emacs-devel@gnu.org; Tue, 24 Feb 2004 12:25:55 -0500 Original-Received: from collins.bwh.harvard.edu (collins [134.174.9.80]) by clifford.bwh.harvard.edu (8.10.2+Sun/8.11.0) with ESMTP id i1OHOFU20064; Tue, 24 Feb 2004 12:24:15 -0500 (EST) Original-Received: from collins.bwh.harvard.edu (localhost [127.0.0.1]) by collins.bwh.harvard.edu (8.12.9+Sun/8.11.0) with ESMTP id i1OHO2vl026431; Tue, 24 Feb 2004 12:24:02 -0500 (EST) Original-Received: (from tzz@localhost) by collins.bwh.harvard.edu (8.12.9+Sun/8.12.9/Submit) id i1OHO0HZ026425; Tue, 24 Feb 2004 12:24:00 -0500 (EST) Original-To: storm@cua.dk (Kim F. Storm) X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" In-Reply-To: (Kim F. Storm's message of "24 Feb 2004 01:37:09 +0100") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (usg-unix-v) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20156 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20156 --=-=-= On 24 Feb 2004, storm@cua.dk wrote: >> - make the next-error-function always local (but not buffer-local) > > The way you use make-local-variable doesn't accomplish that. > > Either use make-variable-buffer-local at the global level (it will > work in this case, as simple.el is pre-loaded. Right. Done. >> (defun compilation-find-buffer (&optional other-buffer) >> ! (let ((next-error-buffer-p compilation-buffer-p)) >> ! (next-error-find-buffer other-buffer))) > > This does not function-bind next-error-buffer-p ... > Does it really work? No, I was confused. Here's another version, which passes in extra tests. I actually like this better because it lets a mode decide if it wants extra tests, but will always check next-error-function as it should. compilation-buffer-p still works as it did before. bytecomp.el should eventually hook into the next-error framework, I think. Should I do that too? Any other modes of interest? I've started using the new next-error heavily, and I wonder how I managed without it :) Ted --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=next-error.patch Content-Description: next-error patch --- /opt/local-csw/encap/emacs-cvs/share/emacs/21.3.50/lisp/progmodes/compile.el Sat Jan 3 17:38:03 2004 +++ /home/tzz/emacs/mine/compile.el Tue Feb 24 12:22:04 2004 @@ -811,7 +811,13 @@ (select-window outwin) (goto-char (point-max))))) ;; Make it so the next C-x ` will use this buffer. - (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'." @@ -1056,12 +1062,6 @@ (setq errors (cdr errors))) errors)) -(defsubst compilation-buffer-p (buffer) - (save-excursion - (set-buffer buffer) - (or compilation-shell-minor-mode compilation-minor-mode - (eq major-mode 'compilation-mode)))) - (defun compilation-next-error (n) "Move point to the next error in the compilation buffer. Prefix arg N says how many error messages to move forwards (or @@ -1363,88 +1363,37 @@ (push-mark) (next-error 1)) +;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p +(defsubst compilation-buffer-p (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." + (or compilation-shell-minor-mode + compilation-minor-mode + (eq major-mode 'compilation-mode) + compilation-next-error-function)) + ;; Return a compilation buffer. ;; If the current buffer is a compilation buffer, return it. ;; If compilation-last-buffer is set to a live buffer, use that. ;; 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 argp) - "Visit next compilation 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. - -\\[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 variables `compilation-parse-errors-function' and -\`compilation-error-regexp-alist' for customization ideas." +(defun compilation-next-error-function (argp) (interactive "P") - (setq compilation-last-buffer (compilation-find-buffer)) (compilation-goto-locus (compilation-next-error-locus ;; We want to pass a number here only if ;; we got a numeric prefix arg, not just C-u. (and (not (consp argp)) (prefix-numeric-value argp)) (consp argp)))) -;;;###autoload (define-key ctl-x-map "`" 'next-error) - -(defun previous-error (argp) - "Visit previous compilation error message and corresponding source code. - -A prefix ARGP specifies how many error messages to move; -negative means move forward to next error messages. - -This operates on the output from the \\[compile] and \\[grep] commands." - (interactive "P") - (next-error (- (prefix-numeric-value argp)))) - -(defun first-error () - "Reparse the error message buffer and start at the first error. -Visit corresponding source code. -This operates on the output from the \\[compile] command." - (interactive) - (next-error '(4))) (defvar compilation-skip-to-next-location nil "*If non-nil, skip multiple error messages for the same source location.") --- /opt/local-csw/encap/emacs-cvs/share/emacs/21.3.50/lisp/replace.el Mon Feb 2 09:23:00 2004 +++ /home/tzz/emacs/mine/replace.el Mon Feb 23 15:09:11 2004 @@ -614,6 +614,19 @@ "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) + "Move to the Nth (default 1) next match in an Occur mode buffer. +Compatibility function for \\[next-error] invocations." + (interactive "p") + (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 +813,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)))) --- /opt/local-csw/encap/emacs-cvs/share/emacs/21.3.50/lisp/simple.el Sun Feb 1 03:12:34 2004 +++ /home/tzz/emacs/mine/simple.el Tue Feb 24 12:23:28 2004 @@ -66,6 +66,115 @@ (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) + "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. + +\\[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)))) + +(defalias 'goto-next-locus 'next-error) +(defalias 'next-match 'next-error) + +(define-key ctl-x-map "`" 'next-error) + +(defun previous-error (argp) + "Visit previous next-error message and corresponding source code. + +A prefix ARGP specifies how many error messages to move; +negative means move forward to next next-error messages. + +This operates on the output from the \\[compile] and \\[grep] commands." + (interactive "P") + (next-error (- (prefix-numeric-value argp)))) + +(defun first-error () + "Reparse the next-error message buffer and start over. +Visit corresponding source code. This operates on the output +from the \\[compile] and \\[grep] commands, for instance." + (interactive) + (next-error '(4))) + +;;; + (defun fundamental-mode () "Major mode not specialized for anything in particular. Other major modes are defined by comparison with this one." --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=next-error.patch2 Content-Description: context version of next-error patch for rms *** /opt/local-csw/encap/emacs-cvs/share/emacs/21.3.50/lisp/replace.el Mon Feb 2 09:23:00 2004 --- /home/tzz/emacs/mine/replace.el Mon Feb 23 15:09:11 2004 *************** *** 614,619 **** --- 614,632 ---- "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) + "Move to the Nth (default 1) next match in an Occur mode buffer. + Compatibility function for \\[next-error] invocations." + (interactive "p") + (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,806 **** (setq occur-revert-arguments (list regexp nlines bufs) buffer-read-only t) (if (> count 0) ! (display-buffer occur-buf) (kill-buffer occur-buf))) (run-hooks 'occur-hook)))) --- 813,822 ---- (setq occur-revert-arguments (list regexp nlines bufs) buffer-read-only t) (if (> count 0) ! (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)))) *** /opt/local-csw/encap/emacs-cvs/share/emacs/21.3.50/lisp/progmodes/compile.el Sat Jan 3 17:38:03 2004 --- /home/tzz/emacs/mine/compile.el Tue Feb 24 12:22:04 2004 *************** *** 811,817 **** (select-window outwin) (goto-char (point-max))))) ;; Make it so the next C-x ` will use this buffer. ! (setq compilation-last-buffer outbuf))) (defun compilation-set-window-height (window) "Set the height of WINDOW according to `compilation-window-height'." --- 811,823 ---- (select-window outwin) (goto-char (point-max))))) ;; Make it so the next C-x ` will use this buffer. ! (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'." *************** *** 1056,1067 **** (setq errors (cdr errors))) errors)) - (defsubst compilation-buffer-p (buffer) - (save-excursion - (set-buffer buffer) - (or compilation-shell-minor-mode compilation-minor-mode - (eq major-mode 'compilation-mode)))) - (defun compilation-next-error (n) "Move point to the next error in the compilation buffer. Prefix arg N says how many error messages to move forwards (or --- 1062,1067 ---- *************** *** 1363,1450 **** (push-mark) (next-error 1)) ;; Return a compilation buffer. ;; If the current buffer is a compilation buffer, return it. ;; If compilation-last-buffer is set to a live buffer, use that. ;; 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!"))))))) ;;;###autoload ! (defun next-error (&optional argp) ! "Visit next compilation 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. ! ! \\[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 variables `compilation-parse-errors-function' and ! \`compilation-error-regexp-alist' for customization ideas." (interactive "P") - (setq compilation-last-buffer (compilation-find-buffer)) (compilation-goto-locus (compilation-next-error-locus ;; We want to pass a number here only if ;; we got a numeric prefix arg, not just C-u. (and (not (consp argp)) (prefix-numeric-value argp)) (consp argp)))) - ;;;###autoload (define-key ctl-x-map "`" 'next-error) - - (defun previous-error (argp) - "Visit previous compilation error message and corresponding source code. - - A prefix ARGP specifies how many error messages to move; - negative means move forward to next error messages. - - This operates on the output from the \\[compile] and \\[grep] commands." - (interactive "P") - (next-error (- (prefix-numeric-value argp)))) - - (defun first-error () - "Reparse the error message buffer and start at the first error. - Visit corresponding source code. - This operates on the output from the \\[compile] command." - (interactive) - (next-error '(4))) (defvar compilation-skip-to-next-location nil "*If non-nil, skip multiple error messages for the same source location.") --- 1363,1399 ---- (push-mark) (next-error 1)) + ;;; test if a buffer is a compilation buffer, using compilation-buffer-internal-p + (defsubst compilation-buffer-p (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." + (or compilation-shell-minor-mode + compilation-minor-mode + (eq major-mode 'compilation-mode) + compilation-next-error-function)) + ;; Return a compilation buffer. ;; If the current buffer is a compilation buffer, return it. ;; If compilation-last-buffer is set to a live buffer, use that. ;; Otherwise, look for a compilation buffer and signal an error ;; if there are none. (defun compilation-find-buffer (&optional other-buffer) ! (next-error-find-buffer other-buffer 'compilation-buffer-internal-p)) ;;;###autoload ! (defun compilation-next-error-function (argp) (interactive "P") (compilation-goto-locus (compilation-next-error-locus ;; We want to pass a number here only if ;; we got a numeric prefix arg, not just C-u. (and (not (consp argp)) (prefix-numeric-value argp)) (consp argp)))) (defvar compilation-skip-to-next-location nil "*If non-nil, skip multiple error messages for the same source location.") *** /opt/local-csw/encap/emacs-cvs/share/emacs/21.3.50/lisp/simple.el Sun Feb 1 03:12:34 2004 --- /home/tzz/emacs/mine/simple.el Tue Feb 24 12:23:28 2004 *************** *** 66,71 **** --- 66,180 ---- (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) + "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. + + \\[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)))) + + (defalias 'goto-next-locus 'next-error) + (defalias 'next-match 'next-error) + + (define-key ctl-x-map "`" 'next-error) + + (defun previous-error (argp) + "Visit previous next-error message and corresponding source code. + + A prefix ARGP specifies how many error messages to move; + negative means move forward to next next-error messages. + + This operates on the output from the \\[compile] and \\[grep] commands." + (interactive "P") + (next-error (- (prefix-numeric-value argp)))) + + (defun first-error () + "Reparse the next-error message buffer and start over. + Visit corresponding source code. This operates on the output + from the \\[compile] and \\[grep] commands, for instance." + (interactive) + (next-error '(4))) + + ;;; + (defun fundamental-mode () "Major mode not specialized for anything in particular. Other major modes are defined by comparison with this one." --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel --=-=-=--