Skip to content

Commit

Permalink
edit: support bash-5.2 rlfunc "vi-edit-and-execute-command"
Browse files Browse the repository at this point in the history
* edit: fix a bug that opt "no-newline" for
  "edit-and-execute-command.edit" did not work
  • Loading branch information
akinomyoga committed Dec 24, 2024
1 parent 55e0ee7 commit c395eb3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
- edit: support `bleopt history_default_point={preserve,begin,end,near,far,{beginning,end}-of-line,preserve-column,...}` (requested by miltieIV2) `#D2297` 37291ff1
- edit: support `bleopt undo_point={first,last,near,auto}` `#D2303` xxxxxxxx
- keymap/vi: add readline-compatible widgets for `vi_imap` and `vi_nmap` (requested by excited-bore) `#D2304` xxxxxxxx
- edit: support bash-5.2 readline bindable function `vi-edit-and-execute-command` `#D2306` xxxxxxxx

## Changes

Expand Down
3 changes: 2 additions & 1 deletion lib/core-decode.emacs-rlfunc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ upcase-word upcase-eword
vi-append-eol -
vi-append-mode -
vi-arg-digit -
vi-back-to-indent -
vi-prev-word vi-rlfunc/prev-word
vi-backward-word vi-command/backward-vword
vi-backward-bigword vi-command/backward-uword
Expand All @@ -133,7 +134,6 @@ vi-forward-word vi-command/forward-vword
vi-forward-bigword vi-command/forward-uword
vi-fword vi-command/forward-vword
vi-fWord vi-command/forward-uword
vi-back-to-indent -
vi-change-case -
vi-change-char -
vi-change-to -
Expand All @@ -142,6 +142,7 @@ vi-column -
vi-complete -
vi-delete -
vi-delete-to -
vi-edit-and-execute-command edit-and-execute-command vi
vi-editing-mode vi-editing-mode
vi-eof-maybe -
vi-fetch-history history-goto
Expand Down
2 changes: 2 additions & 0 deletions lib/core-decode.vi_imap-rlfunc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ vi-column -
vi-complete -
vi-delete -
vi-delete-to -
vi-edit-and-execute-command edit-and-execute-command vi
vi-editing-mode nop
vi-eof-maybe -
vi-fetch-history history-goto
Expand Down Expand Up @@ -171,3 +172,4 @@ yank yank
yank-last-arg insert-last-argument
yank-nth-arg insert-nth-argument
yank-pop yank-pop
paste-from-clipboard -
4 changes: 3 additions & 1 deletion lib/core-decode.vi_nmap-rlfunc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ upcase-word vi_nmap/upcase-eword
vi-append-eol vi_nmap/append-mode-at-end-of-line
vi-append-mode vi_nmap/append-mode
vi-arg-digit vi-command/append-arg
vi-back-to-indent -
vi-prev-word vi-rlfunc/prev-word
vi-backward-word vi-command/backward-vword
vi-backward-bigword vi-command/backward-uword
Expand All @@ -133,7 +134,6 @@ vi-forward-word vi-command/forward-vword
vi-forward-bigword vi-command/forward-uword
vi-fword vi-command/forward-vword
vi-fWord vi-command/forward-uword
vi-back-to-indent -
vi-change-case vi-command/operator toggle_case
vi-change-char vi_nmap/replace-char
vi-change-to vi-rlfunc/change-to
Expand All @@ -142,6 +142,7 @@ vi-column vi-command/nth-column
vi-complete vi-rlfunc/vi-complete
vi-delete vi_nmap/kill-forward-char
vi-delete-to vi-rlfunc/delete-to
vi-edit-and-execute-command vi-command/edit-and-execute-command
vi-editing-mode vi_nmap/insert-mode
vi-eof-maybe vi-rlfunc/eof-maybe
vi-fetch-history vi-command/history-goto
Expand Down Expand Up @@ -171,3 +172,4 @@ yank yank
yank-last-arg -
yank-nth-arg -
yank-pop -
paste-from-clipboard -
2 changes: 1 addition & 1 deletion lib/keymap.vi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ function ble/widget/vi-command/edit-and-execute-command {
ble/keymap:vi/repeat/clear-insert
[[ $_ble_keymap_vi_reg_record ]] &&
ble/widget/vi_nmap/record-register
ble/widget/edit-and-execute-command
ble/widget/edit-and-execute-command vi
}

