From: Bernhard Tittelbach <xro@realraum.at>
To: zsh-workers@zsh.org
Subject: Behaviour of {beginning,end}-of-buffer-or-history
Date: Wed, 01 Jun 2011 21:43:51 +0200 [thread overview]
Message-ID: <is64pk$esq$1@dough.gmane.org> (raw)
Hi,
recently I was dissatisfied with the behavior of my HOME/END keys.
What I wanted was this:
If cursor is a beginning/end of the buffer
then jump to the beginning/end of the history
Else
jump to the beginning/end of that line,
no matter whether we are in a multi- or single-line buffer
Seemingly there are functions that do exactly that:
beginning-of-buffer-or-history
Move to the beginning of the buffer, or if already there, move to the first
event in the history list.
end-of-buffer-or-history
Move to the end of the buffer, or if already there, move to the last
event in the history list.
But in reality, what above functions really do is this:
If cursor is a beginning/end of a buffer
then jump to the beginning/end of the history
ElseIf cursor is somewhere in a SINGLE-LINE buffer
then jump to the beginning/end of the history (why ???)
Else
jump to the beginning/end of the MULTI-LINE buffer
I wonder if this is really how these functions are intended to work ?
At the very least I would consider them misnamed, or does "buffer" really only
ever refer to multi-line buffers ?
In any case I thus wrote a bit of shell code that does the correct thing from my
point of view (improvements welcome):
## ---------------------------------------------------------------------
## beginning-of-line OR beginning-of-buffer OR beginning of history
## (i.e. do it right, like beginning-of-buffer-or-history doesn't)
function jump-position-in-line-or-buffer-or-history
{
local -a buflines beginning_of_lines end_of_lines cur_array
local linepossum=0
buflines=(${(f)BUFFER})
beginning_of_lines=(0)
for ((c=1;c<=$#buflines;c++)) do
linepossum=$(( linepossum + ${#buflines[c]} ))
end_of_lines+=( $linepossum )
beginning_of_lines+=( $((++linepossum)) )
done
cur_array=(${(P)${${WIDGET/line-or-buffer-or-history/lines}//-/_}})
if [[ ${cur_array[(i)$CURSOR]} -le ${#cur_array} ]]; then
zle .${WIDGET/line-or-buffer-or-history/buffer-or-history} "$@"
else
zle .${WIDGET/line-or-buffer-or-history/line} "$@"
fi
}
zle -N beginning-of-line-or-buffer-or-history \
jump-position-in-line-or-buffer-or-history && \
bindkey '\eOH' beginning-of-line-or-buffer-or-history
zle -N end-of-line-or-buffer-or-history \
jump-position-in-line-or-buffer-or-history && \
bindkey '\eOF' end-of-line-or-buffer-or-history
## ---------------------------------------------------------------------
cheers,
Bernhard
next reply other threads:[~2011-06-01 19:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-01 19:43 Bernhard Tittelbach [this message]
2011-06-01 19:57 Bernhard Tittelbach
2011-06-02 2:22 ` Bart Schaefer
2011-06-02 3:04 ` Bernhard Tittelbach
2011-06-02 14:25 ` Bart Schaefer
2011-06-02 16:02 ` Bernhard Tittelbach
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='is64pk$esq$1@dough.gmane.org' \
--to=xro@realraum.at \
--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).