From d4537746a29fc296eac8c1e707c73b2087dc2bf8 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Sun, 8 Oct 2023 15:53:30 +0200 Subject: dummy version --- mut/neovim/fnl/conf/init.fnl | 62 ++++++++++++++++++++----- mut/neovim/fnl/conf/pkgs/cmp.fnl | 90 ++++++++++-------------------------- mut/neovim/fnl/conf/pkgs/harpoon.fnl | 39 ---------------- mut/neovim/fnl/conf/pkgs/test.fnl | 9 ---- mut/neovim/fnl/conf/settings.fnl | 4 +- 5 files changed, 78 insertions(+), 126 deletions(-) delete mode 100644 mut/neovim/fnl/conf/pkgs/harpoon.fnl delete mode 100644 mut/neovim/fnl/conf/pkgs/test.fnl diff --git a/mut/neovim/fnl/conf/init.fnl b/mut/neovim/fnl/conf/init.fnl index 3d3c695..3dec989 100644 --- a/mut/neovim/fnl/conf/init.fnl +++ b/mut/neovim/fnl/conf/init.fnl @@ -11,18 +11,22 @@ ;; (require :conf.events) ;; (require :conf.filetype) ;; (require :conf.newtab) -;; (require :conf.nix-develop) +(require :conf.nix-develop) ;; (require :conf.diagnostic) +(local tel (require :telescope)) +(local themes (require :telescope.themes)) +(local builtin (require :telescope.builtin)) +(tel.setup + {:defaults (vim.tbl_extend :force (themes.get_ivy) {})}) + (let [map vim.keymap.set] - (map :t : "") - ;; pausing and continueing printing output is not necessary inside neovim terminal right? - (map :t : ":q") - (map :n :qo ":copen") - (map :n :qc ":cclose") - (map :n :lo ":lopen") - (map :n :lc ":lclose") + (map :n :qf ":copen") + (map :n :q ":cclose") + (map :n :ll ":lopen") + (map :n :l ":lclose") + (map :n : ":cnext") (map :n "[q" ":cprevious") (map :n "]q" ":cnext") (map :n "[x" ":lprevious") @@ -31,9 +35,45 @@ (map :n "`" ":FocusDispatch ") (map :n "`k" ":K9s ") (map :n "`s" ":Ssh ") - (map :n :p ":NewTab") - (map :n :cf ":tabedit ~/flake|tc ~/flake|Go") - (map :n :cn ":tabedit ~/neovim|tc ~/neovim|Go")) + (map :n ";" ":silent grep ") + (map :n :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 items (fn [cfg] (. (vim.fn.getqflist cfg) :items))) + + (icollect + [_ E (ipairs + (items + {:lines + (icollect [_ e (ipairs qf.items)] + (prettify e.text))}))] + (format E)))) (tset _G :P (lambda [...] (let [inspected (icollect [_ v (ipairs [...])] diff --git a/mut/neovim/fnl/conf/pkgs/cmp.fnl b/mut/neovim/fnl/conf/pkgs/cmp.fnl index 97c0655..1edce94 100644 --- a/mut/neovim/fnl/conf/pkgs/cmp.fnl +++ b/mut/neovim/fnl/conf/pkgs/cmp.fnl @@ -1,20 +1,5 @@ (local cmp (require :cmp)) -(fn string-startswith? [str start] - (= start (string.sub str 1 (string.len start)))) - -(fn string-startswith-anyof? [str start-list] - (fn iter [[item & rest]] - (if (not item) false - (string-startswith? str item) true - (iter rest))) - - (iter start-list)) - -(fn string-startswith-upper? [str] - (local first-char (string.sub str 1 1)) - (= first-char (string.upper first-char))) - (fn has-words-before? [] (local [line col] (vim.api.nvim_win_get_cursor 0)) (local [word & rest] (vim.api.nvim_buf_get_lines 0 (- line 1) line true)) @@ -22,11 +7,8 @@ (local is_string (before:match "%s")) (and (not= col 0) (= is_string nil))) - -(fn edit? [] - (local line (vim.fn.getcmdline)) - (not= nil (line:match "ed?i?t? %.*"))) - +(fn edit? [line] + (not= nil (line:match "^ed?i?t? .*$"))) (fn enum [types key] (. (. cmp types) key)) @@ -64,53 +46,31 @@ :sources (cmp.config.sources [{:name :nvim_lsp} {:name :path} {:name :luasnip}])}) + + ; This tries to emulate somewhat ido mode to find files ; todo sorting based on least recently used (cmp.setup.cmdline ":" - {:completion {:completeopt "menu,menuone,noinsert"} - :matching {:disallow_fuzzy_matching false - :disallow_fullfuzzy_matching false - :disallow_partial_fuzzy_matching false - :disallow_partial_matching false - :disallow_prefix_unmatching false} - - :mapping (cmp.mapping.preset.cmdline { - : (cmp.mapping - (fn [] - (cmp.confirm {:select true :behavior cmp.ConfirmBehavior.Replace}) - (vim.api.nvim_feedkeys " " :c false) - (vim.defer_fn cmp.complete 10)) - [:i :c]) - : (cmp.mapping - (fn [fallback] - (local entry (cmp.get_selected_entry)) - (if (or (= nil entry) (not (edit?))) - (vim.schedule fallback) - (do - (cmp.confirm {:select true :behavior cmp.ConfirmBehavior.Replace}) - (if (entry.completion_item.label:match "%.*/$") - (do - (vim.defer_fn cmp.complete 10)) - (do - (vim.schedule fallback)))))) - [:i :c]) - : {:c (fn [fallback] - (if (not (edit?)) - (fallback) - (do - (local line (vim.fn.getcmdline)) - (local key (vim.api.nvim_replace_termcodes "" true false true)) - (if (= nil (line:match "%.*/$")) - (vim.api.nvim_feedkeys key :c false) - (do - (vim.api.nvim_feedkeys (.. key key) :c false))) - (vim.defer_fn #(cmp.complete) 10))))} - : {:c (fn [fallback] - (fallback) - (vim.defer_fn #(cmp.complete) 10))} - : {:c (fn [fallback] - (cmp.confirm {:select false}) - (vim.defer_fn #(cmp.complete) 10))}}) + {:enabled (fn [] (local val (edit? (vim.fn.getcmdline))) + (if (not val) + (cmp.close)) + val) + :completion {:completeopt "menu,menuone,noinsert"} + :mapping {: (cmp.mapping + (fn [fallback] + (local entry (cmp.get_selected_entry)) + (local line (vim.fn.getcmdline)) + (if (or (= nil entry) (not (edit? line))) + (do + (vim.schedule fallback)) + (do + (cmp.confirm {:select true :behavior cmp.ConfirmBehavior.Replace}) + (if (entry.completion_item.label:match "%.*/$") + (do + (vim.defer_fn cmp.complete 10)) + (do + (vim.schedule fallback)))))) + [:i :c])} :sources (cmp.config.sources [{:name :cmdline} {:name :path}])} @@ -123,6 +83,6 @@ (let [map vim.keymap.set] (map :n :xf (fn [] (vim.api.nvim_feedkeys (.. ":e " (vim.fn.getcwd)) :c false) - (vim.schedule #(vim.api.nvim_feedkeys "/" :c false))))) + (vim.defer_fn #(vim.api.nvim_feedkeys "/" :c false) 10)))) (cmp-setup (require :cmp) true) diff --git a/mut/neovim/fnl/conf/pkgs/harpoon.fnl b/mut/neovim/fnl/conf/pkgs/harpoon.fnl deleted file mode 100644 index 3f5fc48..0000000 --- a/mut/neovim/fnl/conf/pkgs/harpoon.fnl +++ /dev/null @@ -1,39 +0,0 @@ -(local harpoon-mark (require :harpoon.mark)) -(local harpoon-ui (require :harpoon.ui)) -(fn make-harpoon [func] - (fn [] - (func) - (vim.cmd :redrawtabline))) - -(vim.keymap.set :n "[]" (make-harpoon (fn [] (harpoon-mark.add_file)))) -(vim.keymap.set :n "][" (make-harpoon (fn [] (harpoon-ui.toggle_quick_menu)))) -(vim.keymap.set :n "]]" (make-harpoon (fn [] (harpoon-ui.nav_next)))) -(vim.keymap.set :n "[[" (make-harpoon (fn [] (harpoon-ui.nav_prev)))) - -(var use-numbers false) -(local num [1 2 3 4 5]) -(local shortcuts ["+" "-" "<" ">" "\""]) -(fn print-use-numbers [] - (print (vim.inspect use-numbers))) - -(fn toggle-harpoon-mappings [] - (if (not use-numbers) - (do - ; (each [_ i (ipairs shortcuts)] ; (vim.keymap.del :n i)) - (vim.keymap.set :n "[+" (make-harpoon (fn [] (harpoon-ui.nav_file 1)))) - (vim.keymap.set :n "[-" (make-harpoon (fn [] (harpoon-ui.nav_file 2)))) - (vim.keymap.set :n "[<" (make-harpoon (fn [] (harpoon-ui.nav_file 3)))) - (vim.keymap.set :n "[>" (make-harpoon (fn [] (harpoon-ui.nav_file 4)))) - (vim.keymap.set :n "[\"" (make-harpoon (fn [] (harpoon-ui.nav_file 5)))) - (set use-numbers true)) - (do - ; (each [_ s (ipairs shortcuts)] ; (vim.keymap.del :n s) - (vim.keymap.set :n "[1" (make-harpoon (fn [] (harpoon-ui.nav_file 1)))) - (vim.keymap.set :n "[2" (make-harpoon (fn [] (harpoon-ui.nav_file 2)))) - (vim.keymap.set :n "[3" (make-harpoon (fn [] (harpoon-ui.nav_file 3)))) - (vim.keymap.set :n "[4" (make-harpoon (fn [] (harpoon-ui.nav_file 4)))) - (vim.keymap.set :n "[5" (make-harpoon (fn [] (harpoon-ui.nav_file 5)))) - (set use-numbers false)))) - -(vim.api.nvim_create_user_command :H toggle-harpoon-mappings {}) -(toggle-harpoon-mappings) diff --git a/mut/neovim/fnl/conf/pkgs/test.fnl b/mut/neovim/fnl/conf/pkgs/test.fnl deleted file mode 100644 index 4f0bcc4..0000000 --- a/mut/neovim/fnl/conf/pkgs/test.fnl +++ /dev/null @@ -1,9 +0,0 @@ -(tset vim.g "test#strategy" :neovim) -(tset vim.g "test#neovim#term_position" :botright) - -(vim.keymap.set :n :t ":TestNearest" {:silent true}) -(vim.keymap.set :n :C ":TestClass" {:silent true}) -(vim.keymap.set :n :T ":TestFile" {:silent true}) -(vim.keymap.set :n :a ":TestSuite" {:silent true}) -(vim.keymap.set :n :l ":TestLast" {:silent true}) -(vim.keymap.set :n :g ":TestVisit" {:silent true}) diff --git a/mut/neovim/fnl/conf/settings.fnl b/mut/neovim/fnl/conf/settings.fnl index fc0ed3e..f7b52a6 100644 --- a/mut/neovim/fnl/conf/settings.fnl +++ b/mut/neovim/fnl/conf/settings.fnl @@ -58,10 +58,10 @@ relativenumber on exrc on secure on - completeopt "menu,longest,preview" + ; completeopt "menu,longest,preview" wmnu on wop "pum" - wildmode "list:longest" + ; wildmode "list:longest" complete ".,w,k,kspell,b" foldopen "block,hor,jump,mark,percent,quickfix,search,tag" laststatus 3 -- cgit v1.2.3