From 5a4e0914173cd370ab697e485c6a132dc93ae372 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Fri, 4 Nov 2016 14:47:06 +0900 Subject: [PATCH] Update micro init file --- micro/init.lua | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/micro/init.lua b/micro/init.lua index b36e8f8..323f07c 100644 --- a/micro/init.lua +++ b/micro/init.lua @@ -1,10 +1,22 @@ -- ec = require("editorconfig_core") -local function GetProperties(fullpath) - local file = io.popen("echo fullpath: " .. fullpath, "r") +local function getProperties(fullpath) + local file = io.popen("editorconfig '" .. fullpath .. "'", "r") local output = file:read("*all") file:close() - return output + + local properties = {} + -- TODO: Which is better? output:gmatch(), string.gmatch(output, ...) + for line in output:gmatch('([^\n]+)') do + -- TODO: Fix regex + 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 + + return properties end function onViewOpen(view) @@ -13,12 +25,10 @@ function onViewOpen(view) local filename = view.Buf.Path -- prop, names = ec.parse(filepath) local fullpath = JoinPaths(pwd, filename) - local out = GetProperties(fullpath) - messenger:Message("view.Buf.Path: " .. out) + local out = getProperties(fullpath) + messenger:Message("edconf: " .. out["indent_style"]) end - - function onSave(view) messenger:Message("Saved!") end