From 846813e174b8a42ace40bddaf3d64d8ead63b874 Mon Sep 17 00:00:00 2001 From: sefidel Date: Fri, 11 Feb 2022 00:38:15 +0900 Subject: feat(pack)!: migrate to fzf-lua --- fnl/nvrc/keymaps.fnl | 19 ++++---- fnl/nvrc/macro/pack.fnl | 2 +- fnl/nvrc/pack.fnl | 5 +- fnl/nvrc/utils.fnl | 124 +++++++++++++++++------------------------------- 4 files changed, 54 insertions(+), 96 deletions(-) (limited to 'fnl') diff --git a/fnl/nvrc/keymaps.fnl b/fnl/nvrc/keymaps.fnl index 67b0d70..790d21b 100644 --- a/fnl/nvrc/keymaps.fnl +++ b/fnl/nvrc/keymaps.fnl @@ -12,14 +12,12 @@ (map! [v :silent] :/ ":lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode()) ") -(map! [n :silent] :ff ":Telescope find_files ") -(map! [n :silent] :fc ":Telescope grep_string ") -(map! [n :silent] :fs ":Telescope live_grep ") -(map! [n :silent] :fa - ":Telescope find_files follow=true no_ignore=true hidden=true ") -(map! [n :silent] :fb ":Telescope buffers ") -(map! [n :silent] :gc ":Telescope git_commits ") -(map! [n :silent] :gs ":Telescope git_status ") +(map! [n :silent] :ff ":FzfLua files ") +(map! [n :silent] :fc ":FzfLua grep ") +(map! [n :silent] :fs ":FzfLua live_grep ") +(map! [n :silent] :fb ":FzfLua buffers ") +(map! [n :silent] :gc ":FzfLua git_commits ") +(map! [n :silent] :gs ":FzfLua git_status ") (map! [n] :f :Lightspeed_f) (map! [n] :F :Lightspeed_F) @@ -31,14 +29,13 @@ (map! [n :silent] :ra ":TZAtaraxis ") (map! [t] :jk "") -(map! [t :silent] :JK " :lua require ('nvrc.utils').close_buf() ") -(map! [n :silent] :tl ":Telescope terms ") +(map! [t :silent] :JK " :lua require ('nvrc.utils').del_buf() ") ; FIXME This opens on top of existing vertical/horizontal term (map! [n :silent] :th ":execute 15 .. 'new +terminal' | let b:term_type = 'hori' ") (map! [n :silent] :tv ":execute 'vnew +terminal' | let b:term_type = 'vert' ") (map! [n :silent] :tn ":execute 'terminal' | let b:term_type = 'wind' ") -(map! [n :silent] :q ":lua require('nvrc.utils').close_buf() ") +(map! [n :silent] :q ":lua require('nvrc.utils').del_buf() ") (map! [n :silent] :ya ":%y+ ") (map! [n :silent] :bn ":enew ") (map! [n :silent] :wn ":tabnew ") diff --git a/fnl/nvrc/macro/pack.fnl b/fnl/nvrc/macro/pack.fnl index 5ba7896..0adb18a 100644 --- a/fnl/nvrc/macro/pack.fnl +++ b/fnl/nvrc/macro/pack.fnl @@ -25,7 +25,7 @@ options (collect [k v (pairs options)] (if (= k :req) (values :config (format "require('nvrc.packs.%s')" v)) - (= k :init) (values :config (format "require('%s').setup()" v)) + (= k :init) (values :config (format "require('%s').setup({})" v)) (= k :defer) (values :setup (format "require('nvrc.utils').defer_unpack('%s', 5)" v)) (values k v)))] (doto options diff --git a/fnl/nvrc/pack.fnl b/fnl/nvrc/pack.fnl index a1c611a..35bd6df 100644 --- a/fnl/nvrc/pack.fnl +++ b/fnl/nvrc/pack.fnl @@ -24,10 +24,9 @@ (pack! :luukvbaal/stabilize.nvim {:after :jellybeans.vim :init :stabilize}) (pack! :numToStr/Comment.nvim {:module :Comment :init :Comment}) ; TODO: https://github.com/kyazdani42/nvim-tree.lua/issues/951 -(pack! :kyazdani42/nvim-tree.lua {:req :nvimtree :cmd [:NvimTreeToggle :NvimTreeFocus] :commit "d8bf1ad"}) +(pack! :kyazdani42/nvim-tree.lua {:req :nvimtree :defer :nvim-tree.lua}) (pack! :ggandor/lightspeed.nvim {:keys [:s :S :x :X :f :F]}) -(pack! :nvim-telescope/telescope.nvim {:req :telescope :module :telescope :cmd :Telescope}) -(pack! :boppyt/nvrc-extra) +(pack! :ibhagwan/fzf-lua {:init :fzf-lua :module :fzf-lua :cmd :FzfLua}) (pack! :bakpakin/fennel.vim {:ft :fennel}) diff --git a/fnl/nvrc/utils.fnl b/fnl/nvrc/utils.fnl index 6812c0c..52ca454 100644 --- a/fnl/nvrc/utils.fnl +++ b/fnl/nvrc/utils.fnl @@ -19,15 +19,15 @@ the previous value as the first arg. Starting with init." (var result init) (run! (fn [x] - (set result (f result x))) xs) + (set result (f result x))) xs) result) (fn merge! [base ...] (reduce (fn [acc m] - (when m - (each [k v (pairs m)] - (tset acc k v))) - acc) (or base {}) [...])) + (when m + (each [k v (pairs m)] + (tset acc k v))) + acc) (or base {}) [...])) (fn merge [...] (merge! {} ...)) @@ -37,91 +37,53 @@ (let [lsp (. (vim.lsp.util.get_progress_messages) 1)] (when lsp (let [msg (or lsp.message "") - percentage (or lsp.percentage 0) - title (or lsp.title "") - spinners {1"⠋" 2 "⠙" 3 "⠹" 4 "⠸" 5 "⠼" 6 "⠴" 7 "⠦" 8 "⠧" 9 "⠇" 10 "⠏"} - success-icon "^.^!" - ms (/ (vim.loop.hrtime) 1000000) - frame (% (math.floor (/ ms 120)) (length spinners))] - (when (>= percentage 70) + percentage (or lsp.percentage 0) + title (or lsp.title "") + spinners {1 "⠋" + 2 "⠙" + 3 "⠹" + 4 "⠸" + 5 "⠼" + 6 "⠴" + 7 "⠦" + 8 "⠧" + 9 "⠇" + 10 "⠏"} + success-icon "^.^!" + ms (/ (vim.loop.hrtime) 1000000) + frame (% (math.floor (/ ms 120)) (length spinners))] + (when (>= percentage 70) + (let [ertn [(string.format " %%<%s %s %s (%s%%%%) " success-icon + title msg percentage)]] + (lua "return (table.unpack or _G.unpack)(ertn)"))) (let [ertn [(string.format " %%<%s %s %s (%s%%%%) " - success-icon - title msg - percentage)]] - (lua "return (table.unpack or _G.unpack)(ertn)"))) - (let [ertn [(string.format " %%<%s %s %s (%s%%%%) " - (. spinners - (+ frame 1)) - title msg - percentage)]] - (lua "return (table.unpack or _G.unpack)(ertn)"))))) "") + (. spinners (+ frame 1)) title msg percentage)]] + (lua "return (table.unpack or _G.unpack)(ertn)"))))) + "") (fn will_it_fit [width winid] "Returns whether this module will fit in the given width" (> (vim.api.nvim_win_get_width (or (tonumber winid) 0)) width)) -(fn close_buf [force] - "ojroques/nvim-bufdel 'BSD-2'" - (let [opts {:next :cycle :quit false}] - (fn switch-buffer [windows buf] - (let [cur-win (vim.fn.winnr)] - (each [_ winid (ipairs windows)] - (set-forcibly! winid (or (tonumber winid) 0)) - (vim.cmd (string.format "%d wincmd w" (vim.fn.win_id2win winid))) - (vim.cmd (string.format "buffer %d" buf))) - (vim.cmd (string.format "%d wincmd w" cur-win)))) - - (fn get-next-buf [buf] - (var next (vim.fn.bufnr "#")) - (when (and (= opts.next :alternate) (= (vim.fn.buflisted next) 1)) - (lua "return next")) - (for [i 0 (- (vim.fn.bufnr "$") 1) 1] - (set next (+ (% (+ buf i) (vim.fn.bufnr "$")) 1)) - (when (= (vim.fn.buflisted next) 1) - (lua "return next")))) - - (local buf (vim.fn.bufnr)) - (when (= (vim.fn.buflisted buf) 0) - (vim.cmd :close) +(fn del_buf [] + (let [buflisted (vim.fn.getbufinfo {:buflisted 1}) + (cur-winnr cur-bufnr) (values (vim.fn.winnr) (vim.fn.bufnr))] + (when (< (length buflisted) 2) + (vim.cmd "confirm qall") (lua "return ")) - (when (< (length (vim.fn.getbufinfo {:buflisted 1})) 2) - (when opts.quit - (if force (vim.cmd :qall!) (vim.cmd "confirm qall")) - (lua "return ")) - (local (term _) - (pcall (fn [] - (vim.api.nvim_buf_get_var buf :term_type)))) - (when term - (vim.cmd (string.format "setlocal nobl" buf)) - (vim.cmd :enew) - (lua "return ")) - (vim.cmd :enew) - (vim.cmd :bp)) - (local next-buf (get-next-buf buf)) - (local windows (. (. (vim.fn.getbufinfo buf) 1) :windows)) - (if (or force (= (vim.fn.getbufvar buf :&buftype) :terminal)) - (let [(term type) (pcall (fn [] - (vim.api.nvim_buf_get_var buf :term_type)))] - (if term - (if (= type :wind) - (do - (vim.cmd (string.format "%d bufdo setlocal nobl" buf)) - (vim.cmd :BufferLineCycleNext)) - (let [cur-win (vim.fn.winnr)] - (vim.cmd (string.format "%d wincmd c" cur-win)) - (lua "return "))) - (do - (switch-buffer windows next-buf) - (vim.cmd (string.format "bd! %d" buf))))) - (do - (switch-buffer windows next-buf) - (vim.cmd (string.format "silent! confirm bd %d" buf)))) - (when (= (vim.fn.buflisted buf) 1) - (switch-buffer windows buf)))) + (each [_ winid (ipairs (. (. (vim.fn.getbufinfo cur-bufnr) 1) :windows))] + (vim.cmd (string.format "%d wincmd w" (vim.fn.win_id2win winid))) + (vim.cmd (or (and (= cur-bufnr (. (. buflisted (length buflisted)) :bufnr)) + :bp) :bn))) + (vim.cmd (string.format "%d wincmd w" cur-winnr)) + (local is-terminal (= (vim.fn.getbufvar cur-bufnr :&buftype) :terminal)) + (vim.cmd (or (and is-terminal "bd! #") "silent! confirm bd #")))) (fn defer_unpack [pack after] (when pack (set-forcibly! after (or after 0)) - (vim.defer_fn (fn [] ((. (require :packer) :loader) pack)) after))) + (vim.defer_fn (fn [] + ((. (require :packer) :loader) pack)) + after))) -{: merge : lsp_fidget : will_it_fit : close_buf : defer_unpack} +{: merge : lsp_fidget : will_it_fit : del_buf : defer_unpack} -- cgit 1.4.1