summaryrefslogtreecommitdiff
path: root/lisp/ss-org.el
blob: 4a8836c12c421f9ef899e38a4b606c566b8597c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;;; ss-org.el --- Base Org configuration -*- lexical-binding: t; -*-

;;; Commentary:

;; Shared Org setup and note-opening helpers.

;;; Code:

(require 'org)
(require 'ss-core)

(defvar ss-journal-session-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-c C-c") #'ss-journal-session-save-and-dismiss)
    (define-key map (kbd "C-c C-k") #'ss-journal-session-dismiss)
    map)
  "Keymap for focused journal editing sessions.")

(defconst ss-journal-session-header-line
  "Journal session: C-c C-c save and dismiss, C-c C-k dismiss"
  "Header line shown during focused journal editing sessions.")

(define-minor-mode ss-journal-session-mode
  "Minor mode for focused journal editing sessions."
  :lighter " Journal-Session"
  :keymap ss-journal-session-mode-map
  (if ss-journal-session-mode
      (setq-local header-line-format ss-journal-session-header-line)
    (kill-local-variable 'header-line-format)))

(defun ss-journal-session-dismiss ()
  "End the focused journal session without saving automatically."
  (interactive)
  (widen)
  (ss-journal-session-mode -1)
  (quit-window nil (selected-window)))

(defun ss-journal-session-save-and-dismiss ()
  "Save the journal buffer, then end the focused journal session."
  (interactive)
  (save-buffer)
  (ss-journal-session-dismiss))

(defun ss-open-journal ()
  "Open today's journal entry in a focused session, creating it when needed."
  (interactive)
  (ss-open-journal-today-session))

(defun ss-open-journal-today-session ()
  "Open today's journal entry in a focused, dismissable session."
  (interactive)
  (find-file (ss-require-existing-file ss-journal-file))
  (widen)
  (unless (fboundp 'ss-journal-goto-date)
    (user-error "Journal date navigation is unavailable"))
  (ss-journal-goto-date nil 'create)
  (when (fboundp 'ss-journal-ensure-day-sections)
    (ss-journal-ensure-day-sections))
  (org-fold-show-entry)
  (org-fold-show-subtree)
  (org-narrow-to-subtree)
  (ss-journal-session-mode 1))

(defun ss-open-journal-full ()
  "Open `ss-journal-file' with the full buffer visible."
  (interactive)
  (find-file (ss-require-existing-file ss-journal-file))
  (widen))

(defun ss-open-moc ()
  "Open the central MOC note."
  (interactive)
  (find-file (ss-require-existing-file ss-moc-file)))

(defun ss-org-setup ()
  "Initialize base Org configuration."
  (use-package org
    :ensure nil
    :config
    (setq org-directory ss-org-directory
          org-hide-emphasis-markers t
          org-agenda-search-headline-for-time t)
    (add-hook 'org-mode-hook
              (lambda ()
                (setq-local org-hide-emphasis-markers t)
                (font-lock-flush)
                (font-lock-ensure))))

  (use-package git-auto-commit-mode
    :ensure t
    :pin melpa
    :commands (git-auto-commit-mode)
    :init
    (setq gac-shell-and
          (if (string-match-p "fish\\'" shell-file-name)
              " ; and "
            " && ")))

  (add-hook 'emacs-startup-hook
            (lambda ()
              (find-file (ss-require-existing-file ss-moc-file)))))

(provide 'ss-org)

;;; ss-org.el ends here