forked from michaelb/sniprun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request michaelb#140 from michaelb/dev
live_mode
- Loading branch information
Showing
25 changed files
with
172 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sniprun" | ||
version = "1.1.2" | ||
version = "1.2" | ||
authors = ["michaelb <[email protected]>"] | ||
edition = "2018" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local M = {} | ||
|
||
|
||
function M.run() | ||
local sa = require('sniprun.api') | ||
local line = vim.api.nvim_win_get_cursor(0)[1] | ||
local ft = vim.bo.filetype | ||
local opts = require('sniprun').config_values | ||
opts.display = { "VirtualTextOk"} | ||
opts.show_no_output = {} | ||
sa.run_range(line,line, ft, opts) | ||
end | ||
|
||
function M.enable() | ||
vim.cmd [[ | ||
augroup _sniprunlive | ||
autocmd! | ||
autocmd TextChanged * lua require'sniprun.live_mode'.run() | ||
autocmd TextChangedI * lua require'sniprun.live_mode'.run() | ||
augroup end | ||
lua require'sniprun.live_mode'.run() | ||
]] | ||
vim.notify "Enabled Sniprun live mode" | ||
end | ||
|
||
function M.disable() | ||
M.remove_augroup "_sniprunlive" | ||
require('sniprun.display').clear_virtual_text() | ||
vim.notify "Disabled Sniprun live mode" | ||
end | ||
|
||
function M.toggle() | ||
if vim.fn.exists "#_sniprunlive#TextChanged" == 0 then | ||
M.enable() | ||
else | ||
M.disable() | ||
end | ||
end | ||
|
||
function M.remove_augroup(name) | ||
if vim.fn.exists("#" .. name) == 1 then | ||
vim.cmd("au! " .. name) | ||
end | ||
end | ||
|
||
vim.cmd [[ command! SnipLive execute 'lua require("sniprun.live_mode").toggle()' ]] | ||
vim.api.nvim_set_keymap("n", "<Plug>SnipLive", ":lua require'sniprun.live_mode'.toggle()<CR>",{silent=true}) | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# What is sniprun's live mode ? | ||
|
||
The live mode hook the SnipRun command to the TextChanged event, meaning that at every change to make to the buffer, the current line will be sent to sniprun for evaluation. This can mean a lot of times, especially if you type fast. | ||
|
||
The result is a virtual text, displaying at the end of the current line that print the result (stdout) of the line. Nothing is displayed when the line is incomplete / incorrect, a bit like codi. | ||
|
||
# Warnings | ||
|
||
The live mode **will execute code you didn't think really about** (and by that I mean even less than usual) | ||
Thus: | ||
- Your code will get executed **lots** of times; check that your CPU can keep up. Even a slow 60wpm typing can make a Rust program recompile 3x per second, which is also different from sending 3 string/s to a running REPL. | ||
- Sniprun will try to execute even incomplete lines. You hadn't finished typing that `rm /path/to/arghhh` ? sniprun' not aware and removed the parent directory. Whoops. For these reasons, I strongly suggest to: | ||
- never run bash/shell with live mode | ||
- disable the live mode whenever your code modifies files or invoke system commands. | ||
|
||
If you're running a REPL-capable interpreter, while it'll probably work, mind that: | ||
- the REPL will have to gulp a lot of incomplete code without crashing and stuff | ||
- typing b = b + 1 + 1 will increment b by more than 2 !! (since an intermediate b=b+1 is valid and thus changes b before b=b+1+1) | ||
|
||
# Enable and usage | ||
|
||
`live_mode_toggle='enable'` in the config, (set to either 'enable' or 'off' - the default -, the disreptancy is only to force people to come here and read the warnings in case some smart kid want to skip and just set it to 'on') | ||
|
||
and then use the :SnipLive command and start coding. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.