diff --git a/micro/init.lua b/micro/init.lua index 4a36f48..a9ee124 100644 --- a/micro/init.lua +++ b/micro/init.lua @@ -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)