Skip to content

Commit

Permalink
Merge pull request #82 from michaelb/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
michaelb authored May 21, 2021
2 parents c64f2c2 + 148bbbf commit e22b5ef
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Yeah cool but what _code_ goes inside?
---
I just finished some changes, how do I test my code quickly?

-> compile `cargo build --release` and run `nvim --cmd "set rtp+=. -u NORC <testfile>` from the sniprun project root.
-> compile `cargo build --release` and run `nvim --cmd "set rtp+=. -u NONE <testfile>` from the sniprun project root.

---

Expand Down
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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 displayed in multiple (even at the same time) ways:

[Classic](ressources/display_classic.md)| [Virtual Text](ressources/display_virtualtext.md)
:------------------------------------------:|:------------------:
Expand Down Expand Up @@ -95,7 +95,7 @@ Basically, it allows you to run a part of your code.
Do either of:

- Position the cursor on a line `:SnipRun`
- Select some visual range, `:'<,'>SnipRun`
- Select some visual range, `:'<,'>SnipRun`
- Combine a motion with the operator

(preferably through a shortcut!)
Expand All @@ -111,7 +111,7 @@ Sniprun will then:
- **Add boilerplate** when it exists. In C, it surrounds your snip with "int main() {", "}". (disclaimer: oversimplifed)
- **Build** (write to a script file, or compile) the code
- **Execute** the code
- Return stdout, or stderr using the
- Return stdout, or stderr using the


![](ressources/visual_assets/760091.png)
Expand All @@ -126,8 +126,6 @@ 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] recent GLIBC (at least 2.33) if you want to use the precompiled binary, otherwise you'll have to compile sniprun yourself.

