From d68ba61968d163e5d322e72a213536683be5cad1 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Thu, 23 Sep 2021 14:15:42 +0900 Subject: [PATCH] edit: support "nsearch" opts "empty=emulate-readline" --- README.md | 2 +- docs/ChangeLog.md | 1 + lib/core-decode.emacs-rlfunc.txt | 4 ++-- lib/core-decode.vi_imap-rlfunc.txt | 4 ++-- lib/core-decode.vi_nmap-rlfunc.txt | 4 ++-- note.txt | 24 ++++++++++++++++++++++++ src/edit.sh | 23 ++++++++++++++--------- 7 files changed, 46 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f6983913..db72dd48 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Of course ble.sh can be used in combination with other Bash configurations such ## History and roadmap My little experiment has took place in one corner of my `bashrc` in the end of May, 2013 after I enjoyed some article on `zsh-syntax-highlighting`. -I initially thought something can be achieved by writing a few hundred of codes +I initially thought something can be achieved by writing a few hundred of lines of codes but soon realized that everything needs to be re-implemented for the authentic support of syntax highlighting in Bash. I decided to make it as an independent script `ble.sh`. The name stemmed from that of Zsh's line editor, *ZLE* (*Zsh Line Editor*), but suffixed with `.sh` for the implication of being written in shell script. diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 9a8ff69f..cadcbaef 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -27,6 +27,7 @@ - syntax: support tilde expansions in parameter expansions `#D1513` 0506df2 - decode: support `ble-bind -m KEYMAP --cursor DECSCUSR` (motivated by jmederosalvarado) `#D1514` `#D1515` `#D1516` 79d671d - edit: support `nsearch` options (motivated by Alyetama, rashil2000, carv-silva) `#D1517` 9125795 + - edit: support `nsearch` opts `empty=emulate-readline` (motivated by jainpratik163) `#D1661` 0000000 - syntax: support the deprecated redirection `>& file` `#D1539` b9b0de4 - complete: complete file descriptors and heredoc words after redirections `#D1539` b9b0de4 - main: support `blehook ATTACH DETACH`, `BLE_ONLOAD`, `BLE_ATTACHED` `#D1543` 750ca38 diff --git a/lib/core-decode.emacs-rlfunc.txt b/lib/core-decode.emacs-rlfunc.txt index 5ff10bff..e0dbffd1 100644 --- a/lib/core-decode.emacs-rlfunc.txt +++ b/lib/core-decode.emacs-rlfunc.txt @@ -55,8 +55,8 @@ glob-expand-word complete context=glob:insert-all glob-list-expansions complete context=glob:show_menu history-and-alias-expand-line history-and-alias-expand-line history-expand-line history-expand-line -history-search-backward history-search-backward empty=history-move -history-search-forward history-search-forward empty=history-move +history-search-backward history-search-backward empty=emulate-readline +history-search-forward history-search-forward empty=emulate-readline history-substring-search-backward history-substring-search-backward history-substring-search-forward history-substring-search-forward insert-comment insert-comment diff --git a/lib/core-decode.vi_imap-rlfunc.txt b/lib/core-decode.vi_imap-rlfunc.txt index a4582fe2..8b4dfac8 100644 --- a/lib/core-decode.vi_imap-rlfunc.txt +++ b/lib/core-decode.vi_imap-rlfunc.txt @@ -55,8 +55,8 @@ glob-expand-word complete context=glob:insert-all glob-list-expansions complete context=glob:show_menu history-and-alias-expand-line history-and-alias-expand-line history-expand-line history-expand-line -history-search-backward history-search-backward empty=history-move -history-search-forward history-search-forward empty=history-move +history-search-backward history-search-backward empty=emulate-readline +history-search-forward history-search-forward empty=emulate-readline history-substring-search-backward history-substring-search-backward history-substring-search-forward history-substring-search-forward insert-comment insert-comment diff --git a/lib/core-decode.vi_nmap-rlfunc.txt b/lib/core-decode.vi_nmap-rlfunc.txt index c6cf037d..a3db96da 100644 --- a/lib/core-decode.vi_nmap-rlfunc.txt +++ b/lib/core-decode.vi_nmap-rlfunc.txt @@ -55,8 +55,8 @@ glob-expand-word - glob-list-expansions - history-and-alias-expand-line vi_nmap/@edit history-and-alias-expand-line history-expand-line vi_nmap/@edit history-expand-line -history-search-backward history-search-backward empty=history-move -history-search-forward history-search-forward empty=history-move +history-search-backward history-search-backward empty=emulate-readline +history-search-forward history-search-forward empty=emulate-readline history-substring-search-backward history-substring-search-backward history-substring-search-forward history-substring-search-forward insert-comment vi-rlfunc/insert-comment diff --git a/note.txt b/note.txt index 3afc87fe..a85f2b37 100644 --- a/note.txt +++ b/note.txt @@ -2479,9 +2479,14 @@ bash_tips 2021-05-03 + * rlfunc: fetch-history + 8f485ff8 - new readline "fetch-history" bindable command * rlfunc: C-x s, spell-correct-word + 6be3a741 * rlvar: enable-active-region + b1965836 new "enable-active-region" readline variable * rlbind: prior, next + 65822e50 - alias expansion fix in case statements * vi-undo * 5.2 新機能: READLINE_ARGUMENT: 調べてみると引数が存在している時にのみ定義さ @@ -5423,6 +5428,25 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2021-09-23 + + * edit (widget history-search): support empty=emulate-readline (motivated by jainpratik163) [#D1661] + https://github.com/akinomyoga/ble.sh/issues/139 + + history-search-{for,back}ward は検索なので一致場所にカーソルを置くという仕 + 様に今までしてきた。また、空文字列検索の時には空文字列による検索を継続する + 為に、敢えてカーソルを先頭に置く様にしていた。しかし、readline の振る舞いを + 改めて確認した所、空文字列の時には恰も通常の history-prev を使用して移動し + たかの様に振る舞っていながら、空文字検索を継続しているのだという事が判明し + た。仕方がないので ble.sh でもやはり空文字列検索であっても内部的には + nsearch 状態に突入して、但しカーソル位置は末尾にするという具合に変更する事 + にした。 + + 改めて思うに Ref #D1517 https://github.com/akinomyoga/ble.sh/issues/101 で + 要望にあった"2. I would like the cursor to move to the end of line while + searching with Up/Down." というのはこの振る舞いに関連しての事だったのではな + いかという気がする。まあ、今となっては考えても仕方のない事なのかもしれない。 + 2021-09-22 * README: roadmap [#D1660] diff --git a/src/edit.sh b/src/edit.sh index 52c9f8be..a00e2322 100644 --- a/src/edit.sh +++ b/src/edit.sh @@ -7222,11 +7222,13 @@ function ble-edit/nsearch/.goto-match { _ble_edit_nsearch_index=$index _ble_edit_mark=$beg local is_end_marker= - case :$opts: in - (*:point=begin:*) _ble_edit_ind=0 ;; - (*:point=end:*) _ble_edit_ind=${#_ble_edit_str} is_end_marker=1 ;; - (*:point=match-begin:*) _ble_edit_ind=$beg ;; - (*:point=match-end:*|*) _ble_edit_ind=$end is_end_marker=1 ;; + local rex=':point=([^:]*):' + [[ :$opts: =~ $rex ]] + case ${BASH_REMATCH[1]} in + (begin) _ble_edit_ind=0 ;; + (end) _ble_edit_ind=${#_ble_edit_str} is_end_marker=1 ;; + (match-begin) _ble_edit_ind=$beg ;; + (match-end|*) _ble_edit_ind=$end is_end_marker=1 ;; esac # vi_nmap の中にいる時は一致範囲の最後の文字にカーソルを置く @@ -7364,10 +7366,11 @@ function ble-edit/nsearch/backward.fib { ## ## empty=EMPTY ## 空文字列で検索を開始した時の動作を指定します。 -## previous-search 前回の検索文字列を使用して検索します [既定] -## empty-search 空文字列で検索します。 -## hide-status 空文字列検索。nsearch 状態は隠します。 -## history-move 履歴項目移動。コマンドライン先頭に移動します。 +## previous-search 前回の検索文字列を使用して検索します [既定] +## empty-search 空文字列で検索します。 +## hide-status 空文字列検索。nsearch 状態は隠します。 +## history-move 履歴項目移動。コマンドライン先頭に移動します。 +## emulate-readline Readline の動作を模倣します。hide-status 及び point=end を設定します。 ## ## action=ACTION ## 文字列が見つかった時の動作を指定します。 @@ -7420,6 +7423,8 @@ function ble/widget/history-search { return $? ;; (hide-status) opts=$opts:hide-status ;; + (emulate-readline) + opts=hide-status:point=end:$opts ;; (previous-search) _ble_edit_nsearch_needle=$_ble_edit_nsearch_prev ;; esac