zsh-users
 help / color / mirror / code / Atom feed
From: "Peter Slížik" <peter.slizik@gmail.com>
To: zsh <zsh-users@zsh.org>
Subject: A wrong bindkey command breaks the way bck-i-search (Ctrl+R) works
Date: Mon, 26 Jul 2021 16:13:52 +0200	[thread overview]
Message-ID: <CAC-uhUDYyX34h7thLGjCSFYf4CBD-+2jp9As16mkSdqFeqCNfg@mail.gmail.com> (raw)

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

Hello,

I created a few useful helper functions and bound them to specified keys.
For example, pressing " inserts a pair of quotes and puts the cursor inside
them, like this: "|".
Another example, pressing a space fixes some of the typos I'm inclined to
do repeatedly, e.g. pyhton<Space> is expanded to python<Space>.

The implementation is quite straightforward, the widget examines LBUFFER
and RBUFFER and modifies LBUFFER accordingly.

_expand_abbreviations ()
{
    if [[ LBUFFER =~ 'this' && RBUFFER == 'that' ]]; then
        LBUFER+='something '    # mind the trailing space
    fi
}

zle -N expand-abbreviations _expand_abbreviations
bindkey ' ' expand-abbreviations

The problem with this solution is that it breaks the way that Ctrl+R
history search works.
Before, typing a space inside Ctrl+R just underlined the space in the
offered string:

% abcd efgh
zsh: command not found: abcd
% <Ctrl+R>*abcd *efgh    # the space is underlined here
bck-i-search: abcd<Space>

After using the " bindkey ' ' expand-abbreviations" command, the space
finishes the Ctrl+R editor and inserts itself in front of the offered text:
% _abcd efgh    # a space prepended before abcd
and I'm not able to continue with the bck-i-search widget any more.

The behavior is identical for other bound keys, e.g. the double quote mark
in the first example with quote duplication.

I'm pretty sure there's something I'm missing in the bindkey command, but
frankly, the documentation is quite complex and I'm not sure what to look
for.

Any suggestions are appreciated.

Best regards,
Peter Slížik

[-- Attachment #2: Type: text/html, Size: 2159 bytes --]

             reply	other threads:[~2021-07-26 14:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 14:13 Peter Slížik [this message]
2021-07-26 15:58 ` Mikael Magnusson
2021-07-26 21:10   ` Bart Schaefer
2021-07-27 10:31     ` Peter Slížik
2021-07-27 14:51       ` Bart Schaefer
2021-07-27 15:09         ` Peter Slížik
2021-07-27 15:42           ` Bart Schaefer
2021-07-27 15:44             ` Peter Slížik
2021-07-27 22:35         ` Mikael Magnusson
2021-07-27 22:38           ` 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=CAC-uhUDYyX34h7thLGjCSFYf4CBD-+2jp9As16mkSdqFeqCNfg@mail.gmail.com \
    --to=peter.slizik@gmail.com \
    --cc=zsh-users@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).