fixed broken Doc:save monkeypatch
This commit is contained in:
parent
4e93eabbac
commit
ea5e9b0ce5
|
@ -47,7 +47,7 @@ local function save(filename)
|
||||||
core.log("Saved \"%s\"", saved_filename)
|
core.log("Saved \"%s\"", saved_filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns the size of the original indent, and the indent
|
-- returns the size of the original indent, and the indent
|
||||||
-- in your config format, rounded either up or down
|
-- in your config format, rounded either up or down
|
||||||
local function get_line_indent(line, rnd_up)
|
local function get_line_indent(line, rnd_up)
|
||||||
local _, e = line:find("^[ \t]+")
|
local _, e = line:find("^[ \t]+")
|
||||||
|
@ -58,18 +58,18 @@ local function get_line_indent(line, rnd_up)
|
||||||
else
|
else
|
||||||
local indent = e and line:sub(1, e):gsub("\t", soft_tab) or ""
|
local indent = e and line:sub(1, e):gsub("\t", soft_tab) or ""
|
||||||
local number = #indent / #soft_tab
|
local number = #indent / #soft_tab
|
||||||
return e, indent:sub(1,
|
return e, indent:sub(1,
|
||||||
(rnd_up and math.ceil(number) or math.floor(number))*#soft_tab)
|
(rnd_up and math.ceil(number) or math.floor(number))*#soft_tab)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- un/indents text; behaviour varies based on selection and un/indent.
|
-- un/indents text; behaviour varies based on selection and un/indent.
|
||||||
-- * if there's a selection, it will stay static around the
|
-- * if there's a selection, it will stay static around the
|
||||||
-- text for both indenting and unindenting.
|
-- text for both indenting and unindenting.
|
||||||
-- * if you are in the beginning whitespace of a line, and are indenting, the
|
-- * if you are in the beginning whitespace of a line, and are indenting, the
|
||||||
-- cursor will insert the exactly appropriate amount of spaces, and jump the
|
-- cursor will insert the exactly appropriate amount of spaces, and jump the
|
||||||
-- cursor to the beginning of first non whitespace characters
|
-- cursor to the beginning of first non whitespace characters
|
||||||
-- * if you are not in the beginning whitespace of a line, and you indent, it
|
-- * if you are not in the beginning whitespace of a line, and you indent, it
|
||||||
-- inserts the appropriate whitespace, as if you typed them normally.
|
-- inserts the appropriate whitespace, as if you typed them normally.
|
||||||
-- * if you are unindenting, the cursor will jump to the start of the line,
|
-- * if you are unindenting, the cursor will jump to the start of the line,
|
||||||
-- and remove the appropriate amount of spaces (or a tab).
|
-- and remove the appropriate amount of spaces (or a tab).
|
||||||
|
@ -83,7 +83,7 @@ local function indent_text(unindent)
|
||||||
for line = line1, line2 do
|
for line = line1, line2 do
|
||||||
local e, rnded = get_line_indent(doc().lines[line], unindent)
|
local e, rnded = get_line_indent(doc().lines[line], unindent)
|
||||||
doc():remove(line, 1, line, (e or 0) + 1)
|
doc():remove(line, 1, line, (e or 0) + 1)
|
||||||
doc():insert(line, 1,
|
doc():insert(line, 1,
|
||||||
unindent and rnded:sub(1, #rnded - #text) or rnded .. text)
|
unindent and rnded:sub(1, #rnded - #text) or rnded .. text)
|
||||||
end
|
end
|
||||||
l1d, l2d = #doc().lines[line1] - l1d, #doc().lines[line2] - l2d
|
l1d, l2d = #doc().lines[line1] - l1d, #doc().lines[line2] - l2d
|
||||||
|
|
|
@ -415,8 +415,8 @@ local function reload_on_user_module_save()
|
||||||
-- auto-realod style when user's module is saved by overriding Doc:Save()
|
-- auto-realod style when user's module is saved by overriding Doc:Save()
|
||||||
local doc_save = Doc.save
|
local doc_save = Doc.save
|
||||||
local user_filename = system.absolute_path(USERDIR .. PATHSEP .. "init.lua")
|
local user_filename = system.absolute_path(USERDIR .. PATHSEP .. "init.lua")
|
||||||
function Doc:save(filename)
|
function Doc:save(filename, abs_filename)
|
||||||
doc_save(self)
|
doc_save(self, filename, abs_filename)
|
||||||
if self.abs_filename == user_filename then
|
if self.abs_filename == user_filename then
|
||||||
core.reload_module("core.style")
|
core.reload_module("core.style")
|
||||||
core.load_user_directory()
|
core.load_user_directory()
|
||||||
|
|
Loading…
Reference in New Issue