zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: file completion(?) erases word typed
Date: Thu, 17 Nov 2016 13:51:17 -0800	[thread overview]
Message-ID: <161117135117.ZM11086@torch.brasslantern.com> (raw)
In-Reply-To: <20160823224842.GA24864@fujitsu.shahaf.local2>

I think the comment included in the diff is fairly explanatory.  This
change means menu completion sometimes starts earlier than expected
(i.e., on the first or second tab instead of on the second or third)
but that seems preferable to throwing away the set of matches and
starting over at what is probably the wrong place.

It's likely that there are still situations -- probably including
_multi_parts with separators other than "/" -- where this heuristic
fails, but this should catch a lot of common cases (I hope).

If I'm wrong about any of the assertions in that comment, please
point out how the tests could be tweaked.


diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index c292ce7..01e6eaa 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -284,6 +284,29 @@ if [[ $compstate[old_list] = keep || nm -gt 1 ]]; then
     fi
   fi
 
+  if [[ "$compstate[insert]" = *unambiguous &&
+	"$compstate[old_list]" != keep &&
+	"$compstate[nmatches]" -gt 1 &&
+	( "$compstate[insert_positions]" != *:* ||
+	  "$compstate[unambiguous_positions]" == 0* ) &&
+	( "$compstate[unambiguous]" == /## ||
+	  "$compstate[unambiguous_cursor]" -lt ${#PREFIX} ) ]]; then
+    #
+    # We have multiple matches but no useful common prefix to show.
+    # This would result in either erasing an existing prefix on the
+    # line, or adding a prefix that breaks subsequent completions.
+    # Instead, forcibly enter menu completion to cycle the matches.
+    #
+    # The above test is heuristic; what we really need to know
+    # is whether compadd -U or -M is going to cause the current
+    # string on the line to be shortened or removed, but that
+    # information isn't present in the user-visible state.  The
+    # test for unambiguous == /## ideally would apply only for
+    # file completion, but there's no way to detect that either.
+    #
+    compstate[insert]=menu
+  fi
+
   if [[ "$compstate[insert]" = *menu* ]]; then
     [[ "$MENUSELECT" = 00 ]] && MENUSELECT=0
     if [[ -n "$_menu_style[(r)no-select*]" ]]; then


      parent reply	other threads:[~2016-11-17 23:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 22:48 Daniel Shahaf
2016-08-24  5:52 ` Bart Schaefer
2016-08-24 19:13   ` Daniel Shahaf
2016-08-25  0:04     ` Bart Schaefer
2016-08-25  1:19       ` Daniel Shahaf
2016-08-30  7:03     ` Bart Schaefer
2016-09-14  3:49       ` legend for match_str (was: Re: file completion(?) erases word typed) Daniel Shahaf
2016-09-14  5:25         ` Bart Schaefer
2016-11-17 21:51 ` Bart Schaefer [this message]

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=161117135117.ZM11086@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /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).