Julia tem @edit
, @less
, etc. que são muito úteis para ler a implementação de funções. No entanto, você precisa especificar um conjunto de parâmetros (tipo) "bom o suficiente" para que eles encontrem a localização do código.
Em vez disso, InteractiveCodeSearch
fornece algumas macros para escolher interativamente o código que você deseja ler.
@search show
, expressão de chamada de função @search show(stdout, "hello")
, assinatura de chamada de função @search show(::IO, ::String)
, nome do módulo @search Base
, valor do argumento @searchmethods 1
e tipo de argumento @searchmethods ::Int
. using InteractiveCodeSearch
@search show # search method definitions
@searchmethods 1 # search methods defined for integer
@searchhistory # search history (Julia ≥ 0.7)
Comando de correspondência interativo. Por exemplo:
@search
@search x [:shallow | :s | :recursive | :r]
Liste os locais dos arquivos nos quais x
estão definidos em um matcher interativo e, em seguida, abra o local escolhido no editor.
Quando x
é um módulo, apenas as definições de nível superior são pesquisadas. Para pesquisar todas as definições no submódulo, passe o sinalizador :recursive
ou :r
.
@search
Se nenhuma expressão for fornecida, procure o método retornado pela execução anterior; ou seja, x
é padronizado como ans
.
Exemplos
@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
Observe que @search
avalia expressões complexas com .
e []
como segue e pesquise o valor retornado ou o tipo dele:
@search Base . Multimedia . displays[ 2 ] . repl
@searchmethods
@searchmethods x
@searchmethods ::X
Pesquise interativamente methodswith(typeof(x))
ou methodswith(X)
.
Exemplos
@searchmethods 1 # search methods defined for integer
@searchmethods :: Int # search methods defined for a specified type
@searchhistory
@searchhistory
Pesquise o histórico de forma interativa. Restringe interativamente o código que você procura no histórico do REPL.
Limitação/recurso em IJulia : Em IJulia, @searchhistory
pesquisa o histórico do terminal REPL, não o histórico da sessão IJulia atual.
InteractiveCodeSearch.CONFIG
Interface de configuração para InteractiveCodeSearch
.
Exemplos
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
Usando InteractiveCodeSearch.jl por padrão
Coloque o seguinte código em seu ~/.julia/config/startup.jl
(≥ Julia 0.7) ou ~/.juliarc.jl
(Julia 0.6):
using InteractiveCodeSearch
# InteractiveCodeSearch.CONFIG.interactive_matcher = ...