zsh-users
 help / color / mirror / code / Atom feed
* Making file-patterns and tag-order work
@ 2017-03-21  9:49 martin f krafft
  2017-03-22  1:15 ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: martin f krafft @ 2017-03-21  9:49 UTC (permalink / raw)
  To: zsh users list

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

Hello,

I would like completion to differentiate files according to some
globs. To this end, I've configured:

  zstyle ':completion:*:argument-rest:' file-patterns '
    *(-/):directories:directories
    (*.(ba#k|old)|*~):backup-files:"backup files"
    *.(l#[oa]|py[co]|zwc):compiled-files:"compiled files"
    *.te#mp:temp-files:"temp files"
    .*.sw?:vim-swap-files:"vim swap files"
    %p:globbed-files *:all-files

and also went on to hide all these patterns from the catch-alls in
the last line (is there a way to do this without duplication?):

  zstyle ':completion:*:argument-rest:(all|globbed)-files' ignored-patterns \
  '((*.(ba#k|old)|*~)|*.(l#[oa]|py[co]|zwc)|*.te#mp|.*.sw?|*(-/))'

The relevant options in effect are:
  auto_list no_list_ambiguous auto_menu no_menu_complete
  no_bash_auto_list list_packed

and if I now try completion, I can confirm that these tags seem to
work (indentation added for clarity):

  fishbowl:/tmp/cdt.6kIDed% cat ^D
  directories
    foobar/
  backup files
    foo.bk                     foo.old
  compiled files
    foo.a    foo.la   foo.lo   foo.o    foo.pyc  foo.zwc
  temp files
    foo.tmp
  vim swap files
    .foo.txt.swp
  files
    foobar/      foo.c        foo.txt      g

(you can get the directory contents like this:
  touch foo.a foobar foo.bk foo.c foo.la foo.lo foo.o foo.old \
  foo.pyc foo.tmp foo.txt foo.zwc g .foo.txt.swp
)

I then went on to try to order the tags, because I want e.g. the
swap files to appear last:

  zstyle ':completion:*:argument*' tag-order "
    directories
    globbed-files files all-files
    backup-files
    compiled-files
    temp-files
    vim-swap-files
    "

Unfortunately, this does not work yet, and there are two problems:

1. the directories show up under 'files'. Is this because
   directories are special (they could contain files), or am I doing
   something wrong?

2. There is no change in the ordering. I've tried group-order too,
   but no effect. What am I missing?

Thanks for any inputs!

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
"the only difference between the saint and the sinner
 is that every saint has a past and every sinner has a future."
                                                      -- oscar wilde
 
spamtraps: madduck.bogus@madduck.net

[-- Attachment #2: Digital GPG signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current) --]
[-- Type: application/pgp-signature, Size: 1118 bytes --]

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

* Re: Making file-patterns and tag-order work
  2017-03-21  9:49 Making file-patterns and tag-order work martin f krafft
@ 2017-03-22  1:15 ` Bart Schaefer
  2017-03-22  3:35   ` martin f krafft
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2017-03-22  1:15 UTC (permalink / raw)
  To: zsh users list

On Mar 21, 10:49pm, martin f krafft wrote:
}
} I then went on to try to order the tags, because I want e.g. the
} swap files to appear last:
} 
}   zstyle ':completion:*:argument*' tag-order "
}     directories
}     globbed-files files all-files
}     backup-files
}     compiled-files
}     temp-files
}     vim-swap-files
}     "

This is wrong.  If you combine tags into a single string, they will all
be sorted together.  tag-order is a list -- try without the double
quotes around the value (which means you'll need backslashes at the end
of each line, or similar).


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

* Re: Making file-patterns and tag-order work
  2017-03-22  1:15 ` Bart Schaefer
@ 2017-03-22  3:35   ` martin f krafft
  2017-03-23  4:13     ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: martin f krafft @ 2017-03-22  3:35 UTC (permalink / raw)
  To: zsh-users

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

