mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat) implement after-find-file-hook for org-roam-capture (#482)
Allows user to run functions when an `org-roam-capture` is successful. This might come in handy for moving point after finding the new file, since right now, it is at `(point-min)`.
This commit is contained in:
@ -149,14 +149,6 @@ Next, it expands the remaining template string using
|
||||
(completing-read (format "%s: " key ) nil))) nil)
|
||||
(org-capture-fill-template)))
|
||||
|
||||
(defun org-roam-capture--find-file-h ()
|
||||
"Opens the newly created template file.
|
||||
This is added as a hook to `org-capture-after-finalize-hook'."
|
||||
(when-let ((file-path (org-roam-capture--get :file-path)))
|
||||
(unless org-note-abort
|
||||
(find-file file-path)))
|
||||
(remove-hook 'org-capture-after-finalize-hook #'org-roam-capture--find-file-h))
|
||||
|
||||
(defun org-roam-capture--insert-link-h ()
|
||||
"Insert the link into the original buffer, after the capture process is done.
|
||||
This is added as a hook to `org-capture-after-finalize-hook'."
|
||||
@ -303,6 +295,22 @@ This function is used solely in Org-roam's capture templates: see
|
||||
(push val converted)))
|
||||
(append (nreverse converted) `(:org-roam ,org-roam-plist))))
|
||||
|
||||
(defun org-roam-capture--find-file-h ()
|
||||
"Opens the newly created template file.
|
||||
This is added as a hook to `org-capture-after-finalize-hook'.
|
||||
Run the hooks defined in `org-roam-capture-after-find-file-hook'."
|
||||
(unless org-note-abort
|
||||
(when-let ((file-path (org-roam-capture--get :file-path)))
|
||||
(find-file file-path))
|
||||
(run-hooks 'org-roam-capture-after-find-file-hook))
|
||||
(remove-hook 'org-capture-after-finalize-hook #'org-roam-capture--find-file-h))
|
||||
|
||||
(defcustom org-roam-capture-after-find-file-hook nil
|
||||
"Hook that is run right after an Org-roam capture process is finalized.
|
||||
Suitable for moving point."
|
||||
:group 'org-roam
|
||||
:type 'hook)
|
||||
|
||||
(defun org-roam--capture (&optional goto keys)
|
||||
"Create a new file, and return the path to the edited file.
|
||||
The templates are defined at `org-roam-capture-templates'. The
|
||||
|
Reference in New Issue
Block a user