* Re: History completion
2021-12-08 18:54 History completion Juri Linkov
@ 2021-12-08 20:02 ` André A. Gomes
2021-12-09 6:05 ` Manuel Uberti
2021-12-09 17:12 ` Juri Linkov
2021-12-08 20:52 ` [External] : " Drew Adams
` (2 subsequent siblings)
3 siblings, 2 replies; 13+ messages in thread
From: André A. Gomes @ 2021-12-08 20:02 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
Juri Linkov <juri@linkov.net> writes:
> Wouldn't it be nice to allow completion on previous input
> in the minibuffer.
>
> There are two unbound commands ‘previous-complete-history-element’ and
> ‘next-complete-history-element’ but their completion is limited
> only to the beginnings of history items.
>
> So tried to set the minibuffer completion table to the history list:
>
> #+begin_src emacs-lisp
> (defun minibuffer-setup-history-completions ()
> (unless (or minibuffer-completion-table minibuffer-completion-predicate)
> (setq-local minibuffer-completion-table (symbol-value minibuffer-history-variable))))
> (add-hook 'minibuffer-setup-hook 'minibuffer-setup-history-completions)
> #+end_src
This is extremely valuable!!! I have thought about it myself in the
past. My inspiration, perhaps yours too, came from
`comint-previous-matching-input-from-input' and friends.
> It works nicely with ‘icomplete-mode’ and ‘fido-vertical-mode’
> by automatically displaying completions from the history
> depending on input in the minibuffer. But this also has drawbacks:
> while typing a completely new command that doesn't exist in the history,
> it permanently says at the end of the minibuffer: [No matches]
>
> So instead of this, tried to show history completions only after
> typing a special key. TAB can't be reused because in some minibuffers
> such as ‘M-!’ (shell-command), TAB completes the command/file names.
>
> There is ‘C-tab’ bound to file-cache-minibuffer-complete.
> When file-cache is not used, then ‘C-tab’ could be rebound
> to a command that completes on the minibuffer history:
>
> #+begin_src emacs-lisp
> ;; Adapted from ‘minibuffer-complete’:
> (defun minibuffer-complete-history ()
> (interactive)
> (completion-in-region (minibuffer--completion-prompt-end) (point-max)
> (symbol-value minibuffer-history-variable)
> nil))
> (define-key minibuffer-local-map [C-tab] 'minibuffer-complete-history)
> #+end_src
Hopefully I was able to follow you thoroughly.
I think that such a completion should always be triggered by the user,
and not automatically.
To cycle the history ring with a given prefix string, I suggest C-n/p.
The minibuffer is always a single line after all, or am I missing
something? M-n/p can't be taken, and the same applies to C-M-n/p.
Another suggestion would be to follow comint mode's bindings: C-c M-r/s.
But, unlike comint's case, C-c M-p/n aren't being used so it's also an
option.
--
André A. Gomes
"Free Thought, Free World"
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-08 20:02 ` André A. Gomes
@ 2021-12-09 6:05 ` Manuel Uberti
2021-12-09 17:12 ` Juri Linkov
1 sibling, 0 replies; 13+ messages in thread
From: Manuel Uberti @ 2021-12-09 6:05 UTC (permalink / raw)
To: emacs-devel
On 08/12/21 21:02, André A. Gomes wrote:
> To cycle the history ring with a given prefix string, I suggest C-n/p.
> The minibuffer is always a single line after all, or am I missing
> something? M-n/p can't be taken, and the same applies to C-M-n/p.
> Another suggestion would be to follow comint mode's bindings: C-c M-r/s.
> But, unlike comint's case, C-c M-p/n aren't being used so it's also an
> option.
C-n/p are already taken in icomplete-vertical-mode-minibuffer-map, though. (And
I use them every day.)
--
Manuel Uberti
www.manueluberti.eu
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-08 20:02 ` André A. Gomes
2021-12-09 6:05 ` Manuel Uberti
@ 2021-12-09 17:12 ` Juri Linkov
2021-12-09 22:52 ` André A. Gomes
1 sibling, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2021-12-09 17:12 UTC (permalink / raw)
To: André A. Gomes; +Cc: emacs-devel
> I think that such a completion should always be triggered by the user,
> and not automatically.
>
> To cycle the history ring with a given prefix string, I suggest C-n/p.
> The minibuffer is always a single line after all, or am I missing
> something?
This assumption is not always correct. Sometimes the minibuffer
takes a few lines.
> M-n/p can't be taken, and the same applies to C-M-n/p.
Correct.
> Another suggestion would be to follow comint mode's bindings: C-c M-r/s.
> But, unlike comint's case, C-c M-p/n aren't being used so it's also an
> option.
Two key presses is not the most convenient to browse completions.
Horizontal Icomplete uses ‘C-,’ and ‘C-.’.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-09 17:12 ` Juri Linkov
@ 2021-12-09 22:52 ` André A. Gomes
0 siblings, 0 replies; 13+ messages in thread
From: André A. Gomes @ 2021-12-09 22:52 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
Juri Linkov <juri@linkov.net> writes:
>> Another suggestion would be to follow comint mode's bindings: C-c M-r/s.
>> But, unlike comint's case, C-c M-p/n aren't being used so it's also an
>> option.
>
> Two key presses is not the most convenient to browse completions.
> Horizontal Icomplete uses ‘C-,’ and ‘C-.’.
Maybe I got something wrong, but I thought we're discussing commands
that were similar `next-matching-history-element' and
`previous-matching-history-element' (bound to M-s and M-r).
The ones I thought we're referring to would match an element based on a
given prefix (akin to comint-previous-matching-input-from-input and
friends).
IMO, it would make sense to have a symmetric behaviour in comint mode
and the minibuffer. Some will argue that I can just type "^" right
after I call M-r/s in the minibuffer. Well...
In that vein, I suggested C-c M-r/s for the hypothetical
`previous-matching-history-element-from-input' and
`next-matching-history-element-from-input'.
--
André A. Gomes
"Free Thought, Free World"
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [External] : History completion
2021-12-08 18:54 History completion Juri Linkov
2021-12-08 20:02 ` André A. Gomes
@ 2021-12-08 20:52 ` Drew Adams
2021-12-09 8:30 ` Daniel Fleischer
2021-12-09 17:16 ` Juri Linkov
2021-12-09 7:51 ` Manuel Uberti
2022-06-09 7:01 ` Juri Linkov
3 siblings, 2 replies; 13+ messages in thread
From: Drew Adams @ 2021-12-08 20:52 UTC (permalink / raw)
To: Juri Linkov, emacs-devel@gnu.org
> Wouldn't it be nice to allow completion on previous input
> in the minibuffer.
Yet another feature that Icicles introduced and has had since 2005...
https://www.emacswiki.org/emacs/Icicles_-_History_Enhancements
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [External] : History completion
2021-12-08 20:52 ` [External] : " Drew Adams
@ 2021-12-09 8:30 ` Daniel Fleischer
2021-12-09 17:16 ` Juri Linkov
1 sibling, 0 replies; 13+ messages in thread
From: Daniel Fleischer @ 2021-12-09 8:30 UTC (permalink / raw)
To: emacs-devel
Drew Adams [2021-12-08 Wed 20:52] wrote:
> Yet another feature that Icicles introduced and has had since 2005...
>
> https://www.emacswiki.org/emacs/Icicles_-_History_Enhancements
What's old is new again, people keep rediscovering things. I'll give
icicles a try.
--
Daniel Fleischer
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-08 20:52 ` [External] : " Drew Adams
2021-12-09 8:30 ` Daniel Fleischer
@ 2021-12-09 17:16 ` Juri Linkov
2021-12-09 18:13 ` [External] : " Drew Adams
1 sibling, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2021-12-09 17:16 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel@gnu.org
>> Wouldn't it be nice to allow completion on previous input
>> in the minibuffer.
>
> Yet another feature that Icicles introduced and has had since 2005...
>
> https://www.emacswiki.org/emacs/Icicles_-_History_Enhancements
What key does Icicles use to complete on the history?
It seems C-TAB is the most convenient key since
it's the default completion key TAB with the Ctrl modifier.
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [External] : Re: History completion
2021-12-09 17:16 ` Juri Linkov
@ 2021-12-09 18:13 ` Drew Adams
0 siblings, 0 replies; 13+ messages in thread
From: Drew Adams @ 2021-12-09 18:13 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel@gnu.org
> >> Wouldn't it be nice to allow completion on previous input
> >> in the minibuffer.
> >
> > Yet another feature that Icicles introduced and has had since 2005...
> >
> > https://www.emacswiki.org/emacs/Icicles_-_History_Enhancements
>
> What key does Icicles use to complete on the history?
The URL you quoted explains that there are 3 ways
complete against input history, and thus 3 keys.
`M-o', available any time the minibuffer is active
(so not just during input with completion), provides
a form of completion on demand. It uses a recursive
minibuffer. You can use it to insert any number of
previous inputs, using completion. (And you can of
course combine completion with cycling among input
candidates.) Insertion appends to your minibuffer
input, and you can edit the inserted text, of course.
A prefix arg with `M-o' determines whether to follow
an inserted previous with a space char, and whether
to enclose it with "...".
`M-h' and `M-<pause>' are used during completion.
They each provide completion against previous inputs
for the given (i.e., current) minibuffer history.
Neither uses a recursive minibuffer. They just
co-opt the current completion to go against candidates
in the current history list.
`M-<pause>' restricts completion to previous inputs
in the current set of matching candidates. So you
can narrow the set in various ways before using it.
There are other differences between `M-h' and
`M-<pause>'. Read the doc you cited for more info.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-08 18:54 History completion Juri Linkov
2021-12-08 20:02 ` André A. Gomes
2021-12-08 20:52 ` [External] : " Drew Adams
@ 2021-12-09 7:51 ` Manuel Uberti
2021-12-09 17:18 ` Juri Linkov
2022-06-09 7:01 ` Juri Linkov
3 siblings, 1 reply; 13+ messages in thread
From: Manuel Uberti @ 2021-12-09 7:51 UTC (permalink / raw)
To: emacs-devel
On 08/12/21 19:54, Juri Linkov wrote:
> #+begin_src emacs-lisp
> ;; Adapted from ‘minibuffer-complete’:
> (defun minibuffer-complete-history ()
> (interactive)
> (completion-in-region (minibuffer--completion-prompt-end) (point-max)
> (symbol-value minibuffer-history-variable)
> nil))
> (define-key minibuffer-local-map [C-tab] 'minibuffer-complete-history)
> #+end_src
FWIW, I am trying this and I find it very helpful. Thank you for sharing.
--
Manuel Uberti
www.manueluberti.eu
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-09 7:51 ` Manuel Uberti
@ 2021-12-09 17:18 ` Juri Linkov
2021-12-09 17:40 ` Manuel Uberti
0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2021-12-09 17:18 UTC (permalink / raw)
To: Manuel Uberti; +Cc: emacs-devel
>> #+begin_src emacs-lisp
>> ;; Adapted from ‘minibuffer-complete’:
>> (defun minibuffer-complete-history ()
>> (interactive)
>> (completion-in-region (minibuffer--completion-prompt-end) (point-max)
>> (symbol-value minibuffer-history-variable)
>> nil))
>> (define-key minibuffer-local-map [C-tab] 'minibuffer-complete-history)
>> #+end_src
>
> FWIW, I am trying this and I find it very helpful. Thank you for sharing.
One problem is that I can't find a suitable completion style for this
that would match on substrings, e.g. "pu re" to match "git pull --rebase".
The style ‘flex’ is too lax and matches characters anywhere.
The style ‘substring’ is the closest, but it requires moving point
to the middle of the string. Maybe a new style ‘substrings’ is needed
that would match words separated by space as substrings. Also maybe
another style ‘initial-substrings’ that does the same, but only
matches word beginnings.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-09 17:18 ` Juri Linkov
@ 2021-12-09 17:40 ` Manuel Uberti
0 siblings, 0 replies; 13+ messages in thread
From: Manuel Uberti @ 2021-12-09 17:40 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
On 09/12/21 18:18, Juri Linkov wrote:
> One problem is that I can't find a suitable completion style for this
> that would match on substrings, e.g. "pu re" to match "git pull --rebase".
> The style ‘flex’ is too lax and matches characters anywhere.
> The style ‘substring’ is the closest, but it requires moving point
> to the middle of the string. Maybe a new style ‘substrings’ is needed
> that would match words separated by space as substrings. Also maybe
> another style ‘initial-substrings’ that does the same, but only
> matches word beginnings.
Maybe it could be worth to give orderless[1] a try for this?
[1] https://github.com/oantolin/orderless
--
Manuel Uberti
www.manueluberti.eu
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: History completion
2021-12-08 18:54 History completion Juri Linkov
` (2 preceding siblings ...)
2021-12-09 7:51 ` Manuel Uberti
@ 2022-06-09 7:01 ` Juri Linkov
3 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2022-06-09 7:01 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 727 bytes --]
> So instead of this, tried to show history completions only after
> typing a special key. TAB can't be reused because in some minibuffers
> such as ‘M-!’ (shell-command), TAB completes the command/file names.
>
> There is ‘C-tab’ bound to file-cache-minibuffer-complete.
> When file-cache is not used, then ‘C-tab’ could be rebound
> to a command that completes on the minibuffer history.
Actually two keys are needed: one to complete on the history,
and another to complete on the list of default values.
So maybe like the ‘up’ key navigates through the history,
‘C-x up’ could complete on the history, and like ‘down’ key
navigates through the future history, ‘C-x down’ could
complete on it:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: minibuffer-complete-history.patch --]
[-- Type: text/x-diff, Size: 1912 bytes --]
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index cdbde2d340..e0e9893367 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4418,6 +4499,36 @@ minibuffer-choose-completion
(let ((completion-use-base-affixes t))
(choose-completion nil no-exit no-quit))))
+(defun minibuffer-complete-history ()
+ "Complete the minibuffer history as far as possible.
+Like `minibuffer-complete' but completes on the history items
+instead of the default completion table."
+ (interactive)
+ (let ((completions-sort nil)
+ (history (mapcar (lambda (h)
+ ;; Support e.g. `C-x ESC ESC TAB' as
+ ;; a replacement of `list-command-history'
+ (if (consp h) (format "%S" h) h))
+ (symbol-value minibuffer-history-variable))))
+ (completion-in-region (minibuffer--completion-prompt-end) (point-max)
+ history nil)))
+
+(defun minibuffer-complete-defaults ()
+ "Complete minibuffer defaults as far as possible.
+Like `minibuffer-complete' but completes on the default items
+instead of the completion table."
+ (interactive)
+ (let ((completions-sort nil))
+ (when (and (not minibuffer-default-add-done)
+ (functionp minibuffer-default-add-function))
+ (setq minibuffer-default-add-done t
+ minibuffer-default (funcall minibuffer-default-add-function)))
+ (completion-in-region (minibuffer--completion-prompt-end) (point-max)
+ (ensure-list minibuffer-default) nil)))
+
+(define-key minibuffer-local-map [?\C-x up] 'minibuffer-complete-history)
+(define-key minibuffer-local-map [?\C-x down] 'minibuffer-complete-defaults)
+
(defcustom minibuffer-default-prompt-format " (default %s)"
"Format string used to output \"default\" values.
When prompting for input, there will often be a default value,
^ permalink raw reply related [flat|nested] 13+ messages in thread