emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add M-x occur to the menu-bar


From: Ted Zlatanov
Subject: Re: Add M-x occur to the menu-bar
Date: Thu, 05 Feb 2004 12:27:29 -0500
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (usg-unix-v)

On 05 Feb 2004, address@hidden wrote:

> Maybe a more generic approach could be used:
> 
> Let compile.el define a buffer-local compilation-next-error-function
> variable (default value nil) which can be bound in the *occur*
> buffer to #'occur-next (or whatever).
[...]
> With this approach, compile.el doesn't need to know anything about
> occur mode, and future similar modes can hook themselves into
> next-error without modifying compile.el any further.

I see, that is indeed a much better solution.  I've reworked the patch
to do what you suggest; only the universal-prefix is not handled by
occur-next-error.  It is much better from the perspective of
occur-mode, but I had to modify compilation-find-buffer and
compilation-buffer-p to avoid complicating next-error.  Anyhow, see
what you think.

multi-occur should be handled, I don't know if I need to do anything
there.  It works exactly like occur, according to the docs.

> IMO, it would be cleaner to add (provide 'occur) to replace.el and
> just test with (featurep 'occur).

OK, with the change you suggested above I don't need to do this
anymore, but I'll keep it in mind.  By the way, why doesn't
replace.el (provide 'occur)?  No one needed it?

> The autoload of occur-next should be done as an autoload cookie in
> occur.el But I don't see why do you need it at all?

I was calling occur-next explicitly, so I wanted to make sure there
were no compiler warnings.  I see it's unnecessary.

Thanks
Ted

--- 
/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     Thu Feb  5 12:25:00 2004
@@ -36,7 +36,6 @@
   :group 'tools
   :group 'processes)
 
-
 ;;;###autoload
 (defcustom compilation-mode-hook nil
   "*List of hook functions run by `compilation-mode' (see `run-hooks')."
@@ -133,6 +132,15 @@
 A buffer becomes most recent when its compilation is started
 or when it is used with \\[next-error] or \\[compile-goto-error].")
 
+(defvar compilation-next-error-function nil
+  "The next-error analogue for other modes.
+This variable can be bound to a function by a mode.  It is
+buffer-local by default.  Together with
+`compilation-last-buffer', this variable lets modes hook into
+\\[next-error].")
+
+(make-variable-buffer-local 'compilation-next-error-function)
+
 (defvar compilation-in-progress nil
   "List of compilation processes now running.")
 (or (assq 'compilation-in-progress minor-mode-alist)
@@ -1056,11 +1064,20 @@
       (setq errors (cdr errors)))
     errors))
 
-(defsubst compilation-buffer-p (buffer)
+(defsubst compilation-buffer-p (buffer &optional 
allow-with-next-error-function)
+  "Test if BUFFER is a compilation buffer.
+With ALLOW-WITH-NEXT-ERROR-FUNCTION, allow buffer if it has
+`compilation-next-error-function' bound.  This is for use by
+\\[next-error] only."
   (save-excursion
     (set-buffer buffer)
-    (or compilation-shell-minor-mode compilation-minor-mode
-       (eq major-mode 'compilation-mode))))
+    (or compilation-shell-minor-mode 
+       compilation-minor-mode
+       (eq major-mode 'compilation-mode)
+       (and allow-with-next-error-function
+            (buffer-local-value
+             'compilation-next-error-function
+             buffer)))))
 
 (defun compilation-next-error (n)
   "Move point to the next error in the compilation buffer.
@@ -1368,25 +1385,31 @@
 ;; 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)
+(defun compilation-find-buffer (&optional other-buffer allow-with-next-error)
   (if (and (not other-buffer)
-          (compilation-buffer-p (current-buffer)))
+          (compilation-buffer-p (current-buffer) allow-with-next-error))
       ;; 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)
+            (compilation-buffer-p
+             compilation-last-buffer
+             allow-with-next-error)
             (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)))
+       (while (and buffers (or (not (compilation-buffer-p 
+                                     (car buffers) 
+                                     allow-with-next-error))
                                (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))
+                  (compilation-buffer-p 
+                   (current-buffer) 
+                   allow-with-next-error)
                   ;; The current buffer is a compilation buffer.
                   (progn
                     (if other-buffer
@@ -1406,12 +1429,14 @@
 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.
+\\[next-error] normally uses the most recently started
+compilation or grep buffer.  However, it can 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
+`compilation-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
@@ -1420,14 +1445,29 @@
 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))))
+  (setq compilation-last-buffer 
+       (or
+        ;; if compilation-last-buffer was set by an external mode, get that
+        (compilation-find-buffer compilation-last-buffer t)
+        ;; otherwise find a real compilation buffer
+        (compilation-find-buffer)))
+  (if (buffer-local-value 
+       'compilation-next-error-function 
+       compilation-last-buffer)
+      ;; do the right thing for modes that bind compilation-next-error-function
+      (progn
+       (set-buffer compilation-last-buffer)
+       (funcall compilation-next-error-function argp))
+    (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)
+
+(defalias 'goto-next-locus 'next-error)
+(defalias 'next-match 'next-error)
 
 (defun previous-error (argp)
   "Visit previous compilation error message and corresponding source code.

--- /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     Thu Feb  5 12:05:06 2004
@@ -522,6 +522,14 @@
   :type 'hook
   :group 'matching)
 
+;; override compilation-last-buffer
+(defvar occur-last-buffer nil
+  "The most recent occur buffer.
+An occur buffer becomes most recent when its process is started
+or when it is used with \\[occur-next].
+Notice that using \\[next-error] or \\[compile-goto-error] modifies
+`complation-last-buffer' rather than `occur-last-buffer'.")
+
 (put 'occur-mode 'mode-class 'special)
 (defun occur-mode ()
   "Major mode for output from \\[occur].
@@ -614,6 +622,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 +821,11 @@
        (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 occur-last-buffer occur-buf)
+             (setq compilation-last-buffer occur-buf)
+             (setq compilation-next-error-function 'occur-next-error))
          (kill-buffer occur-buf)))
       (run-hooks 'occur-hook))))
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]