zsh-users
 help / color / mirror / code / Atom feed
* make history-complete-older do nothing on empty string
@ 2018-04-18  5:21 ` Vincent Bernat
  2018-04-18  8:40   ` Peter Stephenson
  0 siblings, 1 reply; 15+ messages in thread
From: Vincent Bernat @ 2018-04-18  5:21 UTC (permalink / raw)
  To: zsh-users

Hey!

I sometime hit M-/ by error and this invokes history-complete-older
which then blocks when the current word is empty and it takes me 5-10
seconds to be able to "kill" it. Is there a way to teach this function
to not complete anything on empty (or one-char) input?

Thanks!
-- 
The abuse of greatness is when it disjoins remorse from power.
		-- William Shakespeare, "Julius Caesar"


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18  5:21 ` make history-complete-older do nothing on empty string Vincent Bernat
@ 2018-04-18  8:40   ` Peter Stephenson
  2018-04-18  9:15     ` Vincent Bernat
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Stephenson @ 2018-04-18  8:40 UTC (permalink / raw)
  To: zsh-users

On Wed, 18 Apr 2018 07:21:35 +0200
Vincent Bernat <bernat@luffy.cx> wrote:

> Hey!
> 
> I sometime hit M-/ by error and this invokes history-complete-older
> which then blocks when the current word is empty and it takes me 5-10
> seconds to be able to "kill" it. Is there a way to teach this function
> to not complete anything on empty (or one-char) input?
> 
> Thanks!

I don't think that's a normal effect.

You can try and debug it this way:


_debug_history() {
  _complete_debug _history_complete_word
}
debug_history .complete-word _debug_history
bindkey '^[/' _debug_history


Then when you use the command you should get a log of what it was doing,
though if you have to abort you may well find you have to look for the
most recently created file in /tmp to discover what that was.  If
you get anything, post the result.

pws


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18  8:40   ` Peter Stephenson
@ 2018-04-18  9:15     ` Vincent Bernat
  2018-04-18  9:45       ` Peter Stephenson
  0 siblings, 1 reply; 15+ messages in thread
From: Vincent Bernat @ 2018-04-18  9:15 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

 ❦ 18 avril 2018 09:40 +0100, Peter Stephenson <p.stephenson@samsung.com> :

>> I sometime hit M-/ by error and this invokes history-complete-older
>> which then blocks when the current word is empty and it takes me 5-10
>> seconds to be able to "kill" it. Is there a way to teach this function
>> to not complete anything on empty (or one-char) input?
>
> I don't think that's a normal effect.
>
> You can try and debug it this way:
>
>
> _debug_history() {
>   _complete_debug _history_complete_word
> }
> debug_history .complete-word _debug_history
> bindkey '^[/' _debug_history

Not sure about the second line? debug_history doesn't exist. Shouldn't
it be a "zle" command?
-- 
Whenever you find that you are on the side of the majority, it is time
to reform.
		-- Mark Twain


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18  9:15     ` Vincent Bernat
@ 2018-04-18  9:45       ` Peter Stephenson
  2018-04-18 12:20         ` Vincent Bernat
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Stephenson @ 2018-04-18  9:45 UTC (permalink / raw)
  To: zsh-users

On Wed, 18 Apr 2018 11:15:46 +0200
Vincent Bernat <bernat@luffy.cx> wrote:
>  ❦ 18 avril 2018 09:40 +0100, Peter Stephenson
> <p.stephenson@samsung.com> :
> 
> >> I sometime hit M-/ by error and this invokes history-complete-older
> >> which then blocks when the current word is empty and it takes me
> >> 5-10 seconds to be able to "kill" it. Is there a way to teach this
> >> function to not complete anything on empty (or one-char) input?  
> >
> > I don't think that's a normal effect.
> >
> > You can try and debug it this way:
> >
> >
> > _debug_history() {
> >   _complete_debug _history_complete_word
> > }
> > debug_history .complete-word _debug_history
> > bindkey '^[/' _debug_history  
> 
> Not sure about the second line? debug_history doesn't exist. Shouldn't
> it be a "zle" command?

Sorry, yes, I tried this but copied it out of my history badly.  It's
got "zle -C" in front and there's an underscore (you should find
_debug_history is already autoloaded).  That's


_debug_history() {
  _complete_debug _history_complete_word
}
zle -C _debug_history .complete-word _debug_history
bindkey '^[/' _debug_history


pws


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18  9:45       ` Peter Stephenson
@ 2018-04-18 12:20         ` Vincent Bernat
  2018-04-18 12:58           ` Peter Stephenson
  0 siblings, 1 reply; 15+ messages in thread
