diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2023-06-10 14:27:06 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2023-06-10 14:27:06 +0200 |
commit | 6021565a28e4925b77d4997a553dfad5fbb521fd (patch) | |
tree | 0469234318691534eba00f1f060b3fc57da9832f | |
parent | 791808634684981d0f2db55822fc4ad1c21896b7 (diff) |
Fix cursorline in neo-tree
-rw-r--r-- | fnl/plugins/editor/neo-tree.fnl | 49 | ||||
-rw-r--r-- | fnl/settings/autocmds.fnl | 20 | ||||
-rw-r--r-- | fnl/util/cursorline.fnl | 27 |
3 files changed, 62 insertions, 34 deletions
diff --git a/fnl/plugins/editor/neo-tree.fnl b/fnl/plugins/editor/neo-tree.fnl index 725049b..121cd82 100644 --- a/fnl/plugins/editor/neo-tree.fnl +++ b/fnl/plugins/editor/neo-tree.fnl @@ -1,5 +1,7 @@ ;; File manager. +(local cursorline (require :util.cursorline)) + (fn init [] (set vim.g.neo_tree_remove_legacy_commands 1) (if (= (vim.fn.argc) 1) @@ -10,28 +12,37 @@ (fn deactivate [] (vim.cmd "Neotree close")) -(local opts - {:sources [:filesystem :buffers :git_status :document_symbols] - :source_selector {:winbar false :statusline false} - :enable_git_status false - :enable_diagnostics false - :open_files_do_not_replace_types [:terminal :Trouble :qf :Outline] - :filesystem {:bind_to_cwd false - :follow_current_file true - :use_libuv_file_watcher true} - :window {:position :float - :mappings {:<space> :none - :l :open - :h :close_node - :. :toggle_hidden - :e :focus_preview}} - :default_component_configs {:indent {:with_expanders true - :expander_collapsed "" - :expander_expanded "" - :expander_highlight :NeoTreeExpander}}}) +(local opts {:sources [:filesystem :buffers :git_status :document_symbols] + :source_selector {:winbar false :statusline false} + :use_popups_for_input false + :enable_git_status false + :enable_diagnostics false + :open_files_do_not_replace_types [:terminal :Trouble :qf :Outline] + :filesystem {:bind_to_cwd false + :follow_current_file true + :hijack_netrw_behavior :open_default + :use_libuv_file_watcher true} + :window {:position :float + :popup {:position {:col "50%" :row :10}} + :mappings {:<space> :none + :P {1 :toggle_preview + :config {:use_float true}} + :l :open + :h :close_node + :. :toggle_hidden + :e :focus_preview}} + :default_component_configs {:indent {:with_expanders true + :expander_collapsed "" + :expander_expanded "" + :expander_highlight :NeoTreeExpander}} + :event_handlers [{:event :neo_tree_buffer_enter + :handler cursorline.show} + {:event :neo_tree_buffer_leave + :handler cursorline.show}]}) {1 :nvim-neo-tree/neo-tree.nvim :keys [{1 "-" 2 :<cmd>Neotree<cr> :desc "Open Neotree"}] + :event :VeryLazy :cmd :Neotree : init : deactivate diff --git a/fnl/settings/autocmds.fnl b/fnl/settings/autocmds.fnl index d32f814..a646130 100644 --- a/fnl/settings/autocmds.fnl +++ b/fnl/settings/autocmds.fnl @@ -1,4 +1,7 @@ ;; Autocommands for nvim. + +(local cursorline (require :util.cursorline)) + (local autocmds [[:FileType {:pattern [:qf :help :man :lspinfo :spectre_panel] @@ -38,21 +41,8 @@ (vim.keymap.set :t :<C-j> "<Cmd>wincmd j<CR>" {}) (vim.keymap.set :t :<C-k> "<Cmd>wincmd k<CR>" {}) (vim.keymap.set :t :<C-l> "<Cmd>wincmd l<CR>" {}))}] - [[:InsertLeave :WinEnter] - {:callback (fn [] - (let [(ok cl) (pcall vim.api.nvim_win_get_var 0 - :auto-cursorline)] - (if (and ok cl) - (do - (set vim.wo.cursorline true) - (vim.api.nvim_win_del_var 0 :auto-cursorline)))))}] - [[:InsertEnter :WinLeave] - {:callback (fn [] - (let [cl vim.wo.cursorline] - (if cl - (do - (vim.api.nvim_win_set_var 0 :auto-cursorline cl) - (set vim.wo.cursorline false)))))}]]) + [[:InsertLeave :WinEnter] {:callback cursorline.show}] + [[:InsertEnter :WinLeave] {:callback cursorline.hide}]]) (each [_ autocmd (ipairs autocmds)] (match autocmd diff --git a/fnl/util/cursorline.fnl b/fnl/util/cursorline.fnl new file mode 100644 index 0000000..e094a4a --- /dev/null +++ b/fnl/util/cursorline.fnl @@ -0,0 +1,27 @@ +;; Functions for showing and hiding the cursorline. + +(local ignore-filetypes [:neo-tree]) + +(fn filetype [] + vim.bo.filetype) + +(fn ignore [] + (vim.tbl_contains ignore-filetypes (filetype))) + +(fn show [] + (let [(ok cl) (pcall vim.api.nvim_win_get_var 0 :auto-cursorline)] + (if (and ok cl) + (do + (set vim.wo.cursorline true) + (vim.api.nvim_win_del_var 0 :auto-cursorline))))) + +(fn hide [] + (if (not= (ignore) true) + (do + (let [cl vim.wo.cursorline] + (if cl + (do + (vim.api.nvim_win_set_var 0 :auto-cursorline cl) + (set vim.wo.cursorline false))))))) + +{: show : hide} |