Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable backlinks view - telescope picker and/or vsplit #374

Closed
sotte opened this issue Feb 5, 2024 · 7 comments · Fixed by #415
Closed

Configurable backlinks view - telescope picker and/or vsplit #374

sotte opened this issue Feb 5, 2024 · 7 comments · Fixed by #415
Labels

Comments

@sotte
Copy link
Contributor

sotte commented Feb 5, 2024

🚀 The feature, motivation and pitch

It would be great to have more configuration options for the backlink view. I often have many backlinks. The current implementation always opens the backlink view in a quickfix like view at the bottom and only the height is configurable.

It would be great,

a) if the view would be more configurable: use vsplit, tab, ...
b) or if the backlinks could be piped to telescope to that I can easily search and go to the notes with telescope.

(I guess a similar feature would be useful for tags as well: show all files with a given tag in telescope.)

Alternatives

No response

Additional context

No response

@sotte
Copy link
Contributor Author

sotte commented Feb 5, 2024

For a) one would have to make the botright and split from here configurable.

From the user's perspective it cold look something like this:

backlinks = {
  view_strategy = "vsplit",  -- vsplit|split|tabnew
  ...
}

@epwalsh
Copy link
Owner

epwalsh commented Feb 6, 2024

a) if the view would be more configurable: use vsplit, tab, ...

This is easy enough to support. I'd be happy to review a PR with your suggestion.

b) or if the backlinks could be piped to telescope to that I can easily search and go to the notes with telescope.

The Lua API for gathering backlinks is close to being stable. Once it's stable it would be easy enough for users to pipe that into telescope. And that would be a great example to add to the cookbook.

@epwalsh epwalsh added the contributions welcome Extra attention is needed label Feb 6, 2024
@sotte
Copy link
Contributor Author

sotte commented Feb 6, 2024

This is easy enough to support. I'd be happy to review a PR with your suggestion.

I'm not sure if I have the time right now to implement this. So, anybody, feel free grab this one 👍

I also might wait for the stable API and then use telescope directly.

@epwalsh
Copy link
Owner

epwalsh commented Feb 6, 2024

Sounds good... there's not too much left to do to stabilize the API, I just want to move the functionality into a Client method (it's currently in its own module).

If you don't hear back from me about this within a week or two feel free to ping me.

epwalsh added a commit that referenced this issue Feb 19, 2024
@epwalsh
Copy link
Owner

epwalsh commented Feb 19, 2024

Ok, it's now pretty straightforward to create your own command for this. Here's a snippet:

---@type obsidian.Client
local client = require("obsidian").get_client()

local note = assert(client:resolve_note "OLMo research hub") -- replace with name or ID of your note

client:find_backlinks_async(note, true, function(backlinks)
  local items = {}
  for _, matches in ipairs(backlinks) do
    local path = client:vault_relative_path(matches.path)
    for _, match in ipairs(matches.matches) do
      items[#items + 1] = {
        value = { path = path, line = match.line },
        display = string.format("%s:%s:%s", path, match.line, match.text),
        ordinal = match.text,
        filename = matches.path,
        lnum = match.line,
      }
    end
  end

  local picker = assert(client:picker())
  picker:pick(items, {
    prompt_title = "Backlinks",
    callback = function(value)
      vim.cmd(string.format("e %s", value.path))
      vim.api.nvim_win_set_cursor(0, { tonumber(value.line), 0 })
    end,
  })
end)

I like this a lot, actually, so eventually I'm going to build this in as a configurable "view" for backlinks.

image

@epwalsh
Copy link
Owner

epwalsh commented Feb 19, 2024

Wow, this is actually so much better that I think I just want to make this the default and get rid of the current "location list" view. Of course with telescope you can always open a location list with the search results anyway.

epwalsh added a commit that referenced this issue Feb 19, 2024
Instead of a "location list" buffer. Closes #374.
epwalsh added a commit that referenced this issue Feb 20, 2024
* Open picker for backlinks/tags location

Instead of a "location list" buffer. Closes #374.

* Improve filter field ("ordinal")

* Consolidate code to open a buffer

* improve the `open_buffer` command

* Standardize how we resolve paths

* Fix test

* Revert change to `:vault_relative_path()`

* choose picker on the fly

* fix typo

* Fix another bug with `Executor:map()`

* Add icons and highlights

* Make icons more robust
@sotte
Copy link
Contributor Author

sotte commented Feb 24, 2024

Thank so much @epwalsh. This is great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants