Skip to content

Commit

Permalink
emacs: support widgets "history-nsearch-{for,back}ward-again"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 31, 2019
1 parent 3b2237e commit 60dde2c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 9 deletions.
4 changes: 2 additions & 2 deletions keymap/emacs.rlfunc.txt
Expand Up @@ -71,9 +71,9 @@ menu-complete-backward menu-complete backward
next-history history-next
next-screen-line forward-graphical-line
non-incremental-forward-search-history history-nsearch-forward
non-incremental-forward-search-history-again -
non-incremental-forward-search-history-again history-nsearch-forward-again
non-incremental-reverse-search-history history-nsearch-backward
non-incremental-reverse-search-history-again -
non-incremental-reverse-search-history-again history-nsearch-backward-again
old-menu-complete menu-complete
operate-and-get-next accept-and-next
overwrite-mode overwrite-mode
Expand Down
6 changes: 3 additions & 3 deletions keymap/vi_imap.rlfunc.txt
Expand Up @@ -47,7 +47,7 @@ exchange-point-and-mark exchange-point-and-mark
forward-backward-delete-char delete-forward-backward-char
forward-byte @nomarked forward-byte
forward-char @nomarked forward-char
forward-search-history history-search-forward
forward-search-history history-isearch-forward
forward-word @nomarked forward-uword
glob-complete-word complete context=glob
glob-expand-word complete context=glob:insert-all
Expand All @@ -71,9 +71,9 @@ menu-complete-backward menu-complete backward
next-history history-next
next-screen-line forward-graphical-line
non-incremental-forward-search-history history-nsearch-forward
non-incremental-forward-search-history-again -
non-incremental-forward-search-history-again history-nsearch-forward-again
non-incremental-reverse-search-history history-nsearch-backward
non-incremental-reverse-search-history-again -
non-incremental-reverse-search-history-again history-nsearch-backward-again
old-menu-complete menu-complete
operate-and-get-next accept-and-next
overwrite-mode vi_imap/overwrite-mode
Expand Down
48 changes: 48 additions & 0 deletions memo.txt
Expand Up @@ -3215,6 +3215,54 @@ bash_tips

2019-03-31

