-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
org-ref cite links are not action in ROAM_KEY context #718
Comments
This seems like an org-mode limitation. I cannot exactly reproduce the problem, for me they are highlighted, but I get an error clicking on them. The problem is related to how they are fontified. I don't think org-ref can fix that. |
Thank you, I'll ask on the org mailing list. |
I have investigated further, and I think org does the right thing ( |
For information, this is the reported bug: doomemacs/doomemacs#2880 |
I am reopening this issue as I found further problems, and they seem to be with org-ref proper. When in a keyword context, org-ref cannot get the link using the usual way ( (keyword
(:key "FOO"
:value "http://alan.petitepomme.net/"
:begin 1
:end 38
:post-blank 1
:post-affiliated 1
:parent nil)) This won't change on the orgmode side of things. Nicolas Goaziou suggested on the mailing list to use |
It might be, but I won't have time to look into this for a while. If you want to try it and make a pull request, it might happen faster. I have generally tried not to fight orgmode like this too much like this though, as it makes it harder to debug in the future. |
@brabalan I made some minor changes to make (link-string
(progn (org-in-regexp org-link-any-re)
(cadr (split-string
(match-string-no-properties 0) ":")))) For more details: (defun +org-ref-get-bibtex-key-under-cursor ()
"Return key under the cursor in org-mode.
We search forward from point to get a comma, or the end of the link,
and then backwards to get a comma, or the beginning of the link. that
delimits the keyword we clicked on. We also strip the text
properties."
(let* ((object (org-element-context))
(link-string
(progn (org-in-regexp org-link-any-re)
(cadr (split-string
(match-string-no-properties 0) ":")))))
;; you may click on the part before the citations. here we make
;; sure to move to the beginning so you get the first citation.
(let ((cp (point)))
(goto-char (org-element-property :begin object))
(search-forward link-string (org-element-property :end object))
(goto-char (match-beginning 0))
;; check if we clicked before the path and move as needed.
(unless (< cp (point))
(goto-char cp)))
(if (not (org-element-property :contents-begin object))
;; this means no description in the link
(progn
;; we need the link path start and end
(let (link-string-beginning link-string-end)
(save-excursion
(goto-char (org-element-property :begin object))
(search-forward link-string nil nil 1)
(setq link-string-beginning (match-beginning 0))
(setq link-string-end (match-end 0)))
(let (key-beginning key-end)
;; The key is the text between commas, or the link boundaries
(save-excursion
(if (search-forward "," link-string-end t 1)
(setq key-end (- (match-end 0) 1)) ; we found a match
(setq key-end link-string-end))) ; no comma found so take the end
;; and backward to previous comma from point which defines the start character
(save-excursion
(if (search-backward "," link-string-beginning 1 1)
(setq key-beginning (+ (match-beginning 0) 1)) ; we found a match
(setq key-beginning link-string-beginning))) ; no match found
;; save the key we clicked on.
(let ((bibtex-key
(org-ref-strip-string
(buffer-substring key-beginning key-end))))
(set-text-properties 0 (length bibtex-key) nil bibtex-key)
bibtex-key))))
;; link with description and multiple keys
(if (and (org-element-property :contents-begin object)
(string-match "," link-string)
(equal (org-element-type object) 'link))
;; point is not on the link description
(if (not (>= (point) (org-element-property :contents-begin object)))
(let (link-string-beginning link-string-end)
(save-excursion
(goto-char (org-element-property :begin object))
(search-forward link-string nil t 1)
(setq link-string-beginning (match-beginning 0))
(setq link-string-end (match-end 0)))
(let (key-beginning key-end)
;; The key is the text between commas, or the link boundaries
(save-excursion
(if (search-forward "," link-string-end t 1)
(setq key-end (- (match-end 0) 1)) ; we found a match
(setq key-end link-string-end))) ; no comma found so take the end
;; and backward to previous comma from point which defines the start character
(save-excursion
(if (search-backward "," link-string-beginning 1 1)
(setq key-beginning (+ (match-beginning 0) 1)) ; we found a match
(setq key-beginning link-string-beginning))) ; no match found
;; save the key we clicked on.
(let ((bibtex-key
(org-ref-strip-string
(buffer-substring key-beginning key-end))))
(set-text-properties 0 (length bibtex-key) nil bibtex-key)
bibtex-key)))
;; point is on the link description, assume we want the
;; last key
(let ((last-key (replace-regexp-in-string "[a-zA-Z0-9_-]*," "" link-string)))
last-key))
;; link with description. assume only one key
link-string))))
(advice-add 'org-ref-get-bibtex-key-under-cursor :override '+org-ref-get-bibtex-key-under-cursor) |
This is great, thanks. @jkitchin any chance it could be included? |
@brabalan If this works on your side, I would try to make a pull request. |
I am testing this as a replacement now, if it works out for me, I will integrate the function above in this week. |
this enables cite links inside keywords. Before this did not work because I used org-parsing, which doesn't work on a keyword which parses as a keyword. This solution was proposed by @tshu-w. It works for getting the key under the cursor, and should work for this use. It doesn't work for me yet, but for independent reasons I think. I am unable to open a cite link from a string due to a fontification error. So far I have not been able to figure why, somewhere the cite link fontification goes past the end of the buffer.
I have pushed this as a replacement. Hoepfully it works for you. It fixes the issue of key under cursor in keywords I think. I still can't open the links though because of another fontification issue that I sort of believe is a bug in my emacs setup that is specific to cite links. |
@jkitchin maybe the following will be better since we don't need a regular search if the type of (link-string (if (eq (org-element-type object) 'link)
(org-element-property :path object)
(org-in-regexp org-link-any-re)
(cadr (split-string
(match-string-no-properties 0) ":")))) |
This is partially working for me: I can open the link (using the |
The minibar message is related to the same issue, Luckily for me, the tooltip from the mouse at least works. |
Mouse tooltip works for me too, so I think this is fine at the moment. Thanks! |
This combines a suggestion in issue #718 that is more reliable to get the link string when we are on an org-link, and some better logic to get the link string that works with keys containing colons.
- handle cases when the link is not `org-element`'s primary object see jkitchin#718
Org Roam has a nice feature where you can add a key at the beginning of your file, and citations to that key will be tracked (see https://org-roam.readthedocs.io/en/master/anatomy/#file-refs for a description).
Unfortunately, these links are not active: I cannot use them to access the org-ref menu (that lets me open the corresponding menu).
Here is what the beginning of my file looks like:
The org-ref link is not highlighted and I cannot act on it.
Is it possible to make a link in this setting active? (The link works fine in the text in the body of the file.)
The text was updated successfully, but these errors were encountered: