檢視原始碼 edlin_expand (stdlib v6.2)

Shell 擴展和擴展建議的格式化。

此模組為 Erlang Shell 提供 expand/1,2 的 expand_fun。可以覆寫此 expand_fun io:setopts/1,2

摘要

函數

等同於 expand/2

標準的擴展函數能夠將字串擴展為有效的 Erlang 項。這包括模組名稱

函數

連結到此函數

expand(Bef0)

檢視原始碼 (自 OTP 26.0 起)
-spec expand(Bef0) -> {Res, Completion, Matches}
                when
                    Bef0 :: string(),
                    Res :: yes | no,
                    Completion :: string(),
                    Matches :: [Element] | [Section],
                    Element :: {string(), [ElementOption]},
                    ElementOption :: {ending, string()},
                    Section :: #{title := string(), elems := Matches, options := SectionOption},
                    SectionOption ::
                        {highlight_all} |
                        {highlight, string()} |
                        {highlight_param, integer()} |
                        {hide, title} |
                        {hide, result} |
                        {separator, string()}.

等同於 expand/2

連結到此函數

expand(Bef0, Opts)

檢視原始碼 (自 OTP 26.0 起)
-spec expand(Bef0, Opts) -> {Res, Completion, Matches}
                when
                    Bef0 :: string(),
                    Opts :: [Option],
                    Option :: {legacy_output, boolean()},
                    Res :: yes | no,
                    Completion :: string(),
                    Matches :: [Element] | [Section],
                    Element :: {string(), [ElementOption]},
                    ElementOption :: {ending, string()},
                    Section :: #{title := string(), elems := Matches, options := SectionOption},
                    SectionOption ::
                        {highlight_all} |
                        {highlight, string()} |
                        {highlight_param, integer()} |
                        {hide, title} |
                        {hide, result} |
                        {separator, string()}.

標準的擴展函數能夠將字串擴展為有效的 Erlang 項。這包括模組名稱

1> erla
modules
erlang:

函數名稱

1> is_ato
functions
is_atom(
2> erlang:is_ato
functions
is_atom(

函數類型

1> erlang:is_atom(
typespecs
erlang:is_atom(Term)
any()

並且在沒有其他有效擴展可能時自動添加逗號或右括號。擴展函數還會補全:shell 綁定、記錄名稱、記錄欄位和映射鍵。

如下所示,如果函數標頭具有相同的擴展建議,則會將它們分組在一起,在本例中,它們都具有相同的建議,即 '}'。也有限制地支援過濾掉與提示符上的項類型不匹配的函數類型規範。下方僅顯示 4 個建議,但 erlang:system_info 有更多類型規範。

1> erlang:system_info({allocator, my_allocator
typespecs
erlang:system_info(wordsize | {wordsize, ...} | {wordsize, ...})
erlang:system_info({allocator, ...})
erlang:system_info({allocator_sizes, ...})
erlang:system_info({cpu_topology, ...})
}

expand 函數的返回類型指定為 Element 元組的列表或 Section 映射的列表。引入區段概念是為了為擴展結果啟用更多格式化選項。例如,shell 擴展支援突出顯示文字和隱藏建議。還有一個 {highlight, Text} 會突出顯示標題中所有出現的 Text,以及一個簡化的 highlight_all,它會突出顯示整個標題,如上面的 functionstypespecs 所示。

透過設定 {hide, result}{hide, title} 選項,您可以隱藏建議。有時標題沒有用處,只會產生文字雜訊,在上面的範例中,any/0 結果是標題為 Types 的區段的一部分。目前尚未使用隱藏結果,但其想法是可以在擴展區域中選取區段,並且應收合所有其他區段條目。

可以在標題和結果之間設定自訂分隔符。可以使用 {separator, Separator} 來完成此操作。預設情況下設定為 \n,某些結果會顯示 type_name() ::,後接定義 type_name() 的所有類型。

{ending, Text} ElementOption 只是將 Text 附加到 Element