about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-09-11 08:54:45 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-09-11 08:54:45 +0000
commit602c2d81251d8c57dd1d0ea228dc5a3e8df68e00 (patch)
tree63bf610b0abab02f6767ab94e020e10b1570385e
parentc4d08544c337df958bd614cd8a6ee9891d149bad (diff)
downloadzsh-602c2d81251d8c57dd1d0ea228dc5a3e8df68e00.tar.gz
zsh-602c2d81251d8c57dd1d0ea228dc5a3e8df68e00.tar.xz
zsh-602c2d81251d8c57dd1d0ea228dc5a3e8df68e00.zip
zsh-workers/7778
-rw-r--r--Completion/Base/_regex_arguments67
1 files changed, 45 insertions, 22 deletions
diff --git a/Completion/Base/_regex_arguments b/Completion/Base/_regex_arguments
index 7f6ecd424..12f4d6d2d 100644
--- a/Completion/Base/_regex_arguments
+++ b/Completion/Base/_regex_arguments
@@ -6,6 +6,13 @@
 
 ## usage: _regex_arguments funcname regex
 
+## configuration key used:
+
+# regex_arguments_path
+#  The path to a directory for caching. (default: ~/.zsh/regex_arguments)
+
+##
+
 # _regex_arguments compiles `regex' and emit the result of the state
 # machine into the function `funcname'. `funcname' parses a command line
 # according to `regex' and evaluate appropriate actions in `regex'. Before
@@ -396,31 +403,47 @@ _regex_arguments () {
   local regex index first last nullable
   local i state next
 
-  funcname="$1"
-  shift
-
-  regex=("$@")
-  index=1
-  tbl=()
-  pattern=()
-  lookahead=()
-  parse_action=()
-  complete_action=()
-  _ra_parse_alt
-
-  if (( $? == 2 || index != $#regex + 1 )); then
-    if (( index != $#regex + 1 )); then
-      print "regex parse error at $index: $regex[index]" >&2
-    else
-      print "regex parse error at $index (end)" >&2
+  local cache_dir="${compconfig[regex_arguments_path]:-$HOME/.zsh/regex_arguments}"
+  local cache_file="$cache_dir/$1"
+  local cache_test
+
+  if ! [[ -f "$cache_file" ]] || ! source "$cache_file" "$@"; then
+    cache_test='[[ $# -eq '$#' && "$*" = '"${*:q}"' ]]'
+
+    funcname="$1"
+    shift
+
+    regex=("$@")
+    index=1
+    tbl=()
+    pattern=()
+    lookahead=()
+    parse_action=()
+    complete_action=()
+    _ra_parse_alt
+
+    if (( $? == 2 || index != $#regex + 1 )); then
+      if (( index != $#regex + 1 )); then
+	print "regex parse error at $index: $regex[index]" >&2
+      else
+	print "regex parse error at $index (end)" >&2
+      fi
+      return 1
     fi
-    return 1
-  fi
 
-  funcdef="$(_ra_gen_func)"
+    funcdef="$(_ra_gen_func)"
 
-  unfunction "$funcname" 2>/dev/null
-  eval "${(F)funcdef}"
+    unfunction "$funcname" 2>/dev/null
+    eval "${(F)funcdef}"
+
+    [[ -d "$cache_dir" && -w "$cache_dir" ]] && {
+      print -lr - \
+	"if $cache_test; then" \
+	"$funcdef" \
+	'true; else false; fi' > "${cache_file}.$HOST.$$"
+      mv "${cache_file}.$HOST.$$" "${cache_file}"
+    }
+  fi
 }
 
 _regex_arguments "$@"