[Top][All Lists]
[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: |
Fri, 28 Mar 2008 01:43:32 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) |
>> Below is a new patch with a small improvement: it introduces a new
>> variable `minibuffer-default-add-p' useful to add more elements to the
>> list of defaults several times in chunks when needed (it can keep the
>> current state of added elements to the list of defaults):
>
> OK, then please remove (make-variable-buffer-local
> 'minibuffer-default-add-function). And I suggest to change
> minibuffer-default-add-p into minibuffer-default-add-done (and to
> reverse its default to nil).
In the patch below I renamed minibuffer-default-add-p into
minibuffer-default-add-done, changed its default to nil, and
removed make-variable-buffer-local for minibuffer-default-add-function.
Also I moved (setq minibuffer-default-add-done t) to goto-history-element
just before the call to minibuffer-default-add-function, so there is no
need to set this variable to t in minibuffer-default-add-function
explicitly in normal cases. When necessary, minibuffer-default-add-function
can nullify minibuffer-default-add-done to be able call this function more
than once.
> Also the docstring of minibuffer-default-add-function needs to mention
> that the function should set minibuffer-default-add-done.
minibuffer-default-add-function now doesn't need to set
minibuffer-default-add-done any more, so I updated the
docstrings accordingly.
> This said, I'm wondering when the chunked computation makes sense.
> Do you have an example in mind?
I don't have a concrete example. When the chunked computation makes
sense, a function defined by minibuffer-default-add-function can use
a new specific global variable that will count the number of
function calls. But this is not necessary now, and the main thing
I added is the possibility to call this function more than once,
when this functions sets minibuffer-default-add-done to nil.
This patch also changes the error message "End of history; no next item"
to "End of defaults; no next item" for the end of the list of defaults.
Index: lisp/simple.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/simple.el,v
retrieving revision 1.912
diff -c -r1.912 simple.el
*** lisp/simple.el 26 Mar 2008 03:40:40 -0000 1.912
--- lisp/simple.el 27 Mar 2008 23:35:05 -0000
***************
*** 1304,1313 ****
--- 1305,1353 ----
(defvar minibuffer-temporary-goal-position nil)
+ (defvar minibuffer-default-add-function 'minibuffer-default-add-completions
+ "Function run by `goto-history-element' before consuming
`minibuffer-default'.
+ This is useful to dynamically add more elements to the list
`minibuffer-default'
+ when `goto-history-element' reaches the end of this list.
+ Before calling this function `goto-history-element' sets the variable
+ `minibuffer-default-add-done' to t, so it will call this function only
+ once. In special cases, when this function needs to be called more
+ than once, it can set `minibuffer-default-add-done' to nil explicitly,
+ overriding the setting of this variable to t in `goto-history-element'.")
+
+ (defvar minibuffer-default-add-done nil
+ "When nil, add more elements to the end of the list of default values.
+ The value nil causes `goto-history-element' to add more elements to
+ the list of defaults when it reaches the end of this list. It does
+ this by calling a function defined by `minibuffer-default-add-function'.")
+
+ (make-variable-buffer-local 'minibuffer-default-add-done)
+
+ (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 just 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)
+ (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 (not minibuffer-default-add-done)
+ (functionp minibuffer-default-add-function)
+ (< nabs (- (if (listp minibuffer-default)
+ (length minibuffer-default)
+ 1))))
+ (setq minibuffer-default-add-done t
+ minibuffer-default (funcall minibuffer-default-add-function)))
(let ((minimum (if minibuffer-default
(- (if (listp minibuffer-default)
(length minibuffer-default)
***************
*** 1320,1326 ****
(minibuffer-contents-no-properties)))
(if (< nabs minimum)
(if minibuffer-default
! (error "End of history; no next item")
(error "End of history; no default available")))
(if (> nabs (length (symbol-value minibuffer-history-variable)))
(error "Beginning of history; no preceding item"))
--- 1360,1366 ----
(minibuffer-contents-no-properties)))
(if (< nabs minimum)
(if minibuffer-default
! (error "End of defaults; no next item")
(error "End of history; no default available")))
(if (> nabs (length (symbol-value minibuffer-history-variable)))
(error "Beginning of history; no preceding item"))
Index: lisp/bindings.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.202
diff -c -r1.202 bindings.el
*** lisp/bindings.el 26 Mar 2008 03:32:46 -0000 1.202
--- lisp/bindings.el 27 Mar 2008 23:35:36 -0000
***************
*** 650,656 ****
"^No later matching history item$"
"^No earlier matching history item$"
"^End of history; no default available$"
! "^End of history; no next item$"
"^Beginning of history; no preceding item$"
"^No recursive edit is in progress$"
"^Changes to be undone are outside visible portion of buffer$"
--- 650,656 ----
"^No later matching history item$"
"^No earlier matching history item$"
"^End of history; no default available$"
! "^End of defaults; no next item$"
"^Beginning of history; no preceding item$"
"^No recursive edit is in progress$"
"^Changes to be undone are outside visible portion of buffer$"
--
Juri Linkov
http://www.jurta.org/emacs/
- RE: C-r and C-s in minibuffer should search completion, (continued)
- RE: C-r and C-s in minibuffer should search completion, Drew Adams, 2008/03/20
- Re: C-r and C-s in minibuffer should search completion, Juri Linkov, 2008/03/25
- Re: C-r and C-s in minibuffer should search completion, Juri Linkov, 2008/03/26
- Re: C-r and C-s in minibuffer should search completion, Stefan Monnier, 2008/03/26
- Re: C-r and C-s in minibuffer should search completion, Juri Linkov, 2008/03/26
- Re: C-r and C-s in minibuffer should search completion, Stefan Monnier, 2008/03/26
- Re: C-r and C-s in minibuffer should search completion,
Juri Linkov <=
- Re: C-r and C-s in minibuffer should search completion, Stefan Monnier, 2008/03/29
- minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion), Juri Linkov, 2008/03/29
- Re: minibuffer-default-add-shell-commands, Stefan Monnier, 2008/03/30
- Re: minibuffer-default-add-shell-commands, Juri Linkov, 2008/03/30
- Re: minibuffer-default-add-shell-commands, Reiner Steib, 2008/03/30
- Re: minibuffer-default-add-shell-commands, Juri Linkov, 2008/03/30
- Re: minibuffer-default-add-shell-commands, Reiner Steib, 2008/03/30
- Re: C-r and C-s in minibuffer should search completion, Juri Linkov, 2008/03/29
- Re: C-r and C-s in minibuffer should search completion, Stefan Monnier, 2008/03/30
- Re: C-r and C-s in minibuffer should search completion, Juri Linkov, 2008/03/30