zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Further improvements to _mailboxes
@ 2000-02-28 18:00 Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-02-28 18:00 UTC (permalink / raw)
  To: zsh-workers

This patch is actually about twice as big as the resulting file, because of
reindentation.  Oh, well.

I'm still mysteriously getting a blank entry as the first item in a listing.
This *seems* to be coming from _multi_parts, as when I menu-complete the
first choice offered is `/' which doesn't appear in the listing anywhere.

The patch moves setting up the mailbox caches and extracting the proper
cache elements into their own functions, so that _mailboxes doesn't do
anything directly except setting up and cycling through the tags.  This
will make it easier for people who don't want support for lots of mail
clients to override individual sections -- e.g. I know Sven doesn't want
the entire contents of $maildirectory to be cached.

I've also tried to reflect more accurately that, although pine and mutt
allow the mailbox name to appear in the same shell word as the -f option,
mail, mush and their derivatives require that the mailbox name be in the
following word.  Finally, mush and zmail support "%username" as a short
syntax for /(usr|var){,/spool}/mail/username, so I added that.  It's not
perfect, as it doesn't check whether the user actually has a mailbox.

Index: Completion/User/_mailboxes
===================================================================
@@ -1,27 +1,69 @@
 #autoload
 
-#emulate -L zsh
-setopt localoptions nullglob
+_mailboxes() {
+  #emulate -L zsh
+  local expl nm="$compstate[nmatches]"
+  local pinedirectory="${pinedirectory:-~/mail}"
+  local maildirectory="${maildirectory:-~/Mail}"
 
-# This is still needlessly mutt-biased and should be fixed.
+  if (( ! $+_mailbox_cache )) then
+    _mailbox_cache "$@"
+  fi
 
-local -U dirboxes
-local i j expl muttrc="${muttrc:-~/.muttrc}" files nm="$compstate[nmatches]"
-local pinedirectory="${pinedirectory:-~/mail}"
-local maildirectory="${maildirectory:-~/Mail}"
-
-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=()
+  case "${curcontext}" in
+    (*:mail:*)
+      if [[ "$PREFIX" == +* ]]; then
+	_tags mailboxes
+      else
+        _tags mailboxes files
+      fi;;
+    (*:(mush|zmail|zmlite):*)
+      if [[ "$PREFIX" == [%+]* ]]; then
+	_tags mailboxes
+      else
+        _tags mailboxes files
+      fi;;
+    (*:pine:*)
+      # Files for pine must be absolute paths.
+      if [[ "$PREFIX" == (|-f)[/\~]* ]]; then
+        pinedirectory=''
+        _tags mailboxes files
+      else
+        _tags mailboxes
+      fi;;
+    (*)
+      if [[ "$PREFIX" == (|-f)+* ]]; then
+	_tags mailboxes
+      else
+        _tags mailboxes files
+      fi;;
+  esac
+
+  while _tags; do
+    if _requested mailboxes expl 'mailbox specification'; then
+      _mua_mailboxes "$expl[@]"
+    fi
+    if _requested files expl 'mailbox file'; then
+      [[ "${curcontext}" != *:(mail|mush|zmail|zmlite):* ]] &&
+	compset -P -f
+      _path_files "$expl[@]"
+    fi
+    [[ nm -ne $compstate[nmatches] ]] && return 0
+  done
+
+  return 1
+}
+
+_mailbox_cache () {
+  # Depends on $maildirectory and $pinedirectory from _mailboxes!
+
+  local i j muttrc="${muttrc:-~/.muttrc}"
+  local -aU dirboxes
+  typeset -aU -g _mailbox_cache
+  typeset -aU -g _maildir_cache _mbox_cache _mh_cache _mutt_cache _pine_cache
 
+  setopt localoptions nullglob
+
   [[ -f ${~muttrc:-.} ]] &&
     _mutt_cache=( ${$(grep mailboxes ${~muttrc})[2,-1]} )
 
@@ -43,39 +85,25 @@
     fi
   done
 
-  [[ -n "$_mutt_cache" || -d ~/.elm || -d ~/.mutt ]] &&
-      _mailbox_cache=( \! \< \> )
   [[ -n "$mailpath" ]] &&
       _mailbox_cache=( "${_mailbox_cache[@]}" "${(@)mailpath%%\?*}" )
 
   [[ -n "$MAIL" ]] && _mailbox_cache=( "${_mailbox_cache[@]}" $MAIL )
-fi
-
-# Files for pine must be absolute paths.
+}
 
-if [[ "$PREFIX" != (|-f)+* &&
-      ( "${curcontext}" = *:(mail|mush|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
+_mua_mailboxes() {
+  # Depends on $maildirectory and $pinedirectory from _mailboxes!
 
-    mbox_short=()
-    mbox_names=()
+  local -a mbox_short
+  local -aU mbox_names
 
-    case "${curcontext}" in
+  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
+      if compset -P +; then
         mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
       else
         mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
@@ -86,12 +114,14 @@
       (( $#_mh_cache )) && _multi_parts "${expl[@]}" / _mh_cache
       ;;
     (*:mush:*)
-      if compset -P '+|-f+'; then
+      if compset -P %; then
+        mbox_short=( "${(@k)userdirs}" )
+      elif compset -P +; then
         mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
       else
         mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
 		     "${_mailbox_cache[@]}" )
-        mbox_short=( % \& )
+        mbox_short=( \& % %"${(@k)^userdirs}" )
       fi
       ;;
     (*:mutt:*)
@@ -109,28 +139,26 @@
 		   "${_mailbox_cache[@]}" "${_mh_cache[@]}" )
       ;;
     (*:(zmail|zmlite):*)
-      if compset -P '+|-f+'; then
+      if compset -P %; then
+        mbox_short=( "${(@k)userdirs}" )
+      elif compset -P +; then
         mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
       else
         mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
 		     "${_mailbox_cache[@]}" "${_mh_cache[@]}" )
-        mbox_short=( % \& )
+        mbox_short=( \& % %"${(@k)^userdirs}" )
       fi
       ;;
     (*) # Some other program wants mailbox names?  Use them all?
        mbox_names=( "${_mailbox_cache[@]}" "${_mbox_cache[@]}"
 		    "${_mh_cache[@]}" "${_mutt_cache[@]}" "${_pine_cache[@]}" )
        ;;
-    esac
+  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
+  local ret=1
+  (( $#mbox_names )) && _multi_parts "$@" / mbox_names && ret=0
+  (( $#mbox_short )) && compadd "$@" - "$mbox_short[@]" && ret=0
+  return ret
+}
 
-return 1
+[[ -o kshautoload ]] || _mailboxes "$@"

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: Further improvements to _mailboxes
@ 2000-03-01 12:03 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2000-03-01 12:03 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> I'm still mysteriously getting a blank entry as the first item in a listing.
> This *seems* to be coming from _multi_parts, as when I menu-complete the
> first choice offered is `/' which doesn't appear in the listing anywhere.

