mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat): Support file-property drawers (#1353)
* (feat): Support file-property drawers Add support for file-property drawers in property extraction. This means the following is now supported: :PROPERTIES: :ROAM_ALIAS: alias :ROAM_TAGS: tag1 tag2 :END:
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
### Added
|
||||
- [#1270](https://github.com/org-roam/org-roam/pull/1270) capture: create OLP if it does not exist. Removes need for OLP setup in `:head`.
|
||||
- [#1353](https://github.com/org-roam/org-roam/pull/1353) support file-level property drawers
|
||||
|
||||
### Changed
|
||||
- [#1352](https://github.com/org-roam/org-roam/pull/1352) prefer lower-case for roam_tag and roam_alias in interactive commands
|
||||
|
44
org-roam.el
44
org-roam.el
@ -504,31 +504,45 @@ Use external shell commands if defined in `org-roam-list-files-commands'."
|
||||
(org-roam--list-files (expand-file-name org-roam-directory)))
|
||||
|
||||
;;;; Org extraction functions
|
||||
(defun org-roam--extract-global-props (props)
|
||||
"Extract PROPS from the current org buffer."
|
||||
(let ((collected
|
||||
;; Collect the raw props first
|
||||
;; It'll be returned in the form of
|
||||
;; (("PROP" "value" ...) ("PROP2" "value" ...))
|
||||
(defun org-roam--extract-global-props-drawer (props)
|
||||
"Extract PROPS from the file-level property drawer in Org."
|
||||
(let (ret)
|
||||
(org-with-point-at 1
|
||||
(dolist (prop props ret)
|
||||
(when-let ((v (org-entry-get (point) prop)))
|
||||
(push (cons prop v) ret))))))
|
||||
|
||||
(defun org-roam--collect-keywords (keywords)
|
||||
"Collect all Org KEYWORDS in the current buffer."
|
||||
(if (functionp 'org-collect-keywords)
|
||||
(org-collect-keywords props)
|
||||
(org-collect-keywords keywords)
|
||||
(let ((buf (org-element-parse-buffer))
|
||||
res)
|
||||
(dolist (prop props)
|
||||
(dolist (k keywords)
|
||||
(let ((p (org-element-map buf 'keyword
|
||||
(lambda (kw)
|
||||
(when (string-equal (org-element-property :key kw) prop)
|
||||
(when (string-equal (org-element-property :key kw) k)
|
||||
(org-element-property :value kw)))
|
||||
:first-match nil)))
|
||||
(push (cons prop p) res)))
|
||||
res))))
|
||||
;; convert (("TITLE" "a" "b") ("Another" "c"))
|
||||
;; to (("TITLE" . "a") ("TITLE" . "b") ("Another" . "c"))
|
||||
(push (cons k p) res)))
|
||||
res)))
|
||||
|
||||
(defun org-roam--extract-global-props-keyword (keywords)
|
||||
"Extract KEYWORDS from the current Org buffer."
|
||||
(let (ret)
|
||||
(pcase-dolist (`(,key . ,values) collected)
|
||||
(pcase-dolist (`(,key . ,values) (org-roam--collect-keywords keywords))
|
||||
(dolist (value values)
|
||||
(push (cons key value) ret)))
|
||||
ret)))
|
||||
ret))
|
||||
|
||||
(defun org-roam--extract-global-props (props)
|
||||
"Extract PROPS from the current Org buffer.
|
||||
Props are extracted from both the file-level property drawer (if
|
||||
any), and Org keywords. Org keywords take precedence."
|
||||
(append
|
||||
(org-roam--extract-global-props-keyword props)
|
||||
(org-roam--extract-global-props-drawer props)))
|
||||
|
||||
|
||||
(defun org-roam--get-outline-path ()
|
||||
"Return the outline path to the current entry.
|
||||
|
Reference in New Issue
Block a user