Skip to content

Commit

Permalink
util (bleopt): support "-I" to reinitialize user settings on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jun 12, 2021
1 parent 72c274e commit 959cf27
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ble.pp
Expand Up @@ -1184,7 +1184,7 @@ function ble-update {
#%x inc.r|@|lib/core-syntax-def|
#%x inc.r|@|lib/core-complete-def|

bleopt/check-all
bleopt -I
#------------------------------------------------------------------------------
#%if measure_load_time
time {
Expand Down
2 changes: 1 addition & 1 deletion contrib
Submodule contrib updated 1 files
+24 −12 prompt-git.bash
2 changes: 1 addition & 1 deletion lib/core-syntax.sh
Expand Up @@ -6420,7 +6420,7 @@ function ble/syntax/highlight/getg-from-filename {
function bleopt/check:filename_ls_colors {
ble/syntax/highlight/ls_colors/.parse "$value"
}
value=$bleopt_filename_ls_colors bleopt/check:filename_ls_colors
bleopt -I filename_ls_colors

#------------------------------------------------------------------------------
# ble/syntax/progcolor
Expand Down
1 change: 1 addition & 0 deletions lib/vim-airline.sh
Expand Up @@ -356,6 +356,7 @@ function ble/prompt/backslash:lib/vim-airline {
done
}

bleopt -I vim_airline_@
bleopt keymap_vi_mode_show=
bleopt prompt_status_line='\q{lib/vim-airline}'
bleopt prompt_status_align=$'justify=\r'
4 changes: 3 additions & 1 deletion memo/ChangeLog.md
Expand Up @@ -46,7 +46,9 @@
- prompt: track dependencies and detect changes `#D1590` `#D1591` cf8d949
- prompt: preserve `LINES` and `COLUMNS` for custom sequences `#D1592` 040016d
- color: fix the face initialiation order for uses in prompts (motivated by jmederosalvarado) `#D1593` 321371f
- prompt: support `contrib/prompt-git` dirty checking `#D1601` b2713d9
- prompt (`contrib/prompt-git`): support dirty checking `#D1601` b2713d9
- prompt (`contrib/prompt-git`): do not use `ble/util/idle` in Bash 3 `#D1606` 0000000
- util (`bleopt`): add new option `-I` to reinitialize user settings on reload `#D1607` 0000000
- util, color: refactor configuration interfaces (`bleopt`, `blehook`, `ble-face`) `#D1568` c94d292
- color: support new face setting function `ble-face`
- util (`bleopt`): support option `-r` and `-u` and wildcards in option names
Expand Down
47 changes: 47 additions & 0 deletions note.txt
Expand Up @@ -4683,6 +4683,53 @@ bash_tips

2021-06-12

* reject: idle: 時々自動的に表示更新をかけるべきではないか [#D1608]

裏で処理が走っている間に状態が変化してそれを表示に反映させたい時にはどうす
るのか。現在の実装だとその様な仕組みにはなっていない筈。例えば
textarea#invalidate を実行した時にその場で反映されるだろうか。

処理が一巡したら、もしくはn巡したら更新するのも良い気がする。否、時間を決め
て置いてある程度時間が経ったら更新するというのでも良い。しかしそれならば、
普通の task として n 秒置きに更新をかけるというので良い気がする。その様にし
ておけば idle の他の処理が終わった後でも更新を確認し続ける様になるし自然な
実装であるように思われる。

それとは別に idle 内部の動作によって表示を更新する必要があるのであれば、そ
の動作を起こした側でその場で更新をかけるか或いは新しく task を投入するかす
るべきなのである。

* util (bleopt): 遅延定義された設定項目の check [#D1607]

airline: ble-reload する時に状態が書き換わってしまっているのに bleopt
vim_airline_theme=light の儘なので初期化が正しく為されない。うーん。既定値
から再設定される筈なのだがそれも正しく処理されていない? と思ったがそれは
ble.sh のロード時に処理される事なので遅延ロードされるモジュールの設定には当
て嵌まらないという事。遅延ロードされる時にはその場で "設定" を再現する必要
があるのではないか? 然し、そうすると関連する関数が既に定義済みでないと正し
く動作しない事になる。或いは bleopt -I vim_airline_@ 的な関数を最後に呼び出
して最初期化を強制するという可能性もある。

現在遅延定義される設定項目は恐らく vim_airline 及び vim_surround に限られる。
complete, syntax は ble.sh に設定項目を定義しているので問題にならない。

* done: vim-airline で bleopt -I vim_airline_@ を実行する

* done: 他にも影響のある場所がないか確認する。特に bleopt/check:
を定義しているオプションで、ble.pp の "bleopt -I" よりも後に実行
される可能性のある物が対象である。

確認した所 core-syntax.sh で定義されている check:filename_ls_colors が怪
しい。と思って実際に確認してみた所ちゃんと対策は為されていた。今回のこの
対策を bleopt -I を使う物に置き換える事にする。

* ok: update wiki と思ったが、元々 bleopt はそんなに詳しく説明していなかっ
た。bleopt -u も bleopt -r も wiki には説明が書かれていないので、bleopt
-I について今すぐに追加しなければならないという事はない気がする。一方で、
bleopt のもっと詳しい説明についてはいつか書かなければならない。

* prompt-git: bash 3 では async にできない→修正した [#D1606]

* history: cygwin に於いて arg_offset を処理していない気がするが大丈夫なのか [#D1605]

ble/builtin/history/.load-recent-entries から append:count=$delta という形
Expand Down
51 changes: 31 additions & 20 deletions src/util.sh
Expand Up @@ -20,6 +20,7 @@ function bleopt/.read-arguments/process-option {
flags=E$flags ;;
(reset) flags=r$flags ;;
(changed) flags=u$flags ;;
(initialize) flags=I$flags ;;
(*)
ble/util/print "bleopt: unrecognized long option '--$name'." >&2
flags=E$flags ;;
Expand Down Expand Up @@ -47,6 +48,7 @@ function bleopt/expand-variable-pattern {
## n --color=never
## r --reset
## u --changed
## I --initialize
## @var[out] pvars
## @var[out] specs
function bleopt/.read-arguments {
Expand All @@ -69,6 +71,7 @@ function bleopt/.read-arguments {
case $c in
(r) bleopt/.read-arguments/process-option reset ;;
(u) bleopt/.read-arguments/process-option changed ;;
(I) bleopt/.read-arguments/process-option initialize ;;
(*)
ble/util/print "bleopt: unrecognized option '-c'." >&2
flags=E$flags ;;
Expand Down Expand Up @@ -152,11 +155,12 @@ function bleopt {
' Set ble.sh options. Without arguments, this prints all the settings.' \
'' \
' Options' \
' --help Print this help.' \
' -r, --reset Reset options to the default values' \
' -u, --changed Only select changed options' \
' --help Print this help.' \
' -r, --reset Reset options to the default values' \
' -I, --initialize Re-initialize settings' \
' -u, --changed Only select changed options' \
' --color[=always|never|auto]' \
' Change color settings.' \
' Change color settings.' \
'' \
' Arguments' \
' NAME Print the value of the option.' \
Expand All @@ -183,11 +187,19 @@ function bleopt {
if [[ $flags == *r* ]]; then
local var
for var in "${pvars[@]}"; do
local def=_ble_opt_def_${var#bleopt_}
local name=${var#bleopt_}
ble/is-function bleopt/obsolete:"$name" && continue
local def=_ble_opt_def_$name
[[ ${!def+set} && ${!var-} != "${!def}" ]] &&
ble/array#push specs "$var=${!def}"
done
pvars=()
elif [[ $flags == *I* ]]; then
local var
for var in "${pvars[@]}"; do
bleopt/reinitialize "${var#bleopt_}"
done
pvars=()
fi

if ((${#specs[@]})); then
Expand Down Expand Up @@ -256,21 +268,20 @@ function bleopt/declare {
esac
return 0
}
function bleopt/check-all {
local name defname varname
for defname in "${!_ble_opt_def_@}"; do
name=${defname#_ble_opt_def_}
varname=bleopt_$name
[[ ${!varname} == "${!defname}" ]] && continue
ble/is-function bleopt/obsolete:"$name" && continue
ble/is-function bleopt/check:"$name" || continue

# 一旦値を既定値に戻して改めてチェックを行う。
local value=${!varname}
builtin eval -- "$varname=\$$defname"
bleopt/check:"$name" &&
builtin eval "$varname=\$value"
done
function bleopt/reinitialize {
local name=$1
local defname=_ble_opt_def_$name
local varname=bleopt_$name
[[ ${!defname+set} ]] || return 1
[[ ${!varname} == "${!defname}" ]] && return 0
ble/is-function bleopt/obsolete:"$name" && return 0
ble/is-function bleopt/check:"$name" || return 0

# 一旦値を既定値に戻して改めてチェックを行う。
local value=${!varname}
builtin eval -- "$varname=\$$defname"
bleopt/check:"$name" &&
builtin eval "$varname=\$value"
}

## @bleopt input_encoding
Expand Down

0 comments on commit 959cf27

Please sign in to comment.