From 2a3351e70c80d727e9f20278ce02e9d88336cc03 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 31 Dec 2024 07:54:29 +0900 Subject: [PATCH] keymap.vi: handle history_default_point in vi motion --- blerc.template | 5 +++-- docs/ChangeLog.md | 1 + lib/keymap.vi.sh | 41 +++++++++++++++++++++-------------------- note.txt | 20 ++++++++++++++++++++ src/edit.sh | 16 ++++++++++++---- 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/blerc.template b/blerc.template index bcc3fdf3..5bf3d500 100644 --- a/blerc.template +++ b/blerc.template @@ -333,9 +333,10 @@ ## is specified, te cursor is placed at the same column as before moving the ## history entry. When the versions without "graphical" or "logical" is used, ## a logical or graphical line is used based on "bleopt edit_line_type". The -## default is "end-of-line". +## default is "end-of-line". When "auto" is specified, the behavior is "end" +## by default, but it becomes similar to "near" when called by vi motion. -#bleopt history_default_point= +#bleopt history_default_point=auto ## The following setting controls the history sharing. If it has non-empty diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 2410beaa..57fb9e98 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -71,6 +71,7 @@ - complete: support completion for `execute-named-command` `#D2288` 4fee44e6 - complete: support `ble-face menu_complete_{match,selected}` (requested by simonLeary42) `#D2291` 31f264ad - 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 history_default_point=auto` (reported by miltieIV2) `#D2297` xxxxxxxx - edit: support `bleopt undo_point={first,last,near,auto}` `#D2303` 99af0ece - keymap/vi: add readline-compatible widgets for `vi_imap` and `vi_nmap` (requested by excited-bore) `#D2304` d7ec488a - edit: support bash-5.2 readline bindable function `vi-edit-and-execute-command` `#D2306` c395eb33 diff --git a/lib/keymap.vi.sh b/lib/keymap.vi.sh index e93e040f..2b7d6a85 100644 --- a/lib/keymap.vi.sh +++ b/lib/keymap.vi.sh @@ -3111,36 +3111,37 @@ function ble/widget/vi-command/.history-relative-line { local index histsize ble/history/get-index ble/history/get-count -v histsize + local index0=$index - local ret count=$((offset<0?-offset:offset)) exit=1 + local ret count=$((offset<0?-offset:offset)) ((count--)) while ((count>=0)); do if ((offset<0)); then - ((index>0)) || return "$exit" - ble/widget/history-prev - ret=${#_ble_edit_str} - ble/keymap:vi/needs-eol-fix "$ret" && ((ret--)) - _ble_edit_ind=$ret + ((--index)) + ((index>=0)) || break else - ((indexhistsize)); then + # reached the end of history + ble-edit/history/goto "$histsize" point=none + _ble_edit_ind=${#_ble_edit_str} + else + ble-edit/history/goto "$index" linewise:default-point=near fi + ble/keymap:vi/needs-eol-fix && ((_ble_edit_ind--)) return 0 } diff --git a/note.txt b/note.txt index 030e6c71..726bde06 100644 --- a/note.txt +++ b/note.txt @@ -8097,6 +8097,8 @@ bash_tips * edit: 履歴移動を行った時のカーソル位置の設定 (requested by miltieIV2) [#D2297] https://github.com/akinomyoga/ble.sh/issues/537 + Note: これにより history_preserve_point -> history_default_point に変更した。 + * fixed: 何と今まで "bleopt edit_line_type" が動いていなかった様だ。 * fixed: 何と今まで bleopt/check:input_encoding のエラーメッセージの一部が @@ -8158,6 +8160,24 @@ bash_tips その他は大体動いている様だ。 + 2024-12-31 実は keymap.vi の vi motion 経由で呼び出される履歴移動は + ble/widget/history-{prev,next} を用いていた為に、今回の新しいカーソル位置の + 設定が適用されていなかった? 取り敢えず対応した。 + + ? done: と思ったが、本来は ble/widget/history-{prev,next} が正しく位置を設 + 定する筈だったのでは…? 何故動いていないのだろう? 後で確認する必要がある。 + + →確認した。history-{prev,next} の直後にカーソル位置を手動で設定している + ので折角 ble/widget/history-{prev,next} がカーソル位置を設定してもそれが + 上書きされていた。その処理を削除されたら期待通りの振る舞いになる事も確認 + できた。然し、更に引数付きで履歴項目内を移動した時には何れにしてもカーソ + ル位置を調整する必要がある。そもそも処理をよく見てみると + ble/widget/history-{prev,next} を呼び出す意味はない。単に index を追跡し + てその都度 get-edited-entry で取り出した文字列に含まれる改行を数えれば良 + いだけである。 + + 最後に ble-edit/history/goto を一回呼び出すだけにする事にした。 + 2024-12-12 * style: prefix:$name の形をしている定義関数の呼び出しのクォートを調整 [#D2296] diff --git a/src/edit.sh b/src/edit.sh index 6bf200f9..1659b413 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -8738,10 +8738,10 @@ function ble/widget/print-keyboard-macro { #------------------------------------------------------------------------------ # **** history **** @history -bleopt/declare -v history_default_point 'end' +bleopt/declare -v history_default_point 'auto' function bleopt/check:history_default_point { case $value in - (begin|end|near|far|preserve) return 0 ;; + (begin|end|near|far|preserve|auto) return 0 ;; (beginning-of-line|end-of-line|preserve-column) return 0 ;; (beginning-of-logical-line|end-of-logical-line|preserve-logical-column) return 0 ;; (beginning-of-graphical-line|end-of-graphical-line|preserve-graphical-column) return 0;; @@ -8754,7 +8754,7 @@ function bleopt/check:history_default_point { bleopt/declare -o history_preserve_point history_default_point function bleopt/check:history_preserve_point { case $value in - (begin|end|near|far|preserve) ;; + (begin|end|near|far|preserve|auto) ;; (beginning-of-line|end-of-line|preserve-column) ;; (beginning-of-logical-line|end-of-logical-line|preserve-logical-column) ;; (beginning-of-graphical-line|end-of-graphical-line|preserve-graphical-column) ;; @@ -8849,6 +8849,15 @@ function ble-edit/history/goto/.prepare-point { [[ $ret ]] || ret=$bleopt_history_default_point point=$ret + if [[ $point == auto ]]; then + ble/opts#extract-last-optarg "$point_opts" default-point + if [[ $ret ]]; then + point=$ret + else + point=end + fi + fi + case $point in (near) if [[ :$point_opts: == *:backward:* ]]; then @@ -8913,7 +8922,6 @@ function ble-edit/history/goto/.prepare-point { ## @fn ble-edit/history/goto/.set-point [delta] ## @param[in] delta -## @var[in] index0 index1 ## @var[in] point point_x point_opts ## ## @var[in] _ble_edit_str