emacs-devel
[Top][All Lists]
Advanced

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

Re: C-r and C-s in minibuffer should search completion


From: Juri Linkov
Subject: Re: C-r and C-s in minibuffer should search completion
Date: Tue, 25 Mar 2008 23:44:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

> I believe C-s and C-r in the minibuffer should not only search the
> history but the completion table as well (at least when it's not
> a function).
>
> Could someone implement this feature?

I now have an idea how to implement this feature.

Some time ago I submitted a patch that introduces a new variable
`minibuffer-default-set-function' that extends a list of defaults
when minibuffer position hits the bottom of the list of defaults.

http://lists.gnu.org/archive/html/emacs-devel/2007-12/msg00179.html

This patch was approved by Richard but not installed because
it was undecided where to move mailcap.el.

The patch uses this variable for `shell-command' to append a list of
available mailcap commands to the list of defaults only when the user
types M-n below the default value.

The same could be done for the list of completions.  The patch below
implements a new function `minibuffer-default-add-completions' that
appends a list of all completions to the end of the list of defaults.
It would be good to use this function by default since it is useful
to search the completion table in all minibuffers that have it.

Index: lisp/simple.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/simple.el,v
retrieving revision 1.911
diff -c -r1.911 simple.el
*** lisp/simple.el      23 Mar 2008 22:52:20 -0000      1.911
--- lisp/simple.el      25 Mar 2008 21:43:34 -0000
***************
*** 1304,1313 ****
--- 1305,1339 ----
  
  (defvar minibuffer-temporary-goal-position nil)
  
+ (defvar minibuffer-default-set-function 'minibuffer-default-add-completions
+   "*Function run by `goto-history-element' before using `minibuffer-default'.
+ This is useful to dynamically set the value of `minibuffer-default'
+ before `goto-history-element' reads it when moves into the future.")
+ 
+ (make-variable-buffer-local 'minibuffer-default-set-function)
+ 
+ (defun minibuffer-default-add-completions ()
+   "Return a list of all completions without the default value.
+ This function is used to add all elements of the completion table to
+ the end of the list of defaults after the default value."
+   (interactive)
+   (let ((def minibuffer-default)
+       (all (all-completions ""
+                             minibuffer-completion-table
+                             minibuffer-completion-predicate
+                             t)))
+     (if (listp def)
+       (append def all)
+       (setq all (cons def (delete def all))))))
+ 
  (defun goto-history-element (nabs)
    "Puts element of the minibuffer history in the minibuffer.
  The argument NABS specifies the absolute history position."
    (interactive "p")
+   (when (and (functionp minibuffer-default-set-function)
+            (< nabs (if (stringp minibuffer-default) -1 0)))
+     (setq minibuffer-default (funcall minibuffer-default-set-function)
+         minibuffer-default-set-function nil))
    (let ((minimum (if minibuffer-default
                     (- (if (listp minibuffer-default)
                            (length minibuffer-default)

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




reply via email to

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