- **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 @@ -266,8 +264,7 @@ require'sniprun'.setup({
repl_enable = {}, --" enable REPL-like behavior for the given interpreters
repl_disable = {}, --" disable REPL-like behavior for the given interpreters
inline_messages = 0, --" inline_message (0/1) is a one-line way to display messages
--" to workaround sniprun not being able to display anything
interpreter_options = {}, --" intepreter-specific options, consult docs / :SnipInfo <name>
-- " you can combo different display modes as desired
display = {
Expand All @@ -278,16 +275,21 @@ require'sniprun'.setup({
-- "LongTempFloatingWindow", -- "same as above, but only long results. To use with VirtualText__
-- "Terminal" -- "display results in a vertical split
},
-- customize highlight groups (setting this overrides colorscheme)
snipruncolors = {
snipruncolors = {
SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"},
SniprunFloatingWinOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"},
SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"},
SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",cterfg="Black"},
SniprunFloatingWinErr = {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
borders = 'single' --" display borders around floating windows
--" possible values are 'none', 'single', 'double', or 'shadow'
})
EOF
```
Expand Down Expand Up @@ -385,15 +387,15 @@ println!("-> {}", alphabet);
| ------------ | ------------- | --- | ---------- | ---------------- |
| Ada | Line | | Java | Bloc |
| Bash/Shell | Bloc + REPL\* | | JavaScript | Bloc |
| C | Import | | Julia | Bloc |
| C | Import | | Julia | Bloc + REPL\*\* |
| C++ | Import | | Lisp | Untested |
| Clojure | Untested | | Lua | Bloc |
| COBOL | Untested | | Lua-nvim | Bloc |
| Coffeescript | Bloc | | Markdown (GFM) | Bloc + REPL \*** |
| Coffeescript | Bloc | | Markdown (GFM) | Bloc + REPL \*\*\* |
| C# | Untested | | Perl6 | Line |
| D | Bloc | | Perl | Line |
| Elixir | Untested | | PHP | Untested |
| Elm | Untested | | Python3 | Import +REPL\*\* |
| Elm | Untested | | Python3 | Import +REPL*\* |
| Erlang | Untested | | R | Bloc + REPL \*\* |
| F# | Untested | | Ruby | Bloc |
| Go | Bloc | | Rust | Bloc |
Expand Down Expand Up @@ -423,7 +425,7 @@ Due to its nature, Sniprun may have trouble with programs that :

## Troubleshooting

begin by updating the plugin and running `:checkhealth sniprun`
begin by updating the plugin and running `:SnipReset` and then `:checkhealth sniprun`

- **Silent fail**: the sniprun binary may be incompatible with your distro/OS/arch. Use `bash ./install.sh 1` as post-install to compile locally.
- Terminal and Floating Window display mode do not work: Linked to [this](https://github.com/michaelb/sniprun/issues/70) issue, no fix found yet.
Expand Down
12 changes: 12 additions & 0 deletions doc/Julia_jupyter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The setup for the julia_jupyter interpreter is quite convoluted:

Indeed, the Julia jupyter kernel MUST be started before Sniprun can run (and there is even a consequent delay since the kernel is so slow to start).

You should start a julia jupyter kernel with the following command:
` jupyter-kernel --kernel=julia-1.5 --KernelManager.connection_file=$HOME/.cache/sniprun/julia_jupyter/kernel_sniprun.json`

(adapt to your XDG_CACHE location if you're on Mac)

You manage kernel startup AND shutodwn manually. Why? There is a terrible data race if sniprun does it. Python_jupyter works, julia doesn't. That's about it.

If you want to use another kernel location, post a feature request at github.com/michaelb/sniprun and i'll see what I can do.
20 changes: 12 additions & 8 deletions lua/sniprun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ M.config_values = {
repl_enable = {},
repl_disable = {},

interpreter_options = {
example_original = {
example_option = "--optimize-with-debug-info",
}
},
interpreter_options = {},

display = {
"Classic",
Expand All @@ -33,13 +29,14 @@ M.config_values = {
},

inline_messages = 0,
borders = 'single',

-- default highlight stuff goes here
snipruncolors = {
SniprunVirtualTextOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"},
SniprunFloatingWinOk = {bg="#66eeff",fg="#000000",ctermbg="Cyan",cterfg="Black"},
SniprunFloatingWinOk = {fg="#66eeff",ctermfg="Cyan"},
SniprunVirtualTextErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",cterfg="Black"},
SniprunFloatingWinErr = {bg="#881515",fg="#000000",ctermbg="DarkRed",cterfg="Black"},
SniprunFloatingWinErr = {fg="#881515",ctermfg="DarkRed"},
}

}
Expand Down Expand Up @@ -70,7 +67,7 @@ function M.setup(opts)
if next(opts) == nil then return end
for key,value in pairs(opts) do
if M.config_values[key] == nil then
error(string.format('[Sniprun] Key %s not exist in config values',key))
error(string.format('[Sniprun] Key %s does not exist in config values',key))
return
end
if key == 'snipruncolors' then
Expand All @@ -81,6 +78,7 @@ function M.setup(opts)
M.configure_keymaps()
M.setup_highlights()
M.setup_autocommands()
M.setup_display()

M.config_up = 1
end
Expand All @@ -100,6 +98,12 @@ local highlight = function(group, styles)
end


function M.setup_display()
local D = require'sniprun.display'
D.borders = M.config_values.borders
end


function M.setup_highlights()
local colors_table = M.config_values["snipruncolors"]
if M.custom_highlight then
Expand Down
3 changes: 2 additions & 1 deletion lua/sniprun/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ M.term.buffer = -1
M.term.window_handle = 0
M.term.current_line = -1
M.term.chan = -1
M.borders = 'single'

local NAMESPACE = 'sniprun'

Expand All @@ -29,7 +30,7 @@ function M.fw_open(row, column, message, ok, temp)
vim.api.nvim_buf_set_lines(bufnr,h,h+1,false,{line})
vim.api.nvim_buf_add_highlight(bufnr, namespace_id, hl, h,0,-1) -- highlight lines in floating window
end
M.fw_handle = vim.api.nvim_open_win(bufnr, false, {relative='win', width=w+1, height=h, bufpos=bp, focusable=false, style='minimal',border='single'})
M.fw_handle = vim.api.nvim_open_win(bufnr, false, {relative='win', width=w+1, height=h, bufpos=bp, focusable=false, style='minimal',border=M.borders})
end

function M.term_open()
Expand Down
Loading

0 comments on commit e22b5ef

Please sign in to comment.