From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Default value in previous-matching-history-element Date: Sun, 30 May 2004 23:25:19 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87isedll1s.fsf@mail.jurta.org> References: <44068.217.194.34.123.1085657656.squirrel@wwws.franken.de> <87k6yw827y.fsf@eos.franken.de> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1085949595 1460 80.91.224.253 (30 May 2004 20:39:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 30 May 2004 20:39:55 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun May 30 22:39:48 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BUX5w-0007R8-00 for ; Sun, 30 May 2004 22:39:48 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BUX5v-0003do-00 for ; Sun, 30 May 2004 22:39:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BUX64-0007fo-LR for emacs-devel@quimby.gnus.org; Sun, 30 May 2004 16:39:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BUX62-0007ff-3T for emacs-devel@gnu.org; Sun, 30 May 2004 16:39:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BUX60-0007f7-8e for emacs-devel@gnu.org; Sun, 30 May 2004 16:39:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BUX5z-0007ex-UU for emacs-devel@gnu.org; Sun, 30 May 2004 16:39:52 -0400 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1BUX5f-00049k-OD for emacs-devel@gnu.org; Sun, 30 May 2004 16:39:31 -0400 Original-Received: from [66.33.219.6] (helo=knife.dreamhost.com) by mx20.gnu.org with esmtp (Exim 4.34) id 1BUWxc-0006za-R4 for emacs-devel@gnu.org; Sun, 30 May 2004 16:31:13 -0400 Original-Received: from mail.jurta.org (80-235-38-230-dsl.mus.estpak.ee [80.235.38.230]) by knife.dreamhost.com (Postfix) with ESMTP id D139EE4081 for ; Sun, 30 May 2004 13:31:09 -0700 (PDT) Original-To: emacs-devel@gnu.org In-Reply-To: <87k6yw827y.fsf@eos.franken.de> (Stephan Stahl's message of "29 May 2004 03:13:37 +0200") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:24240 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24240 Stephan Stahl 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/