also sprach Bart Schaefer <schaefer@brasslantern.com> [2017-03-22 14:15 +1300]:
> }   zstyle ':completion:*:argument*' tag-order "
> }     directories
> }     globbed-files files all-files
> }     backup-files
> }     compiled-files
> }     temp-files
> }     vim-swap-files
> }     "
> 
> This is wrong.  If you combine tags into a single string, they
> will all be sorted together.  tag-order is a list -- try without
> the double quotes around the value (which means you'll need
> backslashes at the end of each line, or similar).

I also tried that. It makes absolutely no difference, actually.

Apart from that, tag-order actually takes "sets of space-separated
lists" and I read Peter's description in the Zsh Guide:

  If you put the tags into the same word by quoting, for example
  "local-directories path-directories", then they would be tried at
  the same time, which in this case gives you the effect of the
  default.

to be exactly what I want, i.e. if the completion can be done from
the set of directories or files already, then I *still* want it to
offer me the other tags, and this is why I think I need to put all
the tags into the same set by quoting. If I didn't do this, then the
remaining sets of tags would simply not be considered.

But again, it actually makes no difference whether I use a single
quoted string of all tags, or each tag separately. I think the
problem is elsewhere…

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
"nicht durch zorn, sondern durch lachen tötet man."
                                                 - friedrich nietzsche
 
spamtraps: madduck.bogus@madduck.net

