zsh-workers
 help / color / mirror / code / Atom feed
* Behaviour of {beginning,end}-of-buffer-or-history
@ 2011-06-01 19:43 Bernhard Tittelbach
  0 siblings, 0 replies; 6+ messages in thread
From: Bernhard Tittelbach @ 2011-06-01 19:43 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Behaviour of {beginning,end}-of-buffer-or-history
@ 2011-06-01 19:57 Bernhard Tittelbach
  2011-06-02  2:22 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Bernhard Tittelbach @ 2011-06-01 19:57 UTC (permalink / raw)
  To: zsh-workers

On 2011-06-01 21:43, Bernhard Tittelbach wrote:
> 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 ?
>
to clarify:

I find it odd that {beginning,end}-of-buffer-or-history jumps to the 
beginning/end of the history and not to the beginning/end of the line
if called on a single-line buffer

Jumping to the beginning/end of a line in a multi-line buffer is just an extra 
my function does, and not something I think {beginning,end}-of-buffer-or-history
should do (it's name does not imply any such functionality :)

cheers,
Bernhard


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

end of thread, other threads:[~2011-06-02 16:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-01 19:43 Behaviour of {beginning,end}-of-buffer-or-history Bernhard Tittelbach
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

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