zsh-users
 help / color / mirror / code / Atom feed
* zsh completion help sought
@ 2005-11-30 12:52 Phil Pennock
  2005-11-30 14:10 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Pennock @ 2005-11-30 12:52 UTC (permalink / raw)
  To: zsh-users

Hi,

I'm fairly sure that what I want can be done with the new-style
completion stuff; if so, I'll be able to at last move away from compctl
stuff without spending all my time snarling at the computer I'm using as
it barfs on my bad habits.

I'm getting frustrated trying to understand the manual enough to figure
out what goes where in the zstyle parameters to achieve this.  Please,
someone, have mercy on me.

(1) I use $_<tab> frequently, rather than history expansion, when I'm
    doing multiple operations on one file; I do want it expanded before
    I press return, both as a sanity check and so that I can repeat a
    command using command history.  How do I set a style/function so
    that if the current word is $_ and the cursor is at the end, to
    ignore all those evil no-namespace-workaround-hack functions and
    just expand the $_ variable itself?

(2) As a similar sanity check before pressing return, I like to
    tab-expand a glob to cast an eye over the list and catch my more
    egregrious mistakes.  How do I keep menu-completion turned on for
    tab expansions of a bare suffix but move straight to glob expansion
    if the end of the current word is a '*' ?  (ie, the item you get in
    the new system when tab cycles far enough through the options to
    show you all the options, just before showing you the bare '*')?

The first item is the one which always kills my productivity any time I
try to make the switch.  (And yes, I know that this is my problem, not a
zsh problem, but I want the shell to cater to _my_ whim).

Help, please?

Thanks,
-Phil


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

* Re: zsh completion help sought
  2005-11-30 12:52 zsh completion help sought Phil Pennock
@ 2005-11-30 14:10 ` Peter Stephenson
  2005-11-30 15:29   ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2005-11-30 14:10 UTC (permalink / raw)
  To: zsh-users

Phil Pennock <phil.pennock@globnix.org> wrote:
> (1) I use $_<tab> frequently, rather than history expansion, when I'm
>     doing multiple operations on one file; I do want it expanded before
>     I press return, both as a sanity check and so that I can repeat a
>     command using command history.  How do I set a style/function so
>     that if the current word is $_ and the cursor is at the end, to
>     ignore all those evil no-namespace-workaround-hack functions and
>     just expand the $_ variable itself?

You do know about the non-completion binding ESC-. (widget
insert-last-word) to recover the last word of the previous line (repeat to
go to earlier lines; there's a contributed widget to allow previous words
on the line you've landed on, too)?

In general, it *ought* to be something like this:

# Ensure <TAB> is using expansion through compsys
bindkey '^i' complete-word
# Put the expand completer before the complete completer
zstyle ':completion:*' completer _expand _complete
# Force expand to expand exactly typed parameters.
zstyle ':completion:*:expand:*' accept-exact true

Unfortunately, though you (well, I, with a rather more complicated set of
settings) get $_ expanded this way, you still run into a namespace
problem and get whatever $_ was set to inside the completion function,
which isn't what you want.

If you're wedded to an idea of this kind, you could use an accept-line hack
to get the last thing on the line assigned to a different parameter, say
a:

accept-line() {
  # for the execution of this line, $a is what we remembered from the old one
  typeset -g a=$newa
  # split the line we're about to execute into shell words
  local -a line
  line=(${(z)BUFFER})
  # remember the last shell word for next time
  typeset -g newa=$line[-1]

  # do normal end-of-line processing
  zle .accept-line
}
zle -N accept-line

Putting this all together, your trick ought to work with $a instead of $_.
(I did get this to work, but I can't be sure you have all the same
ingredients I do.  You don't want to see my entire set of styles, believe
me.)

> (2) As a similar sanity check before pressing return, I like to
>     tab-expand a glob to cast an eye over the list and catch my more
>     egregrious mistakes.  How do I keep menu-completion turned on for
>     tab expansions of a bare suffix but move straight to glob expansion
>     if the end of the current word is a '*' ?  (ie, the item you get in
>     the new system when tab cycles far enough through the options to
>     show you all the options, just before showing you the bare '*')?

I'm not sure I follow all of that, but the key step in getting expansion to
insert all expansions is:

zstyle ':completion:*:expand:*' tag-order all-expansions

This says that the choice from the result of the expand completer which is
tagged as all-expansions is to be preferred over others.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com


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

* Re: zsh completion help sought
  2005-11-30 14:10 ` Peter Stephenson
@ 2005-11-30 15:29   ` Phil Pennock
  2005-11-30 16:02     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Pennock @ 2005-11-30 15:29 UTC (permalink / raw)
  To: zsh-users

On 2005-11-30 at 14:10 +0000, Peter Stephenson wrote:
> You do know about the non-completion binding ESC-.

No, I did not.  Given that I'd need to train my fingers into something
else anyway for the $a approach and ESC-. works in all cases, I think
that I'll focus on retraining myself to use the ESC-. binding.  Thanks.

> I'm not sure I follow all of that, but the key step in getting expansion to
> insert all expansions is:

You followed it fine, since:

> zstyle ':completion:*:expand:*' tag-order all-expansions

is perfect.  Thank you.

Which bit of the manual do I need to be focusing on to understand the
binding of the components of zstyle's pattern parameter, please?
zshmodules/style doesn't cover them (but does introduce the
terminology); zshcompsys doesn't seem to cover this, but does describe
what can be bound to the context; I can't find a reference.

Given the generally excellent level of zsh's documentation, I suspect
that the problem is that I'm being a doofus.

Thanks,
-Phil


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

* Re: zsh completion help sought
  2005-11-30 15:29   ` Phil Pennock
@ 2005-11-30 16:02     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2005-11-30 16:02 UTC (permalink / raw)
  To: zsh-users

Phil Pennock <phil.pennock@globnix.org> wrote:
> Which bit of the manual do I need to be focusing on to understand the
> binding of the components of zstyle's pattern parameter, please?

I think the section called COMPLETION SYSTEM CONFIGURATION in the
zshcompsys manual should have everything you need.  The separate items
give the descriptions of each of the colon-separated fields.  It's a bit
light on examples until it puts it all together (around
":completion::complete:dvips:option-o-1:files").  Otherwise, ask a more
specific question.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com


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

end of thread, other threads:[~2005-11-30 16:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-30 12:52 zsh completion help sought Phil Pennock
2005-11-30 14:10 ` Peter Stephenson
2005-11-30 15:29   ` Phil Pennock
2005-11-30 16:02     ` Peter Stephenson

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