mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
@ -122,10 +122,7 @@ Template string :\n%v")
|
|||||||
;;;; Utilities
|
;;;; Utilities
|
||||||
(defun org-roam-dailies-directory--get-absolute-path ()
|
(defun org-roam-dailies-directory--get-absolute-path ()
|
||||||
"Get absolute path to `org-roam-dailies-directory'."
|
"Get absolute path to `org-roam-dailies-directory'."
|
||||||
(-> (concat
|
(expand-file-name org-roam-dailies-directory org-roam-directory))
|
||||||
(file-name-as-directory org-roam-directory)
|
|
||||||
org-roam-dailies-directory)
|
|
||||||
(file-truename)))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-directory ()
|
(defun org-roam-dailies-find-directory ()
|
||||||
"Find and open `org-roam-dailies-directory'."
|
"Find and open `org-roam-dailies-directory'."
|
||||||
@ -140,7 +137,7 @@ If FILE is not specified, use the current buffer's file-path."
|
|||||||
(-> (buffer-base-buffer)
|
(-> (buffer-base-buffer)
|
||||||
(buffer-file-name))))
|
(buffer-file-name))))
|
||||||
(directory (org-roam-dailies-directory--get-absolute-path)))
|
(directory (org-roam-dailies-directory--get-absolute-path)))
|
||||||
(setq path (file-truename path))
|
(setq path (expand-file-name path))
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(and
|
(and
|
||||||
(org-roam--org-file-p path)
|
(org-roam--org-file-p path)
|
||||||
@ -283,7 +280,6 @@ Prefer past dates, unless PREFER-FUTURE is non-nil."
|
|||||||
;;; Navigation
|
;;; Navigation
|
||||||
(defun org-roam-dailies--list-files (&rest extra-files)
|
(defun org-roam-dailies--list-files (&rest extra-files)
|
||||||
"List all files in `org-roam-dailies-directory'.
|
"List all files in `org-roam-dailies-directory'.
|
||||||
|
|
||||||
EXTRA-FILES can be used to append extra files to the list."
|
EXTRA-FILES can be used to append extra files to the list."
|
||||||
(let ((dir (org-roam-dailies-directory--get-absolute-path)))
|
(let ((dir (org-roam-dailies-directory--get-absolute-path)))
|
||||||
(append (--remove (let ((file (file-name-nondirectory it)))
|
(append (--remove (let ((file (file-name-nondirectory it)))
|
||||||
@ -294,48 +290,31 @@ EXTRA-FILES can be used to append extra files to the list."
|
|||||||
(directory-files-recursively dir ""))
|
(directory-files-recursively dir ""))
|
||||||
extra-files)))
|
extra-files)))
|
||||||
|
|
||||||
(defun org-roam-dailies--find-next-note-path (&optional n file)
|
|
||||||
"Find next daily-note from FILE.
|
|
||||||
|
|
||||||
With numeric argument N, find note N days in the future. If N is
|
|
||||||
negative, find note N days in the past.
|
|
||||||
|
|
||||||
If FILE is not provided, use the file visited by the current
|
|
||||||
buffer."
|
|
||||||
(unless (org-roam-dailies--daily-note-p file)
|
|
||||||
(user-error "Not in a daily-note"))
|
|
||||||
(let ((n (or n 1))
|
|
||||||
(file (or file
|
|
||||||
(-> (buffer-base-buffer)
|
|
||||||
(buffer-file-name)))))
|
|
||||||
;; Ensure that the buffer is saved before moving
|
|
||||||
(save-buffer file)
|
|
||||||
(let* ((list (org-roam-dailies--list-files))
|
|
||||||
(position
|
|
||||||
(cl-position-if (lambda (candidate)
|
|
||||||
(string= file candidate))
|
|
||||||
list)))
|
|
||||||
(pcase n
|
|
||||||
((pred (natnump))
|
|
||||||
(if (eq position (- (length list) 1))
|
|
||||||
(user-error "Already at newest note")
|
|
||||||
(message "Showing next daily-note")))
|
|
||||||
((pred (integerp))
|
|
||||||
(if (eq position 0)
|
|
||||||
(user-error "Already at oldest note")
|
|
||||||
(message "Showing previous daily-note"))))
|
|
||||||
(nth (+ position n) list))))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-next-note (&optional n)
|
(defun org-roam-dailies-find-next-note (&optional n)
|
||||||
"Find next daily-note.
|
"Find next daily-note.
|
||||||
|
|
||||||
With numeric argument N, find note N days in the future. If N is
|
With numeric argument N, find note N days in the future. If N is
|
||||||
negative, find note N days in the past."
|
negative, find note N days in the past."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(let* ((n (or n 1))
|
(unless (org-roam-dailies--daily-note-p)
|
||||||
(next (org-roam-dailies--find-next-note-path n)))
|
(user-error "Not in a daily-note"))
|
||||||
(find-file next)
|
(setq n (or n 1))
|
||||||
(run-hooks 'org-roam-dailies-find-file-hook)))
|
(let* ((dailies (org-roam-dailies--list-files))
|
||||||
|
(position
|
||||||
|
(cl-position-if (lambda (candidate)
|
||||||
|
(string= (buffer-file-name (buffer-base-buffer)) candidate))
|
||||||
|
dailies))
|
||||||
|
note)
|
||||||
|
(pcase n
|
||||||
|
((pred (natnump))
|
||||||
|
(when (eq position (- (length dailies) 1))
|
||||||
|
(user-error "Already at newest note")))
|
||||||
|
((pred (integerp))
|
||||||
|
(when (eq position 0)
|
||||||
|
(user-error "Already at oldest note"))))
|
||||||
|
(setq note (nth (+ position n) dailies))
|
||||||
|
(find-file note)
|
||||||
|
(run-hooks 'org-roam-dailies-find-file-hook)))
|
||||||
|
|
||||||
(defun org-roam-dailies-find-previous-note (&optional n)
|
(defun org-roam-dailies-find-previous-note (&optional n)
|
||||||
"Find previous daily-note.
|
"Find previous daily-note.
|
||||||
|
Reference in New Issue
Block a user