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

Combine link-hint-open-link and org-ref-jump-to-visible-key #1053

Open
randomwangran opened this issue Jan 1, 2023 · 3 comments
Open

Combine link-hint-open-link and org-ref-jump-to-visible-key #1053

randomwangran opened this issue Jan 1, 2023 · 3 comments

Comments

@randomwangran
Copy link

org-ref-jump-to-visible-key can identify multiple candidates, but it
does not contain a regular link in Org-mode. link-hint-open-link on the
other hand, can identify a normal link but is not very good at finding
multiple citation keys. We need a strong merge.

Following code snippet can merge two types of link, but I don't feel
this is the best way to achieve this.

(defun wr/pos-getter (arg)
  (plist-get arg :pos))

(defun wr/org-ref-jump-to-visible-key ()
  "Jump to a visible key with avy."
  (interactive)
  (avy-with avy-goto-key
    (avy-process
     (apply #'append
            (list
             (append (mapcar #'wr/pos-getter (link-hint--get-links))
                     (car (save-excursion
                            (org-element-map (org-element-parse-buffer) 'link
                              (lambda (c)
                                (when (assoc (org-element-property :type c) org-ref-cite-types)
                                  (goto-char (org-element-property :begin c))
                                  (let* ((path (org-element-property :path c))
                                         (data (org-ref-parse-cite-path path))
                                         (references (plist-get data :references)))
                                    (append (list (org-element-property :begin c))
                                            (cl-loop for ref in references collect
                                                     (progn
                                                       (search-forward (plist-get ref :key))
                                                       (match-beginning 0))))))))))))))
    (avy--style-fn avy-style))
  (org-open-at-point))

Also please see: noctuid/link-hint.el#209

@jkitchin
Copy link
Owner

jkitchin commented Jan 2, 2023

I am not sure what you are trying to accomplish here. Is it one function that jumps to links or cite keys?

if it is, and your function works, what is the issue?

@randomwangran
Copy link
Author

Is it one function that jumps to links or cite keys?

Yes, it is. The original function only works for citation links. This is what it is supposed to be. There is no issue with this function.

(defun org-ref-jump-to-visible-key ()
"Jump to a visible key with avy."
(interactive)
(avy-with avy-goto-key
(avy-process
(apply #'append
(save-excursion
(org-element-map (org-element-parse-buffer) 'link
(lambda (c)
(when (assoc (org-element-property :type c) org-ref-cite-types)
(goto-char (org-element-property :begin c))
(let* ((path (org-element-property :path c))
(data (org-ref-parse-cite-path path))
(references (plist-get data :references)))
(append (list (org-element-property :begin c))
(cl-loop for ref in references collect
(progn
(search-forward (plist-get ref :key))
(match-beginning 0)))))))))))
(avy--style-fn avy-style)))

However, at the user's level, this is not an optimal function. The primary part of the jumping function is to jump a proper point in a buffer regardless it is a citation link or a normal Org-mode link.

So, I merged them together. It works well so far, but I don't think the way I make it is a robust way. I am writing this issue for users who might have the same issue. I am also open to suggestions to make this snippet a better one.

@jkitchin jkitchin closed this as completed Jan 2, 2023
@jkitchin jkitchin reopened this Jan 2, 2023
@jkitchin
Copy link
Owner

jkitchin commented Jan 2, 2023

It seems fine to me, you just merge two lists of locations for avy.

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

No branches or pull requests

2 participants