I think I found it now... the test if the string to add contained a
separator character was too simple.

Bye
 Sven

diff -ru ../z.old/Completion/Core/_multi_parts Completion/Core/_multi_parts
--- ../z.old/Completion/Core/_multi_parts	Wed Mar  1 11:38:13 2000
+++ Completion/Core/_multi_parts	Wed Mar  1 13:03:21 2000
@@ -162,14 +162,27 @@
 	  tmp2=()
         fi
         for i in "${(@M)matches:#(${(j:|:)~tmp1})*}"; do
-	  if [[ "$i" = *${sep}* ]]; then
+	  case "$i" in
+	  *${sep})
+            compadd "$group[@]" "$expl[@]" -r "$sep" -S "$sep" "$opts[@]" \
+	            -p "$pref" \
+                    -M "r:|${sep}=* r:|=* $match" - "${i%%${sep}*}" && ret=0
+            ;;
+	  ${sep}*)
+            compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" \
+	            -p "$pref" \
+                    -M "r:|${sep}=* r:|=* $match" - "$sep" && ret=0
+            ;;
+	  *${sep}*)
             compadd "$group[@]" "$expl[@]" -r "$sep" -S "$sep" "$opts[@]" \
 	            -p "$pref" \
                     -M "r:|${sep}=* r:|=* $match" - "${i%%${sep}*}" && ret=0
-          else
+            ;;
+          *)
             compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" -p "$pref" \
                     -M "r:|${sep}=* r:|=* $match" - "$i" && ret=0
-          fi
+            ;;
+          esac
         done
       else
         # With normal completion we add all matches one-by-one with
@@ -178,7 +191,7 @@
 
         for i in "${(@M)matches:#(${(j:|:)~tmp1})*}"; do
 	  if [[ "$i" = *${sep}* ]]; then
-            compadd "$group[@]" "$expl[@]" -r "$sep" -S "$sep" "$opts[@]" \
+            compadd "$group[@]" "$expl[@]" "$opts[@]" \
 	            -p "$pref" -s "${i#*${sep}}" \
                     -M "r:|${sep}=* r:|=* $match" - "${i%%${sep}*}" && ret=0
           else

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-03-01 12:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-28 18:00 PATCH: Further improvements to _mailboxes Bart Schaefer
2000-03-01 12:03 Sven Wischnowsky

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).