summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-17 14:47:24 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-17 14:47:24 +0000
commit4f1424edb22d8521756f2f59c3b87b5d70a8d2cf (patch)
treea41ce5a042da52150214b717f7693b887d04aee2
parent30a98cc4d6e54f2a5c356579aa60c2af8d344101 (diff)
downloadzsh-4f1424edb22d8521756f2f59c3b87b5d70a8d2cf.tar.gz
zsh-4f1424edb22d8521756f2f59c3b87b5d70a8d2cf.tar.xz
zsh-4f1424edb22d8521756f2f59c3b87b5d70a8d2cf.zip
zstyle+ simplifies definition of styles (10795)
-rw-r--r--ChangeLog2
-rw-r--r--Functions/Misc/zstyle+35
2 files changed, 37 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ba96db147..042003f63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@
 
 2000-04-17  Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
 
+	* 10795: Functions/Misc/zstyle+: simplify definiton of styles
+
 	* 10790: Doc/Zsh/mod_complist.yo, Src/params.c, Src/Zle/compcore.c,
  	Src/Zle/complete.c, Src/Zle/complist.c, Src/Zle/compresult.c,
  	Src/Zle/zle_tricky.c, Src/Zle/zle_utils.c: scrolling in completion
diff --git a/Functions/Misc/zstyle+ b/Functions/Misc/zstyle+
new file mode 100644
index 000000000..eb3c14df5
--- /dev/null
+++ b/Functions/Misc/zstyle+
@@ -0,0 +1,35 @@
+# This makes defining styles a bit simpler by using a single `+' as a
+# special token that allows to append a context name to the previously
+# used context name. Like this:
+#
+#   zstyle+ ':foo:bar' style1 value1 \
+#         + ':baz'     style2 value2 \
+#         + ':frob'    style3 value3
+#
+# This defines style1 with value1 for the context :foo:bar as usual.
+# But it also defines styles2 with value2 for the context :foo:bar:baz
+# and style3 with value3 for :foo:bar:frob.
+# Of course, any of the sub-contexts after the plus signs may be 
+# empty strings to re-use the previous context unchanged.
+#
+# If you don't want to change all your calls to `zstyle' to use
+# `zstyle+' you can use an alias `alias zstyle=zstyle+' and make sure
+# the completion functions are autoloaded without alias expansion (the
+# -U option to the autoload builtin). The completion system normally
+# loads its functions with without alias expansion.
+
+case "$1" in
+-*) zstyle "$@";;
+
+*)  setopt localoptions noksharrays
+    integer i
+    local context="$1"
+    1=''
+    for ((i=2; $#; ++i)); do
+      if [[ $i -gt $# || "$argv[i]" == '+' ]]; then
+        zstyle "$context${(@)argv[1,i-1]}"
+        shift "i > $# ? $# : i"  # Stupid shift error on i > $#
+  	i=1
+      fi
+    done;;
+esac