Skip to content

Commit

Permalink
complete (source:command/get-desc): show function location and body
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Mar 4, 2022
1 parent f8bbe2c commit 496e798
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -148,6 +148,7 @@
- complete (`action:file`): always suffix `/` to complete symlinked directory names (reported by SuperSandro2000) `#D1759` 397ac1f
- edit (command-help): show source files for functions `#D1779` 7683ab9
- edit (`ble/builtin/exit`): defer exit in trap handlers (motivated by SuperSandro2000) `#D1782` f62fc04 6fdabf3
- complete (`source:command/get-desc`): show function location and body `#D1788` 0000000

## Fixes

Expand Down
13 changes: 10 additions & 3 deletions lib/core-complete.sh
Expand Up @@ -1860,10 +1860,17 @@ function ble/complete/action:command/get-desc {
[[ $path == ?*/"$CAND" ]] && path="from ${path%/"$CAND"}"
title=file value=$path ;;
($_ble_attr_CMD_FUNCTION)

local source lineno
ble/function#get-source-and-lineno "$CAND"

local def; ble/function#getdef "$CAND"
local ret
ble/string#quote-word "$def" ansi:sgrq="$desc_sgrq":quote-empty
title=function value=$ret ;;
ble/string#match "$def" '^[^()]*\(\)[[:space:]]*\{[[:space:]]+(.*[^[:space:]])[[:space:]]+\}[[:space:]]*$' &&
def=${BASH_REMATCH[1]} # 関数の中身を抽出する
local ret sgr0=$'\e[27m' sgr1=$'\e[7m' # Note: sgr-ansi で生成
lines=1 cols=${COLUMNS:-80} x=0 y=0 ble/canvas/trace-text "$def" external-sgr

title=function value="${source##*/}:$lineno $desc_sgrq$ret" ;;
($_ble_attr_CMD_JOBS)
ble/util/joblist.check
local job; ble/util/assign job 'jobs -- "$CAND" 2>/dev/null' || job='???'
Expand Down
19 changes: 15 additions & 4 deletions note.txt
Expand Up @@ -1858,10 +1858,6 @@ bash_tips
また、前者を採用するとしたら -r に対して optarg を要求するのか、或いは -r
に対して optarg を要求するのかで振る舞いが変わってくる。

* complete (action:command): function の description の quote が邪魔。最初の2
行と末尾の } は削除して良い。また、quote ではなくて text と同様の表示の仕方
にしたい気がする。

* trap (lastarg): 一応 heredoc 等を使えば eval の中から複数行の lastarg を設
定する事ができるのではないか。他に複数行で、eval されても余分な実行が起こら
ない様な方法はあるだろうか。不完全な引用符の場合には結局エラーが出力されて
Expand Down Expand Up @@ -6181,6 +6177,21 @@ bash_tips

2022-03-01

* complete (action:command): function の description の quote が邪魔 [#D1788]

最初の2行と末尾の } は削除して良い。また、quote ではなくて trace-text と同
様の表示の仕方にしたい気がする。

trace-text と同様の文字列に変換する関数は既になかったか?

うーん。ble/unicode/GraphemeCluster/.get-ascii-rep という関数があるがこれは
内部的にしか使用されていない。一方で、うーん。というか
ble/canvas/trace-text をそのまま呼び出すべきの気がしてきた。そもそもその為
の関数の筈である。

或いはファイル名と行番号を表示した方が有益の気もする。取り敢えず両方表示す
る事にした。ファイルパスは長くなるので最後の名前だけ表示する事にした。

* complete: --optarg= に対して progcomp が走らない (motivated by rsteube) [#D1787]

これは "--optarg=" 全体に対する引数補完よりも = の右辺 "" に対する優先順位
Expand Down

0 comments on commit 496e798

Please sign in to comment.