mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat)db: add customizability of extra element link parsing (#2042)
Adds two customizable variables: org-roam-db-extra-links-elements and org-roam-db-extra-links-exclude-keys, which govern which elements are to be considered for link parsing by Org-roam. Also added sane defaults to org-roam-db-extra-links-exclude-keys.
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
## TBD
|
## TBD
|
||||||
### Added
|
### Added
|
||||||
|
- [#2042](https://github.com/org-roam/org-roam/pull/2042) Add `org-roam-db-extra-links-elements` and `org-roam-db-extra-links-exclude-keys` for fine-grained control over additional link parsing.
|
||||||
### Removed
|
### Removed
|
||||||
### Fixed
|
### Fixed
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -490,6 +490,35 @@ all headlines with the ~ATTACH~ tag from the Org-roam database, one can set:
|
|||||||
(not (member "ATTACH" (org-get-tags)))))
|
(not (member "ATTACH" (org-get-tags)))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
Org-roam relied on the obtained Org AST for the buffer to parse links. However,
|
||||||
|
links appearing in some places (e.g. within property drawers) are not considered
|
||||||
|
by the Org AST to be links. Therefore, Org-roam takes special care of
|
||||||
|
additionally trying to process these links. Use
|
||||||
|
~org-roam-db-extra-links-elements~ to specify which additional Org AST element
|
||||||
|
types to consider.
|
||||||
|
|
||||||
|
- Variable: org-roam-db-extra-links-elements
|
||||||
|
|
||||||
|
The list of Org element types to include for parsing by Org-roam.
|
||||||
|
|
||||||
|
By default, when parsing Org's AST, links within keywords and
|
||||||
|
property drawers are not parsed as links. Sometimes however, it
|
||||||
|
is desirable to parse and cache these links (e.g. hiding links in
|
||||||
|
a property drawer).
|
||||||
|
|
||||||
|
Additionally, one may want to ignore certain keys from being excluded within
|
||||||
|
property drawers. For example, we would not want ~ROAM_REFS~ links to be
|
||||||
|
self-referential. Hence, to exclude specific keys, we use
|
||||||
|
~org-roam-db-extra-links-exclude-keys~.
|
||||||
|
|
||||||
|
- Variable: org-roam-db-extra-links-exclude-keys
|
||||||
|
|
||||||
|
Keys to ignore when mapping over links.
|
||||||
|
|
||||||
|
The car of the association list is the Org element type (e.g. keyword). The
|
||||||
|
cdr is a list of case-insensitive strings to exclude from being treated as
|
||||||
|
links.
|
||||||
|
|
||||||
** When to cache
|
** When to cache
|
||||||
|
|
||||||
By default, Org-roam is eager in caching: each time an Org-roam file is modified
|
By default, Org-roam is eager in caching: each time an Org-roam file is modified
|
||||||
|
@ -791,6 +791,37 @@ all headlines with the @code{ATTACH} tag from the Org-roam database, one can set
|
|||||||
(not (member "ATTACH" (org-get-tags)))))
|
(not (member "ATTACH" (org-get-tags)))))
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
Org-roam relied on the obtained Org AST for the buffer to parse links. However,
|
||||||
|
links appearing in some places (e.g. within property drawers) are not considered
|
||||||
|
by the Org AST to be links. Therefore, Org-roam takes special care of
|
||||||
|
additionally trying to process these links. Use
|
||||||
|
@code{org-roam-db-extra-links-elements} to specify which additional Org AST element
|
||||||
|
types to consider.
|
||||||
|
|
||||||
|
@defvar org-roam-db-extra-links-elements
|
||||||
|
|
||||||
|
The list of Org element types to include for parsing by Org-roam.
|
||||||
|
|
||||||
|
By default, when parsing Org's AST, links within keywords and
|
||||||
|
property drawers are not parsed as links. Sometimes however, it
|
||||||
|
is desirable to parse and cache these links (e.g. hiding links in
|
||||||
|
a property drawer).
|
||||||
|
@end defvar
|
||||||
|
|
||||||
|
Additionally, one may want to ignore certain keys from being excluded within
|
||||||
|
property drawers. For example, we would not want @code{ROAM_REFS} links to be
|
||||||
|
self-referential. Hence, to exclude specific keys, we use
|
||||||
|
@code{org-roam-db-extra-links-exclude-keys}.
|
||||||
|
|
||||||
|
@defvar org-roam-db-extra-links-exclude-keys
|
||||||
|
|
||||||
|
Keys to ignore when mapping over links.
|
||||||
|
|
||||||
|
The car of the association list is the Org element type (e.g. keyword). The
|
||||||
|
cdr is a list of case-insensitive strings to exclude from being treated as
|
||||||
|
links.
|
||||||
|
@end defvar
|
||||||
|
|
||||||
@node When to cache
|
@node When to cache
|
||||||
@section When to cache
|
@section When to cache
|
||||||
|
|
||||||
|
@ -98,6 +98,32 @@ slow."
|
|||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
|
(defcustom org-roam-db-extra-links-elements '(node-property keyword)
|
||||||
|
"The list of Org element types to include for parsing by Org-roam.
|
||||||
|
|
||||||
|
By default, when parsing Org's AST, links within keywords and
|
||||||
|
property drawers are not parsed as links. Sometimes however, it
|
||||||
|
is desirable to parse and cache these links (e.g. hiding links in
|
||||||
|
a property drawer)."
|
||||||
|
:package-version '(org-roam . "2.2.0")
|
||||||
|
:group 'org-roam
|
||||||
|
:type '(set (const :tag "keywords" keyword)
|
||||||
|
(const :tag "property drawers" node-property)))
|
||||||
|
|
||||||
|
(defcustom org-roam-db-extra-links-exclude-keys '((node-property . ("ROAM_REFS"))
|
||||||
|
(keyword . ("transclude")))
|
||||||
|
"Keys to ignore when mapping over links.
|
||||||
|
|
||||||
|
The car of the association list is the Org element type (e.g.
|
||||||
|
keyword). The cdr is a list of case-insensitive strings to
|
||||||
|
exclude from being treated as links.
|
||||||
|
|
||||||
|
For example, we use this to prevent self-referential links in
|
||||||
|
ROAM_REFS."
|
||||||
|
:package-version '(org-roam . "2.2.0")
|
||||||
|
:group 'org-roam
|
||||||
|
:type '(alist))
|
||||||
|
|
||||||
;;; Variables
|
;;; Variables
|
||||||
(defconst org-roam-db-version 18)
|
(defconst org-roam-db-version 18)
|
||||||
|
|
||||||
@ -353,15 +379,12 @@ If UPDATE-P is non-nil, first remove the file in the database."
|
|||||||
;; Links correctly recognized by Org Mode
|
;; Links correctly recognized by Org Mode
|
||||||
((eq type 'link)
|
((eq type 'link)
|
||||||
(setq link element))
|
(setq link element))
|
||||||
;; Prevent self-referencing links in ROAM_REFS
|
|
||||||
((and (eq type 'node-property)
|
|
||||||
(org-roam-string-equal (org-element-property :key element) "ROAM_REFS"))
|
|
||||||
nil)
|
|
||||||
;; Links in property drawers and lines starting with #+. Recall that, as for Org Mode v9.4.4, the
|
;; Links in property drawers and lines starting with #+. Recall that, as for Org Mode v9.4.4, the
|
||||||
;; org-element-type of links within properties drawers is "node-property" and for lines starting with
|
;; org-element-type of links within properties drawers is "node-property" and for lines starting with
|
||||||
;; #+ is "keyword".
|
;; #+ is "keyword".
|
||||||
((and (or (eq type 'node-property)
|
((and (member type org-roam-db-extra-links-elements)
|
||||||
(eq type 'keyword))
|
(not (member-ignore-case (org-element-property :key element)
|
||||||
|
(cdr (assoc type org-roam-db-extra-links-exclude-keys))))
|
||||||
(setq bounds (org-in-regexp org-link-any-re))
|
(setq bounds (org-in-regexp org-link-any-re))
|
||||||
(setq link (buffer-substring-no-properties
|
(setq link (buffer-substring-no-properties
|
||||||
(car bounds)
|
(car bounds)
|
||||||
|
Reference in New Issue
Block a user