zsh-users
 help / color / mirror / code / Atom feed
* <Tab> completion does not insert a slash
@ 2021-08-04 15:02 Peter Slížik
  2021-08-04 15:45 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Slížik @ 2021-08-04 15:02 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]

Hello zshers,

my <Tab> completion configuration in .zshrc is quite a mess, and it shows.
The result of the completion is quite unpredictable when it comes to the
trailing slash.

Sometimes (for example, with 'git add'), pressing <Tab> inserts a directory
name followed by a shlash.
If I had a modified file in aaa/bbb/ccc, pressing a <Tab> 4 times would
complete the whole command.

git add <Tab>aaa/<Tab>bbb/<Tab>ccc/<Tab>file.py

Other times (e.g. with the 'cd' command), pressing <Tab> would insert just
the directory name, without the trailing slash.
Sometimes I need to press <Tab> two or even three (!) times to produce the
slash. Or just press the slash key, that's faster.

cd <Tab>aaa<Tab><Tab><Tab>/bbb, etc.

I remember when I started using Zsh, the completion engine would insert a
bold slash, which was either kept or removed depending on the further
action.

As I said, I have a lot of settings in my .zshrc and I don't know which of
them could make the change in completion behavior. Could you kindly point
me where to start or how to trace the problem?

Thank you.

Best regards,
Peter

[-- Attachment #2: Type: text/html, Size: 1503 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-04 15:02 <Tab> completion does not insert a slash Peter Slížik
@ 2021-08-04 15:45 ` Bart Schaefer
  2021-08-04 16:49   ` Peter Slížik
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2021-08-04 15:45 UTC (permalink / raw)
  To: Peter Slížik; +Cc: Zsh Users

On Wed, Aug 4, 2021 at 8:02 AM Peter Slížik <peter.slizik@gmail.com> wrote:
>
> As I said, I have a lot of settings in my .zshrc and I don't know which of them could make the change in completion behavior. Could you kindly point me where to start or how to trace the problem?

The place to start is nearly always to first type ctrl+x h instead of
tab, to get a description of the context, and if that doesn't help,
type ctrl+x question-mark in place of tab, to invoke completion
debugging, which leaves a trace file in /tmp.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-04 15:45 ` Bart Schaefer
@ 2021-08-04 16:49   ` Peter Slížik
  2021-08-04 17:26     ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Slížik @ 2021-08-04 16:49 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1549 bytes --]

Ok, my suspicion is that the problem occurs if the completed name can
expand to both a named directory and a local directory.

My directory structure:
/workdirs/projects/myproject/src/python/mymodule/submodule

# Define a named directory
src=/workdirs/projects/myproject/src
: src

# cd inside the tree
cd /workdirs/projects/myproject

# try to go deeper
cd sr<Tab>      # completes 'sr' to 'cd src' (without a slash)
cd src<Tab>    # another tab - emits a bell sound
cd src<Tab>    # yet another tab - add a slash: 'src/'

It seems like the completion engine cannot choose between the named
directory and a local directory of the same name. In reality, they point to
the same dir.

Is there a way to fix this behavior?
I'm using a lot of named directories, they are very convenient. In fact,
they are the main reason I switched to zsh.

Peter

Here,

сре, 4. авг 2021. у 17:45 Bart Schaefer <schaefer@brasslantern.com> је
написао/ла:

> On Wed, Aug 4, 2021 at 8:02 AM Peter Slížik <peter.slizik@gmail.com>
> wrote:
> >
> > As I said, I have a lot of settings in my .zshrc and I don't know which
> of them could make the change in completion behavior. Could you kindly
> point me where to start or how to trace the problem?
>
> The place to start is nearly always to first type ctrl+x h instead of
> tab, to get a description of the context, and if that doesn't help,
> type ctrl+x question-mark in place of tab, to invoke completion
> debugging, which leaves a trace file in /tmp.
>

