Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Enable linewise edit-command when in visual-line

Thank you for your fast response, I did a bit of testing and have a couple
uncertainties that I hope you can assist me with.

> > > > + offset_right=${(SB)${BUFFER[mark_right+1,-1]}#$'\n'}
> > > 
> > > This I'm not sure of -- why mark_right+1 ?
> > 
> > This is because CURSOR and MARK are 0-indexed, according to zshzle(1).
> They're 0-based because position 0 represents an empty line, the
> non-character before $LBUFFER. The BUFFER and LBUFFER arrays
> themselves are still 1-indexed (unless you're crazed enough to be
> using zle with ksharrays).
> BUFFER[CURSOR] is always the character to the left of the visible
> cursor position. To make this work, CURSOR is decremented when
> entering vicmd mode (unless it's already zero), but that doesn't
> change MARK.
> So ... I think this means that in vi-cmd-mode it is necessary to use
> CURSOR+1 when MARK <= CURSOR, but not MARK+1 when CURSOR < MARK? And
> never add one when in emacs mode?

This makes me think I am missing something, because even when setting bindkey -e
in my .zshrc and entering visual-line-mode, a cursor/mark on column 1 on a 2nd
line to the right of the other cursor/mark never includes said 2nd line, despite
it being visually highlighted. That is, while using the suggested:
  right=${${BUFFER[CURSOR,-1]}[(i)$nl]} for MARK <= CURSOR
  right=${${BUFFER[MARK,-1]}[(i)$nl]} for CURSOR < MARK

I had to use CURSOR+1 and MARK+1 from the lines above to fix that edge case.
Which does not wrongfully include the following line when the cursor to the far
right of the first line in emacs mode, as might be expected.

> > lbuffer=$lbuffer[++left,-1]
> That's equivalent to lbuffer= when left=$CURSOR because by definition
> everything after LBUFFER[CURSOR] is empty (and lbuffer=$LBUFFER at
> that point). I believe ((right-left == left+1)) when right=$CURSOR,
> so should be a no-op compared to the original ((REGION_HIGHLIGHT ==
> 1)) case. Disagree?

You are right in that lbuffer= is equivalent for left=$CURSOR, however
lbuffer[right-left,-1]= leaves the leading part of $lbuffer intact even if the
visual selection does not start at the beginning of $BUFFER. And as I
understand, $lbuffer is supposed to represent only the highlighted text before
the cursor, to later figure out cursor positioning for the opened editor.

The only thing that has been working consistently, and what fixes cursor
positioning for me, is the previous:
In both blocks for (( REGION_HIGHLIGHT == 1 )) and (( REGION_HIGHLIGHT == 2 ))

Please let me know if I am missing something.


Messages sorted by: Reverse Date, Date, Thread, Author