[-- Attachment #2: Digital GPG signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current) --]
[-- Type: application/pgp-signature, Size: 1118 bytes --]

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

* Re: Making file-patterns and tag-order work
  2017-03-22  3:35   ` martin f krafft
@ 2017-03-23  4:13     ` Bart Schaefer
  2017-03-24  6:59       ` martin f krafft
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2017-03-23  4:13 UTC (permalink / raw)
  To: martin f krafft, zsh-users

On Mar 22,  4:35pm, martin f krafft wrote:
} 
} also sprach Bart Schaefer <schaefer@brasslantern.com> [2017-03-22 14:15 +1300]:
} > }   zstyle ':completion:*:argument*' tag-order "
} > }     directories
} > }     globbed-files files all-files
} > }     backup-files
} > }     compiled-files
} > }     temp-files
} > }     vim-swap-files
} > }     "
} > 
} > This is wrong.  If you combine tags into a single string, they
} > will all be sorted together.  tag-order is a list -- try without
} > the double quotes around the value (which means you'll need
} > backslashes at the end of each line, or similar).
} 
} I also tried that. It makes absolutely no difference, actually.

Oops, my bad.  You want group-order here, not tag-order.

group-order
     This style is additional to the group-name style to specify the
     order for display of the groups defined by that style (compare
     tag-order, which determines which completions appear at all).

I'm surprised no one else jumped in on this.  The fact that they're both
named "-order" is a bit confusing; for tag-order, it means the order in
which the completions are attempted, and for group-order it means the
order in which the results are displayed.


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

* Re: Making file-patterns and tag-order work
  2017-03-23  4:13     ` Bart Schaefer
@ 2017-03-24  6:59       ` martin f krafft
  2017-03-24  9:19         ` Mikael Magnusson
  0 siblings, 1 reply; 9+ messages in thread
From: martin f krafft @ 2017-03-24  6:59 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

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

Dear Bart,

thank you for engaging with me and trying to help!

also sprach Bart Schaefer <schaefer@brasslantern.com> [2017-03-23 05:13 +0100]:
> Oops, my bad.  You want group-order here, not tag-order.

I tried that too. Using either a single set of tags (i.e. quoted),
or as individual arguments. Unfortunately, neither has any effect.
I am sorry if I failed to make that clearer in my initial mail.

> I'm surprised no one else jumped in on this.  The fact that
> they're both named "-order" is a bit confusing; for tag-order, it
> means the order in which the completions are attempted, and for
> group-order it means the order in which the results are displayed.

Yeah, once you grok this, it seems obvious, which is in part why
I am scratching my head that it's just not working…

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
"in just seven days, i can make you a man!"
                                    -- the rocky horror picture show
 
spamtraps: madduck.bogus@madduck.net

[-- Attachment #2: Digital GPG signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current) --]
[-- Type: application/pgp-signature, Size: 1118 bytes --]

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

* Re: Making file-patterns and tag-order work
  2017-03-24  6:59       ` martin f krafft
@ 2017-03-24  9:19         ` Mikael Magnusson
  2017-03-24 10:18           ` martin f krafft
  0 siblings, 1 reply; 9+ messages in thread
From: Mikael Magnusson @ 2017-03-24  9:19 UTC (permalink / raw)
  To: Bart Schaefer, Zsh Users, martin f krafft

On Fri, Mar 24, 2017 at 7:59 AM, martin f krafft <madduck@madduck.net> wrote:
> Dear Bart,
>
> thank you for engaging with me and trying to help!
>
> also sprach Bart Schaefer <schaefer@brasslantern.com> [2017-03-23 05:13 +0100]:
>> Oops, my bad.  You want group-order here, not tag-order.
>
> I tried that too. Using either a single set of tags (i.e. quoted),
> or as individual arguments. Unfortunately, neither has any effect.
> I am sorry if I failed to make that clearer in my initial mail.

Do you have this set too?
zstyle ':completion:*' group-name ''

-- 
Mikael Magnusson


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

* Re: Making file-patterns and tag-order work
  2017-03-24  9:19         ` Mikael Magnusson
@ 2017-03-24 10:18           ` martin f krafft
  2017-03-24 23:15             ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: martin f krafft @ 2017-03-24 10:18 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Bart Schaefer, Zsh Users

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

also sprach Mikael Magnusson <mikachu@gmail.com> [2017-03-24 10:19 +0100]:
> Do you have this set too?
> zstyle ':completion:*' group-name ''

Yes!

Now if I uncomment this, then using either form of tag- or
group-order, I get this when I hit <tab> or ^D:

  directories
  backup files
  compiled files
  temp files
  vim swap files
  files
    foo.a     foo.c    foo.o     foo.tmp        foo.zwc
    foobar/   foo.la   foo.old   foo.txt        g
    foo.bk    foo.lo   foo.pyc   .foo.txt.swp

Seems like a step, but maybe sideways instead of forwards?

From the manpage, which says about group-name:

  If the name given is the empty string the name of the tag for the
  matches will be used as the name of the group.

it sounds like this is what I want, because the tags have their own
names already defined. And if I set group-name to "", then the files
get properly listed under the group headers I want (taken from the
tags), it's just the order of tag groups that's not correct.

Cheers,

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
"i always had a repulsive need to be something more than human."
                                                      -- david bowie
 
spamtraps: madduck.bogus@madduck.net

[-- Attachment #2: Digital GPG signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current) --]
[-- Type: application/pgp-signature, Size: 1118 bytes --]

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

* Re: Making file-patterns and tag-order work
  2017-03-24 10:18           ` martin f krafft
@ 2017-03-24 23:15             ` Bart Schaefer
  2017-03-25 11:02               ` martin f krafft
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2017-03-24 23:15 UTC (permalink / raw)
  To: martin f krafft; +Cc: Zsh Users

On Mar 24, 11:18am, martin f krafft wrote:
}
} also sprach Mikael Magnusson <mikachu@gmail.com> [2017-03-24 10:19 +0100]:
} > Do you have this set too?
} > zstyle ':completion:*' group-name ''
} 
} Yes!
} 
} Now if I uncomment this, then using either form of tag- or
} group-order, I get this [...]

You obviously have some zstyles you haven't told us about, such as a
"format" style.

I tried this:

zstyle ':completion:*' completer _complete
zstyle ':completion:*:argument-rest:' file-patterns \
  '*(-/):directories:directories    (*.(ba#k|old)|*~):backup-files:"backup files" *.(l#[oa]|py[co]|zwc):compiled-files:"compiled files" *.te#mp:temp-files:"temp files" .*.sw?:vim-swap-files:"vim swap files" %p:globbed-files *:all-files'
