mirror of
https://github.com/elkowar/dots-of-war.git
synced 2024-11-06 03:12:24 +00:00
ugly search stuff
This commit is contained in:
parent
29bc68c151
commit
118a7d1966
6 changed files with 167 additions and 40 deletions
82
files/.config/nvim/fnl/help-thingy.fnl
Normal file
82
files/.config/nvim/fnl/help-thingy.fnl
Normal file
|
@ -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()<CR>")
|
||||
|
||||
|
||||
|
||||
(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
|
|
@ -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 "\\<Space>")
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
:dbg-call
|
||||
(fn [x ...]
|
||||
`(do
|
||||
(a.println ,...)
|
||||
(let [a# (require "aniseed.core")]
|
||||
(a#.println ,...))
|
||||
(,x ,...)))
|
||||
|
||||
:pkg
|
||||
|
|
|
@ -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}})
|
||||
|
||||
|
|
61
files/.config/nvim/fnl/smart-compe-conjure.fnl
Normal file
61
files/.config/nvim/fnl/smart-compe-conjure.fnl
Normal file
|
@ -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))
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue