Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tkf/interactivecodesearch.jl
Interactively search Julia code from terminal
https://github.com/tkf/interactivecodesearch.jl
interactive julia peco percol repl rofi search terminal
Last synced: 2 months ago
JSON representation
Interactively search Julia code from terminal
- Host: GitHub
- URL: https://github.com/tkf/interactivecodesearch.jl
- Owner: tkf
- License: other
- Created: 2018-03-19T04:00:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-06T08:15:02.000Z (over 2 years ago)
- Last Synced: 2024-10-27T09:19:33.127Z (2 months ago)
- Topics: interactive, julia, peco, percol, repl, rofi, search, terminal
- Language: Julia
- Homepage:
- Size: 383 KB
- Stars: 119
- Watchers: 3
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# InteractiveCodeSearch.jl –- Interactively search Julia code
[![Build Status][ci-img]][ci-url]
[![codecov.io][codecov-img]][codecov-url]![gif animation](search.gif "Searching code using @search")
Julia has `@edit`, `@less`, etc. which are very handy for reading the implementation of functions. However, you need to specify a "good enough" set of (type) parameters for them to find the location of the code.
Instead, `InteractiveCodeSearch` provides a few macros to interactively choose the code you want to read.
## Features
* Interactively choose a method signature before opening the code location in your editor.
* Various ways to search methods, such as: by function name `@search show`, function call expression `@search show(stdout, "hello")`, function call signature `@search show(::IO, ::String)`, module name `@search Base`, argument value `@searchmethods 1`, and argument type `@searchmethods ::Int`.
* Interactively search history. It works in IJulia as well.## Examples
```julia
using InteractiveCodeSearch
@search show # search method definitions
@searchmethods 1 # search methods defined for integer
@searchhistory # search history (Julia ≥ 0.7)
```## Requirements
* Interactive matching command. For example:
* [fzf](https://github.com/junegunn/fzf) (default in terminal)
* [peco](https://github.com/peco/peco)
* [percol](https://github.com/mooz/percol)
* [rofi](https://github.com/DaveDavenport/rofi) (GUI; default in IJulia)## Reference
### `@search`
```
@search x [:shallow | :s | :recursive | :r]
```List file locations at which `x` are defined in an interactive matcher and then open the chosen location in the editor.
When `x` is a module, only the top-level definitions are searched. To search all definitions in the submodule, pass `:recursive` or `:r` flag.
```
@search
```If no expression is provided, search for the method returned by the previous execution; i.e., `x` defaults to `ans`.
**Examples**
```julia
@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
```Note that `@search` evaluates complex expression with `.` and `[]` such as follows and search the returned value or the type of it:
```julia
@search Base.Multimedia.displays[2].repl
```### `@searchmethods`
```
@searchmethods x
@searchmethods ::X
```Interactively search through `methodswith(typeof(x))` or `methodswith(X)`.
**Examples**
```julia
@searchmethods 1 # search methods defined for integer
@searchmethods ::Int # search methods defined for a specified type
```### `@searchhistory`
```
@searchhistory
```Search history interactively. Interactively narrows down the code you looking for from the REPL history.
*Limitation/feature in IJulia*: In IJulia, `@searchhistory` searches history of terminal REPL, not the history of the current IJulia session.
### `InteractiveCodeSearch.CONFIG`
Configuration interface for `InteractiveCodeSearch`.**Examples**
```julia
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
```**Using InteractiveCodeSearch.jl by default**
Put the following code in your `~/.julia/config/startup.jl` (≥ Julia 0.7) or `~/.juliarc.jl` (Julia 0.6):
```julia
using InteractiveCodeSearch
# InteractiveCodeSearch.CONFIG.interactive_matcher = ...
```[ci-img]: https://github.com/tkf/InteractiveCodeSearch.jl/actions/workflows/test.yml/badge.svg
[ci-url]: https://github.com/tkf/InteractiveCodeSearch.jl/actions/workflows/test.yml
[codecov-img]: http://codecov.io/github/tkf/InteractiveCodeSearch.jl/coverage.svg?branch=master
[codecov-url]: http://codecov.io/github/tkf/InteractiveCodeSearch.jl?branch=master