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 = ...