zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: More useful setopt / unsetopt completion
Date: Thu, 28 Aug 2014 11:48:27 +0200	[thread overview]
Message-ID: <1409219307-29367-1-git-send-email-mikachu@gmail.com> (raw)

It was bothering me that setopt nono<tab> showed every options with
nono prefixed which isn't even valid, instead of completing nonomatch
and nonotify. I think this will be more helpful. I noticed that the
whole _options_set / _options_unset thing is pointless now that we have
_comp_caller_options, so maybe I'll post a followup patch adjusting the
documentation and removing those.

(and speaking of completion options, rcexpandparam is set, so $^ isn't
needed below)

---
 Completion/Zsh/Command/_setopt   | 22 ++++++++++++++--------
 Completion/Zsh/Command/_unsetopt | 10 ----------
 2 files changed, 14 insertions(+), 18 deletions(-)
 delete mode 100644 Completion/Zsh/Command/_unsetopt

diff --git a/Completion/Zsh/Command/_setopt b/Completion/Zsh/Command/_setopt
index f72c20d..e558b12 100644
--- a/Completion/Zsh/Command/_setopt
+++ b/Completion/Zsh/Command/_setopt
@@ -1,10 +1,16 @@
-#compdef setopt
+#compdef setopt unsetopt
 
-# If you first want to complete only unset options, un-comment the lines
-# setting the _options_unset  array and then use:
-#
-#   _options_unset || _options
-#
-# here.
+local expl ret=1
+local -a onopts offopts
+onopts=( ${(k)_comp_caller_options[(R)on]} )
+offopts=( ${(k)_comp_caller_options[(R)off]} )
+case $service in
+  setopt) onopts=(no$onopts) ;;
+  unsetopt) offopts=(no$offopts) ;;
+esac
+_wanted zsh-options expl 'zsh options (set)' \
+    compadd -J 'enabled options' -M 'M:_= M:{A-Z}={a-z}' -k - onopts && ret=0
+_wanted zsh-options expl 'zsh options (unset)' \
+    compadd -J 'disabled options' -M 'M:_= M:{A-Z}={a-z}' -k - offopts && ret=0
 
-_options
+return ret
diff --git a/Completion/Zsh/Command/_unsetopt b/Completion/Zsh/Command/_unsetopt
deleted file mode 100644
index 75a33e9..0000000
--- a/Completion/Zsh/Command/_unsetopt
+++ /dev/null
@@ -1,10 +0,0 @@
-#compdef unsetopt
-
-# If you first want to complete only unset options, uncomment the lines
-# setting the _options_set  array and then use:
-#
-#   _options_set || _options
-#
-# here.
-
-_options
-- 
1.9.0


             reply	other threads:[~2014-08-28  9:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-28  9:48 Mikael Magnusson [this message]
2014-08-30 20:50 ` 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=1409219307-29367-1-git-send-email-mikachu@gmail.com \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /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).