zsh-workers
 help / color / mirror / code / Atom feed
* auto list choices
@ 2013-03-07  3:57 joe M
  2013-03-07  4:23 ` joe M
  0 siblings, 1 reply; 7+ messages in thread
From: joe M @ 2013-03-07  3:57 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]

Hello,

Not sure how useful this is, but, the attached file does a
list-choices for each self-insert.

I am wondering if anyone has experimented with using
incremental-complete-word switched on, by default. Similar to how
predict-on works. Inserting the prediction into the command line, by
default, and allowing the user to type over the prediction or select
it, etc.

I tried binding complete-word to self-insert and realized that the
solution is not practical. To have complete-word work on each
self-insert, it has to work in a while loop similar to how
incremental-complete-word does.

I tried incr-0.2.zsh, but, that uses the old style
expand-or-complete-prefix. Auto-fu is cool, but, the code seems too
complicated.

Any thoughts, please?

Thanks
Joe

[-- Attachment #2: 80-auto-list-choices.zsh --]
[-- Type: application/octet-stream, Size: 3919 bytes --]

# basde on
#  incremental completion for zsh
#  by y.fujii <y-fujii at mimosa-pudica.net>, public domain

zle -N self-insert self-insert-incr
zle -N vi-backward-delete-char-incr

# got the below idea from bart's email
# > I realize that setopt xtrace and verbose do not help with the widgets.
# Of course they do.  You just have to direct stderr somewhere other than
# the screen.
# Suppose you have a widget you normally define like this:
#    _buggy() {
#       zle beep
#       : other broken stuff
#    }
#    zle -N _buggy
# You can put a wrapper widget around it like so:
#    _debug_buggy() {
#       {
#          setopt localoptions xtrace
#          _buggy "$@"
#       } 2>>| ${TMPPREFIX}_buggy$$
#    }
#    zle -N _buggy _debug_buggy
# Now each time you invoke the binding for _buggy, you'll get output
# appended to the temp file.  If you stick to the convention of naming
# your functions and widgets the same, you can make it generic:
#    _debug_widget() {
#       {
#          setopt localoptions xtrace
#          $WIDGET "$@"
#       } 2>>| ${TMPPREFIX}${WIDGET}$$
#    }
#    zle -N _buggy _debug_widget
#    zle -N _other _debug_widget
# For a more extensive example of this sort of thing, see _complete_debug
# (bound by default to ^X?).
function _debug_widget(){
   {
   setopt localoptions verbose xtrace
   $WIDGET "$@"
   } 2>>| ${TMPPREFIX}${WIDGET}$$
}
# got the below alignment with
#  or, below
#  :52,56s/\s\+/ /g
#  '<,'>Tabularize /\s/l0c0
zle -N self-insert-incr             _debug_widget
zle -N vi-backward-delete-char-incr _debug_widget
# zle -N backward-delete-char-incr    _debug_widget

bindkey -M viins '^h' vi-backward-delete-char-incr
bindkey -M viins '^?' vi-backward-delete-char-incr

bindkey -M viins -R "^A"-"^C" self-insert-incr
bindkey -M viins -R "^E"-"^F" self-insert-incr
bindkey -M viins "^K" self-insert-incr
bindkey -M viins -R "^O"-"^P" self-insert-incr
bindkey -M viins -R "^S"-"^T" self-insert-incr
bindkey -M viins "^X" self-insert-incr
bindkey -M viins -R "^Y"-"^Z" self-insert-incr
bindkey -M viins -R "^\\\\"-"^_" self-insert-incr
bindkey -M viins -R "!"-"i" self-insert-incr
bindkey -M viins -R "j"-"~" self-insert-incr
bindkey -M viins -R "\M-^@"-"\M-^?" self-insert-incr

# to increase the incr-0.2 max matches
export INCR_MAX_MATCHES=60

# function limit-completion () {
#    if ((compstate[nmatches] <= 1)); then
#       zle -M ""
#    elif ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20})); then
#       compstate[list]=""
#       zle -M "too many matches."
#    fi
# }
function limit-completion () {
   # got the line comparing with LINES from
   #  /usr/share/zsh/5.0.2/functions/Zle/incremental-complete-word
   if ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20} \
        || compstate[list_lines]+BUFFERLINES+2 > LINES))
   then
      compstate[list]=''
      zle -M "too many matches."
   fi
}

function self-insert-incr () {
   if zle .self-insert; then
      show-choices
      # complete-word-incr
   fi
}

function vi-backward-delete-char-incr () {
   if zle vi-backward-delete-char; then
      show-choices
      # complete-word-incr
   fi
}

function show-choices () {
   # local cursor_org
   # local buffer_org
   # local cursor_now
   # local buffer_now
   # cursor_org="$CURSOR"
   # buffer_org="$BUFFER"
   comppostfuncs=(limit-completion)
   zle list-choices
   # cursor_now="$CURSOR"
   # buffer_now="$BUFFER"
}

function complete-word-incr () {
   local cursor_org
   local buffer_org
   local cursor_now
   local buffer_now
   local lbuffer_now
   cursor_org="$CURSOR"
   buffer_org="$BUFFER"
   comppostfuncs=(limit-completion)
   zle complete-word
   cursor_now="$CURSOR"
   buffer_now="$BUFFER"
   lbuffer_now="$LBUFFER"
   # if [ "$cursor_now" -gt "$cursor_org" \
   #    -a "$buffer_org[1,cursor_org]" == "$buffer_now[1,cursor_org]" \
   #    -a "$lbuffer_now[-1]" == " " ]
   # then
   #    CURSOR="$cursor_org"
   # fi
}

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

* Re: auto list choices
  2013-03-07  3:57 auto list choices joe M
@ 2013-03-07  4:23 ` joe M
  2013-03-07  4:35   ` joe M
  0 siblings, 1 reply; 7+ messages in thread
From: joe M @ 2013-03-07  4:23 UTC (permalink / raw)
  To: zsh-workers

Hello,


> Not sure how useful this is, but, the attached file does a
> list-choices for each self-insert.

For some reason, when I call list-choices on every self-insert, it
messes up the history commands. For example, When I type '!', it lists
'\!' as a 'reserved word'. When I type in a number, it automatically
expands that number to the history line at that number. It does not
even let me complete the history number. For example, if I want to
type in '!123', it automatically changes the current line under the
cursor to '<history line at line 1>23'.

Any thoughts, please?

Thanks
Joe


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

* Re: auto list choices
  2013-03-07  4:23 ` joe M
