aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2018-10-12 20:22:52 +0200
committerJohn Ankarström <john@ankarstrom.se>2018-10-12 20:22:52 +0200
commit3d6785d73b7ae3020e4873479dc29395bb15cddb (patch)
tree916c30b483f2f596579f8d9c121609eef4faf11d
downloadvis-filetype-settings-3d6785d73b7ae3020e4873479dc29395bb15cddb.tar.gz
first commit
-rw-r--r--LICENSE22
-rw-r--r--README.md29
-rw-r--r--vis-autocmd.lua38
3 files changed, 89 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..216499a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2018 John Ankarström
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject
+to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a191bb7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,29 @@
+## vis-autocmd
+
+This plugin provides a declarative interface for setting vis
+options depending on filetype.
+
+It expects a global variable called `settings` to be defined:
+
+```lua
+settings = {
+ markdown = {"expandtab on", "tabwidth 4"}
+}
+```
+
+In this variable, filetypes are mapped to sets of settings that are
+to be executed when a window containing the specified filetype is
+opened.
+
+If you want to do more than setting simple options, you can specify a function instead:
+
+```lua
+settings = {
+ bash = function(win)
+ -- do things for shell scripts
+ end
+}
+```
+
+Be sure not to run commands that open another window with the same
+filetype, leading to an infinite loop.
diff --git a/vis-autocmd.lua b/vis-autocmd.lua
new file mode 100644
index 0000000..8b60501
--- /dev/null
+++ b/vis-autocmd.lua
@@ -0,0 +1,38 @@
+-- vis-autocmd
+-- (https://github.com/jocap/vis-autocmd)
+
+-- This plugin provides a declarative interface for setting vis
+-- options depending on filetype.
+--
+-- It expects a global variable called `settings` to be defined:
+--
+-- settings = {
+-- markdown = {"expandtab on", "tabwidth 4"}
+-- }
+--
+-- In this variable, filetypes are mapped to sets of settings that are
+-- to be executed when a window containing the specified filetype is
+-- opened.
+--
+-- If you want to do more than setting simple options, you can specify a function instead:
+--
+-- settings = {
+-- bash = function(win)
+-- -- do things for shell scripts
+-- end
+-- }
+--
+-- Be sure not to run commands that open another window with the same
+-- filetype, leading to an infinite loop.
+
+vis.events.subscribe(vis.events.WIN_OPEN, function(win)
+ local window_settings = settings[win.syntax]
+
+ if type(window_settings) == 'table' then
+ for _, setting in pairs(window_settings) do
+ vis:command(setting)
+ end
+ elseif type(window_settings) == 'function' then
+ window_settings(win)
+ end
+end)