aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/plugins/autocomplete.lua7
-rw-r--r--data/plugins/detectindent.lua92
2 files changed, 89 insertions, 10 deletions
diff --git a/data/plugins/autocomplete.lua b/data/plugins/autocomplete.lua
index 484199a9..fde9487e 100644
--- a/data/plugins/autocomplete.lua
+++ b/data/plugins/autocomplete.lua
@@ -10,7 +10,7 @@ local RootView = require "core.rootview"
local DocView = require "core.docview"
local Doc = require "core.doc"
-config.plugins.autocomplete = {
+config.plugins.autocomplete = {
-- Amount of characters that need to be written for autocomplete
min_len = 3,
-- The max amount of visible items
@@ -502,6 +502,11 @@ command.add(predicate, {
suggestions_idx = math.min(suggestions_idx + 1, #suggestions)
end,
+ ["autocomplete:cycle"] = function()
+ local newidx = suggestions_idx + 1
+ suggestions_idx = newidx > #suggestions and 1 or newidx
+ end,
+
["autocomplete:cancel"] = function()
reset_suggestions()
end,
diff --git a/data/plugins/detectindent.lua b/data/plugins/detectindent.lua
index 45ebaee6..20541c82 100644
--- a/data/plugins/detectindent.lua
+++ b/data/plugins/detectindent.lua
@@ -102,6 +102,11 @@ end
local function update_cache(doc)
local type, size, score = detect_indent_stat(doc)
local score_threshold = 4
+ if score < score_threshold then
+ -- use default values
+ type = config.tab_type
+ size = config.indent_size
+ end
cache[doc] = { type = type, size = size, confirmed = (score >= score_threshold) }
doc.indent_info = cache[doc]
end
@@ -111,20 +116,14 @@ local new = Doc.new
function Doc:new(...)
new(self, ...)
update_cache(self)
- if not cache[self].confirmed then
- core.add_thread(function ()
- while not cache[self].confirmed do
- update_cache(self)
- coroutine.yield(1)
- end
- end, self)
- end
end
local clean = Doc.clean
function Doc:clean(...)
clean(self, ...)
- update_cache(self)
+ if not cache[self].confirmed then
+ update_cache(self)
+ end
end
@@ -152,3 +151,78 @@ function DocView:draw(...)
return with_indent_override(self.doc, draw, self, ...)
end
+
+local function set_indent_type(doc, type)
+ cache[doc] = {type = type,
+ size = cache[doc].value or config.indent_size,
+ confirmed = true}
+ doc.indent_info = cache[doc]
+end
+
+local function set_indent_type_command()
+ core.command_view:enter(
+ "Specify indent style for this file",
+ function(value) -- submit
+ local doc = core.active_view.doc
+ value = value:lower()
+ set_indent_type(doc, value == "tabs" and "hard" or "soft")
+ end,
+ function(text) -- suggest
+ return common.fuzzy_match({"tabs", "spaces"}, text)
+ end,
+ nil, -- cancel
+ function(text) -- validate
+ local t = text:lower()
+ return t == "tabs" or t == "spaces"
+ end
+ )
+end
+
+
+local function set_indent_size(doc, size)
+ cache[doc] = {type = cache[doc].type or config.tab_type,
+ size = size,
+ confirmed = true}
+ doc.indent_info = cache[doc]
+end
+
+local function set_indent_size_command()
+ core.command_view:enter(
+ "Specify indent size for current file",
+ function(value) -- submit
+ local value = math.floor(tonumber(value))
+ local doc = core.active_view.doc
+ set_indent_size(doc, value)
+ end,
+ nil, -- suggest
+ nil, -- cancel
+ function(value) -- validate
+ local value = tonumber(value)
+ return value ~= nil and value >= 1
+ end
+ )
+end
+
+
+command.add("core.docview", {
+ ["indent:set-file-indent-type"] = set_indent_type_command,
+ ["indent:set-file-indent-size"] = set_indent_size_command
+})
+
+
+command.add(function()
+ return core.active_view:is(DocView)
+ and cache[core.active_view.doc]
+ and cache[core.active_view.doc].type == "soft"
+ end, {
+ ["indent:switch-file-to-tabs-indentation"] = function() set_indent_type(core.active_view.doc, "hard") end
+})
+
+
+command.add(function()
+ return core.active_view:is(DocView)
+ and cache[core.active_view.doc]
+ and cache[core.active_view.doc].type == "hard"
+ end, {
+ ["indent:switch-file-to-spaces-indentation"] = function() set_indent_type(core.active_view.doc, "soft") end
+})