zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: zsh completion help sought
Date: Wed, 30 Nov 2005 14:10:54 +0000	[thread overview]
Message-ID: <20051130141054.6afa2cd9.pws@csr.com> (raw)
In-Reply-To: <20051130125237.GA30693@parhelion.globnix.org>

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


  reply	other threads:[~2005-11-30 14:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-30 12:52 Phil Pennock
2005-11-30 14:10 ` Peter Stephenson [this message]
2005-11-30 15:29   ` Phil Pennock
2005-11-30 16:02     ` Peter Stephenson

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=20051130141054.6afa2cd9.pws@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /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).