2019-09-18 13:29:06 +09:00
|
|
|
;;; lang/org/contrib/journal.el -*- lexical-binding: t; -*-
|
2019-09-18 13:30:26 +09:00
|
|
|
;;;###if (featurep! +journal)
|
2019-09-18 13:29:06 +09:00
|
|
|
|
2020-04-12 03:41:42 -04:00
|
|
|
(use-package! org-journal
|
2020-04-17 05:07:55 -04:00
|
|
|
:hook (org-mode . +org-journal-mode-maybe)
|
|
|
|
:init
|
2020-04-12 03:41:42 -04:00
|
|
|
;; 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)
|
2020-04-17 05:07:55 -04:00
|
|
|
;; 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")
|
|
|
|
|
2020-04-12 03:41:42 -04:00
|
|
|
;; HACK `org-journal-dir' has is surrounded by setter and `auto-mode-alist'
|
|
|
|
;; magic which makes its needlessly difficult to create an "overrideable"
|
2020-04-17 05:07:55 -04:00
|
|
|
;; 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.
|
2020-04-12 03:41:42 -04:00
|
|
|
(setq org-journal-dir ""
|
2020-04-17 05:07:55 -04:00
|
|
|
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)
|
|
|
|
|
2020-04-12 03:41:42 -04:00
|
|
|
:config
|
2020-04-17 05:07:55 -04:00
|
|
|
;; 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)
|
2020-04-17 16:17:23 +02:00
|
|
|
(stringp buffer-file-name)
|
2020-04-19 22:04:12 -04:00
|
|
|
(stringp org-journal-file-pattern)
|
2020-04-17 05:07:55 -04:00
|
|
|
(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))))
|
|
|
|
|
2020-04-12 03:41:42 -04:00
|
|
|
(when (string-empty-p org-journal-dir)
|
2020-04-17 05:07:55 -04:00
|
|
|
(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)
|
2019-10-31 23:09:43 -04:00
|
|
|
|
2020-01-18 20:34:37 -05:00
|
|
|
(map! (:map org-journal-mode-map
|
|
|
|
:n "]f" #'org-journal-open-next-entry
|
|
|
|
:n "[f" #'org-journal-open-previous-entry
|
|
|
|
:n "C-n" #'org-journal-open-next-entry
|
|
|
|
:n "C-p" #'org-journal-open-previous-entry)
|
2019-10-31 23:09:43 -04:00
|
|
|
(:map org-journal-search-mode-map
|
2020-01-18 20:34:37 -05:00
|
|
|
"C-n" #'org-journal-search-next
|
|
|
|
"C-p" #'org-journal-search-previous)
|
|
|
|
:localleader
|
2019-10-31 23:09:43 -04:00
|
|
|
(:map org-journal-mode-map
|
2020-01-18 20:34:37 -05:00
|
|
|
"c" #'org-journal-new-entry
|
|
|
|
"d" #'org-journal-new-date-entry
|
2019-10-31 23:09:43 -04:00
|
|
|
"n" #'org-journal-open-next-entry
|
2020-01-18 20:34:37 -05:00
|
|
|
"p" #'org-journal-open-previous-entry
|
|
|
|
(:prefix "s"
|
|
|
|
"s" #'org-journal-search
|
|
|
|
"f" #'org-journal-search-forever
|
|
|
|
"F" #'org-journal-search-future
|
|
|
|
"w" #'org-journal-search-calendar-week
|
|
|
|
"m" #'org-journal-search-calendar-month
|
|
|
|
"y" #'org-journal-search-calendar-year))
|
|
|
|
(:map org-journal-search-mode-map
|
|
|
|
"n" #'org-journal-search-next
|
|
|
|
"p" #'org-journal-search-prev)))
|