From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh workers <zsh-workers@zsh.org>
Subject: Re: reverse-menu-complete re-starting completion on 5.2?
Date: Thu, 10 Mar 2016 03:19:56 +0100 [thread overview]
Message-ID: <CAHYJk3SGeRjdbtGyjXBgbWJ71O=oDMX64aQaftvxR7Qem84qrQ@mail.gmail.com> (raw)
In-Reply-To: <160309144505.ZM11492@torch.brasslantern.com>
On Wed, Mar 9, 2016 at 11:45 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Mar 9, 12:41pm, Mikael Magnusson wrote:
> } Subject: Re: reverse-menu-complete re-starting completion on 5.2?
> }
> } On Wed, Mar 9, 2016 at 12:12 PM, Mikael Magnusson <mikachu@gmail.com> wrote:
> } > On Mon, Mar 7, 2016 at 3:05 AM, Mikael Magnusson <mikachu@gmail.com> wrote:
> } >> On Sun, Mar 6, 2016 at 6:41 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> } >>> On Feb 29, 1:45am, Oliver Kiddle wrote:
> } >>> }
> } >>> } [...] I'm really not sure why we need to be so
> } >>> } strict about the completion widget matching the last completion widget.
> } >>>
> } >>> The only reason I can think of is in case menu completion is invoked from
> } >>> within a user-defined widget, or otherwise entered by a different widget
> } >>>
> } >>> Maybe we'd need another flag action for "zle -f" to continue/interrupt
>
> Turns out "zle auto-suffix-retain" already serves this purpose.
>
> This is tricky because widgets created with "zle -C" start directly in
> completion context, which means that "zle" generates an error; i.e., if
> we naively stick this into _generic:
>
> _generic:zle:1: widgets can only be called when ZLE is active
>
> (The error should probably be more specific, since a completion widget is
> merely the wrong *kind* of widget.)
>
> The solution is to make a normal widget for auto-suffix-retain, then invoke
> the completion widget with "zle the-widget -w". This seems a bit more work
> than should be necessary, but see example below.
>
> } >> I can tell you I quite often complete a directory name using normal
> } >> completion, and then press ctrl-n to complete files inside by latest
> } >> modification date.
> }
> } zstyle ':completion:most-recent-file:*' match-original both
> } zstyle ':completion:most-recent-file:*' file-sort modification
> } zstyle ':completion:most-recent-file:*' file-patterns '*:all\ files'
> } zstyle ':completion:most-recent-file:*' hidden all
> } zstyle ':completion:most-recent-file:*' completer _files
> } zle -C most-recent-file menu-complete _generic
> }
> } bindkey "^N" most-recent-file
>
> Just as-is, this works as you desire if the initial directory completion
> is not ambiguous, but cycles if there are multiple possible matches in
> the current menu.
>
> } I would like ^N after TAB to start completion over (even if this was
> } originally a ^N completion), but TAB after ^N to continue the same
> } completion.
>
> The following uses the normal-widget-calls-completion trick. There may
> be a better name for it.
>
> -- 8< --
> # Replaces bindkey in the above, otherwise all the same
>
> complete-most-recent-file () {
> [[ $LASTWIDGET != $WIDGET ]] && zle auto-suffix-retain
> zle most-recent-file -w
> }
> zle -N complete-most-recent-file
>
> bindkey "^N" complete-most-recent-file
> -- 8< --
>
> If we're OK with this, Oliver's patch can remain, but it's possible that
> there are other user-defined widgets that will start behaving unexpectedly.
I did it like this,
## Helper function for most-*-file
function _complete_separately() {
[[ $LASTWIDGET != $WIDGET ]] && zle auto-suffix-retain
zle ${WIDGET#complete-} -w
}
zle -N complete-most-recent-file _complete_separately
zle -N complete-most-accessed-file _complete_separately
Using accept-search instead of auto-suffix-retain also works, but it
eats up the first press without doing anything for some reason (only
if a menu is active).
I don't think anyone else is likely to figure this out by themselves though :).
--
Mikael Magnusson
prev parent reply other threads:[~2016-03-10 2:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20160226175937.GA22547@lorien.comfychair.org>
[not found] ` <160226114511.ZM17604@torch.brasslantern.com>
2016-02-29 0:45 ` Oliver Kiddle
2016-03-06 17:41 ` Bart Schaefer
2016-03-07 2:05 ` Mikael Magnusson
2016-03-09 11:12 ` Mikael Magnusson
2016-03-09 11:41 ` Mikael Magnusson
2016-03-09 22:45 ` Bart Schaefer
2016-03-10 2:19 ` Mikael Magnusson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHYJk3SGeRjdbtGyjXBgbWJ71O=oDMX64aQaftvxR7Qem84qrQ@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).