da0b027334c01af9e9fc85b04cd7126dc812b7b1
[mmh] / docs / COMPLETION-ZSH
1 #
2 # The following several shell functions and `compctl' commands
3 # that will configure the programmable command completion of
4 # the Z Shell (zsh) for the nmh mail system.
5 #
6 # You may need to edit where it says EDIT ME.
7 # These were orginally written for MH by Peter Stephenson
8
9 # The following three functions are best autoloaded.
10 #
11 # mhcomp completes folders (including subfolders).
12 # mhfseq completes sequence names and message numbers.
13 # mhfile completes files in standard nmh locations.
14
15 #
16 # Completion function for nmh folders.  Works with
17 # both + (relative to top) and @ (relative to current).
18 #
19 function mhcomp {
20   local nword args pref char mhpath
21   read -nc nword
22   read -cA args
23
24   pref=$args[$nword]
25   char=$pref[1]
26   pref=$pref[2,-1]
27
28   # The $(...) here accounts for most of the time spent in this function.
29   if [[ $char = + ]]; then
30   #    mhpath=$(mhpath +)
31   # EDIT ME: use a hard wired value here: it's faster.
32     mhpath=~/Mail
33   elif [[ $char = @ ]]; then
34     mhpath=$(mhpath)
35   fi
36
37   eval "reply=($mhpath/$pref*(N-/))"
38
39   # I'm frankly amazed that this next step works, but it does.
40   reply=(${reply#$mhpath/})
41 }
42
43 #
44 # Extract nmh message names and numbers for completion.  Use of the
45 # correct folder, if it is not the current one, requires that it
46 # should be the previous command line argument.
47 #
48 mhfseq() {
49   local folder foldpath words pos nums
50   read -cA words
51   read -cn pos
52
53   # Look for a folder name.
54   # First try the previous word.
55   if [[ $words[$pos-1] = [@+]* ]]; then
56     folder=$words[$pos-1]
57   fi
58   # Else use the current folder ($folder empty)
59
60   if [[ $folder = +* ]]; then
61   # EDIT ME:  use hard-wired path with + for speed.
62     foldpath=~/Mail/$folder[2,-1]
63   else
64     foldpath=$(mhpath $folder)
65   fi
66
67   # Extract all existing message numbers from the folder.
68   nums=($foldpath/<->(N:t))
69   # If that worked, look for marked sequences.
70   # EDIT ME
71   # if you never use non-standard sequences, comment out
72   # or delete the next three lines.
73   if (( $#nums )); then
74     nums=($nums $(mark $folder | awk -F: '{print $1}'))
75   fi
76
77   # EDIT ME:  `unseen' is the value of Unseen-Sequence, if it exists;
78   set -A reply next cur prev first last all unseen $nums
79
80 }
81
82 #
83 # Find an nmh file; for use with -form arguments and the like.
84 # Use with compctl -K mhfile.
85 #
86 mhfile () {
87   local mhfpath file
88   # EDIT ME
89   # Array containing all the places nmh will look for templates etc.
90   mhfpath=(~/Mail /usr/local/nmh/lib)
91
92   # Emulate completeinword behaviour as appropriate
93   local wordstr
94   if [[ -o completeinword ]]; then
95     wordstr='$1*$2'
96   else
97     wordstr='$1$2*'
98   fi
99
100   if [[ $1$2 = */* ]]; then
101     # path given: don't search nmh locations
102     eval "reply=($wordstr(.N))"
103   else
104     # no path:  only search nmh locations.
105     eval "reply=(\$mhfpath/$wordstr(.N:t))"
106   fi
107 }
108
109 # Note: you must type the initial + or @ of a folder name to get
110 # completion, even in places where only folder names are allowed.
111 # Abbreviations for options are not recognised.  Hit tab to complete
112 # the option name first.
113
114 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
115   's[-]' -k "(all noall fast nofast header noheader help list nolist \
116   pack nopack pop push recurse norecurse total nototal)" -- folder folders
117
118 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
119   's[-]' -k "(sequence all noall recurse norecurse showzero noshowzero \
120   alpha noalpha fast nofast help)" -- flist flists
121
122 compctl -K mhfseq -x 's[+][@],c[-1] s[+][@]' \
123   -K mhcomp -S / -q - 'c[-1]' -K mhfseq - \
124   'C[-1,-(editor|whatnowproc)]' -c - \
125   's[-]' -k "(editor noedit \
126   form use nouse whatnowproc nowhatnowproc help)" - \
127   'c[-1,-form]' -K mhfile -- comp
128
129 compctl -K mhfseq -x 's[+][@]' \
130   -K mhcomp -S / -q - 'c[-1]'  -K mhfseq -\
131   's[-]' -k "(annotate noannotate cc nocc \
132   editor noedit filter nofilter form group nogroup \
133   query noquery width whatnowproc nowhatnowproc help)" - 'c[-1,(cc|nocc)]' \
134   -k "(all to cc me)" - 'C[-1,-(filter|form)]' -K mhfile - \
135   'C[-1,-(editor|whatnowproc)]' -c -- repl
136
137 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
138   's[-]' -k "(audit noaudit changecur nochangecur form \
139   file silent nosilent truncate notruncate width help)" - \
140   'C[-1,-(audit|form)]' -K mhfile - 'c[-1,-file]' -f + -- inc
141
142 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
143   's[-]' -k "(sequence add delete list public nopublic zero nozero help)" -- \
144   mark
145
146 compctl -K mhfseq -x 's[+][@]' \
147   -K mhcomp -S / -q - 'c[-1,-file]' -f - 'c[-1,-rmmprov]' -c - \
148   's[-]' -k "(link nolink preserve nopreserve src file \
149   rmmproc normmproc help)" -- refile
150
151 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
152   's[-]' -k "(form \
153   file help width)" - 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile -- scan
154
155 compctl -K mhfseq -x 's[+][@]'  -K mhcomp -S / -q - \
156   's[-]' -k "(draft form moreproc nomoreproc header noheader \
157    showproc length width help)" - 'C[-1,-(show|more)proc]' -c - \
158    'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile - \
159    'c[-1,-length]' -s '$LINES' - 'c[-1,-width]' -s '$COLUMNS' -- show next prev
160
161 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
162   -k "(help)" -- rmm
163
164 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
165   's[-]' -k "(after before cc date datefield from help list nolist \
166   public nopublic search sequence subject to zero nozero not or and \
167   lbrace rbrace)" -- pick
168
169 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' -k '(help)' -- mhpath