telescope.fnl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. (import-macros {: bind! : setup! : module-call!} :macros)
  2. { :setup (fn []
  3. (bind! :n :<leader>fq "<cmd>Telescope quickfix<cr>")
  4. (bind! :n :<leader>fr "<cmd>Telescope registers<cr>")
  5. (bind! :n :<leader>fj "<cmd>Telescope jumplist<cr>")
  6. (bind! :n :<leader>fa "<cmd>Telescope marks<cr>")
  7. (bind! :n :<leader>fh "<cmd>Telescope help_tags<cr>")
  8. (bind! :n :<leader>g "<cmd>Telescope live_grep<cr>")
  9. (bind! :n :<leader>fg "<cmd>Telescope live_grep<cr>")
  10. (bind! :n :<leader>d "<cmd>Telescope treesitter<cr>")
  11. (bind! :n :<leader>b "<cmd>Telescope buffers<cr>")
  12. (bind! :n :<leader>fu "<cmd>Telescope git_status<cr>")
  13. (bind! :n :<leader>fm "<cmd>Telescope man_pages<cr>")
  14. (bind! :n :<leader>fe "<cmd>Telescope diagnostics<cr>")
  15. (bind! :n :<leader>fl "<cmd>Telescope loclist<cr>")
  16. (bind! :n :<leader>fp "<cmd>Telescope spell_suggest<cr>")
  17. (bind! :n :<leader>fo "<cmd>Telescope vim_options<cr>")
  18. (bind! :n :<leader>c "<cmd>Telescope command_history<cr>")
  19. (bind! :n :<leader>i "<cmd>Telescope find_files<cr>")
  20. (bind! :n :z= "<cmd>Telescope spell_suggest<cr>")
  21. (fn list-git-or-default []
  22. (let [code (os.execute "git rev-parse --is-inside-work-tree >/dev/null 2>&1")]
  23. (if (= code 0)
  24. (vim.cmd "Telescope git_files")
  25. (vim.cmd "Telescope find_files"))))
  26. (bind! :n :<leader>ff list-git-or-default)
  27. (bind! :n :<leader>u list-git-or-default)
  28. (fn jump-or-open-terminal []
  29. "If no terminal buffer exists, create one. Otherwise, open new one."
  30. (var term_count 0)
  31. (var last_id 0)
  32. (var terms [ ])
  33. (each [_ id (pairs (vim.api.nvim_list_bufs))]
  34. (when (and (vim.api.nvim_buf_is_loaded id)
  35. (vim.api.nvim_buf_get_option id :buflisted))
  36. (let [name (vim.api.nvim_buf_get_name id)]
  37. (when (vim.startswith name "term://")
  38. (table.insert terms name)
  39. (set term_count (+ term_count 1))
  40. (set last_id id)))))
  41. (if (= term_count 0)
  42. (vim.cmd.terminal)
  43. (= term_count 1)
  44. (vim.cmd.buffer last_id)
  45. (vim.cmd "Telescope buffers default_text=term://")))
  46. (bind! :n :<leader>t jump-or-open-terminal))
  47. :config (fn []
  48. (vim.cmd "PackerLoad plenary.nvim")
  49. (vim.cmd "PackerLoad telescope-ui-select.nvim")
  50. (vim.cmd "PackerLoad telescope-fzf-native.nvim")
  51. (let [actions (require :telescope.actions)]
  52. (setup! :telescope
  53. :defaults {
  54. :mappings {
  55. :i { :<esc> actions.close
  56. :<C-k> actions.move_selection_previous
  57. :<C-j> actions.move_selection_next }
  58. :n { :<C-k> actions.move_selection_previous
  59. :<C-j> actions.move_selection_next }}}
  60. :pickers {
  61. :buffers {
  62. ;;:ignore_current_buffer true
  63. :sort_lastused true }}
  64. :extensions {
  65. :ui-select [
  66. (module-call! :telescope.themes :get_dropdown)
  67. ]
  68. })
  69. (module-call! :telescope :load_extension :ui-select)
  70. (module-call! :telescope :load_extension :fzf))) }