Browse Source

Fix micro/init.lua

pull/15/head
10sr 7 years ago
parent
commit
b19c98f98b
1 changed files with 22 additions and 21 deletions
  1. +22
    -21
      micro/init.lua

+ 22
- 21
micro/init.lua View File

@@ -30,45 +30,46 @@ local function setInsertFinalNewline(properties, view)
end
end

local function applyProperties(properties, view)
setIndentation(properties, view)
-- Currently micro does not support changing coding-systems
-- (Always use utf-8 with LF?)
-- setCodingSystem(properties, view)
-- `ruler' is not what we want!
-- setMaxLineLength(properties, view)
-- setTrimTrailingWhitespace(properties, view)
setInsertFinalNewline(properties, view)
-- messenger:Message("ed output: " .. output)
end

function onEditorConfigExit(output)
-- messenger:Message(output)
-- FIXME: messege when editorconfig exit with error
local properties = {}
-- TODO: Which is better? output:gmatch(), string.gmatch(output, ...)
for line in output:gmatch('([^\n]+)') do
-- TODO: Fix regex
-- TODO: Throw error for invalid output
local key, value = line:match('([^=]*)=(.*)')
key = key:gsub('^%s(.-)%s*$', '%1')
value = value:gsub('^%s(.-)%s*$', '%1')
-- TODO: Throw error when key is empty string
properties[key] = value
end

local view = CurView()

setIndentation(properties, view)
-- Currently micro does not support changing coding-systems
-- (Always use utf-8 with LF?)
-- setCodingSystem(properties, view)
-- `ruler' is not what we want!
-- setMaxLineLength(properties, view)
-- setTrimTrailingWhitespace(properties, view)
setInsertFinalNewline(properties, view)
applyProperties(properties, view)
end

local function applyProperties(view)
-- Is this portable? (work on windows?)
local pwd = os.getenv("PWD")
local filename = view.Buf.Path
-- prop, names = ec.parse(filepath)
local fullpath = JoinPaths(pwd, filename)

-- FIXME: Commands can be injected here!
-- For example, issuing this command will create file b.txt
-- $ micro "a.txt'; touch 'b.txt"
local function getApplyProperties(view)
local fullpath = view.Buf.AbsPath
messenger:Message("editorconfig " .. fullpath)
-- JobSpawn("editorconfig", {fullpath}, "", "", "init.onEditorConfigExit")
JobStart("editorconfig " .. fullpath, "", "", "init.onEditorConfigExit")
end

function onViewOpen(view)
applyProperties(view)
getApplyProperties(view)
-- messenger:Message(view.Buf.AbsPath)
end

function onSave(view)


Loading…
Cancel
Save