dots-of-war/files/.config/nvim/fnl/help-thingy.fnl

50 lines
1.5 KiB
Text
Raw Normal View History

2021-05-11 09:07:17 +00:00
(module help-thingy
2021-05-11 11:23:22 +00:00
{require {utils utils
a aniseed.core
str aniseed.string
fennel aniseed.fennel
popup popup
ts nvim-treesitter}
2021-05-11 09:07:17 +00:00
require-macros [macros]})
(def helpfiles-path (str.join "/" (a.butlast (str.split vim.o.helpfile "/"))))
2021-05-11 11:23:22 +00:00
2021-05-11 09:07:17 +00:00
(def tags
2021-05-11 17:21:48 +00:00
(var entries {})
(each [line _ (io.lines (.. helpfiles-path "/tags"))]
(let [[key file address] (str.split line "\t")]
(tset entries key {:file (.. helpfiles-path "/" file) :address address})))
entries)
2021-05-11 09:07:17 +00:00
(defn find-help-tag-for [topic]
(or (. tags topic)
(. tags (.. topic "()"))
2021-05-11 11:23:22 +00:00
(. tags (.. (string.gsub topic "vim%.api%." "") "()"))
(. tags (.. (string.gsub topic "vim%.fn%." "") "()"))
(. tags (.. (string.gsub topic "fn%." "") "()"))
(. tags (.. (string.gsub topic "vim%.o%." "") "()"))
(. tags (.. (string.gsub topic "vim%.b%." "") "()"))
(. tags (.. (string.gsub topic "vim%.g%." "") "()"))))
2021-05-11 09:07:17 +00:00
(defn help-for-tag [tag]
(var data nil)
(each [line _ (io.lines tag.file)]
(if (= nil data)
(when (~= -1 (vim.fn.match line (tag.address:sub 2)))
(set data [line]))
(if (or (> 2 (length data))
(= "" line)
(= " " (line:sub 1 1))
(= "\t" (line:sub 1 1))
(= "<" (line:sub 1 1)))
(table.insert data line)
(lua "return data")))))
(fn _G.get_help []
2021-05-11 17:21:48 +00:00
(if-let [help-tag (find-help-tag-for (get-current-word))]
(pop (help-for-tag help-tag) :help)))
2021-05-11 09:07:17 +00:00
2021-05-11 20:08:50 +00:00
(utils.keymap :n :ML ":call v:lua.get_help()<CR>")
2021-05-11 09:07:17 +00:00