Skip to content

Commit

Permalink
feat: Resurrect the org-ref code
Browse files Browse the repository at this point in the history
  • Loading branch information
meedstrom committed Sep 7, 2024
1 parent a836f81 commit 90b0e50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
52 changes: 25 additions & 27 deletions org-node-parser.el
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ What this means? See test/org-node-test.el."
;; .. but the actual ref is just the //path
path))))))

;; (defconst org-node-parser--org-ref-type-re
;; (regexp-opt
;; ;; Default keys of `org-ref-cite-types' 2024-07-25
;; '("cite" "nocite" "citet" "citet*" "citep" "citep*" "citealt" "citealt*" "citealp" "citealp*" "citenum" "citetext" "citeauthor" "citeauthor*" "citeyear" "citeyearpar" "Citet" "Citep" "Citealt" "Citealp" "Citeauthor" "Citet*" "Citep*" "Citealt*" "Citealp*" "Citeauthor*" "Cite" "parencite" "Parencite" "footcite" "footcitetext" "textcite" "Textcite" "smartcite" "Smartcite" "cite*" "parencite*" "supercite" "autocite" "Autocite" "autocite*" "Autocite*" "citetitle" "citetitle*" "citeyear" "citeyear*" "citedate" "citedate*" "citeurl" "fullcite" "footfullcite" "notecite" "Notecite" "pnotecite" "Pnotecite" "fnotecite" "cites" "Cites" "parencites" "Parencites" "footcites" "footcitetexts" "smartcites" "Smartcites" "textcites" "Textcites" "supercites" "autocites" "Autocites" "bibentry")))
;; Default keys of `org-ref-cite-types' 2024-07-25
(defconst org-node-parser--org-ref-types
'("cite" "nocite" "citet" "citet*" "citep" "citep*" "citealt" "citealt*" "citealp" "citealp*" "citenum" "citetext" "citeauthor" "citeauthor*" "citeyear" "citeyearpar" "Citet" "Citep" "Citealt" "Citealp" "Citeauthor" "Citet*" "Citep*" "Citealt*" "Citealp*" "Citeauthor*" "Cite" "parencite" "Parencite" "footcite" "footcitetext" "textcite" "Textcite" "smartcite" "Smartcite" "cite*" "parencite*" "supercite" "autocite" "Autocite" "autocite*" "Autocite*" "citetitle" "citetitle*" "citeyear" "citeyear*" "citedate" "citedate*" "citeurl" "fullcite" "footfullcite" "notecite" "Notecite" "pnotecite" "Pnotecite" "fnotecite" "cites" "Cites" "parencites" "Parencites" "footcites" "footcitetexts" "smartcites" "Smartcites" "textcites" "Textcites" "supercites" "autocites" "Autocites" "bibentry"))
(defconst org-node-parser--org-ref-type-re
(regexp-opt org-node-parser--org-ref-types))

(defun org-node-parser--collect-links-until (end id-here)
"From here to buffer position END, look for forward-links.
Expand Down Expand Up @@ -161,36 +162,33 @@ Argument PLAIN-RE is expected to be the value of
;; If point is on a # comment line, skip line
(goto-char (pos-bol))
(looking-at-p "[[:space:]]*# "))
;; The org-ref code is here. Problem is we have to patch $merged-re
;; and $plain-re to match the hundred org-ref types, and that slows
;; things down.
;; (if (and (string-search "&" path)
;; (string-match-p org-node-parser--org-ref-type-re link-type))
;; ;; A citep:, citealt: or some such. Specifically org-ref v3
;; ;; because PATH contains at least one ampersand.
;; (while (string-match "&.+\\b" path)
;; (let ((citekey (match-string 0 path)))
;; (setq path (substring path (match-end 0)))
;; (push (record 'org-node-link
;; id-here
;; (point)
;; link-type
;; (substring citekey 1)) ;; Drop &
;; org-node-parser--result-found-links)))
(push (record 'org-node-link
id-here
(point)
link-type
(string-replace "%20" " " path))
org-node-parser--result-found-links))))
(if (and (string-search "&" path)
(string-match-p org-node-parser--org-ref-type-re link-type))
;; A citep:, citealt: or some such. Specifically org-ref v3
;; because PATH contains at least one ampersand.
(while (string-match "&.+?\\b" path)
(let ((citekey (match-string 0 path)))
(setq path (substring path (match-end 0)))
(push (record 'org-node-link
id-here
(point)
link-type
(substring citekey 1)) ;; Drop &
org-node-parser--result-found-links)))
(push (record 'org-node-link
id-here
(point)
link-type
(string-replace "%20" " " path))
org-node-parser--result-found-links)))))

;; Start over and look for @citekeys
(goto-char beg)
(while (search-forward "[cite" end t)
(let ((closing-bracket (save-excursion (search-forward "]" end t))))
(if closing-bracket
;; The regexp is a modified `org-element-citation-key-re'
(while (re-search-forward "[&@][!#-+./:<>-@^-`{-~[:word:]-]+"
(while (re-search-forward "@[!#-+./:<>-@^-`{-~[:word:]-]+"
closing-bracket t)
(if (save-excursion
(goto-char (pos-bol))
Expand Down
5 changes: 4 additions & 1 deletion org-node.el
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,10 @@ function to update current tables."
(any "])>"))))
(rx-to-string
`(seq word-start
(regexp ,(regexp-opt org-node-link-types t))
(regexp ,(regexp-opt
(append org-node-link-types
org-node-parser--org-ref-types)
t))
":"
(group
(1+ (or (regex ,non-space-bracket)
Expand Down

0 comments on commit 90b0e50

Please sign in to comment.