From 4ff3e88492225e6852e780399a81c4f27f8a10ab Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Thu, 9 Apr 2026 12:04:58 +1000 Subject: Refine focused journal session --- README.md | 5 ++++- lisp/ss-org.el | 56 +++++++++++++++++++++++++++++++++++++++-------- tests/ss-capture-tests.el | 11 +++++++--- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 23aebb4..fce2dd2 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,10 @@ The main bindings are: - `C-c n l` to insert a Denote link - `C-c n j` to open the full `~/org/journal.org` buffer - `C-c n M` to open the MOC -- `C-c n d` to open `~/org/journal.org`, narrowed to today when present +- `C-c n d` to open today's journal entry in a focused session; when today's + entry does not yet exist, the command creates it using the normal journal + datetree structure, then narrows to that entry; inside the session, + `C-c C-c` saves and dismisses, and `C-c C-k` dismisses without auto-saving - `C-c n p` to open the people CRM - `C-c n P` to add a new person card - `C-c n f` to find a person card diff --git a/lisp/ss-org.el b/lisp/ss-org.el index 4bbd92d..4a8836c 100644 --- a/lisp/ss-org.el +++ b/lisp/ss-org.el @@ -6,22 +6,60 @@ ;;; 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 `ss-journal-file', narrowing to today's entry when it exists." + "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) - (goto-char (point-max))) - (when (fboundp 'ss-journal-goto-date) - (if (ss-journal-goto-date) - (progn - (org-fold-show-entry) - (org-fold-show-subtree) - (org-narrow-to-subtree)) - (goto-char (point-max))))) + (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." diff --git a/tests/ss-capture-tests.el b/tests/ss-capture-tests.el index 0af27a5..b91d4ef 100644 --- a/tests/ss-capture-tests.el +++ b/tests/ss-capture-tests.el @@ -84,7 +84,7 @@ (when (file-exists-p file) (delete-file file))))) -(ert-deftest ss-open-journal-keeps-end-fallback-when-today-missing () +(ert-deftest ss-open-journal-creates-missing-today-entry-with-standard-sections () (let* ((file (make-temp-file "ss-journal" nil ".org")) (ss-journal-file file)) (unwind-protect @@ -96,8 +96,13 @@ "*** Notes\n")) (let ((org-overriding-default-time (encode-time 0 0 12 9 4 2026))) (ss-open-journal) - (should-not (buffer-narrowed-p)) - (should (eobp)))) + (should (buffer-narrowed-p)) + (should (equal (org-get-outline-path t) + '("2026" "2026-04-09 Thursday"))) + (should (string-match-p + (regexp-quote + "** 2026-04-09 Thursday\n*** Tasks\n*** Notes\n*** Meetings\n") + (buffer-string))))) (when (buffer-live-p (current-buffer)) (kill-buffer (current-buffer))) (when (file-exists-p file) -- cgit v1.2.3