From f07375057d7334350a2b837cd48b0ef2c70df1bc Mon Sep 17 00:00:00 2001 From: Nihilazo Date: Sun, 19 Sep 2021 20:42:39 +0100 Subject: [PATCH] add micro config --- micro/.config/micro/bindings.json | 6 ++ micro/.config/micro/colorschemes/nico.micro | 29 +++++++++ micro/.config/micro/init.lua | 65 +++++++++++++++++++++ micro/.config/micro/settings.json | 4 ++ 4 files changed, 104 insertions(+) create mode 100644 micro/.config/micro/bindings.json create mode 100644 micro/.config/micro/colorschemes/nico.micro create mode 100644 micro/.config/micro/init.lua create mode 100644 micro/.config/micro/settings.json diff --git a/micro/.config/micro/bindings.json b/micro/.config/micro/bindings.json new file mode 100644 index 0000000..488f107 --- /dev/null +++ b/micro/.config/micro/bindings.json @@ -0,0 +1,6 @@ +{ + "Alt-/": "lua:comment.comment", + "Ctrl-J": "lua:initlua.zettelInsert", + "CtrlUnderscore": "lua:comment.comment", + "MouseRight": "lua:initlua.gotofile" +} diff --git a/micro/.config/micro/colorschemes/nico.micro b/micro/.config/micro/colorschemes/nico.micro new file mode 100644 index 0000000..88ea2f9 --- /dev/null +++ b/micro/.config/micro/colorschemes/nico.micro @@ -0,0 +1,29 @@ +color-link comment "grey" +color-link constant "red" +color-link identifier "cyan" +color-link statement "yellow" +color-link symbol "yellow" +color-link preproc "magenta" +color-link type "green" +color-link special "magenta" +color-link ignore "default" +color-link error ",brightred" +color-link todo ",brightyellow" +color-link indent-char "black" +color-link line-number "yellow" +color-link current-line-number "red" +color-link diff-added "green" +color-link diff-modified "yellow" +color-link diff-deleted "red" +color-link gutter-error ",red" +color-link gutter-warning "red" +#Cursor line causes readability issues. Disabled for now. +#color-link cursor-line "white,black" +color-link color-column "white" +#No extended types. (bool in C) +color-link type.extended "default" +#No bracket highlighting. +color-link symbol.brackets "default" +#Color shebangs the comment color +color-link preproc.shebang "comment" +color-link statusline "black,grey" diff --git a/micro/.config/micro/init.lua b/micro/.config/micro/init.lua new file mode 100644 index 0000000..5d745f1 --- /dev/null +++ b/micro/.config/micro/init.lua @@ -0,0 +1,65 @@ +local micro = import("micro") +local config = import("micro/config") +local buf = import("micro/buffer") +local util = import("micro/util") +local path = import("path") +local time = import("time") + +function gotofile(bp) + local selection = bp.Cursor.CurSelection -- cursor position + local line = bp.buf.Line(bp.buf, selection[1]["Y"]) -- get the current line + local path_start, path_end + -- TODO add other delimiters + + -- search forward from cursor position for a delimiter + -- store it to find the end of the path + for v = selection[1]["X"], #line do + local r = util.RuneAt(line, v) + if r == ')' or r == "}" or r == "]" or r == " " then + path_end = v + break + end + end + + -- do the same, looking backwards, for the start of the path + for v = selection[1]["X"],0, -1 do + local r = util.RuneAt(line,v) + if r == '(' or r == "{" or r == "[" or r == " " then + path_start = v+2 + break + end + end + -- slice up the path and go to that file + if path_start ~= nil and path_end ~= nil then + -- get the path from the buffer + p = string.sub(line, path_start, path_end) + -- get the path relative to current file if it's relative + if not path.IsAbs(p) then + p = path.Join(path.Dir(bp.buf.Path), p) + end + -- open in a split + -- TODO placement that's better than just splitting? + bp.HSplitCmd(bp, {p}) + return false + end +end + +function zettelInsert(bp) + local t = time.Now() -- current unix time + local ut = t.Unix(t) + local cursor = bp.Cursor.Loc + local cursorLoc = buf.Loc(cursor["X"], cursor["Y"]) + local newFilePath = ut .. ".md" + local link = "[[" .. newFilePath .. "]]" + bp.Buf:Replace(cursorLoc, cursorLoc, link ) -- insert link at cursor position + local newBuffer = buf.NewBuffer("# " .. ut .. " - ", path.Join(path.Dir(bp.buf.Path), newFilePath)) + bp.HSplitBuf(bp, newBuffer) + + +end + +function init() + config.MakeCommand("gotofile", gotofile, config.NoComplete) + config.MakeCommand("zi", zettelInsert, config.NoComplete) + config.TryBindKey("MouseRight", "lua:initlua.gotofile", true) +end diff --git a/micro/.config/micro/settings.json b/micro/.config/micro/settings.json new file mode 100644 index 0000000..226a1d8 --- /dev/null +++ b/micro/.config/micro/settings.json @@ -0,0 +1,4 @@ +{ + "colorscheme": "nico", + "softwrap": true +}