| @@ -30,45 +30,46 @@ local function setInsertFinalNewline(properties, view) | |||||
| end | end | ||||
| 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) | function onEditorConfigExit(output) | ||||
| -- messenger:Message(output) | |||||
| -- FIXME: messege when editorconfig exit with error | |||||
| local properties = {} | local properties = {} | ||||
| -- TODO: Which is better? output:gmatch(), string.gmatch(output, ...) | -- TODO: Which is better? output:gmatch(), string.gmatch(output, ...) | ||||
| for line in output:gmatch('([^\n]+)') do | for line in output:gmatch('([^\n]+)') do | ||||
| -- TODO: Fix regex | -- TODO: Fix regex | ||||
| -- TODO: Throw error for invalid output | |||||
| local key, value = line:match('([^=]*)=(.*)') | local key, value = line:match('([^=]*)=(.*)') | ||||
| key = key:gsub('^%s(.-)%s*$', '%1') | key = key:gsub('^%s(.-)%s*$', '%1') | ||||
| value = value:gsub('^%s(.-)%s*$', '%1') | value = value:gsub('^%s(.-)%s*$', '%1') | ||||
| -- TODO: Throw error when key is empty string | |||||
| properties[key] = value | properties[key] = value | ||||
| end | end | ||||
| local view = CurView() | 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 | 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") | JobStart("editorconfig " .. fullpath, "", "", "init.onEditorConfigExit") | ||||
| end | end | ||||
| function onViewOpen(view) | function onViewOpen(view) | ||||
| applyProperties(view) | |||||
| getApplyProperties(view) | |||||
| -- messenger:Message(view.Buf.AbsPath) | |||||
| end | end | ||||
| function onSave(view) | function onSave(view) | ||||