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,41 +179,57 @@ 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."
(pcase (or (org-roam-capture--get :if-new) (let (id)
(user-error "Template needs to specify `:if-new'")) (pcase (or (org-roam-capture--get :if-new)
(`(file ,path) (user-error "Template needs to specify `:if-new'"))
(setq path (expand-file-name (`(file ,path)
(s-trim (org-roam-capture--fill-template path t)) (setq path (expand-file-name
org-roam-directory)) (s-trim (org-roam-capture--fill-template path t))
(set-buffer (org-capture-target-buffer path)) org-roam-directory))
(widen)
(org-roam-capture--add-ref)
(org-id-get-create))
(`(file+olp ,path ,olp)
(setq path (expand-file-name
(s-trim (org-roam-capture--fill-template path t))
org-roam-directory))
(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-roam-capture--add-ref)
(org-id-get-create)))
(`(file+head ,path ,head)
(setq path (expand-file-name
(s-trim (org-roam-capture--fill-template path t))
org-roam-directory))
(let ((exists-p (file-exists-p path)))
(set-buffer (org-capture-target-buffer path)) (set-buffer (org-capture-target-buffer path))
(unless exists-p (widen)
(insert (org-roam-capture--fill-template head t))))
(widen)
(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)))
;; TODO: support node (`(file+olp ,path ,olp)
)) (setq path (expand-file-name
(s-trim (org-roam-capture--fill-template path t))
org-roam-directory))
(set-buffer (org-capture-target-buffer path))
(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))
(widen))
(`(file+head ,path ,head)
(setq path (expand-file-name
(s-trim (org-roam-capture--fill-template path t))
org-roam-directory))
(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))))
(widen)
(org-with-point-at 1
(org-roam-capture--add-ref)
(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
)
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."