From 6516e1a501bd736141b9c2e321591a7bade57bbe Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 2 Apr 2021 14:53:21 -0700 Subject: Update Org-roam config for Org-roam 1.2.3 --- .emacs.d/init-spw.el | 58 ++++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 45 deletions(-) diff --git a/.emacs.d/init-spw.el b/.emacs.d/init-spw.el index cc193459..bf88f2dc 100644 --- a/.emacs.d/init-spw.el +++ b/.emacs.d/init-spw.el @@ -2477,56 +2477,24 @@ mutt's review view, after exiting EDITOR." (add-hook hook #'ggtags-mode))) (spw/when-library-available org-roam - (autoload 'org-roam-dailies-today "org-roam") + (dolist (fn '(org-roam-dailies-find-previous-note + org-roam-dailies-today + org-roam-dailies-find-next-note)) + (autoload fn "org-roam")) - (setq org-roam-directory (expand-file-name "~/doc/notes")) + (setq org-roam-directory (expand-file-name "~/doc/notes") + org-roam-dailies-directory "days/") (global-set-key "\C-cof" #'org-roam-find-file) - (defun spw/org-roam-dailies-ring () - (let* ((today-file (concat (format-time-string "%F") ".org")) - (files (directory-files - org-roam-directory - nil - "\\`[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\.org\\'")) - (ring (make-ring (length files)))) - ;; rotate the list so we begin with today or the closest day after today - (let ((today (cl-do* ((files files (rest files)) - (next (rest files) (rest files))) - ((or (not next) - (string= today-file (car next)) - (string-lessp today-file (car next))) - (setcdr files nil) - next)))) - (setq files (append today files))) - (dolist (file (nreverse files) ring) - (ring-insert ring file)))) - (defun spw/org-roam-dailies-prev (n) - (interactive "p") - (spw/org-roam-dailies-next (* -1 n))) - (defun spw/org-roam-dailies-today () - (interactive) - (call-interactively #'org-roam-dailies-today) - (cons (spw/org-roam-dailies-ring) 0)) - (defun spw/org-roam-dailies-next (n) - (interactive "p") - (let ((today-file (concat (format-time-string "%F") ".org")) - (ring (spw/org-roam-dailies-ring))) - ;; special case: if positive arg and the first item in the ring is not - ;; today, we need to start one earlier - (when (and (> n 0) - (not (string= today-file (ring-ref ring 0)))) - (decf n)) - (find-file (concat org-roam-directory "/" (ring-ref ring n))) - (cons ring n))) + ;; An alternative would be to bind C-c o / to + ;; org-roam-dailies-find-yesterday and -tomorrow, but that would mean the + ;; keys have different meanings in and out of Org-mode buffers. (spw/bind-command-with-ret-val-cycling - (([?\C-c ?o left] . spw/org-roam-dailies-prev) - ("\C-cod" . spw/org-roam-dailies-today) - ([?\C-c ?o right] . spw/org-roam-dailies-next)) - (spw/buffer-ring-cycle-lambda - (car ret-val) - (find-file (concat org-roam-directory "/" buffer)) - :start (cdr ret-val))) + (([?\C-c ?o left] . org-roam-dailies-find-previous-note) + ("\C-cod" . org-roam-dailies-today) + ([?\C-c ?o right] . org-roam-dailies-find-next-note)) + #'org-roam-dailies-find-next-note) ;; don't bother starting it up until we open something in Org-mode (with-eval-after-load 'org -- cgit v1.2.3