zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: completion of filenames
Date: Fri, 13 Dec 2019 11:46:56 -0800	[thread overview]
Message-ID: <CAH+w=7YZCs5Czy7no2juuUfawRFkmHKAHX_vAwTazO8WJ23Y7w@mail.gmail.com> (raw)
In-Reply-To: <fad5ccf0-65c7-4941-0183-967c2c8a823e@eastlink.ca>

On Fri, Dec 13, 2019 at 9:07 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Or not.  Anyway for now I don't even know where to look.

Let's take this all the way back to the beginning for a moment ...

On Tue, Dec 10, 2019 at 8:19 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> As I have it now TAB only completes filenames after some leading
> command.  If I hit TAB at the beginning of a line it seems to want to
> find commands.  Can I have filename completion active right from the
> start?

When there is nothing at all on the command line, completion starts
out in the special "-command-" context.  If you start from "zsh -f"
and load the completion system (compinit) and then type ^x h (as
previously suggested by PWS -- note, you have to let go of the ctrl
key before hitting h) you will find this (apologies for any extraneous
line wrapping):

%
tags in context :completion::complete:-command-::
    commands builtins functions aliases suffix-aliases reserved-words
jobs parameters parameters  (_command_names _autocd)
    commands
                           (_path_commands _path_commands
_command_names _autocd)
    jobs
                           (_jobs _command_names _autocd)
    parameters
                           (_parameters _command_names _autocd)

You'll notice that "files" are not in that description anywhere.

If we add your "zstyle ':completion:*' completer _expand _complete
_files" setting:

%
tags in context :completion::complete:-command-::
    commands builtins functions aliases suffix-aliases reserved-words
jobs parameters parameters  (_command_names _autocd)
    commands
                           (_path_commands _command_names _autocd)
    jobs
                           (_jobs _command_names _autocd)
    parameters
                           (_parameters _command_names _autocd)
tags in context :completion::files:::
    globbed-files  (_files)

Now we have files, but they're still going to be tried only after all
the more specific context has failed to locate anything.  If you want
files to be tried along with all of those other options, you need to
put _files BEFORE _complete in the zstyle, and if you want that to
happen only at an empty prompt, you need to use the specific -command-
context.

zstyle :completion::complete:-command-:: completer _expand _files _complete
zstyle :completion::complete:-command-:: insert-tab false

Note that when you form a list of completers, the implication is that
if an earlier entry in the list finds ANY possible completion, then
the later entries will not be tried.  So at an empty prompt you are
going to get either the default stuff from _complete, or the local
files from _files, depending on which order those appear in the style.
If you want both all the time, a different formulation would be
needed.

You've got one more issue, I think, based on your subsequent question:

> Where is 'expand-or-complete' defined?

You shouldn't be using both expand-or-complete and the _expand
completer.  If you invoke expand-or-complete, it's going to try to do
expansion on the word and if that succeeds it will never proceed into
attempting completion.  To use _expand, you should be re-binding the
TAB key:

bindkey "^I" complete-word

Usually compinit will take care of this for you, but only if the
zstyle definitions appear in your .zshrc (et al) BEFORE you invoke
compinit.  This is in the doc:

       To  initialize  the system, the function compinit should be in a direc-
       tory mentioned  in  the  fpath  parameter  ...  If completion styles (see
       below) are set up  to  perform  expansion  as  well  as  completion  by
       default,  and the TAB key is bound to expand-or-complete, compinit will
       rebind it to complete-word; this is necessary to use the  correct  form
       of expansion.

Does any of this help with your situation?

  reply	other threads:[~2019-12-13 19:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20191210161919epcas1p2c60b547299b6425434345c4f26071643@epcas1p2.samsung.com>
2019-12-10 16:17 ` Ray Andrews
2019-12-10 16:30   ` Peter Stephenson
2019-12-10 16:59     ` Ray Andrews
2019-12-10 17:16       ` Peter Stephenson
2019-12-10 17:45         ` Ray Andrews
2019-12-13 15:59       ` Ray Andrews
2019-12-13 16:24         ` Peter Stephenson
2019-12-13 17:06           ` Ray Andrews
2019-12-13 19:46             ` Bart Schaefer [this message]
2019-12-13 21:10               ` Ray Andrews

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='CAH+w=7YZCs5Czy7no2juuUfawRFkmHKAHX_vAwTazO8WJ23Y7w@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@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).