Skip to content

Commit

Permalink
Merge pull request #95 from michaelb/dev
Browse files Browse the repository at this point in the history
5.10
  • Loading branch information
michaelb authored Sep 11, 2021
2 parents f2e1950 + 77b5dec commit b343cd6
Show file tree
Hide file tree
Showing 29 changed files with 1,692 additions and 436 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ test/
download_dir/
target/
ressources/infofile.txt
Cargo.lock
test_sniprun.log
71 changes: 71 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Lua API to sniprun

You can use sniprun API from:

```lua

local sa = require('sniprun.api')

```

then, some functions are accessible, such as

```
sa.run_range(r_start, r_end, <filetype>, <config>)
sa.run_string(codestring, <filetype>, <config>)
```

ranges are integers matching the (inclusive) line numbers

codestring must be a string

filetype (optionnal) must be a string such as 'python'

config (optionnal) allows to override the default/user config. It's particularly interesting to provide the display type 'Api' in this field if you wish to retrieve sniprun's output without interference on the user UI.


You can register listeners that will be called upon (async) sniprun output:


```
sa.register_listener(custom_function)
```

where custom function is a function that take one unique argument: a table which contains at least two entries:

- 'status' (a string that's either 'ok' or 'error' for now, but your function should accept & manage other values)
- 'message' (also a string, maybe be mutliline)

(Simply put, registered functions are callbacks)




Thus, an example of such a function (imitating the 'Classic' display with 'uwu' tendencies) would be

```
local api_listener = function (d)
if d.status == 'ok' then
print("Nice uwu: ", d.message)
elseif d.status == 'error' then
print("Oh nyow! Somethuwuing went wyong: ", d.message)
else
print("Whut is this myeow? I don't knyow this status type nyah")
end
end
sa.register_listener(api_listener)
```


## Warnings

Beware, sniprun is still thightly coupled to the current nvim buffer & instance, but there should not be dependencies for non-REPL, and interpreters running under Bloc-Level.

REPL-capable and Import level (or more) interpreter may fetch information from the current buffer



5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.5.10
- SageMath & orgmode support
- API
- nvim-notify display method

## v0.5.9
- TypeScript support
- Better README & example.rs
Expand Down
12 changes: 12 additions & 0 deletions CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Before releasing

- check compilation success
- create a version bump commit
- merge
- create a new tag vX.Y.Z on master
- git push --origin vX.Y.Z

# After release

- Check CI status
- Check Releases status
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sniprun"
version = "0.5.9"
version = "0.5.10"
authors = ["michaelb <[email protected]>"]
edition = "2018"

Expand Down
88 changes: 51 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ I know that this README is exhaustively long (for the sake of clarity, bear with

</br>

###### TLDR: ```Plug 'michaelb/sniprun', {'do': 'bash install.sh'} ```, ```:SnipRun```, ```:'<,'>SnipRun```,```:SnipInfo```
###### TLDR: ```Plug 'michaelb/sniprun', {'do': 'bash install.sh'}``` </br> ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ```:SnipRun```, ```:'<,'>SnipRun```,```:SnipInfo```
###### (but please configure the \<Plug> mappings)


Expand Down Expand Up @@ -66,17 +66,20 @@ An example in C, look in the command area:

![](ressources/visual_assets/demo_c.gif)

##### The result can be displayed in multiple (even at the same time) ways:
##### The result can be returned in multiple (even at the same time) ways:

[Classic](ressources/display_classic.md)| [Virtual Text](ressources/display_virtualtext.md)
:------------------------------------------:|:------------------:
![](ressources/visual_assets/classic.png) | ![](ressources/visual_assets/virtual_text.png)
[**Temporary Floating Window**](ressources/display_floating_window.md) | [**Terminal**](ressources/display_terminal.md)
![](ressources/visual_assets/floating_window.png) | ![](ressources/visual_assets/terminal.png)
[**Notification**](ressources/display_notify.md) | [**API**](API.md)
![](ressources/visual_assets/nvimnotify.png) | ![](ressources/visual_assets/api.png)


##### send-to-REPL-like behavior is available for some languages
Python, R, Mathematica, Julia (all real REPLs) and Bash (simulated), coming soon for many other interpreted and compiled languages. Very versatile, you can even run things like GUI plots on the fly!

Python, R, Mathematica, Sage, Julia (all real REPLs) and Bash (simulated), coming soon for many other interpreted and compiled languages. Very versatile, you can even run things like GUI plots on the fly!

![](ressources/visual_assets/demo_repl.gif)

Expand Down Expand Up @@ -126,6 +129,8 @@ Sniprun will then:

- [optionnal] **cargo and the rust toolchain** version >= 1.43.0 (you can find those [here](https://www.rust-lang.org/tools/install)).

- [optionnal] the plugin [nvim-notify](github.com/rcarriga/nvim-notify) for the notification display style

- **Compiler / interpreter** for the languages you work with must be installed & on your \$PATH. In case specific build tools or softwares are required, those are documented in the [doc](https://github.com/michaelb/sniprun/tree/master/doc) folder, for each interpreter, which I urge you to get a look at before getting started as it also contains the potential limitations of each interpreter; this information can also be accessed through `:SnipInfo <interpreter_name>` (tab autocompletion supported).


Expand Down Expand Up @@ -254,45 +259,54 @@ Sniprun is a Lua plugin, but **you don't need** the usual boilerplate: if you do

However, if you want to change some options, you can add this snippet (the default config) to your configuration file and modify if at will (you can remove keys without issue to shorten your config, as the default values are overwritten on a key-by-key basis):

```vim
```bash
lua << EOF
require'sniprun'.setup({
selected_interpreters = {}, --" use those instead of the default for the current filetype
repl_enable = {}, --" enable REPL-like behavior for the given interpreters
repl_disable = {}, --" disable REPL-like behavior for the given interpreters
selected_interpreters = {}, --# use those instead of the default for the current filetype
repl_enable = {}, --# enable REPL-like behavior for the given interpreters
repl_disable = {}, --# disable REPL-like behavior for the given interpreters
interpreter_options = {}, --" intepreter-specific options, consult docs / :SnipInfo <name>
interpreter_options = {}, --# intepreter-specific options, consult docs / :SnipInfo <name>
--" you can combo different display modes as desired
--# you can combo different display modes as desired
display = {
"Classic", -- "display results in the command-line area
"VirtualTextOk", -- "display ok results as virtual text (multiline is shortened)
"Classic", --# display results in the command-line area
"VirtualTextOk", --# display ok results as virtual text (multiline is shortened)
-- "VirtualTextErr", --# display error results as virtual text
-- "TempFloatingWindow", --# display results in a floating window
-- "LongTempFloatingWindow", --# same as above, but only long results. To use with VirtualText__
-- "Terminal", --# display results in a vertical split
-- "NvimNotify", --# display with the nvim-notify plugin
-- "Api" --# return output to a programming interface
},
-- "VirtualTextErr", -- "display error results as virtual text
-- "TempFloatingWindow", -- "display results in a floating window
-- "LongTempFloatingWindow", -- "same as above, but only long results. To use with VirtualText__
-- "Terminal" -- "display results in a vertical split
},
--# You can use the same keys to customize whether a sniprun producing
--# no output should display nothing or '(no output)'
show_no_output = {
"Classic",
"TempFloatingWindow", --# implies LongTempFloatingWindow, which has no effect on its own
},
--" customize highlight groups (setting this overrides colorscheme)
--# customize highlight groups (setting this overrides colorscheme)
snipruncolors = {
SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"},
SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"},
SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",cterfg="Black"},
SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"},
},
--" miscellaneous compatibility/adjustement settings
inline_messages = 0, --" inline_message (0/1) is a one-line way to display messages
--" to workaround sniprun not being able to display anything
--# miscellaneous compatibility/adjustement settings
inline_messages = 0, --# inline_message (0/1) is a one-line way to display messages
--# to workaround sniprun not being able to display anything
borders = 'single' --" display borders around floating windows
--" possible values are 'none', 'single', 'double', or 'shadow'
borders = 'single' --# display borders around floating windows
--# possible values are 'none', 'single', 'double', or 'shadow'
})
EOF
```

Example, to use the interpreter 'Python3_jupyter' whenever possible [instead of the 'Python3_original' default],
Example, to use the interpreter 'Python3\_jupyter' whenever possible [instead of the 'Python3\_original' default],
`lua require'sniprun'.setup({selected_interpreters = {'Python3_jupyter'}})`

**NOTE**: Some interpreters have specific options and dependencies, such as what version / compiler to use: you cand find more about that with `:SnipInfo <interpreter_name>`
Expand All @@ -302,15 +316,15 @@ Example, to use the interpreter 'Python3_jupyter' whenever possible [instead of

All of sniprun functionnalities:

| Shorthand | Lua backend | \<Plug> mapping |
|-----------------------------|--------------------------------------|----------------------------|
| :SnipRun | lua require'sniprun'.run() | \<Plug>SnipRun |
| (normal node) | lua require'sniprun'.run('n') | \<Plug>SnipRunOperator |
| :'<,'>SnipRun (visual mode) | lua require'sniprun'.run('v') | \<Plug>SnipRun |
| :SnipInfo | lua require'sniprun'.info() | \<Plug>SnipInfo |
| :SnipReset | lua require'sniprun'.reset() | \<Plug>SnipReset |
| :SnipReplMemoryClean | lua require'sniprun'.clear_repl() | \<Plug>SnipReplMemoryClean |
| :SnipClose | lua require'sniprun.display'.close() | \<Plug>SnipClose |
| Shorthand | Lua backend | \<Plug> mapping |
|------------------------------|--------------------------------------|----------------------------|
| :SnipRun | lua require'sniprun'.run() | \<Plug\>SnipRun |
| (normal node) | lua require'sniprun'.run('n') | \<Plug\>SnipRunOperator |
| :'\<,'\>SnipRun (visual mode)| lua require'sniprun'.run('v') | \<Plug\>SnipRun |
| :SnipInfo | lua require'sniprun'.info() | \<Plug\>SnipInfo |
| :SnipReset | lua require'sniprun'.reset() | \<Plug\>SnipReset |
| :SnipReplMemoryClean | lua require'sniprun'.clear\_repl() | \<Plug\>SnipReplMemoryClean |
| :SnipClose | lua require'sniprun.display'.close() | \<Plug\>SnipClose |


You can find [here](ressources/old_configuration.md) the 'old'/vimscript way to configure sniprun, still compatible but may be deprecated at some point.
Expand All @@ -321,7 +335,7 @@ You can find [here](ressources/old_configuration.md) the 'old'/vimscript way to

- Map the run command to a simple command such as `<leader>ff` (or just `f` in visual mode)
- Check `SnipInfo` & `:SnipInfo <interpreter_name>` to learn any quirk or tips about the language you're interested in
- The operator mapping allows you to combine movements with sniprun: with the suggested mapping, "\<leader>f + j" will run sniprun on the current line + the line below.
- The operator mapping allows you to combine movements with sniprun: with the suggested mapping, "\<leader\>f + j" will run sniprun on the current line + the line below.

(if you don't know what is the leader key you can find a short explanation [here](https://vim.works/2019/03/03/vims-leader-key-wtf-is-it/)).

Expand Down Expand Up @@ -390,14 +404,14 @@ println!("-> {}", alphabet);
| COBOL | Untested | | Lua-nvim | Bloc + REPL |
| Coffeescript | Bloc | | Markdown | Bloc + REPL\*\*\*|
| C# | Untested | | Mathematica| Bloc + REPL\*\* |
| D | Bloc | | Perl/Perl6 | Line |
| Elixir | Untested | | PHP | Untested |
| D | Bloc | | OrgMode | Bloc + REPL\*\*\*|
| Elixir | Untested | | Perl/Perl6 | Line |
| Elm | Untested | | Python3 | Import +REPL\*\* |
| Erlang | Untested | | R | Bloc + REPL\*\* |
| F# | Untested | | Ruby | Bloc |
| Go | Bloc | | Rust | Bloc |
| Groovy | Untested | | Scala | Bloc |
| Haskell | Line | | Scilab | Untested |
| Groovy | Untested | | SageMath | Import + REPL\*\*|
| Haskell | Line | | Scala | Bloc |
| Idris | Untested | | TypeScript | Bloc |


Expand Down
57 changes: 57 additions & 0 deletions doc/OrgMode_original.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
the Orgmode\_original interpreter helps you running code blocs defined in org code blocs delimiters

inline, switches and headers are not supported/ignored

# example 1

-------------

```
#+NAME: demo
#+BEGIN_SRC bash
echo "lol" # << you can run sniprun on this line
\# or the whole visual selection following:
for i in {1..4};do
echo $i
done
#+END_SRC
```


# example 2

-------------

```
#+NAME: demo_run_whole_bloc
#+BEGIN_SRC rust << running on this line will run the entire bloc
println!("test");
println!("test2");
#+END_SRC
```

-------------

**the language name must be there (otherwise the default * will be used) at the bloc start** and has to match the language name or the filetype associated

\* python, but you can ofc configure that:

```
require'sniprun'.setup({
interpreter_options = {
OrgMode_original = {
default_filetype = 'bash' -- default filetype/language name
}
}
})
```
23 changes: 23 additions & 0 deletions doc/Sage_fifo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Sage\_fifo interpreter

This is a pipe-based implementation: you have to run sniprun once before being able to send code snippets (configure an autcmd?)

A sage REPL is launcher in the background and won't quit until you exit neovim (or after 10h).

This interpreter only works in REPL-mode (and behaves REPL-like by default)

two configurations keys are available:

```
require'sniprun'.setup({
interpreter_options = {
Sage_fifo = {
interpreter = "sage",
sage_user_config = 1, -- the actual value has no effect, only the presence of the key is important
}
}
}
});
```

Sage\_fifo currently support auto-importing python imports
Loading

0 comments on commit b343cd6

Please sign in to comment.