Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Enable linewise edit-command when in visual-line
- X-seq: zsh-workers 52072
- From: Christoffer Lundell <christofferlundell@xxxxxxxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: [PATCH] Enable linewise edit-command when in visual-line
- Date: Mon, 21 Aug 2023 14:13:58 +0000
- Archived-at: <https://zsh.org/workers/52072>
- Feedback-id: 3930316:user:proton
- List-id: <zsh-workers.zsh.org>
Change behavior of edit-command in visual-line mode to edit command linewise
instead of only allowing editing of the text between MARK and CURSOR.
The rationale being that in visual-line mode the entire line(s) appears visually
selected, and so I expect edit-command to operate on the entire line(s).
With this patch everything visually selected will be brought into the editor,
while preserving cursor position where applicable.
I am not entirely sure I handle this correctly, though it appears to work fine
when tested locally with both emacs and vim.
---
Functions/Zle/edit-command-line | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 5f7ea321f..52246b88f 100644
--- a/Functions/Zle/edit-command-line
+++ b/Functions/Zle/edit-command-line
@@ -11,7 +11,7 @@ local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER
local TMPSUFFIX=.zsh
# set up parameters depending on which context we are called from,
# see below comment for more details
-if (( REGION_ACTIVE )); then
+if (( REGION_ACTIVE == 1 )); then
if (( CURSOR < MARK )); then
left=$CURSOR right=$MARK
lbuffer=
@@ -21,6 +21,23 @@ if (( REGION_ACTIVE )); then
fi
(( left++ ))
buffer=$BUFFER[left,right]
+elif (( REGION_ACTIVE == 2 )); then
+ local mark_left mark_right offset_right
+ if (( CURSOR < MARK )); then
+ mark_left=$CURSOR mark_right=$MARK
+ else
+ mark_left=$MARK mark_right=$CURSOR
+ fi
+ left=${(SB)${BUFFER[1,mark_left]}%$'\n'}
+ (( left != 1 )) && (( left++ ))
+ offset_right=${(SB)${BUFFER[mark_right+1,-1]}#$'\n'}
+ if (( offset_right == 1 )); then
+ right=$#BUFFER
+ else
+ (( right = mark_right + offset_right - 1 ))
+ fi
+ lbuffer=${lbuffer[left,CURSOR]}
+ buffer=$BUFFER[left,right]
elif (( ! ZLE_RECURSIVE )); then
prebuffer=$PREBUFFER
fi
--
2.41.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author