Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
MH command completion
- X-seq: zsh-users 268
- From: Peter Stephenson <pws@xxxxxx>
- To: zsh-users@xxxxxxxxxxxxxxx (Zsh users list)
- Subject: MH command completion
- Date: Mon, 01 Jul 1996 11:02:10 +0200
Now is probably a good time to send the latest version of my
zsh completion commands and functions for use with MH.
Major differences from the version in Misc/compctl-examples include
- more MH commands handled
- fixed a bug that array arguments spanning more than one line thought
newline was a possible completion (use "" instead of '' when
spanning newlines)
- mhfseq expanded so that
- if you have e.g. '+zsh <TAB>' it will complete sequences in +zsh
(N.B. folder must be previous argument, parsing too hard otherwise)
- message numbers are completed too (but not ranges --- possible upgrade)
(yes, it uses <->, not <>)
- mhfile looks for MH forms etc. in the right places.
I can't remember why I added the final + argument to inc; probably it
shouldn't really be there.
# Various MH completions by Peter Stephenson
# You may need to edit where it says *Edit Me*.
# The following three functions are best autoloaded.
# mhcomp completes folders (including subfolders),
# mhfseq completes sequence names and message numbers,
# mhfile completes files in standard MH locations.
function mhcomp {
# Completion function for MH folders.
# Works with both + (rel. to top) and @ (rel. to current).
set -x
local nword args pref char mhpath
read -nc nword
read -cA args
pref=$args[$nword]
char=$pref[1]
pref=$pref[2,-1]
# The $(...) here accounts for most of the time spent in this function.
if [[ $char = + ]]; then
# mhpath=$(mhpath +)
# *Edit Me*: use a hard wired value here: it's faster.
mhpath=~/Mail
elif [[ $char = @ ]]; then
mhpath=$(mhpath)
fi
eval "reply=($mhpath/$pref*(N-/))"
# I'm frankly amazed that this next step works, but it does.
reply=(${reply#$mhpath/})
}
mhfseq() {
# Extract MH message names and numbers for completion. Use of the
# correct folder, if it is not the current one, requires that it
# should be the previous command line argument. If the previous
# argument is `-draftmessage', a hard wired draft folder name is used.
local folder foldpath words pos nums
read -cA words
read -cn pos
# Look for a folder name.
# First try the previous word.
if [[ $words[$pos-1] = [@+]* ]]; then
folder=$words[$pos-1]
# Next look and see if we're looking for a draftmessage
elif [[ $words[$pos-1] = -draftmessage ]]; then
# *Edit Me*: shortcut -- hard-wire draftfolder here
# Should really look for a +draftfolder argument.
folder=+drafts
fi
# Else use the current folder ($folder empty)
if [[ $folder = +* ]]; then
# *Edit Me*: use hard-wired path with + for speed.
foldpath=~/Mail/$folder[2,-1]
else
foldpath=$(mhpath $folder)
fi
# Extract all existing message numbers from the folder.
nums=($foldpath/<->(N:t))
# If that worked, look for marked sequences.
# *Edit Me*: if you never use non-standard sequences, comment out
# or delete the next three lines.
if (( $#nums )); then
nums=($nums $(mark $folder | awk -F: '{print $1}'))
fi
# *Edit Me*: `unseen' is the value of Unseen-Sequence, if it exists;
set -A reply next cur prev first last all unseen $nums
}
mhfile () {
# Find an MH file; for use with -form arguments and the like.
# Use with compctl -K mhfile.
local mhfpath file
# *Edit Me*: Array containing all the places MH will look for templates etc.
mhfpath=(~/Mail /usr/local/lib/MH)
# Emulate completeinword behaviour as appropriate
local wordstr
if [[ -o completeinword ]]; then
wordstr='$1*$2'
else
wordstr='$1$2*'
fi
if [[ $1$2 = */* ]]; then
# path given: don't search MH locations
eval "reply=($wordstr(.N))"
else
# no path: only search MH locations.
eval "reply=(\$mhfpath/$wordstr(.N:t))"
fi
}
# Note: you must type the initial + or @ of a folder name to get
# completion, even in places where only folder names are allowed.
# Abbreviations for options are not recognised. Hit tab to complete
# the option name first.
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
's[-]' -k "(all fast nofast header noheader help list nolist \
pack nopack pop push recurse norecurse total nototal)" -- folder
compctl -K mhfseq -x 's[+][@],c[-1,-draftfolder] s[+][@]' \
-K mhcomp -S / -q - 'c[-1,-draftmessage]' -K mhfseq - \
'C[-1,-(editor|whatnowproc)]' -c - \
's[-]' -k "(draftfolder draftmessage nodraftfolder editor noedit \
file form use nouse whatnowproc nowhatnowproc help)" - \
'c[-1,-form]' -K mhfile -- comp
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
's[-]' -k "(audit noaudit changecur nochangecur form format \
file silent nosilent truncate notruncate width help)" - \
'C[-1,-(audit|form)]' -K mhfile - 'c[-1,file]' -f + -- inc
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
's[-]' -k "(sequence add delete list public nopublic zero nozero help)" -- \
mark
compctl -K mhfseq -x 's[+][@]' \
-K mhcomp -S / -q - 'c[-1,-file]' -f - 'c[-1,-rmmprov]' -c - \
's[-]' -k "(draft link nolink preserve nopreserve src file \
rmmproc normmproc help)" -- refile
compctl -K mhfseq -x 's[+][@]' \
-K mhcomp -S / -q - 'c[-1,-draftmessage]' -K mhfseq -\
's[-]' -k "(annotate noannotate cc nocc draftfolder nodraftfolder \
draftmessage editor noedit fcc filter form inplace noinplace query \
noquery width whatnowproc nowhatnowproc help)" - 'c[-1,(cc|nocc)]' \
-k "(all to cc me)" - 'C[-1,-(filter|form)]' -K mhfile - \
'C[-1,-(editor|whatnowproc)]' -c -- repl
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
's[-]' -k "(clear noclear form format header noheader reverse noreverse \
file help width)" - 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile -- scan
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
's[-]' -k "(draft header noheader showproc noshowproc)" - \
'c[-1,showproc]' -c -- show next prev
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
-k "(help)" -- rmm
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
's[-]' -k "(after before cc date datefield from help list nolist \
public nopublic search sequence subject to zero nozero not or and \
lbrace rbrace)" -- pick
compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
-k "(alias check draft draftfolder draftmessage help nocheck \
nodraftfolder)" -- whom
--
Peter Stephenson <pws@xxxxxx> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author