zsh-workers
 help / color / mirror / code / Atom feed
From: Christoffer Lundell <christofferlundell@protonmail.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: [PATCH] Enable linewise edit-command when in visual-line
Date: Mon, 21 Aug 2023 14:13:58 +0000	[thread overview]
Message-ID: <PEEOyknRLLWFRjtZRcuxXrkHEqQYs6bxEPs_PEMqZNVbYD3QjR0HgbERrKA6gpZqMODFfgwDZMe6Nw2GM0f9JbtSN4bcaxrkp6bYsxTR7ZQ=@protonmail.com> (raw)

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



             reply	other threads:[~2023-08-21 14:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21 14:13 Christoffer Lundell [this message]
2023-08-23  3:27 ` Bart Schaefer
2023-08-23  9:06   ` Christoffer Lundell
2023-08-23 17:28     ` Bart Schaefer
2023-08-27 11:38       ` Christoffer Lundell
2023-08-27 20:24         ` 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='PEEOyknRLLWFRjtZRcuxXrkHEqQYs6bxEPs_PEMqZNVbYD3QjR0HgbERrKA6gpZqMODFfgwDZMe6Nw2GM0f9JbtSN4bcaxrkp6bYsxTR7ZQ=@protonmail.com' \
    --to=christofferlundell@protonmail.com \
    --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).