about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-02-21 12:34:57 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-02-21 12:34:57 +0000
commit09ef7f9740e72fd2b62459d88aad8960fe6e296f (patch)
tree457b87fb98a747129ba7fc03bda1b0ff1ec2bebf
parent3b517729cafde567f12b51dadaf5cb58910bc0de (diff)
downloadzsh-09ef7f9740e72fd2b62459d88aad8960fe6e296f.tar.gz
zsh-09ef7f9740e72fd2b62459d88aad8960fe6e296f.tar.xz
zsh-09ef7f9740e72fd2b62459d88aad8960fe6e296f.zip
zsh-workers/9816
-rw-r--r--Completion/Core/_multi_parts17
-rw-r--r--Completion/User/_mailboxes116
2 files changed, 88 insertions, 45 deletions
diff --git a/Completion/Core/_multi_parts b/Completion/Core/_multi_parts
index 92da26f9a..1d3841f86 100644
--- a/Completion/Core/_multi_parts
+++ b/Completion/Core/_multi_parts
@@ -83,7 +83,7 @@ while true; do
   if [[ -n "$PREFIX$SUFFIX" || "$pre" = ${sep}* ]]; then
     tmp1=( "${(@M)matches:#${PREFIX}${SUFFIX}${sep}*}" )
   else
