]> git.lizzy.rs Git - micro.git/commitdiff
Add literate plugin support
authorZachary Yedidia <zyedidia@gmail.com>
Sat, 3 Aug 2019 23:46:51 +0000 (16:46 -0700)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 25 Dec 2019 22:05:11 +0000 (17:05 -0500)
cmd/micro/initlua.go
internal/action/command.go
internal/config/runtime.go
runtime/plugins/literate/literate.lua

index 9220f139d1c96e532ee7c21207334b1668ce1abd..11e97be8e1574051e25acd6546bfad15d8020123 100644 (file)
@@ -8,6 +8,7 @@ import (
 
        "github.com/zyedidia/micro/internal/action"
        "github.com/zyedidia/micro/internal/buffer"
+       "github.com/zyedidia/micro/internal/config"
        "github.com/zyedidia/micro/internal/display"
        ulua "github.com/zyedidia/micro/internal/lua"
        "github.com/zyedidia/micro/internal/screen"
@@ -59,6 +60,16 @@ func luaImportMicroConfig() *lua.LTable {
        ulua.L.SetField(pkg, "OptionValueComplete", luar.New(ulua.L, action.OptionValueComplete))
        ulua.L.SetField(pkg, "NoComplete", luar.New(ulua.L, nil))
        ulua.L.SetField(pkg, "TryBindKey", luar.New(ulua.L, action.TryBindKey))
+       ulua.L.SetField(pkg, "Reload", luar.New(ulua.L, action.ReloadConfig))
+       ulua.L.SetField(pkg, "AddRuntimeFileFromMemory", luar.New(ulua.L, config.PluginAddRuntimeFileFromMemory))
+       ulua.L.SetField(pkg, "AddRuntimeFilesFromDirectory", luar.New(ulua.L, config.PluginAddRuntimeFileFromMemory))
+       ulua.L.SetField(pkg, "AddRuntimeFile", luar.New(ulua.L, config.PluginAddRuntimeFile))
+       ulua.L.SetField(pkg, "ListRuntimeFiles", luar.New(ulua.L, config.PluginListRuntimeFiles))
+       ulua.L.SetField(pkg, "ReadRuntimeFile", luar.New(ulua.L, config.PluginReadRuntimeFile))
+       ulua.L.SetField(pkg, "RTColorscheme", luar.New(ulua.L, config.RTColorscheme))
+       ulua.L.SetField(pkg, "RTSyntax", luar.New(ulua.L, config.RTSyntax))
+       ulua.L.SetField(pkg, "RTHelp", luar.New(ulua.L, config.RTHelp))
+       ulua.L.SetField(pkg, "RTPlugin", luar.New(ulua.L, config.RTPlugin))
 
        return pkg
 }
index a30f6937d2f202124b8487603ec8add47e940036..3bbe935984ba50a28aa75194b0d6912afccad822 100644 (file)
@@ -3,6 +3,7 @@ package action
 import (
        "errors"
        "fmt"
+       "log"
        "os"
        "path/filepath"
        "regexp"
@@ -252,6 +253,29 @@ func (h *BufPane) ToggleLogCmd(args []string) {
 
 // ReloadCmd reloads all files (syntax files, colorschemes...)
 func (h *BufPane) ReloadCmd(args []string) {
+       ReloadConfig()
+}
+
+func ReloadConfig() {
+       config.InitRuntimeFiles()
+       err := config.ReadSettings()
+       if err != nil {
+               screen.TermMessage(err)
+       }
+       config.InitGlobalSettings()
+       InitBindings()
+       InitCommands()
+
+       err = config.InitColorscheme()
+       if err != nil {
+               screen.TermMessage(err)
+       }
+
+       log.Println("RELOAD CONFIG", len(buffer.OpenBuffers))
+       for _, b := range buffer.OpenBuffers {
+               log.Println("UPDATE RULES")
+               b.UpdateRules()
+       }
 }
 
 // ReopenCmd reopens the buffer (reload from disk)
index 4e267ef63b158e78245af53b8922ad536c065e3b..4fc2f18a4992c8de82c3ad522165204070b183f3 100644 (file)
@@ -1132,7 +1132,7 @@ func runtimePluginsLiterateReadmeMd() (*asset, error) {
        return a, nil
 }
 
-var _runtimePluginsLiterateLiterateLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x56\xdf\x6f\xe2\x38\x10\x7e\xe7\xaf\x18\xf9\xee\xd4\xe4\x9a\x44\xe5\x1e\x91\x22\xe5\x4e\xba\x9e\x4e\xda\x6d\x57\xad\xd4\x17\xa0\xc8\x8d\x27\x60\xe1\xd8\x91\xe3\x94\x45\xa5\xff\xfb\x6a\xe2\x00\x21\xbb\xab\x85\xe6\x05\x7b\xf2\xcd\xf7\xcd\xaf\xd8\xc4\x31\x3c\xfd\xfb\xf0\xf8\xff\xfd\x1d\xa4\xc0\xc6\xc9\x4d\x72\xc3\x46\xb2\x80\xff\xd0\xdd\x57\x4e\x1a\x1d\x30\x25\x1d\x5a\xee\x90\x85\x90\xa6\xa0\xa5\x02\xb7\x42\x3d\x02\x00\xf8\x5b\x88\xef\x50\x11\x38\xdb\x60\x38\x42\x2d\x46\xa3\xa2\xd1\x39\xbd\x87\xda\x71\xeb\xea\x8d\x74\xab\xa0\x76\x36\xf2\xfb\x90\x48\x2c\xba\xc6\x12\xc0\x4a\xbd\x4c\xea\xe6\xa5\x05\x8c\xa3\xce\xa0\x50\x07\x1e\x1c\xa6\x69\xbb\x18\x30\xa3\x16\x3d\x5e\xd4\xe2\xd1\xd9\x3e\xb1\xb7\xa4\xe9\xd5\x15\x18\x3b\x94\x89\x7b\x2a\x9d\x6b\x98\xa6\x7e\x35\xcc\xa0\x52\xd2\x05\x1e\x1f\x41\x8d\x55\x2b\xd2\x3e\xca\xe4\x5c\x91\x29\x82\x42\xa2\x12\x35\xa4\xb4\x23\x3d\x36\x61\x11\xbc\xbd\x0f\xa0\x15\x77\x0e\xad\x26\x98\xd7\x2f\x8c\x2d\xb9\x0b\x58\x30\x7d\xfe\xa3\x9e\x5f\x87\x6c\xa0\xe0\x61\x93\x25\xc5\xdd\x39\x47\xb0\x0f\x2d\xc8\xc3\x4e\x77\xfa\x9b\xff\xbd\x1e\xcf\x21\x85\x9c\x72\x3f\x72\x74\xf5\xf0\x88\x41\x72\x46\x3f\x49\xdc\xdc\x57\xa8\x83\x57\x89\x1b\xef\x24\x0b\xd0\xc6\xfd\x64\x14\x68\x06\x7a\x25\xee\x3b\x1c\x3a\x42\x54\xc9\x3f\x4d\x91\x7c\xe1\x6e\x15\x01\x4b\x94\x74\x9d\xeb\x20\xaa\x76\xdb\x86\x74\x2c\x52\x6e\x04\xba\x6d\x85\x34\x98\x8d\x5e\x6b\xb3\xd1\xac\x7d\x5d\x18\x0b\x32\x1d\x47\x07\xfa\xbb\xa6\xfc\x24\x35\xd6\x20\xcc\xa0\xd0\x4a\x6a\xf2\xdf\x23\x27\x04\x0b\x64\x3c\x3e\x56\x45\x16\xfd\xd9\x24\x7c\x04\x2c\x23\xed\x05\x89\x0f\xc3\xa5\xa7\x17\x98\x1f\x8a\xce\x0b\x58\x38\xfd\x6b\x7e\x02\x7d\xb1\xc8\xd7\x07\xcb\xbe\x4e\x83\x44\xeb\xad\x76\xfc\xeb\xad\x54\x6d\xaa\x3e\xc7\x13\x5b\x6f\x93\x24\xc0\x0a\xa9\x5a\xfd\x09\xec\xfb\x11\x33\x7a\x71\x88\x8b\x40\x33\xfd\x6b\x22\x81\x0e\x73\x37\x39\x07\xda\xd6\x5d\x2a\xd4\xbc\xc4\x09\xcc\xd8\x6c\x36\x9b\x51\x3b\x7f\x9f\x9d\xa5\x64\x1b\x85\xf5\xd9\x42\x31\x48\x9d\xab\x46\xb4\x4a\x25\xb7\x6b\x61\x36\xfa\x3c\x21\xef\x5e\x57\x98\x4b\xae\xc8\xfd\x39\xc8\xea\x5d\xe6\xa4\x53\xb8\x3b\xb6\x95\x96\x65\x89\xda\x75\xbb\x4e\x6f\x97\xe5\x2b\xae\x97\x87\xdf\x05\x7d\x40\x1f\x14\x0e\x32\x2e\xc4\x22\xaf\xeb\x5d\x66\x5e\xd1\x6e\xac\x74\xe8\xb7\xb9\x51\xc6\xd6\xf9\x0a\x4b\x1f\x47\x25\x15\xda\x5d\x86\xd6\x1a\xbb\xf0\x27\xc1\x2e\x7b\x31\x66\x7d\x91\xb4\xc0\x82\x37\xea\xfc\x6e\xfa\x63\x85\x5b\x47\xc1\xc6\x71\x9c\xfc\x79\x66\x2f\x7b\xd3\xdc\xb9\x5e\xe8\xa8\x64\x29\x5d\xbc\xb4\xa6\xa9\x88\x40\x0a\xd4\x4e\x16\x12\xed\x65\x34\x97\xcd\xd4\xfe\x39\xf6\xe8\x52\xcf\x93\x82\x65\xf4\x01\xbc\x5d\x16\xf0\xa0\x70\xc4\xf0\xfe\x31\x06\x9f\x3a\x4c\xe7\x97\x67\x7f\xf8\xb2\x7e\x7c\x64\xec\xaf\xf5\x87\x46\x3b\x59\x22\x91\xdc\x5a\x53\x7e\xc6\xd2\xd8\xed\xc9\x2d\xcf\xbc\x0c\xad\xf6\xd6\x64\xcb\x4b\x45\x57\xd7\x21\x00\x7f\xce\x3e\xa0\x32\x5c\x04\xfe\x3f\xc1\xb7\x00\x00\x00\xff\xff\x6b\x4a\xed\x64\x72\x08\x00\x00"
+var _runtimePluginsLiterateLiterateLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x55\x4d\x8f\xe2\x38\x10\xbd\xf3\x2b\x4a\xde\x5d\x75\xb2\x9d\x64\xc5\x1e\x91\x22\x65\xf7\xd0\xa7\xfd\x12\xbd\x73\x02\x1a\x99\xb8\x02\x16\x8e\x1d\xd9\x95\x61\x50\xd3\xff\x7d\xe4\x38\x84\x34\x6a\x69\xa0\x73\x89\xab\xfc\xea\xbd\x2a\x97\x3f\x94\x29\xb9\x82\xd2\xe8\x4a\x6e\x21\x07\x59\x37\xc6\x52\xc4\x6a\x59\x5a\xf3\x5b\x70\xb3\x78\x32\xa9\x5a\x5d\x92\x34\x1a\x1c\x71\x4b\xee\x20\x69\x17\x39\xb2\x49\xb0\xe3\x09\x00\x58\xa4\xd6\x7a\x80\x95\x7a\x9b\xb9\x76\xd3\x01\xa6\x49\xef\x50\xa8\xa3\x00\x8e\xf3\xbc\x1b\x4c\x50\x8b\x11\x33\x6a\x31\xe2\x45\x2d\x9e\xc9\x8e\x89\x83\x27\xcf\x1f\x1e\xc0\xd8\x6b\x99\x74\xa4\xd2\x87\xc6\x79\x1e\x46\x57\x3a\xae\x51\x92\xa2\x80\x4f\xc0\x61\xd3\x89\x40\x58\x08\x87\x4d\x02\x95\x44\x25\x1c\xe4\xde\xf2\x5a\x6c\xc6\x12\x78\x7d\x1b\xc1\x1a\x4e\x84\x56\x7b\x48\xd0\xad\x8c\xad\x39\x45\x2c\x5a\xbc\xfc\xe2\x56\x8f\x31\x1b\x31\x07\xc8\x6c\xeb\x73\xed\x03\x13\x38\xa7\x13\x95\x71\xaf\xb7\xf8\x29\xfc\x1f\xa7\x2b\xc8\xa1\xf4\xf5\x86\xf8\xbe\xfe\x30\x7b\x55\x8c\xd1\x7f\xb6\x55\x85\xf6\xdf\x06\x75\xb4\x69\xab\x10\x21\x2b\xd0\x86\x2e\x2b\xba\x69\xab\xec\x3f\x4e\xbb\x04\x58\xa6\x24\xb1\x18\x68\x87\xba\x83\x5e\x04\x3a\xb3\x63\xbf\xd4\x59\x1a\x81\x74\x6c\x10\x72\x60\xad\xde\x6b\x73\xd0\xac\x9b\xae\x8c\x05\x99\x4f\x93\x4d\x5b\xcd\xfe\x92\x1a\xdd\x3f\x6d\x1d\xc5\x20\xcc\x40\x1a\x08\x94\xd4\x3e\xf8\x0c\x8b\x64\x3a\x8d\x07\x88\xac\xc6\xdb\xc9\x43\x13\x60\x85\xd7\x5c\x7b\xd1\xeb\x34\xfd\x37\x4a\x28\xf4\xb1\x8f\x02\x16\x2f\x7e\x5f\xbd\x83\x6e\x2c\xf2\xfd\xe0\xf1\x85\x7d\x50\xa0\x3b\x6a\xe2\xdf\x9e\xa4\xea\x4a\x0c\xb5\xbd\xf3\x8d\x8c\x2c\x03\x56\x49\xd5\xe9\xcf\x40\x49\x42\xcb\x09\x53\xe6\x27\x86\xbc\x3c\x68\xa9\x7f\x4c\x24\x90\xb0\xa4\xd9\x2d\xd0\x6e\xbd\xa5\x42\xcd\x6b\x9c\xc1\x92\x2d\x97\xcb\xa5\x6f\xe3\xcf\xcb\x9b\x94\x6c\xab\xd0\xdd\x2c\x94\x82\xd4\xa5\x6a\x45\xa7\x54\x73\xbb\x17\xe6\xa0\x6f\x13\x0a\xe1\xae\xc1\x52\x72\xe5\xc3\x5f\xa2\xc2\x9d\x0a\x92\xa4\xf0\x74\x69\xab\x1f\xd6\x35\x6a\xea\xad\x5e\xef\x54\x94\x3b\xae\xb7\xc3\x7f\xed\xf7\xff\x27\x85\xa3\x82\x0b\xb1\x2e\x9d\x3b\x15\xe6\x2b\xda\x83\x95\x84\xc1\x2c\x8d\x32\xd6\x95\x3b\xac\x43\x1e\x8d\x54\x68\x4f\x05\x5a\x6b\xec\x3a\x1c\xe2\x53\xb1\x31\x66\x7f\x97\xb4\xc0\x8a\xb7\xea\xf6\x6e\x86\x5b\x81\x5b\xf2\xc9\xa6\x69\x9a\xfd\x7a\x63\x2f\x47\xbb\xb9\x0f\xbd\x33\x50\xc9\x5a\x52\xba\xb5\xa6\x6d\x3c\x81\x14\xa8\x49\x56\x12\xed\x7d\x34\xf7\xed\xa9\xf3\x77\xe9\xd1\xbd\x91\xef\x16\xac\xf0\x07\xe0\xf5\xbe\x84\xaf\x16\xce\x33\xbc\x7d\x8e\x21\x94\x0e\x8b\xd5\xfd\xd5\x0f\x27\xeb\xe3\x2b\x63\x12\x2e\x38\xff\xe4\x66\x7f\x08\x31\x6f\x35\xc9\x1a\x3d\xd7\x93\x35\xf5\xdf\x58\x1b\x7b\x8c\xd8\xf9\xde\x61\xc9\x19\x3b\xff\xff\xb9\x53\x4d\x60\x98\xcc\x8e\xbc\x56\xfe\x0d\x1a\xd2\x89\xc7\xec\x73\x54\x86\x8b\x28\xf8\xfc\xdd\xfc\xa5\x11\x9c\x70\xee\x4b\x8b\xe2\xee\x89\xf9\x1e\x00\x00\xff\xff\x27\x3a\xf6\x67\x18\x08\x00\x00"
 
 func runtimePluginsLiterateLiterateLuaBytes() ([]byte, error) {
        return bindataRead(
index 913b2d3f7180a97c4f25b52b179166d4eb1079ff..01fcba4b99720faadd94071b56b6da9536c77b57 100644 (file)
@@ -1,7 +1,4 @@
--- VERSION = "1.0.0"
-if GetOption("literate") == nil then
-    AddOption("literate", true)
-end
+local config = import("micro/config")
 
 function startswith(str, start)
    return string.sub(str,1,string.len(start))==start
@@ -12,21 +9,20 @@ function endswith(str, endStr)
 end
 
 function split(string, sep)
-        local sep, fields = sep or ":", {}
-        local pattern = string.format("([^%s]+)", sep)
-        string:gsub(pattern, function(c) fields[#fields+1] = c end)
-        return fields
+    local sep, fields = sep or ":", {}
+    local pattern = string.format("([^%s]+)", sep)
+    string:gsub(pattern, function(c) fields[#fields+1] = c end)
+    return fields
 end
 
-function onViewOpen(view)
-    if not GetOption("literate") then return end
-    if not endswith(view.Buf.Path, ".lit") then
+function onBufferOpen(buf)
+    if not endswith(buf.Path, ".lit") then
         return
     end
 
     local codetype = "unknown"
-    for i=1,view.Buf.NumLines do
-        local line = view.Buf:Line(i-1)
+    for i=1,buf:LinesNum() do
+        local line = buf:Line(i-1)
         if startswith(line, "@code_type") then
             codetype = split(line, " ")[2]
             break
@@ -52,6 +48,7 @@ function onViewOpen(view)
     syntaxFile = syntaxFile .. "                rules: []\n"
     syntaxFile = syntaxFile .. "            - include: " .. codetype .. "\n"
 
-    AddRuntimeFileFromMemory("literate", "syntax", "literate.yaml", syntaxFile)
-    Reload()
+    config.AddRuntimeFileFromMemory("literate", config.RTSyntax, "literate.yaml", syntaxFile)
+    config.Reload()
+    buf:UpdateRules()
 end