telescope-pickers.lua (1007B) - raw


      1 local status_ok, pickers = pcall(require, "telescope.pickers")
      2 if not status_ok then return end    -- if telescope not installed, return
      3 
      4 local finders = require("telescope.finders")
      5 local conf = require("telescope.config").values
      6 local actions = require("telescope.actions")
      7 local action_state = require("telescope.actions.state")
      8 
      9 
     10 telescope_vimwiki_categories_picker = function(opts)
     11     opts = opts or {}
     12     pickers.new(opts, {
     13         prompt_title = "VimWiki Categories",
     14         finder = finders.new_table {
     15             results = vim.g.vw_categories
     16         },
     17         sorter = conf.generic_sorter(opts),
     18         attach_mappings = function(prompt_bufnr, map)
     19             actions.select_default:replace(function()
     20                 actions.close(prompt_bufnr)
     21                 local selection = action_state.get_selected_entry()
     22                 vim.api.nvim_put({ "<!-- category: " .. selection[1] .. " -->", "" }, "", false, true)
     23             end)
     24             return true
     25         end,
     26     }):find()
     27 end