zstyle ':completion:*' format '** %U%d%u **'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:argument*' group-order vim-swap-files directories
globbed-files files all-files backup-files compiled-files temp-files
zstyle ':completion:*:argument-rest:(all|globbed)-files' ignored-patterns \
  '((*.(ba#k|old)|*~)|*.(l#[oa]|py[co]|zwc)|*.te#mp|.*.sw?|*(-/))'

Note I've deliberately munged your group-oder to move vim-swap-files to
the front to make it obvious that something has changed.  Also note no
quotes around the list of tag names in group-order.

With your setopts:

torch% setopt
interactive
nolistambiguous
listpacked
monitor
norcs
shinstdin
zle

I get this:

torch% ls
** vim swap files **
.vimbackup.swp
** directories **
10a/     19139/   a\ \(test\)/   cat/        dumdmdum/   html/      Tt/
11a/     33460/   bar/           dir1/       fooloop@    man/       z/
18875/   a\'b/    baz/           dir\ two/   home@       nowrite/   
** backup files **
file\~
** compiled files **
compiled.a
** temp files **
dummytemp.tmp
** files **

(contents of "files" tag omitted for brevity, but it's all the directories
plus misc other files).

So it sure looks to me as if group-order is working, with the exception of
the "files" tag -- but that's because _ls passes *:files:_files explicitly
to _arguments, I think.


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

* Re: Making file-patterns and tag-order work
  2017-03-24 23:15             ` Bart Schaefer
@ 2017-03-25 11:02               ` martin f krafft
  0 siblings, 0 replies; 9+ messages in thread
From: martin f krafft @ 2017-03-25 11:02 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

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

also sprach Bart Schaefer <schaefer@brasslantern.com> [2017-03-25 00:15 +0100]:
> You obviously have some zstyles you haven't told us about, such as a
> "format" style.

Oh yes, there's plenty of stuff in place, of course. However, I have
already "bisected" my configuration to create a test case where
I can be reasonably sure that things like "format" actually don't
affect the outcome. However, you're right, I could have overlooked
something, so next time…

… this time, however, I think we managed to get one step further,
thanks to your analysis. If I do just the change regarding
vim-swap-files in my setup, then vim-swap-files *also* moves to the
top, independently of the tag-order defined, so it seems that we're
in sync up to this point, and the real question is:

> So it sure looks to me as if group-order is working, with the exception of
> the "files" tag -- but that's because _ls passes *:files:_files explicitly
> to _arguments, I think.

I am using _cat, but same thing I guess.
https://sourceforge.net/p/zsh/code/ci/master/tree/Completion/Unix/Command/_cat
suggests you're right (of course).

Okay, but what does this mean? How can this be addressed? Should
this be addressed? It's not too unreasonable to want to order
"files" freely, right?

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
"the liar at any rate recognises that recreation, not instruction, is
 the aim of conversation, and is a far more civilised being than the
 blockhead who loudly expresses his disbelief in a story which is told
 simply for the amusement of the company."
                                                      -- oscar wilde
 
spamtraps: madduck.bogus@madduck.net

[-- Attachment #2: Digital GPG signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current) --]
[-- Type: application/pgp-signature, Size: 1118 bytes --]

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

end of thread, other threads:[~2017-03-25 11:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21  9:49 Making file-patterns and tag-order work martin f krafft
2017-03-22  1:15 ` Bart Schaefer
2017-03-22  3:35   ` martin f krafft
2017-03-23  4:13     ` Bart Schaefer
2017-03-24  6:59       ` martin f krafft
2017-03-24  9:19         ` Mikael Magnusson
2017-03-24 10:18           ` martin f krafft
2017-03-24 23:15             ` Bart Schaefer
2017-03-25 11:02               ` martin f krafft

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