bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#14784: Occur from more Isearch types


From: Juri Linkov
Subject: bug#14784: Occur from more Isearch types
Date: Thu, 04 Jul 2013 02:28:15 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu)

Severity: wishlist
Tags: patch

Like bug#14673 added `Buffer-menu-multi-occur' to invoke Occur
from multiple marked buffers, it would also make sense to invoke Occur
from other search types where the search space differs from the default
single-buffer search.  Then typing `M-s o' in the minibuffer's isearch
will show occurrences from all minibuffer history elements, and
when typed in the comint's history isearch, will show occurrences
from all shell history elements:

=== modified file 'lisp/simple.el'
--- lisp/simple.el      2013-06-27 00:50:50 +0000
+++ lisp/simple.el      2013-07-03 23:17:01 +0000
@@ -1938,6 +2032,22 @@
 Go to the history element by the absolute history position HIST-POS."
   (goto-history-element hist-pos))
 
+(defun minibuffer-occur (regexp &optional nlines)
+  "Show all entries in the minibuffer history containing a match for REGEXP.
+Like `occur', but acts on the contents of the minibuffer history
+in the currently active minibuffer."
+  (interactive (occur-read-primary-args))
+  (when (and (minibufferp) minibuffer-history-variable)
+    (let* ((history-variable minibuffer-history-variable)
+          (history (symbol-value history-variable)))
+      (with-current-buffer
+         (get-buffer-create (format " *Minibuffer history %s*"
+                                    history-variable))
+       (erase-buffer)
+       (dolist (line history)
+         (insert (query-replace-descr line) "\n"))
+       (occur-1 regexp nlines (list (current-buffer)))))))
+
 
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (define-obsolete-function-alias 'advertised-undo 'undo "23.2")

=== modified file 'lisp/comint.el'
--- lisp/comint.el      2013-06-21 09:37:04 +0000
+++ lisp/comint.el      2013-07-03 23:15:59 +0000
@@ -1570,6 +1570,20 @@
 Go to the history element by the absolute history position HIST-POS."
   (comint-goto-input hist-pos))
 
+(defun comint-history-occur (regexp &optional nlines)
+  "Show all entries in the input history containing a match for REGEXP.
+Like `occur', but acts on the contents of the input history
+in the currently active comint buffer."
+  (interactive (occur-read-primary-args))
+  (when comint-input-ring
+    (let ((input-ring comint-input-ring))
+      (with-current-buffer
+         (get-buffer-create " *Comint history*")
+       (erase-buffer)
+       (dotimes (i (1- (ring-length input-ring)))
+         (insert (query-replace-descr (ring-ref input-ring i)) "\n"))
+       (occur-1 regexp nlines (list (current-buffer)))))))
+
 
 (defun comint-within-quotes (beg end)
   "Return t if the number of quotes between BEG and END is odd.

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el     2013-06-13 22:08:45 +0000
+++ lisp/isearch.el     2013-07-03 23:18:35 +0000
@@ -1785,7 +1888,12 @@ (defun isearch-occur (regexp &optional n
                 isearch-regexp-lax-whitespace
               isearch-lax-whitespace)
             search-whitespace-regexp)))
-    (occur regexp nlines)))
+    (cond ((and (minibufferp) minibuffer-history-variable)
+          (minibuffer-occur regexp nlines))
+         ((and (boundp 'comint-input-ring) comint-input-ring)
+          (comint-history-occur regexp nlines))
+         (t
+          (occur regexp nlines)))))
 
 (declare-function hi-lock-read-face-name "hi-lock" ())





reply via email to

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