zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: tab inserts literal tab instead of completing at beginning of line
Date: Sun, 22 May 2011 19:27:58 -0700	[thread overview]
Message-ID: <110522192758.ZM718@torch.brasslantern.com> (raw)
In-Reply-To: <BANLkTimisOjcUKASf_uM3FTQ5supXGm7kg@mail.gmail.com>

On May 20, 11:55pm, Mikael Magnusson wrote:
} Subject: Re: tab inserts literal tab instead of completing at beginning of
}
} > Ah, I was in my own little world there, I see more context is needed
} > :). What it does is what I described last in my first message: insert
} > a tab if the line is empty, or contains only tabs (presumably you want
} > to paste more than one sometimes), otherwise completion as usual.
} 
} tl;dr nm this whole thing

OK, but the patch did intend to require that the insert-tab zstyle be
set to the value "empty" in order to create the described effect?

} Hmmm, so I'm confused again. It turns out my patch didn't work as well
} as I hoped. When I press ctrl-n or alt-m, it just inserts those
} literally as well.

That's because the style name assumes tab is the completion character.
Presumably you have ctl-n and alt-m bound to do completion as well?

You're running into a strange combination of effects.  The completion
internals initialize compstate[insert]=tab only when an actual tab is
pressed, but the effect of explicitly assigning compstate[insert]=tab
inside a completion function is to change the final keystroke into a
self-insert.

If you look at the code after line 53 in _main_complete, you'll note
that except for the case of "pending" on lines 45-47, insert-tab has
no effect unless compstate[insert]=tab is already true, i.e., unless
you actually did type a TAB character.

} I tried comparing _complete_debug output for
} insert-tab=false and =true, but they were the same.

This is one of those cases where you can't get useful output from
_complete_debug unless you actually bind it to the TAB key.  There
are a few such.  Here's the important part of the diff (blank lines
added for clarity):

 53> [[ 'tab automenu-unambiguous' == tab* ]]

-54> [[ true == (|[[:blank:]]*)(yes|true|on|1)(|[[:blank:]]*) ]]
-55> [[ ::: != :* || -z '' ]]
-56> return 0

+54> [[ false == (|[[:blank:]]*)(yes|true|on|1)(|[[:blank:]]*) ]]
+58> compstate[insert]=automenu-unambiguous

} ( "$KEYS" = $'\t' && "$tmp" = empty && ${#${BUFFER##$'\t'#}} -eq 0 )

You could do it that way, but the real problem is that you're testing
too early.  You want your test on line 54 for the "return 0" on line 56,
not on line 47 for the assignment to compstate[insert].  See below.

Index: Completion/Base/Core/_main_complete
===================================================================
diff -c -r1.12 _main_complete
--- Completion/Base/Core/_main_complete	21 Dec 2010 16:41:14 -0000	1.12
+++ Completion/Base/Core/_main_complete	23 May 2011 02:24:10 -0000
@@ -51,7 +51,9 @@
 fi
 
 if [[ "$compstate[insert]" = tab* ]]; then
-  { [[ "$tmp" = (|[[:blank:]]*)(yes|true|on|1)(|[[:blank:]]*) ]] &&
+  { [[ "$tmp" = (|[[:blank:]]*)(yes|true|on|1)(|[[:blank:]]*) ||
+	( "$tmp" = (|[[:blank:]]*)empty(|[[:blank:]]*) &&
+	  ${#${BUFFER##$'\t'#}} -eq 0 ) ]] &&
     { [[ "$curcontext" != :* || -z "$compstate[vared]" ]] ||
         zstyle -t ":completion:vared${curcontext}:" insert-tab } } && return 0
 


  reply	other threads:[~2011-05-23  2:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-18 22:37 Mikael Magnusson
2011-05-19  5:47 ` Bart Schaefer
2011-05-19  9:36   ` Mikael Magnusson
2011-05-19 15:19     ` Bart Schaefer
2011-05-19 16:00       ` Mikael Magnusson
2011-05-20 21:55         ` Mikael Magnusson
2011-05-23  2:27           ` Bart Schaefer [this message]
2011-05-23  2:55             ` Mikael Magnusson
2011-05-23 16:57               ` Bart Schaefer
2011-05-23 17:11                 ` Mikael Magnusson
2011-05-24  2:55                   ` Bart Schaefer

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=110522192758.ZM718@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).