diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-10-08 17:23:46 +0200 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-10-08 17:23:46 +0200 |
| commit | 77ad911a2c758f03c3a3e34b998cedf126f1ce9c (patch) | |
| tree | e269db33773c7efadcb1aded3b932a8d0224ecb7 | |
| parent | d4537746a29fc296eac8c1e707c73b2087dc2bf8 (diff) | |
just make my own dispatch
| -rw-r--r-- | mut/neovim/fnl/conf/init.fnl | 84 |
1 files changed, 52 insertions, 32 deletions
diff --git a/mut/neovim/fnl/conf/init.fnl b/mut/neovim/fnl/conf/init.fnl index 3dec989..a475013 100644 --- a/mut/neovim/fnl/conf/init.fnl +++ b/mut/neovim/fnl/conf/init.fnl @@ -38,42 +38,62 @@ (map :n "<leader>;" ":silent grep ") (map :n :<leader>xb #(builtin.buffers { :sort_mru true :ignore_current_buffer true}))) -(set vim.opt.quickfixtextfunc :v:lua.PrettifyQf) - ;; I like to use the qf to run a lot of stuff that prints junk ;; Here I just check if ansi control stuff is printed and reparse the lines with efm -(tset _G :PrettifyQf - (fn [info] - (local {: id : winid : start_idx : end_idx} info) - (local qf (vim.fn.getqflist {: id :items 1})) - (local fname (fn [e] - (if (not= 0 e.bufnr) - (vim.fn.bufname (. e :bufnr)) - ""))) - (local s (fn [line pattern] - (let [(result n) (line:gsub pattern "")] - (match n - nil line - _ result)))) - (local prettify #(-> $1 - (s "%c+%[[0-9:;<=>?]*[!\"#$%%&'()*+,-./]*[@A-Z%[%]^_`a-z{|}~]*;?[A-Z]?"))) - (local pos (fn [e] (if (not= 0 e.lnum) - (.. e.lnum " col " e.col) - ""))) - (local format (fn [e] (accumulate [l "" - _ word - (ipairs [(fname e) "|" (pos e) "| " e.text])] - (.. l word)))) +(local qf + (fn [{: id : title}] + (fn [lines] + (local fname (fn [e] + (if (not= 0 e.bufnr) + (vim.fn.bufname (. e :bufnr)) + ""))) + (local s (fn [line pattern] + (let [(result n) (line:gsub pattern "")] + (match n + nil line + _ result)))) + (local prettify #(-> $1 + (s "%c+%[[0-9:;<=>?]*[!\"#$%%&'()*+,-./]*[@A-Z%[%]^_`a-z{|}~]*;?[A-Z]?"))) + (local pos (fn [e] (if (not= 0 e.lnum) + (.. e.lnum " col " e.col) + ""))) + (local format (fn [e] (accumulate [l "" + _ word + (ipairs [(fname e) "|" (pos e) "| " e.text])] + (.. l word)))) + + (local lines (icollect [_ l (ipairs lines)] + (if l + (prettify l)))) + (vim.fn.setqflist [] :a {: id : title : lines})))) - (local items (fn [cfg] (. (vim.fn.getqflist cfg) :items))) +(local job + (fn [cmd] + (local title (table.concat cmd " ")) + (vim.fn.setqflist [] " " {: title}) + (local add2qf (qf (vim.fn.getqflist {:id 0 :title 1}))) + (vim.fn.jobstart + cmd + {:on_stdout (fn [id data] + (if data + (add2qf data))) + :on_stderr (fn [id data] + (if data + (add2qf data))) + :on_exit (fn [id rc] + (if (= rc 0) + (vim.cmd ":cope")))}))) +(var last_job nil) +(vim.api.nvim_create_user_command :Compile (fn [cmd] + (set last_job cmd.fargs) + (job cmd.fargs)) + {:nargs :* :bang true}) +(vim.api.nvim_create_user_command :Recompile (fn [] + (if (not= nil last_job) + (job last_job) + (vim.notify "nothing to recompile"))) + {:bang true}) - (icollect - [_ E (ipairs - (items - {:lines - (icollect [_ e (ipairs qf.items)] - (prettify e.text))}))] - (format E)))) (tset _G :P (lambda [...] (let [inspected (icollect [_ v (ipairs [...])] |
