(feat): Simplify org-roam-store-link (#994)

* (feat): Simplify org-roam-store-link

Drop the wrapper, and refactor as an org-store-link function.
This commit is contained in:
Leo Vivier 2020-08-01 08:02:57 +02:00 committed by GitHub
parent 8881c9732b
commit 76d2e3f6b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 32 deletions

View file

@ -6,7 +6,8 @@
### Features ### Features
-[#974](https://github.com/org-roam/org-roam/pull/974) Protect region targeted by `org-roam-insert` - [#974](https://github.com/org-roam/org-roam/pull/974) Protect region targeted by `org-roam-insert`
- [#994](https://github.com/org-roam/org-roam/pull/994) Simplify org-roam-store-link
### Bugfixes ### Bugfixes

View file

@ -1014,36 +1014,21 @@ for Org-ref cite links."
:order-by (asc from)] :order-by (asc from)]
target)) target))
(defun org-roam-store-link-file () (defun org-roam-store-link ()
"Store a link to an Org-roam file." "Store a link to an Org-roam file or heading."
(when (and (bound-and-true-p org-roam-mode) (when (and (bound-and-true-p org-roam-mode)
(org-roam--org-roam-file-p) (org-roam--org-roam-file-p))
(org-before-first-heading-p)) (if (org-before-first-heading-p)
(when-let ((titles (org-roam--extract-titles))) (when-let ((titles (org-roam--extract-titles)))
(org-link-store-props (org-link-store-props
:type "file" :type "file"
:link (format "file:%s" (abbreviate-file-name buffer-file-name)) :link (format "file:%s" (abbreviate-file-name buffer-file-name))
:description (car titles))))) :description (car titles)))
(let ((id (org-id-get)))
(defun org-roam--store-link (arg &optional interactive?) (org-id-store-link)
"Store a link to the current location within Org-roam. ;; If :ID: was created, update the cache
See `org-roam-store-link' for details on ARG and INTERACTIVE?." (unless id
(let ((org-id-link-to-org-use-id t) (org-roam-db--update-headlines))))))
(id (org-id-get)))
(org-store-link arg interactive?)
;; If :ID: was created, update the cache
(unless id
(org-roam-db--update-headlines))))
(defun org-roam-store-link (arg &optional interactive?)
"Store a link to the current location.
This commands is a wrapper for `org-store-link' which forces the
automatic creation of :ID: properties.
See `org-roam-store-link' for details on ARG and INTERACTIVE?."
(interactive "P\np")
(if (org-roam--org-roam-file-p)
(org-roam--store-link arg interactive?)
(org-store-link arg interactive?)))
(defun org-roam-id-find (id &optional markerp strict) (defun org-roam-id-find (id &optional markerp strict)
"Return the location of the entry with the id ID. "Return the location of the entry with the id ID.
@ -1275,7 +1260,6 @@ nil, or positive. If ARG is `toggle', toggle `org-roam-mode'.
Otherwise, behave as if called interactively." Otherwise, behave as if called interactively."
:lighter " Org-roam" :lighter " Org-roam"
:keymap (let ((map (make-sparse-keymap))) :keymap (let ((map (make-sparse-keymap)))
(define-key map [remap org-store-link] 'org-roam-store-link)
map) map)
:group 'org-roam :group 'org-roam
:require 'org-roam :require 'org-roam
@ -1295,7 +1279,7 @@ M-x info for more information at Org-roam > Installation > Post-Installation Tas
(advice-add 'rename-file :after #'org-roam--rename-file-advice) (advice-add 'rename-file :after #'org-roam--rename-file-advice)
(advice-add 'delete-file :before #'org-roam--delete-file-advice) (advice-add 'delete-file :before #'org-roam--delete-file-advice)
(when (fboundp 'org-link-set-parameters) (when (fboundp 'org-link-set-parameters)
(org-link-set-parameters "file" :face 'org-roam--file-link-face :store #'org-roam-store-link-file) (org-link-set-parameters "file" :face 'org-roam--file-link-face :store #'org-roam-store-link)
(org-link-set-parameters "id" :face 'org-roam---id-link-face)) (org-link-set-parameters "id" :face 'org-roam---id-link-face))
(org-roam-db-build-cache)) (org-roam-db-build-cache))
(t (t