zsh-users
 help / color / mirror / code / Atom feed
* custom completion for listing *.tex is not working
@ 2013-09-03 11:11 Leonardo Barbosa
  2013-09-03 14:32 ` Bart Schaefer
  2013-09-06 13:24 ` zzapper
  0 siblings, 2 replies; 7+ messages in thread
From: Leonardo Barbosa @ 2013-09-03 11:11 UTC (permalink / raw)
  To: zsh-users

Hello all,

I have tried this in order to make zsh suggests TeX files first to vi.

vi() { command vi ${*:-*.tex(om[1])} }
zstyle ':completion:*:*:.tex:*' menu yes select
zstyle ':completion:*:*:.tex:*' file-sort time

However, it doesn't work. Zsh is listing all types of files and not
necessarily the TeX ones first. I have to admit that i don't quite
understand the syntax below. Instead, i copied from a tutorial. Could
any of you suggest me a hands on tutorial for zsh new completion
system? Thanks in advance!

Leo


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

* Re: custom completion for listing *.tex is not working
  2013-09-03 11:11 custom completion for listing *.tex is not working Leonardo Barbosa
@ 2013-09-03 14:32 ` Bart Schaefer
  2013-09-09 11:49   ` Leonardo Barbosa
  2013-09-06 13:24 ` zzapper
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2013-09-03 14:32 UTC (permalink / raw)
  To: Leonardo Barbosa, zsh-users

On Sep 3,  8:11am, Leonardo Barbosa wrote:
}
} I have tried this in order to make zsh suggests TeX files first to vi.
} 
} vi() { command vi ${*:-*.tex(om[1])} }

That doesn't do anything except cause "vi" with no arguments to attempt
to open the single most recent .tex file in the current directory; it
has no effect on tab completion.

} zstyle ':completion:*:*:.tex:*' menu yes select
} zstyle ':completion:*:*:.tex:*' file-sort time

The components of a completer style are (from the manual):

    :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:tag

Mapping that onto the zstyles above, you've told the completion system
that a command named ".tex" should use menu selection sorted by time.
What you want is to have "vi" in that slot.

} However, it doesn't work. Zsh is listing all types of files and not
} necessarily the TeX ones first.

To do that, you adjust the set of possible tags (that last component of
the completion style).  You can see what the current set of tags for "vi"
is by:

zsh% vi <ctrl+x h>
tags in context :completion::complete:vi::
    all-files  (_files _default)

That's not very useful, so you can use the file-patterns style to add
details (see the manual under file-patterns to explain %p):

    zstyle ':completion:*:*:vi:*' file-patterns \
	'*.tex:TeX-files' '%p:all-files'

Note that because file-patterns is defining what the tags will become, the
tag part of the context pattern is always empty for this style.

Now:

torch% vi <ctrl+x h>
tags in context :completion::complete:vi::
    TeX-files  (_files _default) 
    all-files  (_files _default)

You can further refine this using the tag-order style.

} Could any of you suggest me a hands on tutorial for zsh new completion
} system?

The most comprehensive is probably the chapter on zsh completion published
in the "From Bash to Zsh" book.  There is also

   http://zsh.sourceforge.net/Guide/zshguide06.html#l156

but it doesn't really work through a single increasingly complex example
the way you might want a tutorial to do.


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

* Re: custom completion for listing *.tex is not working
  2013-09-03 11:11 custom completion for listing *.tex is not working Leonardo Barbosa
  2013-09-03 14:32 ` Bart Schaefer
@ 2013-09-06 13:24 ` zzapper
  1 sibling, 0 replies; 7+ messages in thread
From: zzapper @ 2013-09-06 13:24 UTC (permalink / raw)
  To: zsh-users

Leonardo Barbosa <barbosa.leonardo@gmail.com> wrote in 
news:CAMXWGTwZB9wP4YbuW703sBErWZhRYrb6YpWZ2mGKqtGo08KOVg@mail.gmail.com:

> Hello all,
> 
I have

zstyle ':completion:*:*:vtex:*' file-patterns '*.tex:tex-files'
function vtex(){gvim $*}

when vtex is a wrapper for vi





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

* Re: custom completion for listing *.tex is not working
  2013-09-03 14:32 ` Bart Schaefer
