about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-17 09:06:05 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-07-17 09:06:05 +0000
commit5452be3a4ac5fcb587981625d1a4e5ccb503f652 (patch)
tree97313237f10c0c174b2bc27cf9b369b7529dfcac
parent027604400ba98f4c947784fc691dc7c93b9bf366 (diff)
downloadzsh-5452be3a4ac5fcb587981625d1a4e5ccb503f652.tar.gz
zsh-5452be3a4ac5fcb587981625d1a4e5ccb503f652.tar.xz
zsh-5452be3a4ac5fcb587981625d1a4e5ccb503f652.zip
15400
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Unix/Type/_path_files10
-rw-r--r--Completion/Zsh/Command/_zstyle325
-rw-r--r--Doc/Zsh/compsys.yo10
4 files changed, 350 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 5aac4ac5a..0c55e92f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-07-17  Sven Wischnowsky  <wischnow@zsh.org>
+
+	* 15400: Completion/Unix/Type/_path_files,
+	Completion/Zsh/Command/_zstyle, Doc/Zsh/compsys.yo: add
+	preserve-prefix style to keep pathname prefix unchanged
+
 2001-07-10  Sven Wischnowsky  <wischnow@zsh.org>
 
 	* 15357: Completion/Base/Completer/_prefix, Src/Zle/compcore.c,
diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index c7eaf2df2..598dc466b 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -264,7 +264,15 @@ else
   linepath=
   realpath=
 
