From d877073959ba4b86da968f63be320875a0f0c2a7 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 8 Jun 2012 07:55:27 +0200 Subject: 47305: edit-command-line: when possible, set $BUFFER directly This avoids the send-break which is both visually unappealing and might break some use cases where the user wishes to wrap edit-command-line in another widget. --- Functions/Zle/edit-command-line | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'Functions/Zle/edit-command-line') diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 991775ea5..1103ca556 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -7,6 +7,11 @@ # except that it will handle multi-line buffers properly. emulate -L zsh +local prebuffer +# see below comment for why this is needed +if (( ! ZLE_RECURSIVE )); then + prebuffer=$PREBUFFER +fi () { exec Date: Wed, 5 Aug 2020 16:47:45 +0200 Subject: 47306: edit-command-line: add editor style --- Completion/Zsh/Command/_zstyle | 1 + Doc/Zsh/contrib.yo | 6 ++++++ Functions/Zle/edit-command-line | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'Functions/Zle/edit-command-line') diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index e9a5d800c..bb871762e 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -143,6 +143,7 @@ styles=( cursor e: edit-buffer e:bool edit-previous e:bool + editor e: insert-kept e: leave-cursor e:bool match e: diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 66e6bdc1e..bab1e3023 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2472,6 +2472,12 @@ item(tt(edit-command-line))( Edit the command line using your visual editor, as in tt(ksh). example(bindkey -M vicmd v edit-command-line) + +The editor to be used can also be specified using the tt(editor) style in +the context of the widget. It is specified as an array of command and +arguments: + +example(zstyle :zle:edit-command-line editor gvim -f) ) tindex(expand-absolute-path) item(tt(expand-absolute-path))( diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 1103ca556..8aaeb738e 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -22,8 +22,12 @@ fi (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2] # Open the editor, placing the cursor at the right place if we know how. - local editor=( "${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}" ) - case $editor in + local -a editor + zstyle -a :zle:$WIDGET editor editor + if (( ! $#editor )); then + editor=( "${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}" ) + fi + case $editor in (*vim*) integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 )) "${(@)editor}" -c "normal! ${byteoffset}go" -- $1;; -- cgit v1.2.3 From 0bc559d0918159e357dc3669e97e9bb67b9610bd Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 5 Aug 2020 17:14:13 +0200 Subject: 47307: edit-command-line: restrict editing to region if it is active --- Functions/Zle/edit-command-line | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'Functions/Zle/edit-command-line') diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 8aaeb738e..3781244b2 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -7,9 +7,20 @@ # except that it will handle multi-line buffers properly. emulate -L zsh -local prebuffer -# see below comment for why this is needed -if (( ! ZLE_RECURSIVE )); then +local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER +# set up parameters depending on which context we are called from, +# see below comment for more details +if (( REGION_ACTIVE )); then + if (( CURSOR < MARK )); then + left=$CURSOR right=$MARK + lbuffer= + else + left=$MARK right=$CURSOR + lbuffer[right-left,-1]= + fi + (( left++ )) + buffer=$BUFFER[left,right] +elif (( ! ZLE_RECURSIVE )); then prebuffer=$PREBUFFER fi @@ -29,10 +40,10 @@ fi fi case $editor in (*vim*) - integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 )) + integer byteoffset=$(( $#prebuffer + $#lbuffer + 1 )) "${(@)editor}" -c "normal! ${byteoffset}go" -- $1;; (*emacs*) - local lines=( "${(@f):-"$PREBUFFER$LBUFFER"}" ) + local lines=( "${(@f):-"$prebuffer$lbuffer"}" ) "${(@)editor}" +${#lines}:$((${#lines[-1]} + 1)) $1;; (*) "${(@)editor}" $1;; esac @@ -48,13 +59,24 @@ fi # the following point) # - when we are at PS2 (CONTEXT == cont && ! ZLE_RECURSIVE) we do want the # break or otherwise the text from PREBUFFER will be inserted twice + # - when the region is active, we only want to change the parts of BUFFER + # covered by the region, and any PREBUFFER stays as PREBUFFER # - in all other cases (that I can think of) we also just want to set # $BUFFER directly. - if [[ $CONTEXT != cont ]] || (( ZLE_RECURSIVE )); then + if (( REGION_ACTIVE )); then + # adjust the length of the region to the length of the edited text + local prelen=$#BUFFER + BUFFER[left,right]="$(<$1)" + if (( MARK > CURSOR )); then + (( MARK += $#BUFFER - prelen )) + else + (( CURSOR += $#BUFFER - prelen )) + fi + elif [[ $CONTEXT != cont ]] || (( ZLE_RECURSIVE )); then BUFFER="$(<$1)" else print -Rz - "$(<$1)" zle send-break fi -} =(<<<"$prebuffer$BUFFER") +} =(<<<"$prebuffer$buffer") -- cgit v1.2.3 From bd328a2a9c230a8232bdfbaa934874b61fa749d5 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Fri, 28 May 2021 22:20:33 +0900 Subject: 48942: Let EDITOR invoked by edit-command-line know it's a zsh script --- ChangeLog | 3 +++ Functions/Zle/edit-command-line | 1 + 2 files changed, 4 insertions(+) (limited to 'Functions/Zle/edit-command-line') diff --git a/ChangeLog b/ChangeLog index d8c20016a..78271d448 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-06-02 Oliver Kiddle + * Akinori MUSHA: 48942: Functions/Zle/edit-command-line: + Let EDITOR invoked by edit-command-line know it's a zsh script + * 48954: Src/Zle/complist.c: avoid crash in reverse-menu-complete from menuselect without 'menu' in $compstate[insert] diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 3781244b2..5f7ea321f 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -8,6 +8,7 @@ emulate -L zsh 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 -- cgit v1.2.3