aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md59
-rw-r--r--edconf.lua13
2 files changed, 72 insertions, 0 deletions
diff --git a/README.md b/README.md
index bc49140..5c1ecef 100644
--- a/README.md
+++ b/README.md
@@ -14,3 +14,62 @@ git clone https://github.com/vktec/vis-editorconfig "$HOME/.config/vis/editorcon
```
Then add `require "editorconfig/edconf"` to your `visrc.lua`.
+
+## Functionality
+
+Not all editorconfig functionality is supported by vis and hence by this
+plugin. At this moment, there is full support for the following settings:
+
+- indent_style
+- indent_size
+- tab_width
+- insert_final_newline
+
+The following settings are implemented partially and / or support is
+turned off by default:
+
+- trim_trailing_whitespace: Turned off by default, can be enabled
+ via `:set edconfhooks on`.
+- end_of_line: Turned off by default, partial support can be enabled
+ via `:set edconfhooks on`. Only `crlf` and `lf` are supported, plain
+ `cr` is not. The implementation is also very basic. If end_of_line
+ is set to `crlf`, a return character will be inserted at the end of
+ each line that does not yet end with `crlf`. If end_of_line is set
+ to `lf`, return characters at the end of a line will be stripped.
+ While I would encourage every vis user to stick to `lf` terminated
+ files, this might be convenient if, for some reason, they do need
+ to compose `crlf` terminated files.
+- max_line_length: Turned off by default, partial support can be
+ enabled via `:set edconfhooks on`. There is no straightforward way
+ to automatically wrap content that might be written in arbitrary
+ programming (or non-programming) languages. For that reason,
+ vis-editorconfig doesn't even try. If max_line_length is enabled,
+ vis-editorconfig issues a warning, however, indicating which lines
+ are longer than the specified length. Note that you will miss this
+ warning if you write your file with `:wq`, so if you care about it,
+ write it with `:w<RETURN>:q`.
+
+The reason those last three settings are optional and turned off by
+default is their scalability. Each of those operations is implemented
+as a pre-save-hook with a complexity of O(n), where n is the filesize.
+Since vis is incredibly good at editing huge files efficiently, there
+seems to be a very real danger that those hooks could cause the editor
+to freeze just before a user's valuable changes are written to disk.
+
+You can turn support for those pre-save-hooks on or off at any time
+by running
+
+ :set edconfhooks on
+
+or
+
+ :set edconfhooks off
+
+If `edconfhooks` are enabled, they will be executed as configured in
+`.editorconfig`. If you want to take a less cautious approach and enable
+these hooks by default, simply add an additional line below the module
+import in `visrc.lua`:
+
+ require('editorconfig/edconf')
+ vis:command('set edconfhooks on') -- supposing you did previously
+ -- require('vis')
diff --git a/edconf.lua b/edconf.lua
index 9b5a546..2ec800b 100644
--- a/edconf.lua
+++ b/edconf.lua
@@ -32,12 +32,17 @@ end
-- Custom functionality
function insert_final_newline(file, path)
+ -- Technically speaking, this is a pre-save-hook as well and could
+ -- therefore respect edconf_hooks_enabled. Since this function runs
+ -- blazingly fast and scales with a complexity of O(1), however,
+ -- there is no need to disable it.
if file:content(file.size-1, file.size) ~= '\n' then
file:insert(file.size, '\n')
end
end
function trim_trailing_whitespace(file, path)
+ if not edconf_hooks_enabled then return end
for i=1, #file.lines do
if string.match(file.lines[i], '[ \t]$') then
file.lines[i] = string.gsub(file.lines[i], '[ \t]*$', '')
@@ -46,6 +51,7 @@ function trim_trailing_whitespace(file, path)
end
function enforce_crlf_eol(file, path)
+ if not edconf_hooks_enabled then return end
for i=1, #file.lines do
if not string.match(file.lines[i], '\r$') then
file.lines[i] = string.gsub(file.lines[i], '$', '\r')
@@ -54,6 +60,7 @@ function enforce_crlf_eol(file, path)
end
function enforce_lf_eol(file, path)
+ if not edconf_hooks_enabled then return end
for i=1, #file.lines do
if string.match(file.lines[i], '\r$') then
file.lines[i] = string.gsub(file.lines[i], '\r$', '')
@@ -65,6 +72,7 @@ global_max_line_length = 80 -- This is ugly, but we do want to use
-- single function that we can register
-- or unregister as needed
function max_line_length(file, path)
+ if not edconf_hooks_enabled then return end
local overlong_lines = {}
for i=1, #file.lines do
if string.len(file.lines[i]) > global_max_line_length then
@@ -167,3 +175,8 @@ end)
vis.events.subscribe(vis.events.FILE_SAVE_POST, function (file, path)
ec_set_values(file.path)
end)
+
+edconf_hooks_enabled = false
+vis:option_register("edconfhooks", "bool", function(value)
+ edconf_hooks_enabled = value
+end)