fuxialexander / org-pdftools

A custom org link type for pdf-tools
GNU General Public License v3.0
335 stars 36 forks source link

show recentf, alongside new ones for pdf targets? #19

Closed mohkale closed 3 years ago

mohkale commented 4 years ago

Is there a recommended way of choosing PDFs, as it stands I've got PDFs put into sub-directories and am quite often only working with one PDF at a time. Whenever I decide to insert a link to that PDF, I have to navigate to the same file which is an error-prone and tasking process.

It'd be nice if, when I decide to insert a PDF link, org-pdftools offers to use my last PDF file or at least shows it as an option alongside the rest of the files in the current directory.

NOTE I'm not using emacs to view the PDFs (so I'm really only using this plugin to create links to PDF slides), so org-store-link isn't really a viable option.

fuxialexander commented 4 years ago

emmm why not use recentf/find-file directly if you're inserting the pdf link (path) manually?

mohkale commented 4 years ago

I'm not opening the PDFs with emacs (using zathura instead) so I'm not sure how that would work. Could you please elaborate?

fuxialexander commented 4 years ago

If you are not using emacs for PDF, how would emacs know which PDF have you opened? If you open PDF in zathura from emacs find-file, I think you can find it in recentf? If you are using Ivy, you can customize counsel-recentf to have an action to insert the selected path with 'pdftools:' prefix:

(defun counsel-recentf-insert-pdftools-link-action (x)
  (with-ivy-window
    (insert (concat "pdftools:" x))))

(ivy-set-actions
 'counsel-recentf
 '(("i" counsel-recentf-insert-pdftools-link-action "insert pdftools link")))
mohkale commented 4 years ago

If you are not using emacs for PDF, how would emacs know which PDF have you opened?

I'm not sure I'm being clear enough with what I'm trying to achieve here 😓. I've got PDFs in a sub directory, let's suppose their 6 directories down.

  1. I open org mode
  2. run org-insert-link
  3. select pdftools and then navigate down 6 whole directories to the PDF I want in the find-file dialog.
  4. hit return and then a link to it is inserted in the current org document at point.

Now I'd like to insert a link to the same document, perhaps with a different page. I'd like it to be as seamless as possible so the process I'd like would be:

  1. run org-insert-link
  2. select pdftools, have pdftools show me my last inserted pdf and just select it immeadiately.
  3. link is inserted.

I believe, seeing as org-pdftools knows which PDFs it's inserted in the past, you could introduce an intermediary variable to store the last inserted PDF or a history of them.

Then instead of using org-link-complete-file in org-pdftools-complete-link, you create your own file selection dialog, which also presents recently inserted PDFs to the user. I believe initial argument in read-file-name could achieve something like this, albeit it only supports a single file/candidate.

S.N.

As an alternative, I'd also be okay with an optional feature wherein once org-pdftools inserts a PDF link, it updates the value set by org-store-link. Such that the current value of org-store-link is equivalent to if I had opened the last inserted pdf at the desired page and then run M-x org-store-link manually. This option is probably easier to implement.

fuxialexander commented 4 years ago

read-file-name looks like an infinite rabbit hole so I'd rather not jump into it. Mess with org-store-link history will potentially pollute the history with a lot of repetitive entries. I prefer this to be implemented as an extra function:

(defun org-pdftools-get-previous-link ()
  (interactive)
  (completing-read "org-pdftools history: " org-link--insert-history nil nil "^pdftools:"))