jalvesaq / zotcite

Neovim plugin for integration with Zotero
GNU General Public License v3.0
159 stars 13 forks source link

integrate telescope into Zseek #87

Closed adam-coates closed 2 weeks ago

adam-coates commented 3 weeks ago

46 This might close this.

Idea is to be able to search for references using multiple keywords :Zseek <keyword1> <keyword2> etc

The telescope preview window shows the title and abstract, whereas the picker shows only the author and date (for now). Implementation can be changed and it might be more useful to display the full citation data (i.e. what is returned with <leader>za

This functionality can be added to, for instance to insert the citation key when pressing enter (this would be handy). I just haven't quite figured out the logic behind doing that yet, theoretically it would be just as easy to pass the output from the telescope picker as input to get.citation_key but I've tried a few things but not got very far with that yet.

I see this as a start though to integrate telescope into the plugin (this might be useful for the :Zselectannotations command for example.

jalvesaq commented 3 weeks ago

Thanks! That's a good idea! But it's not working on my side. :Zseek keyword opens Telescope with an empty list. :Zseek (with no keyword) does the same; nothing happens when I start typing.

Note: Your pull request has a spurious file: .DS_Store.

adam-coates commented 3 weeks ago

Okay I am wondering if this is a version issue because on my office windows PC all works okay.

Nvim version: 0.10.0 Telescope config:

return {
  "nvim-telescope/telescope.nvim",
  branch = "0.1.x",
  dependencies = {
    "nvim-lua/plenary.nvim",
    { "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
    "nvim-tree/nvim-web-devicons",
  },
  config = function()
    local telescope = require("telescope")
    local actions = require("telescope.actions")

    telescope.setup({
      defaults = {
        path_display = { "truncate " },
        mappings = {
          i = {
            ["<C-k>"] = actions.move_selection_previous, -- move to prev result
            ["<C-j>"] = actions.move_selection_next, -- move to next result
            ["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
          },
        },
      },
    })

    telescope.load_extension("fzf")

    -- set keymaps
    local keymap = vim.keymap 

    keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "Fuzzy find files in cwd" })
    keymap.set("n", "<leader>fr", "<cmd>Telescope oldfiles<cr>", { desc = "Fuzzy find recent files" })
    keymap.set("n", "<leader>fs", "<cmd>Telescope live_grep<cr>", { desc = "Find string in cwd" })
    keymap.set("n", "<leader>fc", "<cmd>Telescope grep_string<cr>", { desc = "Find string under cursor in cwd" })
  end,
}

You're right apologies, I made the changes on a mac. Will remove.

adam-coates commented 3 weeks ago

I have attached here a minimal config that works on my side. nvim.zip

jalvesaq commented 3 weeks ago

I will look at this later. Ideally, it should work without the need for special configuration, or the old behavior should remain an option. Also, since there are many variables used only by telescope, it could be better to put most of the code in a separate lua module, e.g.seek.lua.

adam-coates commented 3 weeks ago

Okay great, yeah you're right different module would make sense. If this only works with a certain version of nvim then I think implementing an if statement would suffice to ensure that a fallback would be the older more robust Zseek

Otherwise if this really is because of the special config of telescope I'd probably say to abandon this or go about it a different way.

jalvesaq commented 3 weeks ago

Same result with your minimal nvim directory: empty Telescope dialogue box.

adam-coates commented 3 weeks ago

That's strange. If the nvim versions are the same also, I'm not sure how to narrow this down without echoing out some of the variables and doing some debugging from my side.

Perhaps this could be left open for now, but if there's minimal progress then I'll close this.

adam-coates commented 3 weeks ago

Also I just want to double check that ~/.local/nvim and ~/.cache/nvim are clean before trying the minimal config? And if so then for sure its an issue with my code.

Edit: or I have just thought that the Zotero version might be playing a role here too.

jalvesaq commented 2 weeks ago

It works. But not with any keyword. I was testing with author names that are in Zotero's database, but zotcite is not finding them any more.

jalvesaq commented 2 weeks ago

I upgraded Zotero to version 7 and the result didn't change. Then, I noted that the problem was my fault: I had set the value of the YAML field "collections". I'm sorry for that. Everything is working.

Just one comment: "Zotero References" doesn't seem to be a good prompt title because we don't type the reference in the prompt; we type a pattern.

adam-coates commented 2 weeks ago

Great! I have tested this out with MacOS, Windows and Linux and not had any issues.

What was needed to get it to work from your side?

Glad to hear it works with Zotero 7, I have been using Zotero 6 also I've yet to upgrade.

For the prompt, perhaps "Zotero references search pattern". In this case being more descriptive might benefit.

jalvesaq commented 2 weeks ago

I think "Zotero references search pattern" is too long. Perhaps just "Search pattern", and in the results box, instead of "results", "References" or "Zotero references".

jalvesaq commented 2 weeks ago

I'm sorry, but I wasn't clear. I meant the title of the results window:

diff --git a/lua/zotcite/get.lua b/lua/zotcite/get.lua
index 8133f40..e4efa22 100644
--- a/lua/zotcite/get.lua
+++ b/lua/zotcite/get.lua
@@ -222,8 +222,9 @@ M.refs = function(key)
     pickers
         .new({}, {
             prompt_title = "Search pattern",
+            results_title = "Zotero references",
             finder = finders.new_table({
-                references = references,
+                results = references,
                 entry_maker = function(entry)
                     local displayer = entry_display.create({
                         separator = " ",
adam-coates commented 2 weeks ago

Apologies, my misunderstanding. I have changed it now. I was thinking to have this also as a separate lua module?

jalvesaq commented 2 weeks ago

Thank you! I'll merge it now.