@ 2013-03-07  4:35   ` joe M
  2013-03-08 15:48     ` joe M
  0 siblings, 1 reply; 7+ messages in thread
From: joe M @ 2013-03-07  4:35 UTC (permalink / raw)
  To: zsh-workers

Hello,

> For some reason, when I call list-choices on every self-insert, it
> messes up the history commands. For example, When I type '!', it lists

Where is the list-choices code? I see a compdef -k list-choices in the
_next_tags file. But, not sure if that is the actual code that is run
when list-choices is called?

Thanks
Joe


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

* Re: auto list choices
  2013-03-07  4:35   ` joe M
@ 2013-03-08 15:48     ` joe M
  2013-03-09 15:25       ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: joe M @ 2013-03-08 15:48 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 105 bytes --]

Hello,

This code does a list-choices on every self-insert. Might be of
interest to someone.

Thanks
Joe

[-- Attachment #2: 80-auto-list-choices.zsh --]
[-- Type: application/octet-stream, Size: 3047 bytes --]

# basde on
#  incremental completion for zsh
#  by y.fujii <y-fujii at mimosa-pudica.net>, public domain

zle -N self-insert self-insert-incr
# zle -N vi-backward-delete-char-incr

# bindkey -M viins '^h' vi-backward-delete-char-incr
# bindkey -M viins '^?' vi-backward-delete-char-incr

# to increase the incr-0.2 max matches
export INCR_MAX_MATCHES=60

# function limit-completion () {
#    if ((compstate[nmatches] <= 1)); then
#       zle -M ""
#    elif ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20})); then
#       compstate[list]=""
#       zle -M "too many matches."
#    fi
# }
function limit-completion () {
   # got the line comparing with LINES from
   #  /usr/share/zsh/5.0.2/functions/Zle/incremental-complete-word
   if ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20} \
        || compstate[list_lines]+BUFFERLINES+2 > LINES))
   then
      compstate[list]=''
      zle -M "too many matches."
   fi
}

