zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: Enhancing math expressions a bit
Date: Wed, 07 Jul 1999 14:29:34 +0200	[thread overview]
Message-ID: <9907071229.AA12427@ibmth.df.unipi.it> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Wed, 07 Jul 1999 13:57:49 DFT." <9907071157.AA19534@ibmth.df.unipi.it>

Peter Stephenson wrote:
> Sven Wischnowsky wrote:
> > Ok, with the last patch and the one below, I hacked these two widgets
> 
> I'll make a directory Functions/Zle and put these in

I changed them a bit to make them presentable, so here's what I actually
put in Functions/Zle.  I hope I've deciphered the behaviour OK --- does the
incremental_completer really work yet?

Comments on behaviour:

- <TAB> in i-c-w should probably cause the function to exit if it
  gets a unique completion.  (Note menucompletion is now explicitly
  turned off inside the function.)
- a left parenthesis typed in insert-files is causing the whole function to
  crash; probably also nobadpattern needs to be set inside (I have it
  set all the time).


# incremental-complete-word() {

# Autoload this function, run `zle -N <func-name>' and bind <func-name>
# to a key.

# This allows incremental completion of a word.  After starting this
# command, a list of completion choices is shown after every character you
# type, which you can delete with ^h or DEL.  RET will accept the
# completion so far.  You can hit TAB to do normal completion and ^g to
# abort back to the state when you started.
#
# Completion keys:
#   incremental_prompt   Prompt to show in status line during icompletion
#   incremental_stop     Pattern matching keys which will cause icompletion
#                        to stop and the key to re-executed
#   incremental_break    Pattern matching keys which will cause icompletion
#                        to stop and the key to be discarded
#   incremental_completer  Name of completion widget to call to get choices

emulate -L zsh
unsetopt menucomplete # doesn't work well

local key lbuf="$LBUFFER" rbuf="$RBUFFER" pmpt

[[ -n "$compconfig[incremental_completer]" ]] &&
set ${(s.:.)compconfig[incremental_completer]}
pmpt="${compconfig[incremental_prompt]-incremental completion...}"

zle list-choices
zle -R "$pmpt"
read -k key

while [[ '#key' -ne '#\\r' && '#key' -ne '#\\n' &&
         '#key' -ne '#\\C-g' ]]; do
  if [[ "$key" = ${~compconfig[incremental_stop]} ]]; then
    zle -U "$key"
    return
  elif [[ "$key" = ${~compconfig[incremental_break]} ]]; then
    return
  elif [[ '#key' -eq '#\\C-h' || '#key' -eq '#\\C-?' ]]; then
    [[ $#LBUFFER -gt $#l ]] && LBUFFER="$LBUFFER[1,-2]"
  elif [[ '#key' -eq '#\\t' ]]; then
    zle complete-word "$@"
  else
    LBUFFER="$LBUFFER$key"
  fi
  zle list-choices "$@"
  zle -R "$pmpt"
  read -k key
done

if [[ '#key' -eq '#\\C-g' ]]; then
  LBUFFER="$lbuf"
  RBUFFER="$rbuf"
fi
zle -Rc
# }


# insert-files() {

# Autoload this function, run `zle -N <func-name>' and bind <func-name>
# to a key.

# This function allows you type a file pattern, and see the results of the
# expansion at each step.  When you hit return, they will be inserted into
# the command line.

local key str files

files=( *(N) )
if (( $#files )); then
  zle -R "files: ${str}_" "$files[@]"
else
  zle -R "files: ${str}_ (failed)"
fi
read -k key
while [[ '#key' -ne '#\\r' && '#key' -ne '#\\n' &&
         '#key' -ne '#\\C-g' ]]; do
  if [[ '#key' -eq '#\\C-h' || '#key' -eq '#\\C-?' ]]; then
    [[ -n "$str" ]] && str="$str[1,-2]"
  else
    str="$str$key"
  fi
  files=( ${~str}*(N) )
  if (( $#files )); then
    zle -R "files: ${str}_" "$files[@]"
  else
    zle -R "files: ${str}_ (failed)"
  fi
  read -k key
done
zle -Rc
if [[ '#key' -ne '#\\C-g' && $#files -gt 0 ]]; then
  [[ "$LBUFFER[-1]" = ' ' ]] || files=('' "$files[@]")
  LBUFFER="$LBUFFER$files "
fi
# }

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


  reply	other threads:[~1999-07-07 12:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-07  8:15 Sven Wischnowsky
1999-07-07 10:42 ` Andrej Borsenkow
1999-07-07 11:40 ` Andrej Borsenkow
1999-07-07 11:57 ` Peter Stephenson
1999-07-07 12:29   ` Peter Stephenson [this message]
1999-07-07  9:32 Sven Wischnowsky
1999-07-07 11:05 Sven Wischnowsky
1999-07-07 13:23 Sven Wischnowsky
1999-07-07 13:16 ` Peter Stephenson
1999-07-13 13:03 Sven Wischnowsky
1999-07-13 12:40 ` Peter Stephenson
1999-07-13 13:24 Sven Wischnowsky
1999-07-13 13:11 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9907071229.AA12427@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).