zsh-workers
 help / color / mirror / code / Atom feed
From: joe M <joe9mail@gmail.com>
To: zsh-workers@zsh.org
Subject: auto list choices
Date: Wed, 6 Mar 2013 22:57:13 -0500	[thread overview]
Message-ID: <CAHjjW16YTVg=qqcGLFmwgXBZ5Xn43kY9buce_r8t60iZ0QWQjQ@mail.gmail.com> (raw)

[-- 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
}

             reply	other threads:[~2013-03-07  3:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-07  3:57 joe M [this message]
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

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='CAHjjW16YTVg=qqcGLFmwgXBZ5Xn43kY9buce_r8t60iZ0QWQjQ@mail.gmail.com' \
    --to=joe9mail@gmail.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).