zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Strange menu selection with _arguments and matcher-list
Date: Tue, 27 Dec 2005 00:22:10 +0000	[thread overview]
Message-ID: <1051227002210.ZM30956@candle.brasslantern.com> (raw)

I'm working on improving _su, mainly so that it'll call _normal on the
argument of the -c flag, the way _sh does.  I've got what I think is
a fairly straightforward _arguments call, but I get some very strange
behavior from menu selection.

Here's a relatively small test case; I haven't tried all possible smaller
cases, but it does at least appear to require multiple options that go to
the same state plus the wildcard "non-option arguments" pattern and the
"matcher-list" completion style.

Affects 4.2.5 and later, so it's not a multi-byte thing, but not 4.0.x.

----------

_foo () {
  local -A opt_args
  local -a args state context
  local line

  args=(
    '(--command)-c[pass command to shell]:command string:->command'
    '(-c)--command=-[pass command to shell]:command string:->command'
    '-f[pass -f to shell (csh)]'
    '(--login)-l[use a login shell]'
    '(-l)--login[use a login shell]'
    '(-p --preserve-environment)-m[do not reset environment]'
    '(-m --preserve-environment)-p[do not reset environment]'
    '(-m -p)--preserve-environment[do not reset environment]'
    '(--shell)-s[run the specified shell]:shell:->shell'
    '(-s)--shell=-[run the specified shell]:shell:->shell'
    '*:arguments:->rest'
  )

  _arguments -R $args[@] ||
  case $state in
    (command)
      compset -q
      _normal
      ;;
    (shell)
      compadd ${(f)^"$(</etc/shells)"}(N)
      ;;
    (rest)
      _users
      ;;
   esac
}
compdef _foo foo

zstyle ':completion:*' matcher-list '' 'r:|[-._,]=** r:|=**' 'm:{a-zA-Z}={A-Za-z} r:|[-._,]=** r:|=**' 'r:|[-._,]=** r:|=** l:|=*'
zstyle ':completion:*' completer _oldlist _expand _complete _match _ignored _approximate _prefix
zstyle ':completion:*' menu 'yes=long' 'select=9'

----------

Given the above, type

  foo anything -<TAB>

and watch strange things happen:

++++++++++
schaefer<529> foo anything --command=
--command                                      
--login                                        
--preserve-environment                         
--shell                                        
-f                                             
-c                                             
-l                                             
-p                                             
-s                                             
                                               
                                               
                                               
-m                                             
                                               
                                               
-- pass command to shell                       
-- use a login shell                           
-- do not reset environment                    
-- run the specified shell                     
-- pass -f to shell (csh)                      
--command                                      
--login                                        
--preserve-environment
++++++++++


             reply	other threads:[~2005-12-27  0:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-27  0:22 Bart Schaefer [this message]
2005-12-27  5:26 ` Bart Schaefer

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=1051227002210.ZM30956@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@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).