* emacs: history-nsearch-{for,back}ward-again [#D1053]
again の実装は簡単である。と思ったが nsearch 自体の振る舞いが変だ。

x fixed: 検索文字列として有限の物を入力していても `' not found というメッセージが出る。
これは一番端に達した時に needle をロードしていなかったのが原因。
何れにしても local needle=$_ble_edit_nsearch_needle を実行する様にした。

x fixed: 同じ履歴内容の物に一致すると範囲着色が為されない?
調べてみるとちゃんと mark_active 及び mark ind は設定されている。
それなのに描画している時に着色が適用されないという状態。
これは一体何が起こっているのだろうか…。

reset-and-check-dirty で変更が起こらないとちゃんと着色されないという事なのか。
うーん。ble/textarea#render まで行ったが
其処でもちゃんと mark_active mark ind は設定されている。
それなのに着色される時とされない時がある。

x fixed: というより、そもそも何故か2回ずつ render が呼び出されている。
これはどういう事だろうか。何故2回呼び出す必要がある。
設計上は1回呼び出すだけの筈なのではないのか…。
不思議だ…。.hook が2回呼び出されているのか?
DEL は一文字で受信できる筈だし、もしそうだとしても状態が変化しない筈なので
textarea#render が2回実行される事はない筈なのである…。

調べるとどうも EPILOGUE は 1回しか呼び出されていない。
ble/bind/.tail の中で複数回 textarea#render が呼び出されている。
中を確認すると idle.do を実行した後にもう一度 textarea#render を呼び出している。
つまり、2回 textarea#render が呼び出される所までは良い。

問題は何故何も操作をしていない筈なのに dirty が立つのかという事。
あー。これは caret_state がちゃんと初期化されない制御パスがある…。
直した c7599a2

さてそれでも着色が為されない場合というのが存在している。
もしかすると layer 側の問題だろうか…。
うーん。layer:region/update を観察する。selection の取得まではできている。

あー。分かった。変更点がなかった場合に PREV_BUFF を更新する必要があったのだった。
直した 23796bc

x fixed: 更に途中で何故か操作不能になるという現象も発生していたはず…。
今再度試してみたらやはり再現する。これは何だろう。
一度 C-r してから C-s で端まで到達すると上にも下にも動けなくなる。

検索範囲が狭められている…。
これはどうも start の初期化の問題の様である。
直した 3b2237e 動くようになった。

* emacs: menu-complete-backward [#D1052]
これは簡単である。

Expand Down
16 changes: 15 additions & 1 deletion src/edit.sh
Expand Up @@ -6342,6 +6342,8 @@ function ble-decode/keymap:isearch/define {

## @var _ble_edit_nsearch_needle
## 検索対象の文字列を保持します。
## @var _ble_edit_nsearch_input
## 最後にユーザ入力された検索対象を保持します。
## @var _ble_edit_nsearch_opts
## 検索の振る舞いを制御するオプションを保持します。
## @arr _ble_edit_nsearch_stack[]
Expand All @@ -6356,6 +6358,7 @@ function ble-decode/keymap:isearch/define {
## @var _ble_edit_nsearch_index
## 最後に検索した位置を表します。
## 検索が一致した場合は _ble_edit_nsearch_match と同じになります。
_ble_edit_nsearch_input=
_ble_edit_nsearch_needle=
_ble_edit_nsearch_opts=
_ble_edit_nsearch_stack=()
Expand Down Expand Up @@ -6520,8 +6523,11 @@ function ble/widget/history-search {
ble-edit/content/clear-arg

# initialize variables
if [[ :$opts: == *:input:* ]]; then
if [[ :$opts: == *:input:* || :$opts: == *:again:* && ! $_ble_edit_nsearch_input ]]; then
ble/builtin/read -ep "nsearch> " _ble_edit_nsearch_needle || return 1
_ble_edit_nsearch_input=$_ble_edit_nsearch_needle
elif [[ :$opts: == *:again:* ]]; then
_ble_edit_nsearch_needle=$_ble_edit_nsearch_input
else
_ble_edit_nsearch_needle=${_ble_edit_str::_ble_edit_ind}
fi
Expand Down Expand Up @@ -6552,6 +6558,12 @@ function ble/widget/history-nsearch-backward {
function ble/widget/history-nsearch-forward {
ble/widget/history-search input:substr:forward
}
function ble/widget/history-nsearch-backward-again {
ble/widget/history-search again:substr:backward
}
function ble/widget/history-nsearch-forward-again {
ble/widget/history-search again:substr:forward
}
function ble/widget/history-search-backward {
ble/widget/history-search backward
}
Expand Down Expand Up @@ -6780,6 +6792,8 @@ function ble-decode/keymap:safe/bind-history {
ble-decode/keymap:safe/.bind 'C-x n' 'history-substring-search-forward'
ble-decode/keymap:safe/.bind 'C-x <' 'history-nsearch-backward'
ble-decode/keymap:safe/.bind 'C-x >' 'history-nsearch-forward'
ble-decode/keymap:safe/.bind 'C-x ,' 'history-nsearch-backward-again'
ble-decode/keymap:safe/.bind 'C-x .' 'history-nsearch-forward-again'

ble-decode/keymap:safe/.bind 'M-.' 'insert-last-argument'
ble-decode/keymap:safe/.bind 'M-_' 'insert-last-argument'
Expand Down
37 changes: 34 additions & 3 deletions src/util.sh
Expand Up @@ -230,13 +230,44 @@ function ble/debug/print-variables/.append {
local q=\' Q="''\'"
_ble_local_out=$_ble_local_out"$1='${2//$q/$Q}'"
}
function ble/debug/print-variables/.append-array {
local q=\' Q="''\'" arr=$1 index=0; shift
local index=0 elem out=$arr'=('
for elem; do
((index++)) && out=$out' '
out=$out$q${elem//$q/$Q}$q
done
out=$out')'
_ble_local_out=$_ble_local_out$out
}
function ble/debug/print-variables {
(($#)) || return 0
local _ble_local_var=$1 _ble_local_out=
while ble/debug/print-variables/.append "$1" "${!1}"; shift; (($#)); do

local flags= tag=
local -a _ble_local_vars=()
while (($#)); do
local arg=$1; shift
case $arg in
(-t) tag=$1; shift ;;
(-*) echo "print-variables: unknown option '$arg'" >&2
flags=${flags}e ;;
(*) ble/array#push _ble_local_vars "$arg" ;;
esac
done
[[ $flags == *e* ]] && return 1

local _ble_local_out= _ble_local_var=
[[ $tag ]] && _ble_local_out="$tag: "
ble/util/unlocal flags tag arg
for _ble_local_var in "${_ble_local_vars[@]}"; do
if ble/is-array "$_ble_local_var"; then
builtin eval -- "ble/debug/print-variables/.append-array \"\$_ble_local_var\" \"\${$_ble_local_var[@]}\""
else
ble/debug/print-variables/.append "$_ble_local_var" "${!_ble_local_var}"
fi
_ble_local_out=$_ble_local_out' '
done
ble/bin/echo "$_ble_local_out"
ble/bin/echo "${_ble_local_out%' '}"
}
#%end

Expand Down

0 comments on commit 60dde2c

Please sign in to comment.