unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Default value in previous-matching-history-element
       [not found] <44068.217.194.34.123.1085657656.squirrel@wwws.franken.de>
@ 2004-05-29  1:13 ` Stephan Stahl
  2004-05-30 14:31   ` Richard Stallman
  2004-05-30 20:25   ` Juri Linkov
  0 siblings, 2 replies; 3+ messages in thread
From: Stephan Stahl @ 2004-05-29  1:13 UTC (permalink / raw)


Hi.

-----
I'm sorry. I have sent a message about this without a subject so i
suppose no one read the first one.. I have changed the patch a little
bit since the time.
-----

Since i learned that M-n while doing completing-read and friends
brings up the default value and lets you edit it, i used that feature
very often.

However it does not work in previous-matching-history-element (M-r
while the minibuffer is active). The following very simple patch
will do the trick..

Maybe someone wants to include that in emacs.

*** simple.1.645.el	Sat May 29 02:47:35 2004
--- simple.new.el	Sat May 29 02:47:15 2004
***************
*** 949,963 ****
  See also `minibuffer-history-case-insensitive-variables'."
    (interactive
     (let* ((enable-recursive-minibuffers t)
  	  (regexp (read-from-minibuffer "Previous element matching (regexp): "
  					nil
  					minibuffer-local-map
  					nil
! 					'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))))
--- 949,965 ----
  See also `minibuffer-history-case-insensitive-variables'."
    (interactive
     (let* ((enable-recursive-minibuffers t)
+ 	  (default (car minibuffer-history-search-history))
  	  (regexp (read-from-minibuffer "Previous element matching (regexp): "
  					nil
  					minibuffer-local-map
  					nil
! 					'minibuffer-history-search-history
! 					default)))
       ;; Use the last regexp specified, by default, if input is empty.
       (list (if (string= regexp "")
  	       (if minibuffer-history-search-history
! 		   default
  		 (error "No previous history search regexp"))
  	     regexp)
  	   (prefix-numeric-value current-prefix-arg))))
-- 
Stephan Stahl

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

* Re: Default value in previous-matching-history-element
  2004-05-29  1:13 ` Default value in previous-matching-history-element Stephan Stahl
@ 2004-05-30 14:31   ` Richard Stallman
  2004-05-30 20:25   ` Juri Linkov
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Stallman @ 2004-05-30 14:31 UTC (permalink / raw)
  Cc: emacs-devel

I will install a similar fix.  Thanks.

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

* Re: Default value in previous-matching-history-element
  2004-05-29  1:13 ` Default value in previous-matching-history-element Stephan Stahl
  2004-05-30 14:31   ` Richard Stallman
@ 2004-05-30 20:25   ` Juri Linkov
  1 sibling, 0 replies; 3+ messages in thread
From: Juri Linkov @ 2004-05-30 20:25 UTC (permalink / raw)


Stephan Stahl <stahl@eos.franken.de> writes:
> Since i learned that M-n while doing completing-read and friends
> brings up the default value and lets you edit it, i used that feature
> very often.

One restriction of M-n feature is that it allows only one default element
accessible by M-n.  The following patch extends it to allow a list of
default values available for choosing by repeatedly typing M-n in the
minibuffer.

A list of default values might be useful, for example, for
`dired-guess-shell-command' which currently pushes all command guesses
temporarily into history.  If the user wants to repeat the last command
he must scroll all guesses by M-p before he reaches the first history
item.  This is inconvenient.  The second patch below places command guesses
to a list of default values accessible by M-n.

There are other places where a list of default value is useful.  For
example, `grep' provides only one default value based on the current
tag around point.  But it could provide additionally commands composed
with the text from the kill ring, from active region, etc.

Index: emacs/lisp/simple.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v
retrieving revision 1.645
diff -u -r1.645 simple.el
--- emacs/lisp/simple.el	28 May 2004 21:00:14 -0000	1.645
+++ emacs/lisp/simple.el	30 May 2004 18:37:31 -0000
@@ -1039,7 +1110,11 @@
   (interactive "p")
   (or (zerop n)
       (let ((narg (- minibuffer-history-position n))
-	    (minimum (if minibuffer-default -1 0))
+	    (minimum (if minibuffer-default
+                         (- (if (listp minibuffer-default)
+                                (length minibuffer-default)
+                              1))
+                       0))
 	    elt minibuffer-returned-to-present)
 	(if (and (zerop minibuffer-history-position)
 		 (null minibuffer-text-before-history))
@@ -1061,8 +1136,10 @@
 	(goto-char (point-max))
 	(delete-minibuffer-contents)
 	(setq minibuffer-history-position narg)
-	(cond ((= narg -1)
-	       (setq elt minibuffer-default))
+	(cond ((< narg 0)
+	       (setq elt (if (listp minibuffer-default)
+                             (nth (1- (abs narg)) minibuffer-default)
+                           minibuffer-default)))
 	      ((= narg 0)
 	       (setq elt (or minibuffer-text-before-history ""))
 	       (setq minibuffer-returned-to-present t)

Index: emacs/lisp/dired-x.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/dired-x.el,v
retrieving revision 1.54
diff -u -r1.54 dired-x.el
--- emacs/lisp/dired-x.el	31 Mar 2004 16:09:18 -0000	1.54
+++ emacs/lisp/dired-x.el	30 May 2004 18:37:32 -0000
@@ -1091,56 +1105,28 @@
 
 (defun dired-guess-shell-command (prompt files)
   "Ask user with PROMPT for a shell command, guessing a default from FILES."
-
   (let ((default (dired-guess-default files))
-        default-list old-history val (failed t))
-
+        default-list val)
     (if (null default)
         ;; Nothing to guess
         (read-from-minibuffer prompt nil nil nil 'dired-shell-command-history)
-
-      ;; Save current history list
-      (setq old-history dired-shell-command-history)
-
       (if (listp default)
-
           ;; More than one guess
           (setq default-list default
                 default (car default)
                 prompt (concat
                         prompt
                         (format "{%d guesses} " (length default-list))))
-
         ;; Just one guess
         (setq default-list (list default)))
-
-      ;; Push all guesses onto history so that they can be retrieved with M-p
-      ;; and put the first guess in the prompt but not in the initial value.
-      (setq dired-shell-command-history
-            (append default-list dired-shell-command-history)
-            prompt (concat prompt (format "[%s] " default)))
-
-      ;; The unwind-protect returns VAL, and we too.
-      (unwind-protect
-          ;; BODYFORM
-          (progn
-            (setq val (read-from-minibuffer prompt nil nil nil
-                                            'dired-shell-command-history)
-                  failed nil)
-            ;; If we got a return, then use default.
-            (if (equal val "")
-                (setq val default))
-            val)
-
-        ;; UNWINDFORMS
-        ;; Undo pushing onto the history list so that an aborted
-        ;; command doesn't get the default in the next command.
-        (setq dired-shell-command-history old-history)
-        (if (not failed)
-            (or (equal val (car-safe dired-shell-command-history))
-                (setq dired-shell-command-history
-                      (cons val dired-shell-command-history))))))))
-
+      ;; Put the first guess in the prompt but not in the initial value.
+      (setq prompt (concat prompt (format "[%s] " default)))
+      ;; All guesses can be retrieved with M-n
+      (setq val (read-from-minibuffer prompt nil nil nil
+                                      'dired-shell-command-history
+                                      default-list))
+      ;; If we got a return, then return default.
+      (if (equal val "") default val))))
 
 ;;; REDEFINE.
 ;;; Redefine dired-aux.el's version:

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

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

end of thread, other threads:[~2004-05-30 20:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <44068.217.194.34.123.1085657656.squirrel@wwws.franken.de>
2004-05-29  1:13 ` Default value in previous-matching-history-element Stephan Stahl
2004-05-30 14:31   ` Richard Stallman
2004-05-30 20:25   ` 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).