unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* next-matching-history-element default [patch]
@ 2004-12-25 21:08 Kevin Ryde
  2004-12-27  4:09 ` Richard Stallman
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Ryde @ 2004-12-25 21:08 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

In next-matching-history-element, pressing Ret to use the default
before any regexp has ever been given produces an unhelpful error
message.  Eg. with -q -no-site-file,

	C-x C-f M-s Ret
	=> Wrong type argument: consp, nil

I see previous-matching-history-element recently got that tweaked
(1995-05-26).  Perhaps next should be the same.


2004-12-26  Kevin Ryde  <user42@zip.com.au>

        * simple.el (next-matching-history-element): Same `interactive' form
        as previous-matching-history-element, for better error if history is
        empty, and to make default available with M-n.


[-- Attachment #2: simple.el.next-regexp.diff --]
[-- Type: text/plain, Size: 1090 bytes --]

*** simple.el.~1.673.~	Thu Dec 23 08:11:51 2004
--- simple.el	Fri Dec 24 18:00:25 2004
***************
*** 1113,1123 ****
  					nil
  					minibuffer-local-map
  					nil
! 					'minibuffer-history-search-history)))
       ;; Use the last regexp specified, by default, if input is empty.
       (list (if (string= regexp "")
! 	       (setcar minibuffer-history-search-history
! 		       (nth 1 minibuffer-history-search-history))
  	     regexp)
  	   (prefix-numeric-value current-prefix-arg))))
    (previous-matching-history-element regexp (- n)))
--- 1113,1125 ----
  					nil
  					minibuffer-local-map
  					nil
! 					'minibuffer-history-search-history
!  					(car minibuffer-history-search-history))))
       ;; Use the last regexp specified, by default, if input is empty.
       (list (if (string= regexp "")
! 	       (if minibuffer-history-search-history
! 		   (car minibuffer-history-search-history)
! 		 (error "No previous history search regexp"))
  	     regexp)
  	   (prefix-numeric-value current-prefix-arg))))
    (previous-matching-history-element regexp (- n)))

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: next-matching-history-element default [patch]
  2004-12-25 21:08 next-matching-history-element default [patch] Kevin Ryde
@ 2004-12-27  4:09 ` Richard Stallman
  2004-12-28  1:28   ` Juri Linkov
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Stallman @ 2004-12-27  4:09 UTC (permalink / raw)
  Cc: emacs-devel

Thanks.  I'll install that.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: next-matching-history-element default [patch]
  2004-12-27  4:09 ` Richard Stallman
@ 2004-12-28  1:28   ` Juri Linkov
  0 siblings, 0 replies; 3+ messages in thread
From: Juri Linkov @ 2004-12-28  1:28 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:
> Thanks.  I'll install that.

This indeed fixes the long-standing problem in `next-matching-history-element'
(I think the reason it was not fixed for a long time is that everyone
uses M-r, not M-s which finds nothing from the initial history position),
but I have a change I implemented three months ago that will depreciate
`previous-matching-history-element' (and `next-matching-history-element').

The change I propose is to use isearch to search the minibuffer history.
This way Emacs will provide an incremental search in the history in
the same way as shells using readline already provide.

The following patch sets the value of `isearch-search-fun-function' in
the minibuffer to a function similar to `Info-isearch-search' used to
search through Info multiple nodes.

This also requires three fixes in isearch.el to work better
in the case when isearch-search-fun-function is specified
and when isearch is used in the minibuffer.

Index: lisp/simple.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v
retrieving revision 1.674
diff -u -r1.674 simple.el
--- lisp/simple.el	27 Dec 2004 16:34:43 -0000	1.674
+++ lisp/simple.el	28 Dec 2004 00:52:57 -0000
@@ -1143,11 +1143,13 @@
 
 (defvar minibuffer-temporary-goal-position nil)
 
