zsh-users
 help / color / mirror / code / Atom feed
* MH command completion
@ 1996-07-01  9:02 Peter Stephenson
  1996-07-01 11:34 ` Peter Stephenson
  1997-01-05  1:04 ` MH command completion problems John Harres
  0 siblings, 2 replies; 5+ messages in thread
From: Peter Stephenson @ 1996-07-01  9:02 UTC (permalink / raw)
  To: Zsh users list

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@ifh.de>       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.



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

* Re: MH command completion
  1996-07-01  9:02 MH command completion Peter Stephenson
@ 1996-07-01 11:34 ` Peter Stephenson
  1997-01-05  1:04 ` MH command completion problems John Harres
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1996-07-01 11:34 UTC (permalink / raw)
  To: Zsh users list

pws@ifh.de wrote:
> Now is probably a good time to send the latest version of my
> zsh completion commands and functions for use with MH.

Sorry, I was doing a final test before posting and inserted a `set -x'
into the mhcomp function near the top: this needs to be deleted.  If
you haven't, you'll find out soon enough.

-- 
Peter Stephenson <pws@ifh.de>       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.



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

* MH command completion problems
  1996-07-01  9:02 MH command completion Peter Stephenson
  1996-07-01 11:34 ` Peter Stephenson
@ 1997-01-05  1:04 ` John Harres
  1997-01-06  8:35   ` Peter Stephenson
  1 sibling, 1 reply; 5+ messages in thread
From: John Harres @ 1997-01-05  1:04 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh users list

I've been a happy user of Peter Stephenson's mh completion commands, but
I've noticed a problem that I hoped someone might know the solution to.
When I do a:

folder +work/

and then hit <tab>, all I get is "folder +work//", and any subsequent
<tab>'s just add slashes.  Nothing is listed below either.

Suggestions?

John Harres
harres@uwyo.edu


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

* Re: MH command completion problems
  1997-01-05  1:04 ` MH command completion problems John Harres
@ 1997-01-06  8:35   ` Peter Stephenson
  1997-01-06 15:24     ` John Harres
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 1997-01-06  8:35 UTC (permalink / raw)
  To: Zsh users list

John Harres wrote:
> I've been a happy user of Peter Stephenson's mh completion commands, but
> I've noticed a problem that I hoped someone might know the solution to.
> When I do a:
> 
> folder +work/
> 
> and then hit <tab>, all I get is "folder +work//", and any subsequent
> <tab>'s just add slashes.  Nothing is listed below either.
> 
> Suggestions?

I've noticed the slash sometimes gets doubled, which I've never
tracked down, but I think it's internal to zle_tricky.c (some
confusion with suffixes?), since if you type one slash and list the
completions with ^D, they appear correct.  I haven't seen it fail to
complete subfolders, however.  I presume there is more than one
subfolder, so it can't start a completion.  It should still be able to
autolist, though.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


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

* Re: MH command completion problems
  1997-01-06  8:35   ` Peter Stephenson
@ 1997-01-06 15:24     ` John Harres
  0 siblings, 0 replies; 5+ messages in thread
From: John Harres @ 1997-01-06 15:24 UTC (permalink / raw)
  To: zsh-users; +Cc: Peter Stephenson

> John Harres wrote:
> > I've been a happy user of Peter Stephenson's mh completion commands, but
> > I've noticed a problem that I hoped someone might know the solution to.
> > When I do a:
> > 
> > folder +work/
> > 
> > and then hit <tab>, all I get is "folder +work//", and any subsequent
> > <tab>'s just add slashes.  Nothing is listed below either.
> > 
> > Suggestions?
> 
> I've noticed the slash sometimes gets doubled, which I've never
> tracked down, but I think it's internal to zle_tricky.c (some
> confusion with suffixes?), since if you type one slash and list the
> completions with ^D, they appear correct.  I haven't seen it fail to
> complete subfolders, however.  I presume there is more than one
> subfolder, so it can't start a completion.  It should still be able to
> autolist, though.
> 
I tried the ^D, and you are right, it did list the subfolders correctly.
Subsequently hitting <tab> still only inserts more /'s.

John Harres
harres@uwyo.edu


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

end of thread, other threads:[~1997-01-06 15:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-01  9:02 MH command completion Peter Stephenson
1996-07-01 11:34 ` Peter Stephenson
1997-01-05  1:04 ` MH command completion problems John Harres
1997-01-06  8:35   ` Peter Stephenson
1997-01-06 15:24     ` John Harres

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