@ 2013-09-09 11:49   ` Leonardo Barbosa
  2013-09-10 15:08     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Leonardo Barbosa @ 2013-09-09 11:49 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Thanks for you prompt answer, Bart. I have tried your suggestion.
zstyle ':completion:*:*:vi:*' file-patterns '*.tex:TeX-files' '%p:all-files'


However, by doing so, it only through TeX files. So if <tab> multiples
times it keeps suggesting the same TeX files, repeatedly, to me. I'd
like TeX files to be priority, but, in case of more <tab>'s, it cycles
through other files in the menu, too.

I saw you example is similar to this example in the zsh manual:
zstyle ':completion:*:*:rm:*' file-patterns \ '*.o:object-files' '%p:all-files'

So in theory, it should have worked. Any idea?

An just one more question, how can i make zsh to highlight the
selected file in the menu while cycling through files?

Best

Leo

On Tue, Sep 3, 2013 at 11:32 AM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Sep 3,  8:11am, Leonardo Barbosa wrote:
> }
> } I have tried this in order to make zsh suggests TeX files first to vi.
> }
> } vi() { command vi ${*:-*.tex(om[1])} }
>
> That doesn't do anything except cause "vi" with no arguments to attempt
> to open the single most recent .tex file in the current directory; it
> has no effect on tab completion.
>
> } zstyle ':completion:*:*:.tex:*' menu yes select
> } zstyle ':completion:*:*:.tex:*' file-sort time
>
> The components of a completer style are (from the manual):
>
>     :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:tag
>
> Mapping that onto the zstyles above, you've told the completion system
> that a command named ".tex" should use menu selection sorted by time.
> What you want is to have "vi" in that slot.
>
> } However, it doesn't work. Zsh is listing all types of files and not
> } necessarily the TeX ones first.
>
> To do that, you adjust the set of possible tags (that last component of
> the completion style).  You can see what the current set of tags for "vi"
> is by:
>
> zsh% vi <ctrl+x h>
> tags in context :completion::complete:vi::
>     all-files  (_files _default)
>
> That's not very useful, so you can use the file-patterns style to add
> details (see the manual under file-patterns to explain %p):
>
>     zstyle ':completion:*:*:vi:*' file-patterns \
>         '*.tex:TeX-files' '%p:all-files'
>
> Note that because file-patterns is defining what the tags will become, the
> tag part of the context pattern is always empty for this style.
>
> Now:
>
> torch% vi <ctrl+x h>
> tags in context :completion::complete:vi::
>     TeX-files  (_files _default)
>     all-files  (_files _default)
>
> You can further refine this using the tag-order style.
>
> } Could any of you suggest me a hands on tutorial for zsh new completion
> } system?
>
> The most comprehensive is probably the chapter on zsh completion published
> in the "From Bash to Zsh" book.  There is also
>
>    http://zsh.sourceforge.net/Guide/zshguide06.html#l156
>
> but it doesn't really work through a single increasingly complex example
> the way you might want a tutorial to do.


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

* Re: custom completion for listing *.tex is not working
  2013-09-09 11:49   ` Leonardo Barbosa
@ 2013-09-10 15:08     ` Bart Schaefer
  2013-09-10 16:31       ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2013-09-10 15:08 UTC (permalink / raw)
  To: Leonardo Barbosa; +Cc: zsh-users

On Sep 9,  8:49am, Leonardo Barbosa wrote:
}
} zstyle ':completion:*:*:vi:*' file-patterns '*.tex:TeX-files' '%p:all-files'
} 
} However, by doing so, it only through TeX files.

Yes, note from the example in the manual "if there is no matching file":

     For example, to make the rm command first complete only names of
     object files and then the names of all files if there is no
     matching object file

What the manual doesn't make clear is that file-patterns may have its
values combined in sets the same way tag-order might.  So start by
removing a couple of quotes:

zstyle ':completion:*:*:vi:*' file-patterns '*.tex:TeX-files %p:all-files'

Next you need to tell completion that even though all those tags are to
be combined into a single listing, you still want the files separated
into groups within the listing:

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

(The empty string here is a shorthand for "automatically use the tag
names as the group names, so I don't have to repeat all of that.")

This will get you the TeX-files group first, followed by the all-files
group, all within one listing that you can tab through.

} An just one more question, how can i make zsh to highlight the
} selected file in the menu while cycling through files?

Assuming you want this everywhere and not just for vi:

zstyle ':completion:*' menu select=2

This will enter highlighted selection if there are 2 or more matches.
Selection normally starts on the second press of tab (which has nothing
to do with select=2); add "yes=1" if you want it to start immediately
on the first tab.  There are a whole lot of other details controlled
 with the menu style; you might want "yes=long" instead, or a value
larger than select=2, etc.


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

* Re: custom completion for listing *.tex is not working
  2013-09-10 15:08     ` Bart Schaefer
@ 2013-09-10 16:31       ` Peter Stephenson
  2013-09-10 16:45         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2013-09-10 16:31 UTC (permalink / raw)
  To: Bart Schaefer, zsh-users

On Tue, 10 Sep 2013 08:08:52 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> What the manual doesn't make clear is that file-patterns may have its
> values combined in sets the same way tag-order might.

Isn't that what this bit is saying?

  The tags of all strings in the value will be offered  by  _files
  and  used  when  looking  up other styles.  Any tags in the same
  word will be offered at the same time and  before  later  words.
  If no `:tag' is given the `files' tag will be used.

'Word' is perhaps a little confusing where it means 'command line
argument'.

pws


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

* Re: custom completion for listing *.tex is not working
  2013-09-10 16:31       ` Peter Stephenson
@ 2013-09-10 16:45         ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2013-09-10 16:45 UTC (permalink / raw)
  To: zsh-users

On Sep 10,  5:31pm, Peter Stephenson wrote:
} Subject: Re: custom completion for listing *.tex is not working
}
} On Tue, 10 Sep 2013 08:08:52 -0700
} Bart Schaefer <schaefer@brasslantern.com> wrote:
} > What the manual doesn't make clear is that file-patterns may have its
} > values combined in sets the same way tag-order might.
} 
} Isn't that what this bit is saying?

Yes, it is.  But that part is buried in the middle of a lot of text,
and there are no examples of that usage (unlike tag-order whose first
example is of that).

I've forgotten whether group-order acts the same way (or where it would
matter if it does).


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

end of thread, other threads:[~2013-09-10 16:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-03 11:11 custom completion for listing *.tex is not working Leonardo Barbosa
2013-09-03 14:32 ` Bart Schaefer
2013-09-09 11:49   ` Leonardo Barbosa
2013-09-10 15:08     ` Bart Schaefer
2013-09-10 16:31       ` Peter Stephenson
2013-09-10 16:45         ` Bart Schaefer
2013-09-06 13:24 ` zzapper

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