#------------------------------------------------------------------------------
Expand Down
22 changes: 12 additions & 10 deletions note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,8 @@ bash_tips

2024-12-23

* vi_[in]map: rlfunc "paste-from-clipboard" の対応

* vi_cmap: :marks の対応。ないと marks のデバグの時に不便

* vi_nmap: pu をした時のカーソル位置が vim と一致しない
Expand Down Expand Up @@ -3460,16 +3462,6 @@ bash_tips

* isearch: 現在行と全く同じ内容の行には一致しないというオプション

2022-04-13

* bash が `vi-edit-and-execute-command' を追加している。

これは自分が以下で報告した事が元になっているのだろう。
https://lists.gnu.org/archive/html/help-bash/2022-02/msg00031.html

d70b5339 で追加されている。つまり help-bash で発言した次の日には修正が入っ
ていたのだった。

2022-03-19

* 編集文字列に含まれる制御文字の反転表示の可能性
Expand Down Expand Up @@ -7703,6 +7695,16 @@ bash_tips

2024-12-23

* 2022-04-13 bash が `vi-edit-and-execute-command' を追加している [#D2306]

これは自分が以下で報告した事が元になっているのだろう。
https://lists.gnu.org/archive/html/help-bash/2022-02/msg00031.html

d70b5339 で追加されている。つまり help-bash で発言した次の日には修正が入っ
ていたのだった。

2024-12-23 これはエディタを指定して実行する物。新しく追加する事にした。

* edit: bash-5.3 "bash-vi-complete" を実装 [#D2305]

bash-vi-complete は vi-complete に似た readline bindable function の様だが
Expand Down
38 changes: 26 additions & 12 deletions src/edit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8133,6 +8133,26 @@ function ble/widget/default/accept-single-line-or {
function ble/widget/accept-single-line-or-newline {
ble/widget/accept-single-line-or newline
}
function ble/widget/edit-and-execute-command.editor {
ret=${bleopt_editor:-${VISUAL:-${EDITOR-}}}
[[ $ret ]] && return 0

local -a editors=()
if [[ :$opts: == *:vi:* ]] && ble/bin#has vim; then
editors=(vim vi emacs nano)
elif [[ :$opts: == *:emacs:* ]]; then
editors=(emacs nano vim vi)
else
editors=(emacs vim nano vi)
fi

for ret in "${editors[@]}"; do
ble/bin#has "$ret" && return 0
done

ret=vi
return 1
}
## @fn ble/widget/edit-and-execute-command.edit content opts
## @var[in] content
## @var[in] opts
Expand All @@ -8145,22 +8165,16 @@ function ble/widget/edit-and-execute-command.edit {
local file=$_ble_base_run/$$.blesh-fc.bash
ble/util/print "$content" >| "$file"

local fallback=vi
if ble/bin#has emacs; then
fallback='emacs -nw'
elif ble/bin#has vim; then
fallback=vim
elif ble/bin#has nano; then
fallback=nano
fi
local ret
ble/widget/edit-and-execute-command.editor; local editor=$ret

if [[ $opts != *:no-newline:* ]]; then
if [[ :$opts: != *:no-newline:* ]]; then
_ble_edit_line_disabled=1 ble/textarea#render leave
ble/widget/.newline # #D1800 (呼び出し元で exec/register)
fi

ble/term/leave
${bleopt_editor:-${VISUAL:-${EDITOR:-$fallback}}} "$file"; local ext=$?
"$editor" "$file"; local ext=$?
ble/term/enter

if ((ext)); then
Expand All @@ -8173,7 +8187,7 @@ function ble/widget/edit-and-execute-command.edit {
}
function ble/widget/edit-and-execute-command.impl {
local ret=
ble/widget/edit-and-execute-command.edit "$1"
ble/widget/edit-and-execute-command.edit "$1" "$2"
local command=$ret

ble/string#match "$command" $'[\n]+$' &&
Expand All @@ -8192,7 +8206,7 @@ function ble/widget/edit-and-execute-command.impl {
}
function ble/widget/edit-and-execute-command {
ble-edit/content/clear-arg
ble/widget/edit-and-execute-command.impl "$_ble_edit_str"
ble/widget/edit-and-execute-command.impl "$_ble_edit_str" "$1"
}

function ble/widget/insert-comment/.remove-comment {
Expand Down

0 comments on commit c395eb3

Please sign in to comment.