From: Vincent Bernat @ 2018-04-18 12:20 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

 ❦ 18 avril 2018 10:45 +0100, Peter Stephenson <p.stephenson@samsung.com> :

> Sorry, yes, I tried this but copied it out of my history badly.  It's
> got "zle -C" in front and there's an underscore (you should find
> _debug_history is already autoloaded).  That's
>
>
> _debug_history() {
>   _complete_debug _history_complete_word
> }
> zle -C _debug_history .complete-word _debug_history
> bindkey '^[/' _debug_history

Thanks!

So, the result file is 700k

  +_history_complete_word:3> local expl direction stop curcontext=''
  +_history_complete_word:5> [[ -z '' ]]
  +_history_complete_word:6> curcontext=history-words:::
  +_history_complete_word:11> [[ _debug_history = *newer ]]
  +_history_complete_word:14> direction=older
  +_history_complete_word:17> zstyle -t :completion:history-words::::history-words stop
  +_history_complete_word:19> zstyle -T :completion:history-words::::history-words list
  +_history_complete_word:21> [[ self-insert = _history-complete-* ]]
  +_history_complete_word:70> _hist_stop=''
  +_history_complete_word:71> _hist_old_prefix=''
  +_history_complete_word:72> _history_complete_word_gen_matches
   +_history_complete_word_gen_matches:2> [[ -n '' ]]
   +_history_complete_word_gen_matches:4> _main_complete _history
    +_main_complete:11> local IFS=$' \t\n\C-@'
    +_main_complete:25> eval $'local -A _comp_caller_options;\n             _comp_caller_options=(${(kv)options[@]});\n             setopt localoptions localtraps localpatterns ${_comp_options[@]};\n             local IFS=$\' \\t\\r\\n\\0\';\n             builtin enable -p \\| \\~ \\( \\? \\* \\[ \\< \\^ \\# 2>&-;\n             exec </dev/null;\n             trap - ZERR;\n             local -a reply;\n             local REPLY;\n             local REPORTTIME;\n             unset REPORTTIME'
     +(eval):1> local -A _comp_caller_options
     +(eval):2> _comp_caller_options=( posixargzero off autolist on printexitvalue off kshzerosubscript off histreduceblanks off chaselinks off extendedglob on localloops off histnostore off automenu on globcomplete on unset on listpacked off promptsubst on shwordsplit off pathdirs off kshtypeset off listtypes on warncreateglobal off promptbang off dotglob off
[...]
     +_history:19> local opt expl max slice hmax=66742 beg=2
     +_history:21> zstyle -t :completion:history-words:history::: remove-all-dups
     +_history:22> opt=-
     +_history:27> zstyle -t :completion:history-words:history::: sort
     +_history:30> opt=-V
     +_history:33> zstyle -s :completion:history-words:history::: range max
     +_history:42> max=66742
     +_history:43> slice=66742
     +_history:46> PREFIX=''
     +_history:47> IPREFIX=''
     +_history:48> SUFFIX=''
     +_history:49> ISUFFIX=''
     +_history:54> local -a hslice
     +_history:55> [[ 0 -eq 0 && beg -lt max ]]
     +_history:56> [[ -n '' ]]
     +_history:58> hslice=(
[...my whole history]

I don't see where it should stop if there is no current word. I test
with "echo<space><meta-/>".

Thanks!
-- 
Use the fundamental control flow constructs.
            - The Elements of Programming Style (Kernighan & Plauger)


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 12:20         ` Vincent Bernat
@ 2018-04-18 12:58           ` Peter Stephenson
  2018-04-18 13:28             ` Peter Stephenson
  2018-04-18 16:11             ` Bart Schaefer
  0 siblings, 2 replies; 15+ messages in thread
From: Peter Stephenson @ 2018-04-18 12:58 UTC (permalink / raw)
  To: zsh-users

On Wed, 18 Apr 2018 14:20:42 +0200
Vincent Bernat <bernat@luffy.cx> wrote:
>    +_history:19> local opt expl max slice hmax=66742 beg=2
>     +_history:21> zstyle -t :completion:history-words:history::: remove-all-dups
>     +_history:22> opt=-
>     +_history:27> zstyle -t :completion:history-words:history::: sort
>     +_history:30> opt=-V
>     +_history:33> zstyle -s :completion:history-words:history::: range max
>     +_history:42> max=66742
>     +_history:43> slice=66742
>     +_history:46> PREFIX=''
>     +_history:47> IPREFIX=''
>     +_history:48> SUFFIX=''
>     +_history:49> ISUFFIX=''
>     +_history:54> local -a hslice
>     +_history:55> [[ 0 -eq 0 && beg -lt max ]]
>     +_history:56> [[ -n '' ]]
>     +_history:58> hslice=(

So when you interrupted it it was apparently reading in 66742 history
words; there's nothing further at the end of the file?  (We can tweak
complete_debug to add timing info if it's helpful, see below.)  Is the
behaviour acceptable if you use the style, for example:

zstyle ':completion:history-words:*' range 100

?

Here's a way of getting timing information in the debug by changing
_complete_debug (you'd probably have to copy it into your $fpath).

diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug
index 85a0f37..1ff7630 100644
--- a/Completion/Base/Widget/_complete_debug
+++ b/Completion/Base/Widget/_complete_debug
@@ -15,7 +15,7 @@ integer debug_fd=-1
   fi
 
   local -a debug_indent; debug_indent=( '%'{3..20}'(e. .)' )
-  local PROMPT4 PS4="${(j::)debug_indent}+%N:%i> "
+  local PROMPT4 PS4="${(j::)debug_indent}+%D{%S.%.}:%N:%i> "
   setopt xtrace
   : $ZSH_NAME $ZSH_VERSION
   ${1:-_main_complete}


pws


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 12:58           ` Peter Stephenson
@ 2018-04-18 13:28             ` Peter Stephenson
  2018-04-18 16:15               ` Vincent Bernat
  2018-04-18 16:11             ` Bart Schaefer
  1 sibling, 1 reply; 15+ messages in thread
From: Peter Stephenson @ 2018-04-18 13:28 UTC (permalink / raw)
  To: zsh-users

On Wed, 18 Apr 2018 13:58:17 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> So when you interrupted it it was apparently reading in 66742 history
> words; there's nothing further at the end of the file?  (We can tweak
> complete_debug to add timing info if it's helpful, see below.)

Come to think of it, the fact that it's outputting all those words for
debug purposes is going to make a big difference, so I'm not sure how
much this is telling us.  If this turns out not to be the crucial point,
we can disable debugging around it.

> Is the behaviour acceptable if you use the style, for example:
> 
> zstyle ':completion:history-words:*' range 100
> 
> ?

This should give some indication, though.

pws


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 12:58           ` Peter Stephenson
  2018-04-18 13:28             ` Peter Stephenson
@ 2018-04-18 16:11             ` Bart Schaefer
  2018-04-18 16:28               ` Vincent Bernat
  2018-04-18 18:41               ` Vincent Bernat
  1 sibling, 2 replies; 15+ messages in thread
From: Bart Schaefer @ 2018-04-18 16:11 UTC (permalink / raw)
  To: Zsh Users

On Wed, Apr 18, 2018 at 5:58 AM, Peter Stephenson
<p.stephenson@samsung.com> wrote:
>
> So when you interrupted it it was apparently reading in 66742 history
> words

Some people have really large shell history.  Manipulating that many
completion possibilities takes a long time.

Vincent, what version of zsh are you running?  There were some memory
management optimizations done in the past year or so that might speed
up large history accesses in general.

Although it would be nice to find out exactly what part of completion
is occupying time in this case (if only so that we might look into
making it interruptible), to answer the original question:

You'd want a wrapper around _history_complete_word to check the state
of the editor buffer, or you could copy that function to a location at
the front of your $fpath and modify it.  The test you want is probably
something like:

[[ ${LBUFFER:- } == ' ' && ${RBUFFER:- } == ' ' ]] && return 1

There's a space after :- in both of those references.  This means "if
either the buffer is empty or the cursor is sitting in the middle of a
run of spaces, then return" (i.e. don't complete anything).


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 13:28             ` Peter Stephenson
@ 2018-04-18 16:15               ` Vincent Bernat
  0 siblings, 0 replies; 15+ messages in thread
From: Vincent Bernat @ 2018-04-18 16:15 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

 ❦ 18 avril 2018 14:28 +0100, Peter Stephenson <p.stephenson@samsung.com> :

>> So when you interrupted it it was apparently reading in 66742 history
>> words; there's nothing further at the end of the file?  (We can tweak
>> complete_debug to add timing info if it's helpful, see below.)
>
> Come to think of it, the fact that it's outputting all those words for
> debug purposes is going to make a big difference, so I'm not sure how
> much this is telling us.  If this turns out not to be the crucial point,
> we can disable debugging around it.

There was additional output, but I thought it was meaningless since I
think it shouldn't try to complete at all when the current word is
empty.

For the remaining:

http://paste.debian.net/1020908/

>
>> Is the behaviour acceptable if you use the style, for example:
>> 
>> zstyle ':completion:history-words:*' range 100
>> 
>> ?
>
> This should give some indication, though.

Yes, with this, it works fast. However, it doesn't use all history
anymore for regular completion. The search is done only on the last 100
items of the history. I would prefer to have complete completion when
there is at least one character in the current word and nothing when
not. I don't think people are interested to expand the empty word with
the content of the history.

In the meantime, this is a good workaround. Thanks!
-- 
It is a wise father that knows his own child.
		-- William Shakespeare, "The Merchant of Venice"


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 16:11             ` Bart Schaefer
@ 2018-04-18 16:28               ` Vincent Bernat
  2018-04-18 18:41               ` Vincent Bernat
  1 sibling, 0 replies; 15+ messages in thread
From: Vincent Bernat @ 2018-04-18 16:28 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

 ❦ 18 avril 2018 09:11 -0700, Bart Schaefer <schaefer@brasslantern.com> :

> You'd want a wrapper around _history_complete_word to check the state
> of the editor buffer, or you could copy that function to a location at
> the front of your $fpath and modify it.  The test you want is probably
> something like:
>
> [[ ${LBUFFER:- } == ' ' && ${RBUFFER:- } == ' ' ]] && return 1
>
> There's a space after :- in both of those references.  This means "if
> either the buffer is empty or the cursor is sitting in the middle of a
> run of spaces, then return" (i.e. don't complete anything).

Thanks, I am using this and it works as I would expect:

#v+
# Don't do history completion on empty words
function vbe-history-complete-older() {
  [[ ${LBUFFER[-1]} == ' ' || ${LBUFFER} == '' ]] && return 1
  zle _history-complete-older "$@"
}
zle -N vbe-history-complete-older
bindkey "^[/" vbe-history-complete-older
#v-

-- 
Harp not on that string.
		-- William Shakespeare, "Henry VI"


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 16:11             ` Bart Schaefer
  2018-04-18 16:28               ` Vincent Bernat
@ 2018-04-18 18:41               ` Vincent Bernat
  2018-04-18 18:53                 ` Ray Andrews
  1 sibling, 1 reply; 15+ messages in thread
From: Vincent Bernat @ 2018-04-18 18:41 UTC (permalink / raw)
  To: Zsh Users

 ❦ 18 avril 2018 09:11 -0700, Bart Schaefer <schaefer@brasslantern.com> :

> Vincent, what version of zsh are you running?  There were some memory
> management optimizations done in the past year or so that might speed
> up large history accesses in general.

FI, it is 5.5.1. And HISTFILE is set to 20000 (since years).
-- 
Follow each decision as closely as possible with its associated action.
            - The Elements of Programming Style (Kernighan & Plauger)


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 18:41               ` Vincent Bernat
@ 2018-04-18 18:53                 ` Ray Andrews
  2018-04-19  5:49                   ` Vincent Bernat
  0 siblings, 1 reply; 15+ messages in thread
From: Ray Andrews @ 2018-04-18 18:53 UTC (permalink / raw)
  To: zsh-users

On 18/04/18 11:41 AM, Vincent Bernat wrote:
>   ❦ 18 avril 2018 09:11 -0700, Bart Schaefer <schaefer@brasslantern.com> :
>
>> Vincent, what version of zsh are you running?  There were some memory
>> management optimizations done in the past year or so that might speed
>> up large history accesses in general.
> FI, it is 5.5.1. And HISTFILE is set to 20000 (since years).

Just curious: Why would completion on an empty string everbe useful?


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

* Re: make history-complete-older do nothing on empty string
  2018-04-18 18:53                 ` Ray Andrews
@ 2018-04-19  5:49                   ` Vincent Bernat
  2037-12-03 12:10                     ` Ray Andrews
  0 siblings, 1 reply; 15+ messages in thread
From: Vincent Bernat @ 2018-04-19  5:49 UTC (permalink / raw)
  To: zsh-users

 ❦ 18 avril 2018 11:53 -0700, Ray Andrews <rayandrews@eastlink.ca> :

>>> Vincent, what version of zsh are you running?  There were some memory
>>> management optimizations done in the past year or so that might speed
>>> up large history accesses in general.
>> FI, it is 5.5.1. And HISTFILE is set to 20000 (since years).
>
> Just curious: Why would completion on an empty string everbe useful?

Dunno. I want it to do nothing too if that's what you are asking.
-- 
When one burns one's bridges, what a very nice fire it makes.
		-- Dylan Thomas


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

* Re: make history-complete-older do nothing on empty string
  2018-04-19  5:49                   ` Vincent Bernat
@ 2037-12-03 12:10                     ` Ray Andrews
  2037-12-03 14:36                       ` Ray Andrews
  0 siblings, 1 reply; 15+ messages in thread
From: Ray Andrews @ 2037-12-03 12:10 UTC (permalink / raw)
  To: zsh-users

On 18/04/18 10:49 PM, Vincent Bernat wrote:
>   ❦ 18 avril 2018 11:53 -0700, Ray Andrews <rayandrews@eastlink.ca> :
>
>>>> Vincent, what version of zsh are you running?  There were some memory
>>>> management optimizations done in the past year or so that might speed
>>>> up large history accesses in general.
>>> FI, it is 5.5.1. And HISTFILE is set to 20000 (since years).
>> Just curious: Why would completion on an empty string everbe useful?
> Dunno. I want it to do nothing too if that's what you are asking.
Yeah.  It seems to me that the thing would/should know that it has 
nothing to do.  It's sorta like writing a program to find the first 
prime number divisible by two, the program will run for a long time 
without producing much.  I'm wondering if the devs just overlooked that, 
or if perhaps the idea of completion on an empty string might actually 
have some sort of meaning.  Completion seems to be such a complex thing 
that maybe it does -- the sound of one hand clapping.



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

* Re: make history-complete-older do nothing on empty string
  2037-12-03 12:10                     ` Ray Andrews
@ 2037-12-03 14:36                       ` Ray Andrews
  0 siblings, 0 replies; 15+ messages in thread
From: Ray Andrews @ 2037-12-03 14:36 UTC (permalink / raw)
  To: zsh-users

On 03/12/37 04:10 AM, Ray Andrews wrote:
> Dunno. I want it to do nothing too if that's what you are asking.
> Yeah.  It seems to me that the thing would/should know that it has 
> nothing to do.  It's sorta like writing a program to find the first 
> prime number divisible by two, the program will run for a long time 
> without producing much.  I'm wondering if the devs just overlooked 
> that, or if perhaps the idea of completion on an empty string might 
> actually have some sort of meaning.  Completion seems to be such a 
> complex thing that maybe it does -- the sound of one hand clapping.
>
Come to think, that's bad logic.  The reverse is the case.  Since 
completion is a progressive exclusion, if the search string is empty, 
then everything is matched because nothing is excluded.  It might not be 
very useful, but it is not logically invalid.
>
>


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

end of thread, other threads:[~2018-04-19 18:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180418052832epcas2p1df623a44c88edae226f65a2d5edc90f2@epcas2p1.samsung.com>
2018-04-18  5:21 ` make history-complete-older do nothing on empty string Vincent Bernat
2018-04-18  8:40   ` Peter Stephenson
2018-04-18  9:15     ` Vincent Bernat
2018-04-18  9:45       ` Peter Stephenson
2018-04-18 12:20         ` Vincent Bernat
2018-04-18 12:58           ` Peter Stephenson
2018-04-18 13:28             ` Peter Stephenson
2018-04-18 16:15               ` Vincent Bernat
2018-04-18 16:11             ` Bart Schaefer
2018-04-18 16:28               ` Vincent Bernat
2018-04-18 18:41               ` Vincent Bernat
2018-04-18 18:53                 ` Ray Andrews
2018-04-19  5:49                   ` Vincent Bernat
2037-12-03 12:10                     ` Ray Andrews
2037-12-03 14:36                       ` Ray Andrews

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