zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh workers <zsh-workers@zsh.org>
Subject: Re: reverse-menu-complete re-starting completion on 5.2?
Date: Wed, 9 Mar 2016 14:45:05 -0800	[thread overview]
Message-ID: <160309144505.ZM11492@torch.brasslantern.com> (raw)
In-Reply-To: <CAHYJk3R8TJLbSQYqAAJyvYjMZvgy2+W8qkGO9DLyEQmXOGppNQ@mail.gmail.com>

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.


  reply	other threads:[~2016-03-09 22:45 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 [this message]
2016-03-10  2:19               ` Mikael Magnusson

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=160309144505.ZM11492@torch.brasslantern.com \
    --to=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).