function self-insert-incr () {
   if zle .self-insert; then
      show-choices
      # complete-word-incr
   fi
}

function vi-backward-delete-char-incr () {
   if zle vi-backward-delete-char; then
      show-choices
      # complete-word-incr
   fi
}

function show-choices () {
   # local cursor_org
   # local buffer_org
   # local cursor_now
   # local buffer_now
   # cursor_org="$CURSOR"
   # buffer_org="$BUFFER"
   # if [[ "$BUFFER[1]" != "!" ]]
   # echo $widgets[list-choices]
   #  user:_zsh_highlight_widget_list-choices
   # mv 91-history-substring-search.zsh \
   #     91-history-substring-search.zsh.disable
   # rm 90-syntax.zsh
   # echo $widgets[list-choices]
   #  completion:.list-choices:_main_complete
   # compinit is redirecting list-choices to _main_complete
   #  and the _normal called by _main_complete is doing a
   #  bang expansion as soon as it sees a ! in the string
   #  Hence, do not call list-choices if there is a ! in that line
   #  or, instead of filtering $BUFFER on !, unsetopt BANG_HIST
   #  as list-choices is checking on BANG_HIST before expanding
   #  the !.
   # if [[ "$BUFFER" != *\!* && \
   unsetopt localoptions BANG_HIST
   # do not list-choices if it is a paste, pending > 0 in such cases
   # do not list-choices if editing in the middle of a word
   if [[ "$PENDING" -eq 0  && \
         ( -z "$RBUFFER" || "$RBUFFER[1]" == ' ' )
         ]]
   then
      comppostfuncs=(limit-completion)
      zle list-choices
   fi
   # cursor_now="$CURSOR"
   # buffer_now="$BUFFER"
}

function complete-word-incr () {
   local cursor_org
   local buffer_org
   local cursor_now
   local buffer_now
   local lbuffer_now
   cursor_org="$CURSOR"
   buffer_org="$BUFFER"
   comppostfuncs=(limit-completion)
   zle complete-word
   cursor_now="$CURSOR"
   buffer_now="$BUFFER"
   lbuffer_now="$LBUFFER"
   # if [ "$cursor_now" -gt "$cursor_org" \
   #    -a "$buffer_org[1,cursor_org]" == "$buffer_now[1,cursor_org]" \
   #    -a "$lbuffer_now[-1]" == " " ]
   # then
   #    CURSOR="$cursor_org"
   # fi
}

# vim: set filetype=zsh shiftwidth=3 tabstop=3 expandtab fileformat=unix

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

