pkg update and first config fix
org-brain not working, add org-roam
This commit is contained in:
@@ -31,6 +31,14 @@
|
||||
:group 'org-ref)
|
||||
|
||||
|
||||
(defcustom org-ref-activate-ref-links t
|
||||
"If non-nil use font lock to activate ref links.
|
||||
Activation can be slow in large documents with a lot of ref
|
||||
links. Set this to nil to turn off activation."
|
||||
:type 'boolean
|
||||
:group 'org-ref)
|
||||
|
||||
|
||||
(defface org-ref-ref-face
|
||||
`((t (:inherit org-link :foreground "dark red")))
|
||||
"Face for ref links in org-ref."
|
||||
@@ -38,12 +46,14 @@
|
||||
|
||||
|
||||
(defvar org-ref-label-re
|
||||
(rx (group-n 1 (one-or-more (any word "-.:?!`'/*@+|(){}<>&_^$#%~"))))
|
||||
(rx-to-string
|
||||
'(group-n 1 (one-or-more (any word "-.:?!`'/*@+|(){}<>&_^$#%~"))))
|
||||
"Regexp for labels.")
|
||||
|
||||
|
||||
(defvar org-ref-label-link-re
|
||||
(rx "label:" (group-n 1 (one-or-more (any word "-.:?!`'/*@+|(){}<>&_^$#%~"))))
|
||||
(rx-to-string
|
||||
`(seq "label:" (group-n 1 (one-or-more (any word "-.:?!`'/*@+|(){}<>&_^$#%~")))))
|
||||
"Regexp for label links.")
|
||||
|
||||
|
||||
@@ -112,6 +122,14 @@ The label should always be in group 1.")
|
||||
(goto-char (+ begin deltap (- (length new-type) (length old-type))))))
|
||||
|
||||
|
||||
(defvar-local org-ref-label-cache nil
|
||||
"Buffer-local cache variable for labels.")
|
||||
|
||||
|
||||
(defvar-local org-ref-buffer-chars-modified-tick nil
|
||||
"Buffer-local variable to hold `buffer-chars-modified-tick'.")
|
||||
|
||||
|
||||
(defun org-ref-get-labels ()
|
||||
"Return a list of referenceable labels in the document.
|
||||
You can reference:
|
||||
@@ -128,21 +146,55 @@ Returns a list of cons cells (label . context).
|
||||
|
||||
It is important for this function to be fast, since we use it in
|
||||
font-lock."
|
||||
(let ((case-fold-search t)
|
||||
(rx (string-join org-ref-ref-label-regexps "\\|"))
|
||||
(labels '())
|
||||
context)
|
||||
(save-excursion
|
||||
(org-with-wide-buffer
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward rx nil t)
|
||||
(setq context (buffer-substring
|
||||
(save-excursion (forward-line -1) (point))
|
||||
(save-excursion (forward-line +2) (point))))
|
||||
(cl-pushnew (cons (match-string-no-properties 1) context)
|
||||
labels))))
|
||||
;; reverse so they are in the order we find them.
|
||||
(delete-dups (reverse labels))))
|
||||
(if (or
|
||||
;; if we have not checked we have to check
|
||||
(null org-ref-buffer-chars-modified-tick)
|
||||
;; Now check if buffer has changed since last time we looked. We check
|
||||
;; this with the buffer-chars-modified-tick which keeps track of changes.
|
||||
;; If this hasn't changed, no chars have been modified.
|
||||
(not (= (buffer-chars-modified-tick)
|
||||
org-ref-buffer-chars-modified-tick)))
|
||||
;; We need to search for all the labels either because we don't have them,
|
||||
;; or the buffer has changed since we looked last time.
|
||||
(let ((case-fold-search t)
|
||||
(rx (string-join org-ref-ref-label-regexps "\\|"))
|
||||
(labels '())
|
||||
oe ;; org-element
|
||||
context
|
||||
data)
|
||||
(save-excursion
|
||||
(org-with-wide-buffer
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward rx nil t)
|
||||
(save-match-data
|
||||
;; Here we try to get some relevant context for different things you
|
||||
;; might reference.
|
||||
(setq oe (org-element-context)
|
||||
context (string-trim
|
||||
(pcase (car oe)
|
||||
('latex-environment (buffer-substring
|
||||
(org-element-property :begin oe)
|
||||
(org-element-property :end oe)))
|
||||
;; figure
|
||||
('paragraph (buffer-substring
|
||||
(org-element-property :begin oe)
|
||||
(org-element-property :end oe)))
|
||||
('table (buffer-substring
|
||||
(org-element-property :begin oe)
|
||||
(org-element-property :end oe)))
|
||||
;; Headings fall here.
|
||||
(_ (buffer-substring (line-beginning-position)
|
||||
(line-end-position)))))))
|
||||
(cl-pushnew (cons (match-string-no-properties 1) context)
|
||||
labels))))
|
||||
|
||||
;; reverse so they are in the order we find them.
|
||||
(setq
|
||||
org-ref-buffer-chars-modified-tick (buffer-chars-modified-tick)
|
||||
org-ref-label-cache (delete-dups (reverse labels))))
|
||||
|
||||
;; retrieve the cached data
|
||||
org-ref-label-cache))
|
||||
|
||||
|
||||
(defun org-ref-ref-jump-to (&optional path)
|
||||
@@ -184,26 +236,27 @@ POSITION is the point under the mouse I think."
|
||||
The PATH should be a comma-separated list of labels.
|
||||
Argument START is the start of the link.
|
||||
Argument END is the end of the link."
|
||||
(let ((labels (mapcar 'car (org-ref-get-labels))))
|
||||
(goto-char start)
|
||||
(cl-loop for label in (split-string path ",") do
|
||||
(search-forward label)
|
||||
;; store property so we can follow it later.
|
||||
(put-text-property (match-beginning 0)
|
||||
(match-end 0)
|
||||
'org-ref-ref-label
|
||||
label)
|
||||
(when org-ref-activate-ref-links
|
||||
(let ((labels (mapcar 'car (org-ref-get-labels))))
|
||||
(goto-char start)
|
||||
(cl-loop for label in (split-string path ",") do
|
||||
(search-forward label)
|
||||
;; store property so we can follow it later.
|
||||
(put-text-property (match-beginning 0)
|
||||
(match-end 0)
|
||||
'org-ref-ref-label
|
||||
label)
|
||||
|
||||
(unless (member label labels)
|
||||
|
||||
(put-text-property (match-beginning 0)
|
||||
(match-end 0)
|
||||
'face
|
||||
'font-lock-warning-face)
|
||||
(put-text-property (match-beginning 0)
|
||||
(match-end 0)
|
||||
'help-echo
|
||||
"Label not found")))))
|
||||
(unless (member label labels)
|
||||
|
||||
(put-text-property (match-beginning 0)
|
||||
(match-end 0)
|
||||
'face
|
||||
'font-lock-warning-face)
|
||||
(put-text-property (match-beginning 0)
|
||||
(match-end 0)
|
||||
'help-echo
|
||||
"Label not found"))))))
|
||||
|
||||
|
||||
(defun org-ref-ref-export (cmd keyword _desc backend)
|
||||
|
||||
Reference in New Issue
Block a user