]> git.lizzy.rs Git - micro.git/blobdiff - runtime/plugins/literate/literate.lua
Merge
[micro.git] / runtime / plugins / literate / literate.lua
index aa41f4150efec945f3313473214f81a6c212a13f..5ef9ac22b89a70cbcbd05d2d0d98df5c2be568ba 100644 (file)
@@ -1,5 +1,7 @@
 VERSION = "1.0.0"
 
+local config = import("micro/config")
+
 function startswith(str, start)
    return string.sub(str,1,string.len(start))==start
 end
@@ -9,20 +11,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 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
@@ -48,6 +50,7 @@ function onViewOpen(view)
     syntaxFile = syntaxFile .. "                rules: []\n"
     syntaxFile = syntaxFile .. "            - include: " .. codetype .. "\n"
 
-    AddRuntimeFileFromMemory("literate", "syntax", "literate.yaml", syntaxFile)
-    Reload()
+    config.AddRuntimeFileFromMemory(config.RTSyntax, "literate.yaml", syntaxFile)
+    config.Reload()
+    buf:UpdateRules()
 end