-(defun next-history-element (n)
-  "Insert the next element of the minibuffer history into the minibuffer."
+(defun next-history-element (n &optional narg)
+  "Insert Nth next element of the minibuffer history into the minibuffer.
+The optional argument NARG overrides the N argument and specifies the
+absolute history position instead of relative position specified by N."
   (interactive "p")
-  (or (zerop n)
-      (let ((narg (- minibuffer-history-position n))
+  (unless (and (zerop n) (not narg))
+      (let ((narg (or narg (- minibuffer-history-position n)))
 	    (minimum (if minibuffer-default -1 0))
 	    elt minibuffer-returned-to-present)
 	(if (and (zerop minibuffer-history-position)
@@ -1221,6 +1221,64 @@
   ;; Return the width of everything before the field at the end of
   ;; the buffer; this should be 0 for normal buffers.
   (1- (minibuffer-prompt-end)))
+
+;; isearch the minibuffer history
+(add-hook 'minibuffer-setup-hook 'minibuffer-isearch-initialize)
+
+(defun minibuffer-isearch-initialize ()
+  (set (make-local-variable 'isearch-search-fun-function)
+       'minibuffer-history-isearch-search)
+  (set (make-local-variable 'isearch-wrap-function)
+       'minibuffer-history-isearch-wrap)
+  (set (make-local-variable 'isearch-push-state-function)
+       'minibuffer-history-isearch-push-state))
+
+(defun minibuffer-history-isearch-search ()
+  (cond
+   (isearch-word
+    (if isearch-forward 'word-search-forward 'word-search-backward))
+   (t
+    (lambda (string bound noerror)
+      (let ((search-fun
+             (cond
+              (isearch-regexp
+               (if isearch-forward 're-search-forward 're-search-backward))
+              (t
+               (if isearch-forward 'search-forward 'search-backward)))))
+        (or (funcall search-fun string
+                     (or bound (unless isearch-forward (minibuffer-prompt-end)))
+                     noerror)
+            (unless bound
+              (condition-case nil
+                  (progn
+                    (while (not (funcall
+                                 search-fun string
+                                 (unless isearch-forward (minibuffer-prompt-end))
+                                 noerror))
+                      (cond
+                       (isearch-forward
+                        (next-history-element 1)
+                        (goto-char (minibuffer-prompt-end)))
+                       (t
+                        (previous-history-element 1)
+                        (goto-char (point-max)))))
+                    (point))
+                (error nil)))))))))
+
+(defun minibuffer-history-isearch-wrap ()
+  (if (not isearch-word)
+      (if isearch-forward
+          (next-history-element 0 (length (symbol-value minibuffer-history-variable)))
+        (next-history-element 0 0)))
+  (goto-char (if isearch-forward (minibuffer-prompt-end) (point-max))))
+
+(defun minibuffer-history-isearch-push-state ()
+  `(lambda (cmd)
+     (minibuffer-history-isearch-pop-state cmd ,minibuffer-history-position)))
+
+(defun minibuffer-history-isearch-pop-state (cmd hist-pos)
+  (next-history-element 0 hist-pos))
+
 \f
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (defalias 'advertised-undo 'undo)

Index: lisp/isearch.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.249
diff -u -r1.249 isearch.el
--- lisp/isearch.el	15 Dec 2004 10:08:51 -0000	1.249
+++ lisp/isearch.el	28 Dec 2004 00:59:44 -0000
@@ -1300,9 +1300,11 @@
       ;; Not regexp, not reverse, or no match at point.
       (if (and isearch-other-end (not isearch-adjusted))
 	  (goto-char (if isearch-forward isearch-other-end
-		       (min isearch-opoint
-			    isearch-barrier
-			    (1+ isearch-other-end)))))
+		       (if isearch-search-fun-function
+			   (1+ isearch-other-end)
+			 (min isearch-opoint
+			      isearch-barrier
+			      (1+ isearch-other-end))))))
       (isearch-search)
       ))
   (isearch-push-state)
@@ -1879,10 +1881,19 @@
               isearch-message)
 	    (isearch-message-suffix c-q-hack ellipsis)
 	    )))
-    (if c-q-hack
+    (if (or (and (minibuffer-window-active-p (selected-window))
+		 isearch-success
+		 (not isearch-invalid-regexp))
+	    c-q-hack)
 	m
       (let ((message-log-max nil))
-	(message "%s" m)))))
+	(message "%s" m)
+	(when (and (minibuffer-window-active-p (selected-window))
+		   (not isearch-invalid-regexp))
+	  (sit-for (or isearch-original-minibuffer-message-timeout
+		       minibuffer-message-timeout
+                       0))
+	  (message ""))))))
 
 (defun isearch-message-prefix (&optional c-q-hack ellipsis nonincremental)
   ;; If about to search, and previous search regexp was invalid,
@@ -1900,6 +1911,7 @@
 		   (if isearch-adjusted "pending " "")
 		   (if (and isearch-wrapped
 			    (not isearch-wrap-function)
+			    (not isearch-search-fun-function)
 			    (if isearch-forward
 				(> (point) isearch-opoint)
 			      (< (point) isearch-opoint)))

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-12-28  1:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-25 21:08 next-matching-history-element default [patch] Kevin Ryde
2004-12-27  4:09 ` Richard Stallman
2004-12-28  1:28   ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).