zsh-workers
 help / color / mirror / code / Atom feed
* Strange menu selection with _arguments and matcher-list
@ 2005-12-27  0:22 Bart Schaefer
  2005-12-27  5:26 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2005-12-27  0:22 UTC (permalink / raw)
  To: zsh-workers

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
++++++++++


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

* Re: Strange menu selection with _arguments and matcher-list
  2005-12-27  0:22 Strange menu selection with _arguments and matcher-list Bart Schaefer
@ 2005-12-27  5:26 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2005-12-27  5:26 UTC (permalink / raw)
  To: zsh-workers

On Dec 27, 12:22am, Bart Schaefer wrote:
}
} Affects 4.2.5 and later, so it's not a multi-byte thing, but not 4.0.x.

compadd -2V is being called once for each matcher-list entry when the
_complete completer is processed, creating four separate groups of the
same completions.  That doesn't explain why the display is messed up.

Some experimentation reveals that if I omit the -R option of _arguments,
the extra calls to compadd are not made, so the odd behavior is avoided.
This must mean that sometimes [[ nm -ne "$compstate[nmatches]" ]] is true
when -R would cause a false ($? == 300) return, but I don't know why that
would change the possible matches that are added.

I still think a bug has been introduced somewhere since 4.0.x, but having
a workaround is helpful.


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

end of thread, other threads:[~2005-12-27  5:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-27  0:22 Strange menu selection with _arguments and matcher-list Bart Schaefer
2005-12-27  5:26 ` Bart Schaefer

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