* Re: auto list choices
  2013-03-08 15:48     ` joe M
@ 2013-03-09 15:25       ` Bart Schaefer
  2013-03-10  5:45         ` joe M
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2013-03-09 15:25 UTC (permalink / raw)
  To: zsh-workers

On Mar 8, 10:48am, joe M wrote:
} 
} This code does a list-choices on every self-insert. Might be of
} interest to someone.

Some brief critique:

(1) It's annoying to use application/octet-stream for text attachments.
This probably isn't your fault, you just have a broken email program,
or you haven't told it that the ".zsh" extension means a text type.

(2) In this line in list-completion:

   if ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20} \
        || compstate[list_lines]+BUFFERLINES+2 > LINES))

The backslash-continuation is not necessary, "((" begins a syntactic
construct which continues even across newlines to the matching "))".

(3) In show-choices, this:

   unsetopt localoptions BANG_HIST

is not doing what you want.  This UNSETS the localoptions option, which
makes the unset of BANG_HIST become permanent outside the function.  You
meant

   setopt localoptions NO_BANG_HIST

or more verbosely

   setopt localoptions; unsetopt BANG_HIST

However, locally unsetting BANG_HIST is the correct solution to the
problem you were having, so good job figuring that out.


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

* Re: auto list choices
  2013-03-09 15:25       ` Bart Schaefer
