-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add ex/citar-search-pdf-contents to wiki #477
Comments
If I understand correctly, the key step is to get a dired buffer showing all the files for selected entries? Another way to accomplish this is to run At that point you have to mark all the PDFs and you can run |
That's right. So you don't know a way to do this? |
The procedure I gave does this, using The code to look at is in The advantage of doing it this way is that it includes files given in the "file" field, rather than just files in a particular directory. |
I mean using dired directly. I'm not sure that's the best approach, but I wanted to experiment with it. So, for example:
Yeah, I want to avoid that, given we know upfront which files they are. This seems related to previous discussions with @oantolin about "mark-all"-like behavior for running actions.
That's true. But I don't like the idea of requiring people to mark the files for this case, since the idea is we want to search the pdf contents for all of them. Any ideas for solving that? |
Hmm ... I'll experiment more, but the exported buffer doesn't include all the files; it includes the candidates against which one can run the |
OK, I see what you're saying. But it's definitely not elegant, with the bigger problem being the fact that on my vertico setup (Doom), once I select one candidate, the prompt is erased, and I have to duplicate the search again. That's not practical if I want files related to, say, 20 candidates. But I agree the embark-export approach is in theory a good approach. Do you happen to know how to get vertico to retain the search string? |
Does this do what you're looking for? (defun ex/citar-search-pdf-contents ()
"Search pdfs."
(interactive)
(let* ((refs (citar-select-refs))
(dir
(if (equal (length citar-library-paths) 1)
(car citar-library-paths)
(completing-read "Directory to search: " citar-library-paths)))
(files (citar-file--files-for-multiple-entries refs (list dir) '("pdf")))
(string (read-string "String: ")))
(pdf-occur-search files string t))) The function |
Yes, I believe it is! Here's the result, after entering the search string: Or at least, this is what I was aiming for. It does have the advantage that it includes the context for the search. Now that I think about it, it also still seems to have some of the limitations in terms of multiple-candidates that I note above with embark. We really need a way to run actions on "all" filtered candidates. But I don't believe that's currently possible. |
What's the problem with running this on all the directories listed in (defun ex/citar-search-pdf-contents ()
"Search pdfs."
(interactive)
(let* ((refs (citar-select-refs))
(files (citar-file--files-for-multiple-entries refs citar-library-paths '("pdf")))
(string (read-string "String: ")))
(pdf-occur-search files string t))) |
There's no problem; I just had missed I updated the main post with this example code. |
I've been holding out on using emacs for PDFs, but this function might be a tipping point. Great idea. |
I added this to the wiki for now. I'm thinking we can use this to develop ideas for new functions. https://github.com/bdarcus/citar/wiki/Example-functions#pdf-tools-integration |
I've also wanted to run actions on all filtered candidates, but I'm not sure where this functionality should be added. Perhaps |
I think @minad and @oantolin had concluded it probably belongs in embark for this reason. See: ... and in particular oantolin/embark#253 (comment). |
Yes, but it's not yet entirely clear how the exact solution for multi actions could look like. A rough plan:
Step 2 and 3 are optional, the only moderate addition needed to act on all candidates is |
True, but 1 might be a reasonable first step? At least for this use case (user wants to search the content of PDFs of associated with the selected candidates), it would be, since there's no harm in some non-relevant candidates. |
Sure, but it is up to @oantolin if he would accept such a PR. Adding such a command should be a small addition. Maybe a bit of refactoring of If I recall correctly we also discussed another possible solution for multiple candidates, where target finders are modified such that they don't return a single candidate but a list of multiple candidates. I am not sure if that would be better. It seems better to me to reuse the |
Reusing |
On this @roshanshariff ...
Am I right we should add something like this first function? (defun citar-file--files-from-field-multiple (keys-entries)
"Extract files from field for KEYS-ENTRIES."
(seq-map
(lambda (ke)
(citar-file--parse-file-field (cdr ke) citar-file-variable))
keys-entries))
(defun ex/citar-search-pdf-contents ()
"Search pdfs."
(interactive)
(let* ((refs (citar-select-refs))
(files
(citar-file--files-for-multiple-entries
refs citar-library-paths '("pdf")))
(parsed-files
(citar-file--files-from-field-multiple refs))
(string (read-string "Search string: ")))
(pdf-occur-search (concat files parsed-files) string t))) |
I wrote an |
EDIT: I forgot to update its documentation to say that's what it does. I'll open a small PR to fix that. |
@oantolin, do you think it makes sense to be able to mark a command to run once with all the candidates, rather than repeatedly for each candidate? That would be useful here, for running a search over the PDF files of all entries. Of course, Embark would need to know how to coalesce all the candidates into one minibuffer input, maybe assuming the command uses EDIT: This is discussed in oantolin/embark#166. |
@roshanshariff Yes, I believe this is something we also considered at some point in the old discussion. For crm commands For my taste the current |
This reminds me of another point - do we also need a CRM candidate collector which only collects the selected candidates instead of all candidates? At this point the design clashes a bit with a potential Maybe I should deprecate and remove |
@minad, I for one really like the idea of a vertico CRM implementation 👍 The |
@minad said:
None taken! It's messy for my taste too. In the case of @roshanshariff Yes, we should definitely think of adding a way to pass all targets at once to an action. One issue is that Also, I was thinking that maybe the |
@oantolin yes, this is the embark-select idea I had in mind and we discussed earlier. It does not sound that bad in the way you describe it 😄 I suspect that the UI would be slightly worse than a specifically tailored vertico UI. But with the big advantage of being completion UI independent. And the other big advantage that I don't have to change anything in vertico 😛 |
I think we should at least give the UI agnostic approach in embark a try as a prototype. If it turns out that it is not user friendly enough we can still opt for UI specific solutions. In the case of embark collect, the UI specific solution could rely on marking the candidates directly in the collect buffer. You've mentioned some addition to the tabulated list mode a while ago which allows marking. Maybe this already works in the candidate collector? Does it also work in grid mode? |
Thanks! I tested it a bit, and seems to work as expected.
This indeed was my wonder in terms of next steps. The obvious cases here where it's important to do this are:
How might such a mark UI work vis-a-vis standard selection? I wonder if, from a user POV, the only difference is with the latter the prompt is reset upon selection, while in the latter it would stick? We earlier discussed on the selectrum UI the idea to allow something like radian-software/selectrum#489 (comment) Does that have promise? |
For crm vertico-mark would be the same as standard selection. For normal cr commands vertico-mark would not be relevant for the return value but only for multi actions via embark-act-all. However I think we should first try to implement the embark-only solution since it will integrate automatically with all different frontends. Only if the result is not satisfactory we should consider UI-specific solutions. As you probably remember before I made consult-crm I had a vertico-crm prototype. But the prototype was insufficient and didn't work in all scenarios. Therefore I discarded that approach and went with consult-crm. It is a lot less obvious how the perfect vertico-crm UI looks like if you are really implementing it in Vertico. At this point you have a lot of flexibility but I also don't want to blow up the scope of Vertico infinitely. The consult-crm UI already goes a long way with limited means and the advantage that it can be used with different UIs.
A shift-TAB input preserving submit command can be easily implemented for consult-crm in the user config or like in doom. Similarly one could implement it as part of vertico-crm if such a thing materializes. |
Makes sense. And the idea here is one would mark in a collect buffer? So a workflow something like ...
...?
Can you please give me an example? |
I don't have an example at hand. But the |
WDYM by "next iteration"? |
consult-crm behaves like multiple calls to completing-read in a loop. After each selection a "new iteration" is started. However technically it works differently internally, so iteration is not really the right word. What I should say, after submitting the selection the original input string should be inserted again. |
I'm going to close this, since it's now on the wiki, and we've done what we can with it. But I think this is a really cool little command that demonstrates the value of the clean design of citar more generally. For both reasons, we may want to include it in citar proper at some point. Separately, I did suggest to iyefrat to include |
I don't think we necessarily want to add this to citar per se (it's another dependency, and specific to PDF), but this could be a good candidate for the wiki.
Adding this in case others are interested; an idea from a private email.
Is there some way to elegantly:
It seems to me a solution that hooks up citar and pdf-tools would be the way to go, and specifically to exploit pdf-occur.
It seems like
pdf-occur-dired-do-search
should be what we need. To use it, usedired
to mark the files you want to search, and then run that command.Just need to figure out which files to mark (using citar), and how much of this can be handled programmatically.
Originally posted by @bdarcus in #476
Turns out the solution is
pdf-occur-search
.The text was updated successfully, but these errors were encountered: