zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Tweaking predict-on
Date: Sat, 4 Mar 2000 19:32:10 +0000	[thread overview]
Message-ID: <1000304193210.ZM24987@candle.brasslantern.com> (raw)

If you really want to pound on the completion system, enable predict-on for
a while.  Having completion attempted on every keystroke shows up all kinds
of things; in particular I've gotten the undo system into a very bad state
by cut'n'pasting a function definition during predict-on and then trying to
undo my way out of the resulting chaos.  Not reliably repeatable, though.

I'm wondering if it would be worthwhile for ZLE and completion widgets to
be able to do some sort of FIONREAD test and react differently when there
is typeahead ... it won't work everywhere, but ...

Of course that may go slightly less haywire after this patch, so if you're
interested in debugging "undo" you may want an older predict-on.

This patch changes:

* Remove "emulate -L zsh" for benefit of the completion system.

* Add test of whether we're inside a multi-line buffer, and don't attempt
  predictive typing in that case.

* Reformat a long line.

Index: Functions/Zle/predict-on
===================================================================
@@ -36,10 +36,15 @@
   zle -A .backward-delete-char backward-delete-char
 }
 insert-and-predict () {
-  emulate -L zsh
-  if [[ ${RBUFFER[1]} = ${KEYS[-1]} ]]
+  setopt localoptions noshwordsplit noksharrays
+  if [[ $LBUFFER = *$'\012'* ]]
   then
-    # same as what's typed, just move on
+    # Editing a multiline buffer, it's unlikely prediction is wanted
+    zle .$WIDGET "$@"
+    return
+  elif [[ ${RBUFFER[1]} = ${KEYS[-1]} ]]
+  then
+    # Same as what's typed, just move on
     ((++CURSOR))
   else
     LBUFFER="$LBUFFER$KEYS"
@@ -92,12 +97,15 @@
   return 0
 }
 delete-backward-and-predict() {
-  emulate -L zsh
   if [[ -n "$LBUFFER" ]]
   then
+    setopt localoptions noshwordsplit noksharrays
+    if [[ $LBUFFER = *$'\012'* ]] then
+      # Editing a multiline buffer, it's unlikely prediction is wanted
+      zle .$WIDGET "$@"
     # If the last widget was e.g. a motion, then probably the intent is
     # to actually edit the line, not change the search prefix.
-    if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]]
+    elif [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]]
     then
       ((--CURSOR))
       zle .history-beginning-search-forward || RBUFFER=""
@@ -118,7 +126,8 @@
 
 predict-limit-list() {
   if (( compstate[list_lines]+BUFFERLINES > LINES ||
-	( compstate[list_max] != 0 && compstate[nmatches] > compstate[list_max] ) ))
+	( compstate[list_max] != 0 &&
+	    compstate[nmatches] > compstate[list_max] ) ))
   then
     compstate[list]=''
     compstate[force_list]=yes

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


             reply	other threads:[~2000-03-04 19:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-04 19:32 Bart Schaefer [this message]
2000-03-09  9:45 Sven Wischnowsky

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=1000304193210.ZM24987@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --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).