fix olp-related functionality

This commit is contained in:
Jethro Kuan
2021-04-13 23:55:37 +08:00
parent 121d08562d
commit 4cddc21c02

View File

@@ -179,6 +179,7 @@ run Org-capture's template expansion."
(defun org-roam-capture--goto-location () (defun org-roam-capture--goto-location ()
"Initialize the buffer, and goto the location of the new capture. "Initialize the buffer, and goto the location of the new capture.
Return the ID of the location." Return the ID of the location."
(let (id)
(pcase (or (org-roam-capture--get :if-new) (pcase (or (org-roam-capture--get :if-new)
(user-error "Template needs to specify `:if-new'")) (user-error "Template needs to specify `:if-new'"))
(`(file ,path) (`(file ,path)
@@ -188,18 +189,18 @@ Return the ID of the location."
(set-buffer (org-capture-target-buffer path)) (set-buffer (org-capture-target-buffer path))
(widen) (widen)
(org-roam-capture--add-ref) (org-roam-capture--add-ref)
(org-id-get-create)) (setq id (org-id-get-create)))
(`(file+olp ,path ,olp) (`(file+olp ,path ,olp)
(setq path (expand-file-name (setq path (expand-file-name
(s-trim (org-roam-capture--fill-template path t)) (s-trim (org-roam-capture--fill-template path t))
org-roam-directory)) org-roam-directory))
(set-buffer (org-capture-target-buffer path)) (set-buffer (org-capture-target-buffer path))
(let ((m (org-roam-capture-find-or-create-olp olp)))
(goto-char m))
(widen)
(org-with-point-at 1 (org-with-point-at 1
(org-roam-capture--add-ref) (org-roam-capture--add-ref)
(org-id-get-create))) (setq id (org-id-get-create)))
(let ((m (org-roam-capture-find-or-create-olp olp)))
(goto-char m))
(widen))
(`(file+head ,path ,head) (`(file+head ,path ,head)
(setq path (expand-file-name (setq path (expand-file-name
(s-trim (org-roam-capture--fill-template path t)) (s-trim (org-roam-capture--fill-template path t))
@@ -211,9 +212,24 @@ Return the ID of the location."
(widen) (widen)
(org-with-point-at 1 (org-with-point-at 1
(org-roam-capture--add-ref) (org-roam-capture--add-ref)
(org-id-get-create))) (setq id (org-id-get-create))))
(`(file+head+olp ,path ,head ,olp)
(setq path (expand-file-name
(s-trim (org-roam-capture--fill-template path t))
org-roam-directory))
(widen)
(let ((exists-p (file-exists-p path)))
(set-buffer (org-capture-target-buffer path))
(unless exists-p
(insert (org-roam-capture--fill-template head t))))
(org-with-point-at 1
(org-roam-capture--add-ref)
(setq id (org-id-get-create)))
(let ((m (org-roam-capture-find-or-create-olp olp)))
(goto-char m)))
;; TODO: support node ;; TODO: support node
)) )
id))
(defun org-roam-capture-find-or-create-olp (olp) (defun org-roam-capture-find-or-create-olp (olp)
"Return a marker pointing to the entry at OLP in the current buffer. "Return a marker pointing to the entry at OLP in the current buffer.
@@ -257,7 +273,7 @@ you can catch it with `condition-case'."
(setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0))) (setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0)))
(setq start found (setq start found
end (save-excursion (org-end-of-subtree t t)))) end (save-excursion (org-end-of-subtree t t))))
(point-marker)))) (copy-marker end))))
(defun org-roam-capture--get-ref-path (ref) (defun org-roam-capture--get-ref-path (ref)
"Return the file and point of reference REF." "Return the file and point of reference REF."