Skip to content

Commit

Permalink
util (ble/util/type): fix a bug that aliases are not properly highlig…
Browse files Browse the repository at this point in the history
…hted
  • Loading branch information
akinomyoga committed May 4, 2021
1 parent c89aa23 commit 45b30a7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ble.pp
Expand Up @@ -286,6 +286,10 @@ function ble/base/restore-bash-options {
[[ $_ble_bash_setx && ! -o xtrace ]] && set -x
[[ $_ble_bash_sete && ! -o errexit ]] && set -e # set -e は最後
} 2>/dev/null # set -x 対策 #D0930
function ble/base/reinforce-bash-options {
# bind -x が終わる度に設定が復元されてしまうので毎回設定し直す。
shopt -u expand_aliases
}

{
# 対策 expand_aliases (暫定) 終了
Expand Down
7 changes: 4 additions & 3 deletions memo/ChangeLog.md
Expand Up @@ -52,7 +52,8 @@
- util (`bleopt`): fix a bug that old values are double-expanded on init (fixup 82c5ece) `#D1521` f795c07
- complete (`ble/complete/source:file`): remove slow old codes (reported by timjrd) `#D1512` e5be0c1
- main: preserve user-space overridden builtins `#D1519` 0860be0
- syntax (`ble/syntax:bash/simple-word/eval`): optimize large array passing `#D1522` 0000000
- util (`ble/util/type`): fix a bug that aliases are not properly highlighted (reported by 3ximus) `#D1526` 0000000
- syntax (`ble/syntax:bash/simple-word/eval`): optimize large array passing (motivated by timjrd) `#D1522` c89aa23

## Fixes

Expand Down Expand Up @@ -104,8 +105,8 @@
- util, etc: ensure each function to work with arbitrary `IFS` `#D1490` `#D1491` 5f9adfe
- tui, canvas (`ble/canvas/trace`): support `opts=clip` `#D1493` 61ce90c
- tui, edit: add a new render mode for full-screen applications 817889d
- main: prefer `nawk` over `mawk` and `gawk` `#D1523` `#D1524` 0000000
- test (`test-canvas`): fix dependency on `ext/contra` `#D1525` 0000000
- main: prefer `nawk` over `mawk` and `gawk` `#D1523` `#D1524` c89aa23
- test (`test-canvas`): fix dependency on `ext/contra` `#D1525` c89aa23

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel2
Expand Down
32 changes: 32 additions & 0 deletions note.txt
Expand Up @@ -4282,6 +4282,38 @@ bash_tips

2021-05-04

* syntax: 着色決定時に expand_aliases 設定が退避されている [#D1526]
https://github.com/akinomyoga/ble.sh/issues/103

0860be0 に於いて内部では alias が展開されない様に shopt -u expand_aliases
を設定していた。然し、よく考えてみたら構文着色等に於いて expand_aliases が
有効かどうかによって処理を変えていた。つまり expand alias の処理の際にちゃ
んと退避した設定を確認する必要がある。

実際に修正しようとしたら話はそう単純ではない様である。そもそも自分で shopt
-s/-u expand_aliases を変更しようとしても完全に無視されてしまう。次のユーザー
状態になる頃には勝手に元の値に戻ってしまっている。何故? 例えば
POSIXLY_CORRECT を手で弄っている所為だろうか。或いは expand_aliases の保存
復元の呼び出しタイミングが混ざっているからだろうか。それとも bind -x の中で
変更した expand_aliases の状態は抜けると消えてしまうという事なのだろうか。

やはり自分では何も操作していないのに expand_aliases の設定が変わってしまっ
ている。うーん。という事は…どうすれば良いのか?

* 内部で shopt -u expand_aliases にしたいというのは…。毎回 bind head で設
定し直すぐらいしかできない→ bind/.head で再設定する様にした。

* ユーザーが設定した設定が保持されないという事に関しては。これは明示的に自
分で保存復元する必要がある。特に restore する時には shopt -u
expand_aliases も明示的に実行する。→これは bind/.head で設定する様にした
ので、わざわざ自分で実行しなくても良い。

* エイリアスを展開する時に一時的に shopt -s expand_aliases 状態を復元する。
と思ったが、それでは駄目だった。様々な所で ble/util/type を呼び出していて、
その結果が alias にならないとそもそも expand-alias 関数自体が呼び出されな
い。修正するべきは expand-alias ではなくて ble/util/type の方である。こち
らを修正したら動く様になった。

* util: test-canvas.sh ext/contra 依存性の解消 [#D1525]

test-canvas.sh がエラーを出す様になっている。試すとテストを取り入れた時から
Expand Down
1 change: 1 addition & 0 deletions src/edit.sh
Expand Up @@ -8262,6 +8262,7 @@ fi

function ble-edit/bind/.head {
ble-edit/bind/stdout.on
ble/base/reinforce-bash-options

[[ $bleopt_internal_suppress_bash_output ]] ||
ble-edit/bind/.head/adjust-bash-rendering
Expand Down
5 changes: 4 additions & 1 deletion src/util.sh
Expand Up @@ -2536,7 +2536,10 @@ fi
## @param[in] command
## 種類を判定するコマンド名を指定します。
function ble/util/type {
ble/util/assign-array "$1" 'builtin type -a -t -- "$3" 2>/dev/null' "$2"
[[ $_ble_attached && $_ble_bash_expand_aliases ]] && shopt -s expand_aliases
ble/util/assign-array "$1" 'builtin type -a -t -- "$3" 2>/dev/null' "$2"; local ext=$?
[[ $_ble_attached && $_ble_bash_expand_aliases ]] && shopt -u expand_aliases
return "$ext"
}
## @fn ble/util/expand-alias word
## @var[out] ret
Expand Down

0 comments on commit 45b30a7

Please sign in to comment.