Fix "no year zero" error when starting org-journal

This commit is contained in:
Henrik Lissner 2020-05-07 00:23:29 -04:00
parent a80ae71b05
commit 333bdd44c0
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -2,44 +2,35 @@
;;;###if (featurep! +journal) ;;;###if (featurep! +journal)
(use-package! org-journal (use-package! org-journal
:hook (org-mode . +org-journal-mode-maybe) :hook (org-load . org-journal-update-auto-mode-alist)
:init ;; This is necessary if the user decides opens a journal file directly, via
;; HACK org-journal does some file-path magic at load time that creates ;; `find-file' or something, and not through org-journal's commands.
;; duplicate and hard-coded `auto-mode-alist' entries, so we suppress it :mode ("/[0-9]\\{8\\}\\.org\\(?:\\.gpg\\)?\\'" . org-journal-mode)
;; and use the more generalize regexp (above). :preface
(advice-add #'org-journal-update-auto-mode-alist :override #'ignore) ;; Not using the .org file extension causes needless headache with file
;; Not using the .org file extension causes so much needless headache with ;; detection for no compelling reason, so we make it the default, so
;; file detection, and for no compelling reason, so we make it the default, so ;; `org-journal' doesn't have to do all its `auto-mode-alist' magic.
;; `org-journal' doesn't have to do all this silly magic. (defvar org-journal-file-format "%Y%m%d.org")
(setq org-journal-file-format "%Y%m%d.org")
;; HACK `org-journal-dir' has is surrounded by setter and `auto-mode-alist' ;; HACK `org-journal-dir' is surrounded with setters and `auto-mode-alist'
;; magic which makes its needlessly difficult to create an "overrideable" ;; magic which makes it difficult to create an better default for Doom
;; default for Doom users, so we set this to an empty string (a ;; users. We set this here so we can detect user-changes to it later.
;; non-string would throw an error) so we can detect changes to it later. (setq org-journal-dir "journal/"
(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. ;; 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. ;; Open in "other window" is less predictable, and can replace a window
;; we wanted to keep visible.
org-journal-find-file #'find-file) org-journal-find-file #'find-file)
:config :config
;; This is necessary if the user decides opens a journal file directly, via (when (or (equal org-journal-dir "journal/")
;; `find-file' or something, and not through org-journal's commands. (not (equal org-journal-file-format "%Y%m%d.org")))
(defun +org-journal-mode-maybe () ;; HACK `org-journal' does some file-path magic at load time that creates
"Activate `org-journal-mode', maybe." ;; several, duplicate and hard-coded `auto-mode-alist' entries, so get
(and (eq major-mode 'org-mode) ;; rid of them all here so we can create a one-true-entry right after.
(stringp buffer-file-name) (setq auto-mode-alist (rassq-delete-all 'org-journal-mode auto-mode-alist))
(stringp org-journal-file-pattern) ;; ...By exploiting `org-journal-dir''s setter
(string-match-p org-journal-file-pattern buffer-file-name) (setq! org-journal-dir (expand-file-name org-journal-dir org-directory)))
(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)))
(advice-remove #'org-journal-update-auto-mode-alist #'ignore)
(setq! org-journal-dir org-journal-dir)
(map! (:map org-journal-mode-map (map! (:map org-journal-mode-map
:n "]f" #'org-journal-open-next-entry :n "]f" #'org-journal-open-next-entry