Code Monkey home page Code Monkey logo

Comments (2)

1trapbox avatar 1trapbox commented on September 23, 2024

.autocomplete__key-bindings

I tried modifying this file. comment some code snippets.
but ctrl + r, still brings up the history widget.

#!/bin/zsh
zmodload zsh/complist
zmodload -F zsh/parameter p:funcstack p:functions
zmodload -F zsh/terminfo p:terminfo

local -Pa prefix=( '\e'{\[,O} )
typeset -ga _autocomplete__key_up=( ${^prefix}A )
typeset -ga _autocomplete__key_down=( ${^prefix}B )
typeset -ga _autocomplete__key_alt_up=( '\e'$^_autocomplete__key_up '\e[1;3A' )
typeset -ga _autocomplete__key_alt_down=( '\e'$^_autocomplete__key_down '\e[1;3B' )

${0}:bind() {
  local -P keymap=$1 widget=$2
  shift 2
  builtin bindkey -M "$keymap" "${@:^^widget}"
}

${0}:bind-menu() {
  0=${0%:*}
  ${0}:bind isearch "$@"
  ${0}:bind menuselect "$@"
}

${0}:bound() {
  [[ $( builtin bindkey -M "$1" "$3" ) == \"[^[:space:]]##\"\ $2 ]]
}

${0}:rebind() {
  0=${0%:*}

  local -P keymap=$1 old=$2 new=$3 key=
  shift 3
  for key; do
    ${0}:bound "$keymap" "$old" "$key" &&
        builtin bindkey -M "$keymap" "$key" "$new"
  done
}

${0}:unbind() {
  0=${0%:*}
  ${0}:bound "$1" "$2" "$3" &&
      builtin bindkey -M "$1" -r "$2"
}

${0}:bind main    up-line-or-search $_autocomplete__key_up[@]
${0}:bind-menu    up-history        $_autocomplete__key_up[@]
${0}:bind main  down-line-or-select $_autocomplete__key_down[@]
${0}:bind-menu  down-history        $_autocomplete__key_down[@]

${0}:rebind emacs   up-line-or-{history,search} '^P'
${0}:bind-menu      up-history                  '^P'
${0}:rebind emacs down-line-or-{history,select} '^N'
${0}:bind-menu    down-history                  '^N'

${0}:rebind vicmd   up-line-or-{history,search} 'k'
${0}:rebind vicmd down-line-or-{history,select} 'j'

local -Pa menukeys=(
                '^@' accept-and-hold
                '^_' .undo
    "$terminfo[kpp]" backward-word
    "$terminfo[knp]"  forward-word
               '^[v' backward-word
                '^V'  forward-word
)
builtin bindkey -M isearch    "$menukeys[@]"
builtin bindkey -M menuselect "$menukeys[@]"

${0}:precmd() {
  emulate -L zsh
  setopt $_autocomplete__func_opts[@]

  0=${0%:*}

  ${0}:rebind main  expand-or-complete        complete-word '\t'
  ${0}:rebind main  expand-or-complete-prefix complete-word '\t'
  ${0}:rebind main  menu-expand-or-complete   complete-word '\t'

  local backtab=$terminfo[kcbt]
  ${0}:rebind main undefined-key insert-unambiguous-or-complete "$backtab"

  ${0}:bound main complete-word '\t' &&
      ${0}:bind-menu accept-line '\t'

  ${0}:bind main  history-search-backward $_autocomplete__key_alt_up[@]
  ${0}:bind-menu  vi-backward-blank-word  $_autocomplete__key_alt_up[@]
  ${0}:bind main  menu-select             $_autocomplete__key_alt_down[@]
  ${0}:bind-menu  vi-forward-blank-word   $_autocomplete__key_alt_down[@]

#  ${0}:rebind emacs history-search-backward history-search-backward '\ep'
#  ${0}:bind-menu                            vi-backward-blank-word  '\ep'
#  ${0}:rebind emacs history-search-forward  menu-select             '\en'
#  ${0}:bind-menu                            vi-forward-blank-word   '\en'

#  ${0}:rebind vicmd vi-rev-repeat-search    history-search-backward 'N'
#  ${0}:rebind vicmd vi-repeat-search        menu-select             'n'

#  ${0}:rebind emacs history-incremental-search-backward{,}         '^R'
#  ${0}:bind-menu    history-incremental-search-backward            '^R'
#  ${0}:rebind emacs history-incremental-search-forward menu-search '^S'
#  ${0}:bind-menu    history-incremental-search-forward             '^S'

#  ${0}:rebind vicmd {vi-history,history-incremental}-search-backward '/'
#  ${0}:rebind vicmd  vi-history-search-forward         menu-search   '?'

  unset -m '_autocomplete__key_*'
  unfunction ${0}:{{,re,un}bind,bound}
}

from zsh-autocomplete.

Numenorean avatar Numenorean commented on September 23, 2024

it took me almost two days to find out that there is apparently no way to rebind builtin shortcuts because of that shitty precmd trick to bind the keys just before the prompt appears. Works only if I manually execute bindkey in prompt.

What I tried:

source $XDG_DATA_HOME/zinit/plugins/marlonrichert---zsh-autocomplete/zsh-autocomplete.plugin.zsh

testfunc() {
    echo "test"
    zle       reset-prompt
}
zle -N testfunc
bindkey '\E[1;3A' testfunc # Alt-Up

Zsh log:

+/home/emon/.config/zsh/.zshrc:169> bindkey '\E[1;3A' testfunc
+.autocomplete__key-bindings:precmd:16> .autocomplete__key-bindings:bind main history-search-backward '\e\e[A' '\e\eOA' '\e[1;3A'
+.autocomplete__key-bindings:bind:3> bindkey -M main '\e\e[A' history-search-backward '\e\eOA' history-search-backward '\e[1;3A' history-search-backward

IMHO that should be added to README to not to misguide the other people

from zsh-autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.