Skip to content

Commit

Permalink
edit: support "nsearch" opts "empty=emulate-readline"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 23, 2021
1 parent 75bd04c commit d68ba61
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/core-decode.emacs-rlfunc.txt
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/core-decode.vi_imap-rlfunc.txt
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/core-decode.vi_nmap-rlfunc.txt
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions note.txt
Expand Up @@ -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: 調べてみると引数が存在している時にのみ定義さ
Expand Down Expand Up @@ -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]
Expand Down
23 changes: 14 additions & 9 deletions src/edit.sh
Expand Up @@ -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 の中にいる時は一致範囲の最後の文字にカーソルを置く
Expand Down Expand Up @@ -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
## 文字列が見つかった時の動作を指定します。
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d68ba61

Please sign in to comment.