-    tmp1=
+    tmp1=()
   fi
 
   if (( $#tmp1 )); then
@@ -233,10 +233,21 @@ while true; do
     PREFIX="${opre}${osuf}"
     SUFFIX=""
 
-    [[ -n "$pref" && "$orig" != "$pref" ]] &&
+    if [[ -n "$pref" && "$orig" != "$pref" ]]; then
+      if [[ "$pref" = *${sep} ]]; then
+        compadd "$group[@]" "$expl[@]" "$opts[@]" \
+                -p "${pref%${sep}*${sep}}${sep}" -S "$sep" \
+                -M "r:|${sep}=* r:|=* $match" - "${${pref%${sep}}##*${sep}}"
+
+      elif [[ "$pref" = *${sep}* ]]; then
+        compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" \
+                -p "${pref%${sep}*}${sep}" \
+                -M "r:|${sep}=* r:|=* $match" - "${pref##*${sep}}"
+      else
         compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" \
                 -M "r:|${sep}=* r:|=* $match" - "$pref"
-
+      fi
+    fi
     return
   fi
 done
diff --git a/Completion/User/_mailboxes b/Completion/User/_mailboxes
index 2cf5361ba..f95bc0907 100644
--- a/Completion/User/_mailboxes
+++ b/Completion/User/_mailboxes
@@ -6,7 +6,7 @@ setopt localoptions nullglob
 # This is still needlessly mutt-biased and should be fixed.
 
 local -U dirboxes
-local i j expl muttrc="${muttrc:-~/.muttrc}"
+local i j expl muttrc="${muttrc:-~/.muttrc}" files nm="$compstate[nmatches]"
 local pinedirectory="${pinedirectory:-~/mail}"
 local maildirectory="${maildirectory:-~/Mail}"
 
@@ -15,6 +15,13 @@ if (( ! $+_mailbox_cache )) then
   typeset -U -g _mailbox_cache
   typeset -U -g _maildir_cache _mbox_cache _mh_cache _mutt_cache _pine_cache
 
+  _mailbox_cache=()
+  _mbox_cache=()
+  _maildir_cache=()
+  _mh_cache=()
+  _mutt_cache=()
+  _pine_cache=()
+
   [[ -f ${~muttrc:-.} ]] &&
     _mutt_cache=( ${$(grep mailboxes ${~muttrc})[2,-1]} )
 
@@ -41,48 +48,73 @@ if (( ! $+_mailbox_cache )) then
   [[ -n "$mailpath" ]] &&
       _mailbox_cache=( "${_mailbox_cache[@]}" "${(@)mailpath%%\?*}" )
 
-  _mailbox_cache=( "${_mailbox_cache[@]}" $MAIL )
+  [[ -n "$MAIL" ]] && _mailbox_cache=( "${_mailbox_cache[@]}" $MAIL )
 fi
 
-if _wanted files expl 'mailbox specification'; then
-  local -U mbox_names
-  case "${curcontext}" in
-  (*:elm:*) # I've probably got this wrong, or at least incomplete
-    mbox_names=( "${_mbox_cache[@]}" "${_mailbox_cache[@]}" )
-    compadd "${expl[@]}" - \! \< \>;;
-  (*:mail:*)
-    if compset -P '+|-f+'; then
-      mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
-    else
-      mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}" "${_mailbox_cache[@]}" )
-      _path_files -J all-files
-    fi;;
-  (*:mh:*) # I've probably got this wrong, or at least incomplete
-    (( $#_mh_cache )) && _multi_parts "${expl[@]}" / _mh_cache
-    return;;
-  (*:mutt:*)
-    mbox_names=( "${_mutt_cache[@]}" "${_mailbox_cache[@]}" "${_maildir_cache[@]}" )
-    compadd "${expl[@]}" - \! \< \>;;
-  (*:pine:*)
-    # Pine is like mail but with no leading `+' to disambiguate;
-    # any files not in $pinedirectory must be absolute paths.
-    mbox_names=( "${(@)_pine_cache#$~pinedirectory/}" "${_mbox_cache[@]}" )
-    # _path_files -J all-files -g '/*'
-    ;;
-  (*:(zmail|zmlite):*)
-    if compset -P '+|-f+'; then
-      mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
-    else
-      mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
-		   "${_mailbox_cache[@]}" "${_mh_cache[@]}" )
-      compadd "${expl[@]}" - % \&
-      _path_files -J all-files
-    fi
-    ;;
-  (*) # Some other program wants mailbox names?  Use them all?
-    mbox_names=( "${_mailbox_cache[@]}" "${_mbox_cache[@]}"
-		 "${_mh_cache[@]}" "${_mutt_cache[@]}" "${_pine_cache[@]}" );;
-  esac
+# Files for pine must be absolute paths.
 
-  (( $#mbox_names )) && _multi_parts "${expl[@]}" / mbox_names
+if [[ "$PREFIX" != (|-f)+* &&
+      ( "${curcontext}" = *:(mail|zmail|zmlite):* ||
+        ( "${curcontext}" = *:pine:* && "$PREFIX" = (|-f)[/\~]* ) ) ]]; then
+  _tags mailboxes files
+else
+  _tags mailboxes
 fi
+
+while _tags; do
+  if _requested mailboxes expl 'mailbox specification'; then
+    local mbox_short
+    local -U mbox_names
+
+    mbox_short=()
+    mbox_names=()
+
+    case "${curcontext}" in
+    (*:elm:*) # I've probably got this wrong, or at least incomplete
+      mbox_names=( "${_mbox_cache[@]}" "${_mailbox_cache[@]}" )
+      mbox_short=( \! \< \> )
+      ;;
+    (*:mail:*)
+      if compset -P '+|-f+'; then
+        mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
+      else
+        mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}" "${_mailbox_cache[@]}" )
+      fi
+      ;;
+    (*:mh:*) # I've probably got this wrong, or at least incomplete
+      (( $#_mh_cache )) && _multi_parts "${expl[@]}" / _mh_cache
+      ;;
+    (*:mutt:*)
+      mbox_names=( "${_mutt_cache[@]}" "${_mailbox_cache[@]}" "${_maildir_cache[@]}" )
+      mbox_short=( \! \< \> );;
+    (*:pine:*)
+      # Pine is like mail but with no leading `+' to disambiguate;
+      # any files not in $pinedirectory must be absolute paths.
+      mbox_names=( "${(@)_pine_cache#$~pinedirectory/}" "${_mbox_cache[@]}" )
+      ;;
+    (*:(zmail|zmlite):*)
+      if compset -P '+|-f+'; then
+        mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
+      else
+        mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
+		     "${_mailbox_cache[@]}" "${_mh_cache[@]}" )
+        mbox_short=( % \& )
+      fi
+      ;;
+    (*) # Some other program wants mailbox names?  Use them all?
+       mbox_names=( "${_mailbox_cache[@]}" "${_mbox_cache[@]}"
+		    "${_mh_cache[@]}" "${_mutt_cache[@]}" "${_pine_cache[@]}" )
+       ;;
+    esac
+
+    (( $#mbox_names )) && _multi_parts "${expl[@]}" / mbox_names
+    (( $#mbox_short )) && compadd "$expl[@]" - "$mbox_short[@]"
+  fi
+  if _requested files expl 'mailbox file'; then
+    compset -P -f
+    _path_files "$expl[@]"
+  fi
+  [[ nm -ne $compstate[nmatches] ]] && return 0
+done
+
+return 1