aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/vis/plugins/suw.lua32
-rw-r--r--config/vis/visrc.lua5
2 files changed, 35 insertions, 2 deletions
diff --git a/config/vis/plugins/suw.lua b/config/vis/plugins/suw.lua
new file mode 100644
index 0000000..b68e123
--- /dev/null
+++ b/config/vis/plugins/suw.lua
@@ -0,0 +1,32 @@
+--- a module for writing to to a file by increasing privilege
+-- @author [Alejandro Baez](https://twitter.com/a_baez)
+-- @module suw
+
+--- cmd for sudo write and quit
+local suwq = function()
+ local file = vis.win.file
+ vis:command((", > sudo tee %s"):format(file.name))
+
+ vis:command("q!")
+end
+
+--- cmd for sudo write
+local suw = function()
+ local file = vis.win.file
+ vis:command((", > sudo tee %s"):format(file.name))
+
+ vis.events.emit(vis.events.FILE_SAVE_PRE, function(...) return true end)
+ vis.events.emit(vis.events.FILE_SAVE_POST, function(...)
+ file.modified = false
+ end)
+end
+
+local function main()
+ local comment = "write to file with privilege"
+
+ vis:command_register("suw", suw, comment)
+ vis:command_register("suwq", suwq, comment .. " and quit")
+end
+
+
+return main() \ No newline at end of file
diff --git a/config/vis/visrc.lua b/config/vis/visrc.lua
index ce42ab9..a4a2a14 100644
--- a/config/vis/visrc.lua
+++ b/config/vis/visrc.lua
@@ -8,6 +8,8 @@ require('plugins/vis-commentary/vis-commentary')
-- This hooks vis.events.START so its fine to load it before the default settings
require('plugins/vis-modelines/vis-modelines')
+require('plugins/suw')
+
vis.events.subscribe(vis.events.INIT, function()
-- Your global configuration options
local theme = "default"
@@ -31,8 +33,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win)
win:set_syntax("diff")
end
- local filetype = win.file.name:match(".*%.(.*)")
- if filetype == "py" then
+ if win.syntax == "python" then
vis:command("set expand")
end
end