InteractiveCodeSearch.jl
v0.4.3
Julia 有@edit
、 @less
等,對於閱讀函數的實作非常方便。但是,您需要指定一組「足夠好」的(類型)參數,以便它們找到程式碼的位置。
相反, InteractiveCodeSearch
提供了一些巨集來互動式地選擇您想要閱讀的程式碼。
@search show
、函式呼叫運算式@search show(stdout, "hello")
、函式呼叫簽章@search show(::IO, ::String)
、模組名稱@search Base
、參數值@searchmethods 1
和參數類型@searchmethods ::Int
。 using InteractiveCodeSearch
@search show # search method definitions
@searchmethods 1 # search methods defined for integer
@searchhistory # search history (Julia ≥ 0.7)
互動式匹配命令。例如:
@search
@search x [:shallow | :s | :recursive | :r]
列出在互動式匹配器中定義x
的檔案位置,然後在編輯器中開啟所選位置。
當x
是模組時,僅搜尋頂級定義。若要搜尋子模組中的所有定義,請傳遞:recursive
或:r
標誌。
@search
如果沒有提供表達式,則搜尋上一次執行返回的方法;即x
預設為ans
。
範例
@search show # all method definitions
@search @time # all macro definitions
@search Base . Enums # methods and macros in a module
@search REPL :r # search the module recursively
@search * ( :: Integer , :: Integer ) # methods with specified types
@search dot (π, ℯ) # methods with inferred types
請注意, @search
使用 計算複雜表達式.
和[]
如下,搜尋返回值或其類型:
@search Base . Multimedia . displays[ 2 ] . repl
@searchmethods
@searchmethods x
@searchmethods ::X
透過methodswith(typeof(x))
或methodswith(X)
進行互動式搜尋。
範例
@searchmethods 1 # search methods defined for integer
@searchmethods :: Int # search methods defined for a specified type
@searchhistory
@searchhistory
互動式搜尋歷史記錄。以互動方式縮小您從 REPL 歷史記錄中尋找的程式碼範圍。
IJulia 中的限制/功能:在 IJulia 中, @searchhistory
搜尋終端機 REPL 的歷史記錄,而不是目前 IJulia 會話的歷史記錄。
InteractiveCodeSearch.CONFIG
InteractiveCodeSearch
的設定介面。
範例
using InteractiveCodeSearch
InteractiveCodeSearch . CONFIG . interactive_matcher = ` fzf ... ` # default in terminal
InteractiveCodeSearch . CONFIG . interactive_matcher = ` peco `
InteractiveCodeSearch . CONFIG . interactive_matcher = ` percol `
InteractiveCodeSearch . CONFIG . interactive_matcher =
` rofi -dmenu -i -p "?" ` # use GUI matcher (default in non-terminal
# environment like IJulia)
InteractiveCodeSearch . CONFIG . interactive_matcher =
` rofi -dmenu -i -p "?" -fullscreen ` # bigger screen
InteractiveCodeSearch . CONFIG . open = edit # default
InteractiveCodeSearch . CONFIG . open = less # use Base.less to read code
InteractiveCodeSearch . CONFIG . auto_open = true # default
InteractiveCodeSearch . CONFIG . auto_open = false # open matcher even when there
# is only one candidate
InteractiveCodeSearch . CONFIG . trigger_key = ' ) ' # insert "@search" on ')' (default)
InteractiveCodeSearch . CONFIG . trigger_key = nothing # disable shortcut
預設使用 InteractiveCodeSearch.jl
將以下程式碼放入~/.julia/config/startup.jl
(≥ Julia 0.7) 或~/.juliarc.jl
(Julia 0.6) 中:
using InteractiveCodeSearch
# InteractiveCodeSearch.CONFIG.interactive_matcher = ...