-  if [[ "$pre[1]" = / ]]; then
+  if zstyle -s ":completion:${curcontext}:" preserve-prefix tmp1 &&
+     [[ -n "$tmp1" && "$pre" = (#b)(${~tmp1})* ]]; then
+
+    pre="$pre[${#match[1]}+1,-1]"
+    orig="$orig[${#match[1]}+1,-1]"
+    donepath="$match[1]"
+    prepaths=( '' )
+
+  elif [[ "$pre[1]" = / ]]; then
     # If it is a absolute path name, we remove the first slash and put it in
     # `donepath' meaning that we treat it as the path that was already handled.
     # Also, we don't use the paths from `-W'.
diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
new file mode 100644
index 000000000..37590f0d9
--- /dev/null
+++ b/Completion/Zsh/Command/_zstyle
@@ -0,0 +1,325 @@
+#compdef zstyle
+
+local curcontext="$curcontext" state context ostate line expl ctop
+local nm=$compstate[nmatches] mesg
+typeset -A opt_args
+
+typeset -A styles
+# Assoc array of styles; the values give the possible top-level
+# contexts (currently c for completion, z for zftp or cz for both),
+# followed by a colon, followed by a state to enter, empty if none.
+styles=(
+  accept-exact		 c:bool
+  add-space		 c:bool
+  ambiguous              c:bool
+  assign-list            c:
+  auto-description	 c:
+  avoid-completer        c:
+  break-keys             c:
+  cache-path		 'c:_wanted directories expl directory _path_files -/'
+  cache-policy           c:_functions
+  call-command           c:bool
+  command                c:command
+  commands               c:
+  complete               c:bool
+  completer		 c:completer
+  completions		 c:bool
+  condition		 c:bool
+  cursor		 c:cursor
+  disable-stat		 c:bool
+  disabled               c:bool
+  domains                c:
+  expand		 c:
+  fake-files		 c:fake-files
+  fake-parameters	 c:fake-params
+  file-patterns		 c:filepat
+  file-sort              c:fsort
+  force-list             c:
+  format		 c:
+  glob			 c:bool
+  global                 c:bool
+  group-name		 c:
+  group-order		 c:tag
+  groups		 c:_groups
+  hidden		 c:bool
+  hosts			 c:_hosts
+  hosts-ports		 c:host-port
+  users-hosts-ports	 c:user-host-port
+  ignore-line            c:ignline
+  ignore-parents         c:ignorepar
+  ignored-patterns	 c:
+  insert-ids             c:insert-ids
+  insert-tab             c:bool
+  insert-unambiguous	 c:insunambig
+  keep-prefix		 c:keep-prefix
+  last-prompt		 c:bool
+  list			 c:listwhen
+  list-colors		 c:
+  list-packed		 c:bool
+  list-prompt            c:
+  list-rows-first	 c:bool
+  list-suffixes		 c:bool
+  local			 c:
+  match-original	 c:match-orig
+  matcher		 c:
+  matcher-list		 c:
+  max-errors		 c:
+  menu			 c:boolauto
+  numbers		 c:bool
+  old-list		 c:bool
+  old-matches            c:oldmatches
+  old-menu		 c:bool 
+  original		 c:bool
+  packageset		 c:packageset
+  path			 'c:_wanted directories expl directory _path_files -/'
+  ports			 c:_ports
+  prefix-hidden		 c:bool
+  prefix-needed		 c:bool
+  preserve-prefix        c:preserve-prefix
+  range                  c:
+  regular                c:bool
+  remote-access		 c:bool
+  remove-all-dups	 c:bool
+  select-prompt          c:
+  select-scroll          c:
+  single-ignored         c:single-ignored
+  sort			 c:bool
+  special-dirs		 c:sdirs
+  squeeze-slashes	 c:bool
+  stop			 c:stop
+  stop-keys		 c:
+  subst-globs-only       c:bool
+  substitute		 c:bool
+  suffix		 c:bool
+  tag-order		 c:tag
+  try-to-use-pminst	 c:bool
+  use-cache		 c:bool
+  use-compctl		 c:urgh
+  users			 c:_users
+  users-hosts		 c:user-host
+  verbose		 c:bool
+  word			 c:bool
+
+  chpwd			 z:bool
+  progress		 z:progress
+  remote_glob		 z:bool
+  titlebar		 z:bool
+  update		 z:
+)
+
+local taglist
+taglist=(accounts all-files all-expansions arguments arrays
+association-keys bookmarks builtins characters colors commands corrections
+cursors cvs default descriptions devices directories directory-stack
+displays expansions extensions files fonts functions globbed-files groups
+history-words hosts indexes jobs keymaps keysyms local-directories
+libraries limits manuals maps messages modifiers modules my-accounts
+named-directories names nicknames options original other-accounts packages
+parameters path-directories paths pods ports prefixes processes
+processes-names ps regex sequences sessions signals strings tags targets
+types urls users values warnings widgets windows zsh-options)
+
+_arguments -C ':context:->contexts' ':style:->styles' '*:argument:->style-arg'
+
+while [[ -n $state ]]; do
+  ostate=$state
+  state=
+
+  case "$ostate" in
+    contexts)
+      if [[ $PREFIX != :*: ]]; then
+	_wanted contexts expl context compadd -P : -S : completion zftp
+      elif [[ $PREFIX = :completion:* ]] && _tags contexts; then
+        mesg=''
+        case "$PREFIX" in
+        :completion:[^:]#) mesg=function ;;
+        :completion:[^:]#:[^:]#) mesg=completer ;;
+        :completion:[^:]#:[^:]#:[^:]#) mesg='command or context' ;;
+        :completion:[^:]#:[^:]#:[^:]#:[^:]#) mesg=argument ;;
+        :completion:[^:]#:[^:]#:[^:]#:[^:]#:[^:]#) mesg=tag ;;
+	esac
+	[[ -n "$mesg" ]] && _message "$mesg"
+      fi
+      ;;
+
+    styles)
+      # Get the top-level context we're completing for, if any.
+      if [[ $words[2] = :(completion|zftp):* ]]; then
+	ctop=${words[2][2]}
+      else
+        ctop=cz
+      fi
+      _wanted styles expl style \
+         compadd -M 'r:|-=* r:|=*' -k "styles[(R)[^:]#[$ctop][^:]#:*]"
+      ;;
+      
+    style-arg)
+      state="${styles[$words[3]]#*:}"
+      ;;
+
+    bool) 
+      _wanted values expl boolean compadd true false
+      ;;
+
+    boolauto) 
+      _wanted values expl boolean compadd true false auto select
+      ;;
+
+    cursor)
+      _wanted values expl 'cursor positioning' compadd complete key default
+      ;;
+
+    completer)
+      _wanted values expl completer \
+	compadd _complete _approximate _correct _match \
+                _expand _list _menu _oldlist _ignored _prefix _history
+      ;;
+
+    fsort)
+      _wanted values expl 'how to sort files' \
+	compadd name size links time date modification access inode change reverse
+      ;;
+
+    user-host-port)
+      if [[ $PREFIX != *[@:]* ]]; then
+	_users -S @
+      elif [[ $PREFIX = *[@:]*[[@:]* ]]; then
+	compset -P 2 '*[:@]'
+	_ports
+      else
+	compset -P 1 '*[:@]'
+	_hosts -S :
+      fi
+      ;;
+
+    host-port)
+      if [[ $PREFIX != *:* ]]; then
+	_hosts -S :
+      else
+	compset -P 1 '*:'
+	_ports
+      fi
+      ;;
+
+    listwhen)
+      _wanted values expl 'when to list completions' \
+	compadd always never sometimes
+      ;;
+
+    packageset)
+      _wanted values expl 'default package set' \
+        compadd available installed uninstalled
+      ;;
+
+    progress)
+      _wanted values expl 'progress meter style' \
+        compadd none bar percent
+      ;;
+
+    sdirs)
+      _wanted values expl 'whether to complete . or ..' \
+        compadd true false ..
+      ;;
+
+    stop)
+      _wanted values expl 'when to insert matches' \
+	compadd true false verbose
+      ;;
+
+    tag)
+      compset -q
+      if compset -P '*:*:'; then
+        _message description
+      elif compset -P '*:'; then
+        _message 'tag alias'
+      else
+        _wanted tags expl tag compadd -a taglist
+      fi
+      ;;
+
+    filepat)
+      if compset -P '*:*:'; then
+        _message description
+      elif compset -P '*:'; then
+        _message tag
+      else
+        _message 'glob patterns'
+      fi
+      ;;
+
+    user-host)
+      if [[ $PREFIX = *[@:]* ]]; then
+	compset -P '*[@:]'
+	_hosts
+      else
+	_users -S @
+      fi
+      ;;
+
+    ignorepar)
+      _wanted values expl 'which parents to ignore' \
+        compadd parent pwd .. directory
+      ;;
+
+    single-ignored)
+      _wanted values expl 'how to handle a single ignored match' \
+          compadd - show menu
+      ;;
+
+    command)
+      shift 3 words
+      (( CURRENT -= 3 ))
+      _normal
+      ;;
+
+    insert-ids)
+      _wanted values expl 'when to insert process IDs' \
+          compadd - menu single longer
+      ;;
+
+    fake-files)
+      _message 'prefix and names'
+      ;;
+
+    fake-params)
+      _message 'name and optional type'
+      ;;
+
+    ignline) 
+      _wanted values expl 'ignore strings on the line' compadd true false current current-shown other
+      ;;
+
+    keep-prefix) 
+      _wanted values expl 'keep prefix' compadd true false changed
+      ;;
+
+    match-orig) 
+      _wanted values expl "match without inserting \`*'" compadd only both
+      ;;
+
+    oldmatches) 
+      _wanted values expl 'use list of old matches' compadd true false only
+      ;;
+
+    insunambig) 
+      _wanted values expl 'insert unambiguous string' compadd true false pattern
+      ;;
+
+    preserve-prefix)
+      _message 'pattern matching prefix to keep'
+      ;;
+
+    urgh) 
+      _wanted values expl no compadd no false off 0
+      ;;
+
+    _*)
+      ${=ostate}
+      ;;
+
+    *)
+      ;;
+  esac
+done
+
+[[ $compstate[nmatches] != $nm ]]
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index aedad700d..c5260245a 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1834,6 +1834,16 @@ all.
 
 The default style for this style is `true'.
 )
+kindex(preserve-prefix, completion style)
+item(tt(preserve-prefix))(
+This style is used when completing path names.  Its value should be a
+pattern matching an initial prefix of the word to complete that should
+be left unchanged under all circumstances.  For example, on some Unices
+an initial `tt(//)' (double slash) has a special meaning and hence
+should be kept.  For that one could set this style to the string
+`tt(//)'.  As another example, setting this style to `tt(?:/)' under
+Cygwin would allow completion after `tt(a:/...)' and the like.
+)
 kindex(range, completion style)
 item(tt(range))(
 This is used by the tt(_history) completer and the