Skip to content

Add an internal changelist #3476

Open
Open
@kimabrandt

Description

@kimabrandt

Can a changelist be added?

It's just a copy of the jumplist!?

diff --git i/lua/telescope/builtin/__internal.lua w/lua/telescope/builtin/__internal.lua
index 1687401..47086fe 100644
--- i/lua/telescope/builtin/__internal.lua
+++ w/lua/telescope/builtin/__internal.lua
@@ -1507,6 +1507,38 @@ internal.jumplist = function(opts)
     :find()
 end

+internal.changelist = function(opts)
+  opts = opts or {}
+
+  if opts.bufnr == nil then
+    opts.bufnr = vim.api.nvim_get_current_buf()
+  end
+
+  local changelist = vim.fn.getchangelist()[1]
+
+  -- reverse the list
+  local sorted_changelist = {}
+  for i = #changelist, 1, -1 do
+    if vim.api.nvim_buf_is_valid(opts.bufnr) then
+      changelist[i].text = vim.api.nvim_buf_get_lines(opts.bufnr, changelist[i].lnum - 1, changelist[i].lnum, false)[1]
+        or ""
+      table.insert(sorted_changelist, changelist[i])
+    end
+  end
+
+  pickers
+    .new(opts, {
+      prompt_title = "Changelist",
+      finder = finders.new_table {
+        results = sorted_changelist,
+        entry_maker = make_entry.gen_from_quickfix(opts),
+      },
+      previewer = conf.qflist_previewer(opts),
+      sorter = conf.generic_sorter(opts),
+    })
+    :find()
+end
+
 local function apply_checks(mod)
   for k, v in pairs(mod) do
     mod[k] = function(opts)
diff --git i/lua/telescope/builtin/init.lua w/lua/telescope/builtin/init.lua
index 6e27c27..a19e85f 100644
--- i/lua/telescope/builtin/init.lua
+++ w/lua/telescope/builtin/init.lua
@@ -413,6 +413,12 @@ builtin.tagstack = require_on_exported_call("telescope.builtin.__internal").tags
 ---@field trim_text boolean: trim results text (default: false)
 builtin.jumplist = require_on_exported_call("telescope.builtin.__internal").jumplist

+--- Lists items from Vim's changelist, jumps to location on `<cr>`
+---@param opts table: options to pass to the picker
+---@field show_line boolean: show results text (default: true)
+---@field trim_text boolean: trim results text (default: false)
+builtin.changelist = require_on_exported_call("telescope.builtin.__internal").changelist
+
 --
 --
 -- LSP-related Pickers

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhancement to performance, inner workings or existent features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions