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: Wed, 04 Feb 2004 15:39:07 -0500
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (usg-unix-v)

On Fri, 30 Jan 2004, address@hidden wrote:

On Thu, 29 Jan 2004, address@hidden wrote:
> 
>> You are probably right.  But I think the biggest problem here will
>> be finding th right rules for this command to follow, which will
>> give results that the users like and find natural.
> 
> I guess I'll produce something as a starting point and see how
> people like it.  I'll patch next-error if needed, and occur
> definitely will need to set the right variable.
> 
>> How about goto-next-locus?
> 
> OK, I'll defalias to goto-next-locus and next-match.

Attached is a patch for replace.el (occur) and compile.el
(next-error).  I also defalias as mentioned above.

It tries to be smart about the current buffer, to simulate what
next-error does already.  It also handles negative and positive
arguments as usual.  It does not handle the universal prefix
argument.

If occur has not been loaded at all (checked by soft-intern of
"occur-last-buffer") next-error behaves exactly as before, looking at
grep and compile output.

I'm sure the code needs corrections, so feel free to critique.  The
diff should have been done at the same, level too...  It should be
enough to get the idea across.

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     Wed Feb  4 15:35:28 2004
@@ -31,12 +31,15 @@
 
 ;;; Code:
 
+;; autoload occur-next when needed
+(eval-and-compile
+  (autoload 'occur-next "replace"))
+
 (defgroup compilation nil
   "Run compiler as inferior of Emacs, parse error messages."
   :group 'tools
   :group 'processes)
 
-
 ;;;###autoload
 (defcustom compilation-mode-hook nil
   "*List of hook functions run by `compilation-mode' (see `run-hooks')."
@@ -1406,12 +1409,13 @@
 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 occur,
+compilation or grep buffer.  However, it can operate on any
+buffer with output from the \\[compile], \\[grep], and \\[occur]
+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
@@ -1420,14 +1424,38 @@
 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))))
+  (if (and (intern-soft "occur-last-buffer") ; has this been defvar'd?
+          ;; special case for running next-error in a compile/grep buffer
+          (not (equal (current-buffer) (compilation-find-buffer)))
+          ;; occur sets compilation-last-buffer to occur-last-buffer
+          ;; also, allow for running next-error in an occur buffer
+          (or
+           (equal occur-last-buffer (current-buffer))
+           (equal occur-last-buffer compilation-last-buffer)))
+      ;; do the right thing for occur
+      (progn
+       (set-buffer compilation-last-buffer)
+       (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)
+       (setq compilation-last-buffer occur-last-buffer))
+    ;; otherwise, grep/compile behavior
+    (progn
+      (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)
+
+(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     Wed Feb  4 14:54:14 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].
@@ -800,7 +808,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 occur-last-buffer occur-buf)
+             (setq compilation-last-buffer occur-buf))
          (kill-buffer occur-buf)))
       (run-hooks 'occur-hook))))
 

reply via email to

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