@ 2013-03-10  5:45         ` joe M
  2013-03-10 18:23           ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: joe M @ 2013-03-10  5:45 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 3729 bytes --]

Hello Bart,

Thanks a lot for responding. I find your comments very informative and
a treasure trove for me.

> Some brief critique:
>
> (1) It's annoying to use application/octet-stream for text attachments.
> This probably isn't your fault, you just have a broken email program,
> or you haven't told it that the ".zsh" extension means a text type.

gmail is adding application/octet-stream. I will send both the .zsh
file and a .txt file.

> (2) In this line in list-completion:
>
>    if ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20} \
>         || compstate[list_lines]+BUFFERLINES+2 > LINES))
>
> The backslash-continuation is not necessary, "((" begins a syntactic
> construct which continues even across newlines to the matching "))".

On a slightly different note, I do not feel comfortable using the ((
.. )) construct as it does not show up properly in the xtrace/verbose
log. This is how it shows up.

+limit-completion:21> (( compstate[list_lines] > 60         ||
compstate[list_lines]+BUFFERLINES+2 > LINES ))

whereas the [[ .. ]] construct shows up like this:

+limit-completion:23> [[ 7 -gt 60 ||+limit-completion:23> expr 7 + 2 + 2
+limit-completion:23> [[ 7 -gt 60 || 11 -gt 47 ]]

I think the [[ .. ]] is more comprehensible.


>    setopt localoptions; unsetopt BANG_HIST
>
> However, locally unsetting BANG_HIST is the correct solution to the
> problem you were having, so good job figuring that out.

Fixed it. I picked the above localoptions from your earlier code on
_debug_widget.

I could not figure out why the below lines do not work. They return a blank.

   echo "4: $(expr ${compstate[list_lines]})"
   echo "5: $(expr $compstate[list_lines])"
   echo "6: $(expr $compstate[list_lines] + $BUFFERLINES)"
   echo "7: $(expr $compstate[list_lines] + $BUFFERLINES + 2)"

They are in lines 42 .. 45 of the attached script.

The debugging output from the lines 35 .. 57 of the attached file is:

+limit-completion:7> echo 'started limit-completion'
started limit-completion
+limit-completion:8> echo 'compstate[list_lines]: 8'
compstate[list_lines]: 8
+limit-completion:9> echo 'INCR_MAX_MATCHES: 60'
INCR_MAX_MATCHES: 60
+limit-completion:10> echo 'BUFFERLINES: 2'
BUFFERLINES: 2
+limit-completion:11> echo 'list_lines: 8'
list_lines: 8
+limit-completion:12> expr 8 + 2 + 2
+limit-completion:12> echo 'expr list_lines: 12'
expr list_lines: 12
+limit-completion:13> echo '----- no idea why these below lines do not work'
----- no idea why these below lines do not work
+limit-completion:14> echo '4: '
4:
+limit-completion:15> echo '5: '
5:
+limit-completion:16> echo '6: '
6:
+limit-completion:17> echo '7: '
7:
+limit-completion:18> echo '----- no idea why the above lines do not work'
----- no idea why the above lines do not work
+limit-completion:19> echo 'LINES: 47'
LINES: 47
+limit-completion:20> echo 'ended limit-completion'
ended limit-completion
+limit-completion:23> [[ 8 -gt 60 ||+limit-completion:23> expr 8 + 2 + 2
+limit-completion:23> [[ 8 -gt 60 || 12 -gt 47 ]]

Whereas, when I tried the associative array workings from the command
line, it worked fine:
- (0:c:/tmp)  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
typeset -A NAME
- (0:c:/tmp)  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
NAME=(test1 1 test2 2 test3 3 test4 4)
- (0:i:/tmp)  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
echo $NAME
1 2 3 4
- (0:i:/tmp)  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
echo $NAME[test1]
1
- (0:i:/tmp)  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
expr $NAME[test1] + 2
3
- (0:i:/tmp)  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
echo $(expr $NAME[test1] + 2)
3
- (0:i:/tmp)  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
echo "$(expr $NAME[test1] + 2)"
3

Any thoughts, please?

Thanks
Joe

[-- Attachment #2: 80-auto-list-choices.zsh.txt --]
[-- Type: text/plain, Size: 4354 bytes --]

#!/usr/bin/zsh

# based on
#  incremental completion for zsh
#  by y.fujii <y-fujii at mimosa-pudica.net>, public domain

# got the below alignment with
#  or, below
#  :11,12s/\s\+/ /g
#  '<,'>Tabularize /\s/l0c0
zle -N self-insert      self-insert-incr
# zle -N vi-backward-delete-char-incr

# bindkey -M viins '^h' vi-backward-delete-char-incr
# bindkey -M viins '^?' vi-backward-delete-char-incr

# to increase the incr-0.2 max matches
export INCR_MAX_MATCHES=60

# function limit-completion () {
#    if ((compstate[nmatches] <= 1)); then
#       zle -M ""
#    elif ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20})); then
#       compstate[list]=""
#       zle -M "too many matches."
#    fi
# }
function limit-completion () {
   # got the line comparing with LINES from
   #  /usr/share/zsh/5.0.2/functions/Zle/incremental-complete-word
   local list_lines
   list_lines=$compstate[list_lines]
   {
   setopt localoptions xtrace verbose
   echo "started limit-completion"
   echo "compstate[list_lines]: $compstate[list_lines]"
   echo "INCR_MAX_MATCHES: ${INCR_MAX_MATCHES:-20}"
   echo "BUFFERLINES: $BUFFERLINES"
   echo "list_lines: $list_lines"
   echo "expr list_lines: $(expr $list_lines + $BUFFERLINES + 2)"
   echo "----- no idea why these below lines do not work"
   echo "4: $(expr ${compstate[list_lines]})"
   echo "5: $(expr $compstate[list_lines])"
   echo "6: $(expr $compstate[list_lines] + $BUFFERLINES)"
   echo "7: $(expr $compstate[list_lines] + $BUFFERLINES + 2)"
   echo "----- no idea why the above lines do not work"
   echo "LINES: $LINES"
   echo "ended limit-completion"
   # if ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20} \
   #      || compstate[list_lines]+BUFFERLINES+2 > LINES))
   if [[ "$list_lines" -gt "${INCR_MAX_MATCHES:-20}" \
         || $(expr $list_lines + $BUFFERLINES + 2) -gt "$LINES" ]]
   then
      compstate[list]=''
      zle -M "too many matches."
   fi
   }  2>>| /tmp/zsh-limit-completion.log 1>&2
}

function self-insert-incr () {
   # echo "started self-insert-incr"
   if zle .self-insert; then
      show-choices
      # complete-word-incr
   fi
}

function vi-backward-delete-char-incr () {
   if zle vi-backward-delete-char; then
      show-choices
      # complete-word-incr
   fi
}

function show-choices () {
   # local cursor_org
   # local buffer_org
   # local cursor_now
   # local buffer_now
   # cursor_org="$CURSOR"
   # buffer_org="$BUFFER"
   # if [[ "$BUFFER[1]" != "!" ]]
   # echo $widgets[list-choices]
   #  user:_zsh_highlight_widget_list-choices
   # mv 91-history-substring-search.zsh \
   #     91-history-substring-search.zsh.disable
   # rm 90-syntax.zsh
   # echo $widgets[list-choices]
   #  completion:.list-choices:_main_complete
   # compinit is redirecting list-choices to _main_complete
   #  and the _normal called by _main_complete is doing a
   #  bang expansion as soon as it sees a ! in the string
   #  Hence, do not call list-choices if there is a ! in that line
   #  or, instead of filtering $BUFFER on !, unsetopt BANG_HIST
   #  as list-choices is checking on BANG_HIST before expanding
   #  the !.
   # if [[ "$BUFFER" != *\!* && \
     setopt localoptions
   unsetopt BANG_HIST
   # setopt xtrace verbose
   # do not list-choices if there is a ! in that word
   #  but, as I could not figure out the word vs line,
   #  just skipping on any line with a !
   # do not list-choices if it is a paste, pending > 0 in such cases
   # do not list-choices if editing in the middle of a word
   if [[ "$BUFFER" != *\!* \
         && "$PENDING" -eq 0  \
         && ( -z "$RBUFFER" || "$RBUFFER[1]" == ' ' ) \
         ]]
   then
      comppostfuncs=(limit-completion)
      zle list-choices
   fi
   # cursor_now="$CURSOR"
   # buffer_now="$BUFFER"
}

function complete-word-incr () {
   local cursor_org
   local buffer_org
   local cursor_now
   local buffer_now
   local lbuffer_now
   cursor_org="$CURSOR"
   buffer_org="$BUFFER"
   comppostfuncs=(limit-completion)
   zle complete-word
   cursor_now="$CURSOR"
   buffer_now="$BUFFER"
   lbuffer_now="$LBUFFER"
   # if [ "$cursor_now" -gt "$cursor_org" \
   #    -a "$buffer_org[1,cursor_org]" == "$buffer_now[1,cursor_org]" \
   #    -a "$lbuffer_now[-1]" == " " ]
   # then
   #    CURSOR="$cursor_org"
   # fi
}

# vim: set filetype=zsh shiftwidth=3 tabstop=3 expandtab fileformat=unix

[-- Attachment #3: 80-auto-list-choices.zsh --]
[-- Type: application/octet-stream, Size: 4354 bytes --]

#!/usr/bin/zsh

# based on
#  incremental completion for zsh
#  by y.fujii <y-fujii at mimosa-pudica.net>, public domain

# got the below alignment with
#  or, below
#  :11,12s/\s\+/ /g
#  '<,'>Tabularize /\s/l0c0
zle -N self-insert      self-insert-incr
# zle -N vi-backward-delete-char-incr

# bindkey -M viins '^h' vi-backward-delete-char-incr
# bindkey -M viins '^?' vi-backward-delete-char-incr

# to increase the incr-0.2 max matches
export INCR_MAX_MATCHES=60

# function limit-completion () {
#    if ((compstate[nmatches] <= 1)); then
#       zle -M ""
#    elif ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20})); then
#       compstate[list]=""
#       zle -M "too many matches."
#    fi
# }
function limit-completion () {
   # got the line comparing with LINES from
   #  /usr/share/zsh/5.0.2/functions/Zle/incremental-complete-word
   local list_lines
   list_lines=$compstate[list_lines]
   {
   setopt localoptions xtrace verbose
   echo "started limit-completion"
   echo "compstate[list_lines]: $compstate[list_lines]"
   echo "INCR_MAX_MATCHES: ${INCR_MAX_MATCHES:-20}"
   echo "BUFFERLINES: $BUFFERLINES"
   echo "list_lines: $list_lines"
   echo "expr list_lines: $(expr $list_lines + $BUFFERLINES + 2)"
   echo "----- no idea why these below lines do not work"
   echo "4: $(expr ${compstate[list_lines]})"
   echo "5: $(expr $compstate[list_lines])"
   echo "6: $(expr $compstate[list_lines] + $BUFFERLINES)"
   echo "7: $(expr $compstate[list_lines] + $BUFFERLINES + 2)"
   echo "----- no idea why the above lines do not work"
   echo "LINES: $LINES"
   echo "ended limit-completion"
   # if ((compstate[list_lines] > ${INCR_MAX_MATCHES:-20} \
   #      || compstate[list_lines]+BUFFERLINES+2 > LINES))
   if [[ "$list_lines" -gt "${INCR_MAX_MATCHES:-20}" \
         || $(expr $list_lines + $BUFFERLINES + 2) -gt "$LINES" ]]
   then
      compstate[list]=''
      zle -M "too many matches."
   fi
   }  2>>| /tmp/zsh-limit-completion.log 1>&2
}

function self-insert-incr () {
   # echo "started self-insert-incr"
   if zle .self-insert; then
      show-choices
      # complete-word-incr
   fi
}

function vi-backward-delete-char-incr () {
   if zle vi-backward-delete-char; then
      show-choices
      # complete-word-incr
   fi
}

function show-choices () {
   # local cursor_org
   # local buffer_org
   # local cursor_now
   # local buffer_now
   # cursor_org="$CURSOR"
   # buffer_org="$BUFFER"
   # if [[ "$BUFFER[1]" != "!" ]]
   # echo $widgets[list-choices]
   #  user:_zsh_highlight_widget_list-choices
   # mv 91-history-substring-search.zsh \
   #     91-history-substring-search.zsh.disable
   # rm 90-syntax.zsh
   # echo $widgets[list-choices]
   #  completion:.list-choices:_main_complete
   # compinit is redirecting list-choices to _main_complete
   #  and the _normal called by _main_complete is doing a
   #  bang expansion as soon as it sees a ! in the string
   #  Hence, do not call list-choices if there is a ! in that line
   #  or, instead of filtering $BUFFER on !, unsetopt BANG_HIST
   #  as list-choices is checking on BANG_HIST before expanding
   #  the !.
   # if [[ "$BUFFER" != *\!* && \
     setopt localoptions
   unsetopt BANG_HIST
   # setopt xtrace verbose
   # do not list-choices if there is a ! in that word
   #  but, as I could not figure out the word vs line,
   #  just skipping on any line with a !
   # do not list-choices if it is a paste, pending > 0 in such cases
   # do not list-choices if editing in the middle of a word
   if [[ "$BUFFER" != *\!* \
         && "$PENDING" -eq 0  \
         && ( -z "$RBUFFER" || "$RBUFFER[1]" == ' ' ) \
         ]]
   then
      comppostfuncs=(limit-completion)
      zle list-choices
   fi
   # cursor_now="$CURSOR"
   # buffer_now="$BUFFER"
}

function complete-word-incr () {
   local cursor_org
   local buffer_org
   local cursor_now
   local buffer_now
   local lbuffer_now
   cursor_org="$CURSOR"
   buffer_org="$BUFFER"
   comppostfuncs=(limit-completion)
   zle complete-word
   cursor_now="$CURSOR"
   buffer_now="$BUFFER"
   lbuffer_now="$LBUFFER"
   # if [ "$cursor_now" -gt "$cursor_org" \
   #    -a "$buffer_org[1,cursor_org]" == "$buffer_now[1,cursor_org]" \
   #    -a "$lbuffer_now[-1]" == " " ]
   # then
   #    CURSOR="$cursor_org"
   # fi
}

# vim: set filetype=zsh shiftwidth=3 tabstop=3 expandtab fileformat=unix

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

* Re: auto list choices
  2013-03-10  5:45         ` joe M