[-- Attachment #2: Type: text/html, Size: 2260 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-04 16:49   ` Peter Slížik
@ 2021-08-04 17:26     ` Bart Schaefer
  2021-08-11 20:03       ` Peter Slížik
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2021-08-04 17:26 UTC (permalink / raw)
  To: Peter Slížik; +Cc: Zsh Users

On Wed, Aug 4, 2021 at 9:50 AM Peter Slížik <peter.slizik@gmail.com> wrote:
>
> It seems like the completion engine cannot choose between the named directory and a local directory of the same name. In reality, they point to the same dir.
>
> Is there a way to fix this behavior?

Yes.  The default is to offer all possible completions at the same
time, but you can change that with the tag-order zstyle.

The default behaves mostly like this:
zstyle :completion::complete:cd:: tag-order "local-directories
named-directories"
(all tags in the same space-separated string are offered at the same time)

What you want is more like this:
zstyle :completion::complete:cd:: tag-order local-directories named-directories

You can reverse the order if you prefer to see the named-directories first:
zstyle :completion::complete:cd:: tag-order named-directories local-directories

Anything in a tag you don't include in the list will be offered if
there are no results for the tags you do list.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-04 17:26     ` Bart Schaefer
@ 2021-08-11 20:03       ` Peter Slížik
  2021-08-11 20:23         ` Peter Slížik
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Slížik @ 2021-08-11 20:03 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 2387 bytes --]

Sorry for the late reply, I tried both versions (with and without
parentheses).

I tried to descend into 'src/python/api' by typing 'cd s<Tab>', later with
src completed, 'cd src/py<Tab>'.
Here are the results: using the value 'tag-order local-directories
named-directories' helped with completing src/, the directory name was
completed immediately upon hitting Tab. The second dir (python) was not
completed on the first Tab press. Typing another Tab did *not* produce a
list of suggestions.

Here is the result of 'sr<ctrl+x h>' and 'src/py<ctrl+x h>'.

% cd sr<ctrl+x h>
tags in context :completion::complete:cd::
local-directories named-directories      (_cd)
users named-directories directory-stack  (_tilde _cd)
users                                    (_users _tilde _cd)

% cd src/py<ctrl+x h>
tags in context :completion::complete:cd::
named-directories  (_cd)
local-directories  (_cd)

% cd src/python/<ctrl+x h>
(no results)

Do you think that there is anything suspicious? Personally I wonder why
there are duplicated entries in the first case and why are the tags listed
in a reversed order in the second case. And yes, the empty result list in
the last case.

Peter

сре, 4. авг 2021. у 19:26 Bart Schaefer <schaefer@brasslantern.com> је
написао/ла:

> On Wed, Aug 4, 2021 at 9:50 AM Peter Slížik <peter.slizik@gmail.com>
> wrote:
> >
> > It seems like the completion engine cannot choose between the named
> directory and a local directory of the same name. In reality, they point to
> the same dir.
> >
> > Is there a way to fix this behavior?
>
> Yes.  The default is to offer all possible completions at the same
> time, but you can change that with the tag-order zstyle.
>
> The default behaves mostly like this:
> zstyle :completion::complete:cd:: tag-order "local-directories
> named-directories"
> (all tags in the same space-separated string are offered at the same time)
>
> What you want is more like this:
> zstyle :completion::complete:cd:: tag-order local-directories
> named-directories
>
> You can reverse the order if you prefer to see the named-directories first:
> zstyle :completion::complete:cd:: tag-order named-directories
> local-directories
>
> Anything in a tag you don't include in the list will be offered if
> there are no results for the tags you do list.
>

[-- Attachment #2: Type: text/html, Size: 3446 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-11 20:03       ` Peter Slížik
@ 2021-08-11 20:23         ` Peter Slížik
  2021-08-11 22:20           ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Slížik @ 2021-08-11 20:23 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 3102 bytes --]

OK, more clarification. I've used "zstyle
':completion:*:*:*:*:descriptions'".

Now it seems that with the second completed path, the completion engine
cannot decide between these two:

% cd src/python<Tab>
-- directory after cdablevar --
-- local directory --

Frankly, I still don't understand what the problem is, because I'm *inside*
a dir pointed to by a named directory (src/ in this case) and both
"directory after cdablevar" and "local directory" are the same directory
anyway.

Peter

сре, 11. авг 2021. у 22:03 Peter Slížik <peter.slizik@gmail.com> је
написао/ла:

> Sorry for the late reply, I tried both versions (with and without
> parentheses).
>
> I tried to descend into 'src/python/api' by typing 'cd s<Tab>', later with
> src completed, 'cd src/py<Tab>'.
> Here are the results: using the value 'tag-order local-directories
> named-directories' helped with completing src/, the directory name was
> completed immediately upon hitting Tab. The second dir (python) was not
> completed on the first Tab press. Typing another Tab did *not* produce a
> list of suggestions.
>
> Here is the result of 'sr<ctrl+x h>' and 'src/py<ctrl+x h>'.
>
> % cd sr<ctrl+x h>
> tags in context :completion::complete:cd::
> local-directories named-directories      (_cd)
> users named-directories directory-stack  (_tilde _cd)
> users                                    (_users _tilde _cd)
>
> % cd src/py<ctrl+x h>
> tags in context :completion::complete:cd::
> named-directories  (_cd)
> local-directories  (_cd)
>
> % cd src/python/<ctrl+x h>
> (no results)
>
> Do you think that there is anything suspicious? Personally I wonder why
> there are duplicated entries in the first case and why are the tags listed
> in a reversed order in the second case. And yes, the empty result list in
> the last case.
>
> Peter
>
> сре, 4. авг 2021. у 19:26 Bart Schaefer <schaefer@brasslantern.com> је
> написао/ла:
>
>> On Wed, Aug 4, 2021 at 9:50 AM Peter Slížik <peter.slizik@gmail.com>
>> wrote:
>> >
>> > It seems like the completion engine cannot choose between the named
>> directory and a local directory of the same name. In reality, they point to
>> the same dir.
>> >
>> > Is there a way to fix this behavior?
>>
>> Yes.  The default is to offer all possible completions at the same
>> time, but you can change that with the tag-order zstyle.
>>
>> The default behaves mostly like this:
>> zstyle :completion::complete:cd:: tag-order "local-directories
>> named-directories"
>> (all tags in the same space-separated string are offered at the same time)
>>
>> What you want is more like this:
>> zstyle :completion::complete:cd:: tag-order local-directories
>> named-directories
>>
>> You can reverse the order if you prefer to see the named-directories
>> first:
>> zstyle :completion::complete:cd:: tag-order named-directories
>> local-directories
>>
>> Anything in a tag you don't include in the list will be offered if
>> there are no results for the tags you do list.
>>
>

[-- Attachment #2: Type: text/html, Size: 4560 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-11 20:23         ` Peter Slížik
@ 2021-08-11 22:20           ` Bart Schaefer
  2021-08-16 21:39             ` Peter Slížik
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2021-08-11 22:20 UTC (permalink / raw)
  To: Peter Slížik; +Cc: Zsh Users

On Wed, Aug 11, 2021 at 1:23 PM Peter Slížik <peter.slizik@gmail.com> wrote:
>
> сре, 11. авг 2021. у 22:03 Peter Slížik <peter.slizik@gmail.com> је написао/ла:
>>
>> Sorry for the late reply, I tried both versions (with and without parentheses).

I don't know what "with and without parentheses" means here.

>> % cd sr<ctrl+x h>
>> tags in context :completion::complete:cd::
>> local-directories named-directories      (_cd)
>> users named-directories directory-stack  (_tilde _cd)
>> users                                    (_users _tilde _cd)
>>
>> % cd src/py<ctrl+x h>
>> tags in context :completion::complete:cd::
>> named-directories  (_cd)
>> local-directories  (_cd)
>>
>> % cd src/python/<ctrl+x h>
>> (no results)

Are there any subdirectories inside src/python/ ?  The only case in
which I can get this to reproduce is when there's nothing more to
complete.

If there are subdirectories, a possibility is that the permissions on
either the python directory or the subdirectories are preventing
further names from being found.

This is the case where you switch to running <ctrl+x ?> and look at
the trace file.

>> Do you think that there is anything suspicious? Personally I wonder why there are duplicated entries in the first case and why are the tags listed in a reversed order in the second case.

The output of c-x h is not sorted by the tag-order style, it's in the
order that the tags are populated by the completion function.  _cd
happens to check for named directories first.  In an actual completion
pass, filtering the display according to tag-order happens later,
after all the possible tags have been populated.

> OK, more clarification. I've used "zstyle ':completion:*:*:*:*:descriptions'".
>
> Now it seems that with the second completed path, the completion engine cannot decide between these two:
>
> % cd src/python<Tab>
> -- directory after cdablevar --
> -- local directory --

I don't have your set of "hash -d" entries nor your file structure,
but with the closest guess I can make using the zsh source tree, I get
that result only when there are no subdirectories left to complete.
What does (execution of, not completion of)
  ls -ld ~src/python/*(/)
show you at that point?

> Frankly, I still don't understand what the problem is, because I'm inside a dir pointed to by a named directory (src/ in this case) and both "directory after cdablevar" and "local directory" are the same directory anyway.

Whether they're the same directory doesn't actually matter; the tags
have caused them to be placed in separate groups, so as far as
completion is concerned they are different alternatives.  The
"directory after cdablevar" branch has gone down the full path
$src/python (and then hidden a prefix) whereas the local directory
branch has used the relative path src/python and completion is only
looking for unique strings, not filesystem targets.  The filesystem is
only examined to generate the strings that are compared.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-11 22:20           ` Bart Schaefer
@ 2021-08-16 21:39             ` Peter Slížik
  2021-08-16 21:41               ` Peter Slížik
  2021-08-16 22:17               ` Bart Schaefer
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Slížik @ 2021-08-16 21:39 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1981 bytes --]

>
>
> Are there any subdirectories inside src/python/ ?  The only case in
> which I can get this to reproduce is when there's nothing more to
> complete.
>

Yes, there are four subdirectories and a bunch of files.

% ls src/python/
API CMakeFiles CMakeLists.txt XYZ Makefile.am Apps, etc.

What strikes me is that the completion provides different results depending
on whether the final slash is real or "transient" (hopefully I'm using
correct terminology).

# All the following provide the same result:
% cd src/pyt<Ctrl+D>
% cd src/python<Ctrl+D>
% cd src/python/<Ctrl+D>    # the final slash is transient
-- directory after cdablevar --
-- local directory --
python/

But in this case, the result is different.
% cd src/python/<Ctrl+D>    # the final slash is real
-- directory after cdablevar --
-- local directory --
API/         Apps/        CMakeFiles/  XYZ/

Maybe the behaviour is expected, but I would expect the transient slash to
work exactly the same way a real slash does.

After I've discovered the 'description' zstyle option, I'm observing how
the completion works and find it even more confusing.
For example, in my Ubuntu system, the standard 'watch' command is located
in /usr/bin. The /bin dir is actually a symlink to the /usr/bin/dir. And I
have an alias called 'which', which expands to itself and adds two extra
arguments.

% whence -a watch
watch --interval=0.3 tail -50
/usr/bin/watch
/bin/watch

BUT, trying to complete it in a command position identifies it either as a
named directory, or as a parameter. (?!)

% wa<Ctrl+D>

-- external command --
-- executable file --
-- builtin command --
-- alias --
-- parameter --
-- named directory --
wait         wallpapers/  wapps        watchbm
wall         wapi         watch        watchgnupg

% wat<Ctrl+D>
-- external command --
-- alias --
-- parameter --
watch       watchbm     watchgnup

The <Ctrl+X>? log file is quite long (3961 lines); I'm not sure how to make
sense of it.

Best regards,
Peter

[-- Attachment #2: Type: text/html, Size: 3089 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-16 21:39             ` Peter Slížik
@ 2021-08-16 21:41               ` Peter Slížik
  2021-08-16 22:17               ` Bart Schaefer
  1 sibling, 0 replies; 11+ messages in thread
From: Peter Slížik @ 2021-08-16 21:41 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 148 bytes --]

 > And I have an alias called 'which', which expands to itself and adds two
extra arguments.

==> I have an alias called 'watch', of course.

Peter

[-- Attachment #2: Type: text/html, Size: 270 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-16 21:39             ` Peter Slížik
  2021-08-16 21:41               ` Peter Slížik
@ 2021-08-16 22:17               ` Bart Schaefer
  2021-08-17  8:57                 ` Peter Slížik
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2021-08-16 22:17 UTC (permalink / raw)
  To: Peter Slížik; +Cc: Zsh Users

On Mon, Aug 16, 2021 at 2:40 PM Peter Slížik <peter.slizik@gmail.com> wrote:
>
> What strikes me is that the completion provides different results depending on whether the final slash is real or "transient" (hopefully I'm using correct terminology).
>
> Maybe the behaviour is expected, but I would expect the transient slash to work exactly the same way a real slash does.

No, it doesn't.  The transient slash is just showing you that this is
in fact a directory.  You still actually have to type either a slash,
or one non-tab character after the slash, to make it "real" before
completion will proceed deeper down the tree, otherwise you're just
cycling the menu at the preceding input position.

> After I've discovered the 'description' zstyle option, I'm observing how the completion works and find it even more confusing.
> [...] trying to complete it in a command position identifies it either as a named directory, or as a parameter. (?!)
>
> % wa<Ctrl+D>
> -- external command --
> -- executable file --
> -- builtin command --
> -- alias --
> -- parameter --
> -- named directory --
> wait         wallpapers/  wapps        watchbm
> wall         wapi         watch        watchgnupg

The descriptions here are showing you every place from which a
completion string was gathered, but then all the completions are
lumped together at the end.  (That is, you get all the descriptions,
and then all the completions.)  If you actually want the completion
strings to appear immediately after each description, you have to add

zstyle ':completion:*' group-name ""


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: <Tab> completion does not insert a slash
  2021-08-16 22:17               ` Bart Schaefer
@ 2021-08-17  8:57                 ` Peter Slížik
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Slížik @ 2021-08-17  8:57 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 832 bytes --]

> The descriptions here are showing you every place from which a
> completion string was gathered, but then all the completions are
> lumped together at the end.  (That is, you get all the descriptions,
> and then all the completions.)  If you actually want the completion
> strings to appear immediately after each description, you have to add
>
> zstyle ':completion:*' group-name ""
>

My bad. I used to have this on, but later turned it off in an attempt to
minimize the amount of configuration changes and forgot about it.

I think it's time to close this thread. The analysis of Ctrl-X ? logs would
take (I guess) a few days of studying the inner workings of the completion
system and I cannot afford such a time allocation at the moment. I'd like
to thank all who answered and namely Bart for the advice and patience.

Peter

[-- Attachment #2: Type: text/html, Size: 1134 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-08-17  8:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 15:02 <Tab> completion does not insert a slash Peter Slížik
2021-08-04 15:45 ` Bart Schaefer
2021-08-04 16:49   ` Peter Slížik
2021-08-04 17:26     ` Bart Schaefer
2021-08-11 20:03       ` Peter Slížik
2021-08-11 20:23         ` Peter Slížik
2021-08-11 22:20           ` Bart Schaefer
2021-08-16 21:39             ` Peter Slížik
2021-08-16 21:41               ` Peter Slížik
2021-08-16 22:17               ` Bart Schaefer
2021-08-17  8:57                 ` Peter Slížik

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).