From 118a7d1966e0907d3cee03f9a98afed8adcba0df Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Tue, 11 May 2021 11:07:17 +0200 Subject: [PATCH] ugly search stuff --- files/.config/nvim/fnl/help-thingy.fnl | 82 +++++++++++++++++++ files/.config/nvim/fnl/init.fnl | 2 + files/.config/nvim/fnl/macros.fnl | 3 +- files/.config/nvim/fnl/plugins/compe.fnl | 40 ++++----- .../.config/nvim/fnl/smart-compe-conjure.fnl | 61 ++++++++++++++ files/.config/nvim/fnl/utils.fnl | 19 ----- 6 files changed, 167 insertions(+), 40 deletions(-) create mode 100644 files/.config/nvim/fnl/help-thingy.fnl create mode 100644 files/.config/nvim/fnl/smart-compe-conjure.fnl diff --git a/files/.config/nvim/fnl/help-thingy.fnl b/files/.config/nvim/fnl/help-thingy.fnl new file mode 100644 index 0000000..b4ef38b --- /dev/null +++ b/files/.config/nvim/fnl/help-thingy.fnl @@ -0,0 +1,82 @@ +(module help-thingy + {autoload {utils utils + a aniseed.core + str aniseed.string + fennel aniseed.fennel + popup popup} + require-macros [macros]}) + +(defn get-current-word [] + (let [col (. (vim.api.nvim_win_get_cursor 0) 2) + line (vim.api.nvim_get_current_line)] + (.. (vim.fn.matchstr (string.sub line 1 (+ col 1)) + "\\k*$") + (string.sub ( vim.fn.matchstr (string.sub line (+ col 1)) + "^\\k*") + 2)))) + + + +(def helpfiles-path (str.join "/" (a.butlast (str.split vim.o.helpfile "/")))) +(def tags + (let [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)) + +(defn find-help-tag-for [topic] + (or (. tags topic) + (. tags (.. topic "()")) + (. 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." "") "()")))) + + +(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"))))) + +(defn pop [text] + (var width 0) + (each [_ line (ipairs text)] + (when (> (length line) width) + (set width (length line)))) + (let [bufnr (vim.api.nvim_create_buf false true)] + (vim.api.nvim_buf_set_option bufnr :bufhidden "wipe") + (vim.api.nvim_buf_set_option bufnr :filetype "help") + (vim.api.nvim_buf_set_lines bufnr 0 -1 true text) + (popup.create bufnr {:padding [1 1 1 1] :width width}))) + + +(fn _G.get_help [] + (let [help-tag (find-help-tag-for (get-current-word))] + (when help-tag + (pop (help-for-tag help-tag))))) + +(utils.keymap :n :L ":call v:lua.get_help()") + + + +(def rtp vim.o.runtimepath) +(str.split rtp ",") + + +; vim.api.nvim_buf_get_name +; vim.api.nvim_buf_call +; vim.api.nvim_buf_set_text +; vim.api.nvim_buf_set_var +; vim.fn.bufnr diff --git a/files/.config/nvim/fnl/init.fnl b/files/.config/nvim/fnl/init.fnl index 38a40c8..1b4d555 100644 --- a/files/.config/nvim/fnl/init.fnl +++ b/files/.config/nvim/fnl/init.fnl @@ -20,6 +20,8 @@ (make-errors-epic (require "plugins.lsp")) (make-errors-epic (require "keybinds")) +(make-errors-epic (require "smart-compe-conjure")) + ; Basic setup --------------------------------------- foldstart (vim-let mapleader "\\") diff --git a/files/.config/nvim/fnl/macros.fnl b/files/.config/nvim/fnl/macros.fnl index 9322fbf..c048871 100644 --- a/files/.config/nvim/fnl/macros.fnl +++ b/files/.config/nvim/fnl/macros.fnl @@ -27,7 +27,8 @@ :dbg-call (fn [x ...] `(do - (a.println ,...) + (let [a# (require "aniseed.core")] + (a#.println ,...)) (,x ,...))) :pkg diff --git a/files/.config/nvim/fnl/plugins/compe.fnl b/files/.config/nvim/fnl/plugins/compe.fnl index a08687e..25daa20 100644 --- a/files/.config/nvim/fnl/plugins/compe.fnl +++ b/files/.config/nvim/fnl/plugins/compe.fnl @@ -1,24 +1,24 @@ (module plugins.compe {autoload {compe compe}}) -(compe.setup - {:enabled true - :autocomplete false - :debug false - :min_length 1 - :preselect "enable" - :throttle_time 80 - :source_timeout 200 - :incomplete_delay 400 - :max_abbr_width 100 - :max_kind_width 100 - :max_menu_width 100 - :documentation true - :source {:path true - :buffer true - :calc true - :nvim_lsp true - :nvim_lua true - :vsnip false - :conjure true}}) +;(compe.setup + ;{:enabled true + ;:autocomplete false + ;:debug false + ;:min_length 1 + ;:preselect "enable" + ;:throttle_time 80 + ;:source_timeout 200 + ;:incomplete_delay 400 + ;:max_abbr_width 100 + ;:max_kind_width 100 + ;:max_menu_width 100 + ;:documentation true + ;:source {:path true + ;:buffer true + ;:calc true + ;:nvim_lsp true + ;:nvim_lua true + ;:vsnip false + ;:conjure true}}) diff --git a/files/.config/nvim/fnl/smart-compe-conjure.fnl b/files/.config/nvim/fnl/smart-compe-conjure.fnl new file mode 100644 index 0000000..18f5003 --- /dev/null +++ b/files/.config/nvim/fnl/smart-compe-conjure.fnl @@ -0,0 +1,61 @@ +(module smart-compe-conjure + {require {utils utils + a aniseed.core + str aniseed.string + fennel aniseed.fennel + popup popup + compe compe + help help-thingy} + require-macros [macros]}) + + +(def fuck (require "compe_conjure")) + + +(def my_source {}) +(set my_source.new + (fn [] + (setmetatable {} {:__index my_source}))) + +(set my_source.determine fuck.determine) +(set my_source.get_metadata fuck.get_metadata) +(set my_source.complete fuck.complete) +(set my_source.abort fuck.abort) +(set my_source.documentation + (fn [self args] + (a.println (fennel.view args)) + (args.callback + (let [help-tag (help.find-help-tag-for args.completed_item.word)] + (when help-tag + (var lines ["```help"]) + (each [_ line (ipairs (help.help-for-tag help-tag))] + (table.insert lines line)) + (table.insert lines "```") + lines))))) + +(compe.register_source :epic (my_source.new)) + + +(compe.setup + {:enabled true + :autocomplete false + :debug false + :min_length 1 + :preselect "enable" + :throttle_time 80 + :source_timeout 200 + :incomplete_delay 400 + :max_abbr_width 100 + :max_kind_width 100 + :max_menu_width 100 + :documentation true + :source {:path true + :buffer true + :calc true + :nvim_lsp true + :nvim_lua true + :vsnip false + :epic true}}) + + +;(print (fennel.view compe)) diff --git a/files/.config/nvim/fnl/utils.fnl b/files/.config/nvim/fnl/utils.fnl index e8a856b..7979be2 100644 --- a/files/.config/nvim/fnl/utils.fnl +++ b/files/.config/nvim/fnl/utils.fnl @@ -43,30 +43,11 @@ (nvim.buf_del_keymap 0 mode from) (nvim.del_keymap mode from))) -(defn pairs->tuples [xs] - (let [result []] - (each-pair [l r xs] - (table.insert result (values l r))) - result)) - (defn safe-require [name] (xpcall #(require name) #(a.println (.. "Error sourcing " name ":\n" (fennel.traceback $1))))) -(defn use [...] - "Iterates through the arguments as pairs and calls packer's function for - each of them. Works around Fennel not liking mixed associative and sequential - tables as well. - Additionally sources the file set in the :mod field of the plugin options" - (let [pkgs [...] - packer (require "packer")] - (packer.startup - (fn [use] - (each-pair [name opts pkgs] - (-?> opts (. :mod) (safe-require-plugin-config)) - (use (a.assoc opts 1 name))))))) - (defn buffer-content [bufnr] "Returns a table of lines in the given buffer"