@ 2013-03-10 18:23           ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2013-03-10 18:23 UTC (permalink / raw)
  To: zsh-workers

On Mar 10, 12:45am, joe M wrote:
}
} gmail is adding application/octet-stream. I will send both the .zsh
} file and a .txt file.

Amusingly, ".zsh.txt" sets off my anti-virus because it appears to be
one file type masquerading as another.

Gmail is a bit of a conundrum for this list, because we'd actually prefer
that code/patches/etc. be pasted in-line rather than attached, but then
you get into line-wrapping/reformatting issues.

Here's a thought (I haven't tried it yet) -- try adding a definition for
the ".zsh" extension in your ~/.mime.types file or the equivalent and
restart your web browser.  Maybe the browser will pick that up and send
that file type to gmail when the attachment is uploaded.

} On a slightly different note, I do not feel comfortable using the ((
} .. )) construct as it does not show up properly in the xtrace/verbose
} log. This is how it shows up.
} 
} +limit-completion:21> (( compstate[list_lines] > 60         ||
} compstate[list_lines]+BUFFERLINES+2 > LINES ))

This is somewhat related to the thread I started a few days ago about
expansions not showing up when xtracing array subscripts.  What both
of those have in common is that it would sometimes be nice to trace
the details of parameter expansion and math evaluation.

