diff --git a/modules/lang/org/contrib/journal.el b/modules/lang/org/contrib/journal.el index 52498a38f..11ffacd3c 100644 --- a/modules/lang/org/contrib/journal.el +++ b/modules/lang/org/contrib/journal.el @@ -2,23 +2,42 @@ ;;;###if (featurep! +journal) (use-package! org-journal - :mode ("/\\(?1:[0-9]\\{4\\}\\)\\(?2:[0-9][0-9]\\)\\(?3:[0-9][0-9]\\)\\(\\.gpg\\)?\\'" - . org-journal-mode) - :preface + :hook (org-mode . +org-journal-mode-maybe) + :init ;; HACK org-journal does some file-path magic at load time that creates ;; duplicate and hard-coded `auto-mode-alist' entries, so we suppress it ;; and use the more generalize regexp (above). (advice-add #'org-journal-update-auto-mode-alist :override #'ignore) + ;; Not using the .org file extension causes so much needless headache with + ;; file detection, and for no compelling reason, so we make it the default, so + ;; `org-journal' doesn't have to do all this silly magic. + (setq org-journal-file-format "%Y%m%d.org") + ;; HACK `org-journal-dir' has is surrounded by setter and `auto-mode-alist' ;; magic which makes its needlessly difficult to create an "overrideable" - ;; default for Doom users, so we set this to an empty string (anything - ;; else will throw an error) so we can detect it being changed later. + ;; default for Doom users, so we set this to an empty string (a + ;; non-string would throw an error) so we can detect changes to it later. (setq org-journal-dir "" - org-journal-cache-file (concat doom-cache-dir "org-journal")) + org-journal-cache-file (concat doom-cache-dir "org-journal") + ;; Doom opts for an "open in a popup or here" strategy as a default. + ;; Open in "other window" is less consistent and harder to predict. + org-journal-find-file #'find-file) + :config + ;; This is necessary if the user decides opens a journal file directly, via + ;; `find-file' or something, and not through org-journal's commands. + (defun +org-journal-mode-maybe () + "Activate `org-journal-mode', maybe." + (and (eq major-mode 'org-mode) + (string-match-p org-journal-file-pattern buffer-file-name) + (let ((org-mode-hook (remq '+org-journal-mode-maybe org-mode-hook))) + (org-journal-mode)))) + (when (string-empty-p org-journal-dir) - (setq! org-journal-dir (expand-file-name "journal/" org-directory))) - (setq org-journal-find-file #'find-file) + (setq org-journal-dir (expand-file-name "journal/" org-directory))) + + (advice-remove #'org-journal-update-auto-mode-alist #'ignore) + (setq! org-journal-dir org-journal-dir) (map! (:map org-journal-mode-map :n "]f" #'org-journal-open-next-entry