The trouble is that doing so would produce a LOT of output, often not
ordered in a way that a reader could easily follow.  Hard to find the
right balance.

Anyway you can use the (( )) expression but also expand the parameters
explicitly rather than implicitly:

    (( $compstate[list_lines] > 60 ||
       $compstate[list_lines]+$BUFFERLINES+2 > $LINES )) 

which traces like

    zsh:4> ((  10 > 60 ||
         10+24+2 > 24  ))

You do need to be a bit more careful that the expansions won't result in
empty strings and thereby cause a syntax error.  (It'd be nice if the
trace did something a little more sensible with the embedded newline.)

} I could not figure out why the below lines do not work. They return a blank.
} 
}    echo "4: $(expr ${compstate[list_lines]})"
}    echo "5: $(expr $compstate[list_lines])"
}    echo "6: $(expr $compstate[list_lines] + $BUFFERLINES)"
}    echo "7: $(expr $compstate[list_lines] + $BUFFERLINES + 2)"
} 
} They are in lines 42 .. 45 of the attached script.

Hmm, I have no idea either -- it works for me.

----- no idea why these below lines do not work
: limit-completion:14:cursh cmdsubst; expr 78
: limit-completion:14:cursh; echo '4: 78'
4: 78
: limit-completion:15:cursh cmdsubst; expr 78
: limit-completion:15:cursh; echo '5: 78'
5: 78
: limit-completion:16:cursh cmdsubst; expr 78 + 1
: limit-completion:16:cursh; echo '6: 79'
6: 79
: limit-completion:17:cursh cmdsubst; expr 78 + 1 + 2
: limit-completion:17:cursh; echo '7: 81'
7: 81
: limit-completion:18:cursh; echo '----- no idea why the above lines do not
work
'
----- no idea why the above lines do not work

Comparing that to your output, you're missing the "cmdsubst" lines for
expr; you should have two lines of trace for source lines 14-17 the
same way you do for source lines 12 and 23.  I suspect some kind of a
race condition between the parent shell and the $(expr ...) subshell
both writing to the same descriptors, though I'm not sure why it would
only crop up in that specific spot.

Replace the $(expr ...) with $(( ... )) and see if that "fixes" it.


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

end of thread, other threads:[~2013-03-10 18:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-07  3:57 auto list choices joe M
2013-03-07  4:23 ` joe M
2013-03-07  4:35   ` joe M
2013-03-08 15:48     ` joe M
2013-03-09 15:25       ` Bart Schaefer
2013-03-10  5:45         ` joe M
2013-03-10 18:23           ` Bart Schaefer

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