From 9d4151baa6cfae552db974723ac8cc0a88f18d03 Mon Sep 17 00:00:00 2001 From: Daniel Nicolai Date: Sat, 20 Feb 2021 16:56:00 +0100 Subject: [PATCH 1/4] Create insert journal headline at point I have a project where I would like to use journal style headlines outside a journal file. This small adjustment enables the option to insert journal style headlines at point. I thought it might be useful sometimes for other user too. If you think the extra command is too "exclusive" to be added by default then it is no problem if you remove it. But then it would still be nice to keep the optional `insert-at-point` argument. --- org-journal.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/org-journal.el b/org-journal.el index cc70a2c..06b98f3 100644 --- a/org-journal.el +++ b/org-journal.el @@ -632,7 +632,7 @@ This allows the use of `org-journal-tag-alist' and (when (re-search-backward "^#\\+" nil t) (org-ctrl-c-ctrl-c))))) -(defun org-journal--insert-entry-header (time) +(defun org-journal--insert-entry-header (time &optional insert-at-point) "Create new journal entry if there isn't one." (let ((entry-header (if (functionp org-journal-date-format) @@ -641,7 +641,8 @@ This allows the use of `org-journal-tag-alist' and (user-error "org-journal-date-format is empty, this won't work")) (concat org-journal-date-prefix (format-time-string org-journal-date-format time))))) - (goto-char (point-min)) + (unless insert-at-point + (goto-char (point-min))) (unless (if (org-journal--daily-p) (or (search-forward entry-header nil t) (and (goto-char (point-max)) nil)) (cl-loop @@ -690,6 +691,11 @@ This allows the use of `org-journal-tag-alist' and (org-set-tags org-crypt-tag-matcher))) (run-hooks 'org-journal-after-header-create-hook)))) +(defun org-journal-insert-header-at-point () + "Create journal style headline at point." + (interactive) + (org-journal--insert-entry-header (current-time) t)) + (defun org-journal--insert-entry (time org-extend-today-until-active-p) "Insert a new entry." (unless (eq (current-column) 0) (insert "\n")) From 412328e05d2c19339774db3b9e292d7f57db2c93 Mon Sep 17 00:00:00 2001 From: Daniel Nicolai Date: Wed, 24 Feb 2021 14:39:32 +0100 Subject: [PATCH 2/4] Improve new-scheduled-entry command Currently the command inserts the time preceding the TODO. This PR implements fixes (non-desctructively), but it assumes that #335 and #337 get merged first. --- org-journal.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/org-journal.el b/org-journal.el index 06b98f3..a530cc5 100644 --- a/org-journal.el +++ b/org-journal.el @@ -696,7 +696,7 @@ This allows the use of `org-journal-tag-alist' and (interactive) (org-journal--insert-entry-header (current-time) t)) -(defun org-journal--insert-entry (time org-extend-today-until-active-p) +(defun org-journal--insert-entry (time org-extend-today-until-active-p &optional todo) "Insert a new entry." (unless (eq (current-column) 0) (insert "\n")) (let* ((day-discrepancy (- (time-to-days (current-time)) (time-to-days time))) @@ -712,11 +712,11 @@ This allows the use of `org-journal-tag-alist' and (format-time-string org-journal-time-format))) ;; “time” is on some other day, use blank timestamp (t "")))) - (insert org-journal-time-prefix timestamp)) + (insert (concat org-journal-time-prefix (when todo "TODO ") timestamp))) (run-hooks 'org-journal-after-entry-create-hook)) ;;;###autoload -(defun org-journal-new-entry (prefix &optional time) +(defun org-journal-new-entry (prefix &optional time todo) "Open today's journal file and start a new entry. With a PREFIX arg, open the today's file, create a heading if it doesn't exist yet, @@ -770,7 +770,7 @@ hook is run." (goto-char (point-max))) (when should-add-entry-p - (org-journal--insert-entry time org-extend-today-until-active-p)) + (org-journal--insert-entry time org-extend-today-until-active-p todo)) (if (and org-journal-hide-entries-p (org-journal--time-entry-level)) (outline-hide-sublevels (org-journal--time-entry-level)) @@ -1068,12 +1068,12 @@ With non-nil prefix argument create a regular entry instead of a TODO entry." org-journal-carryover-items) (when (time-less-p time (current-time)) (user-error "Scheduled time needs to be in the future")) - (org-journal-new-entry nil time) - (unless prefix - (insert "TODO ")) + (org-journal-new-entry nil time (not prefix)) (save-excursion (insert "\n") - (org-insert-time-stamp time)))) + (insert "SCHEDULED: ") + (org-insert-time-stamp time t) + (org-cycle)))) ;;;###autoload (defun org-journal-reschedule-scheduled-entry (&optional time) From 3236a83191ace4734d2f357990fa2326a84142a8 Mon Sep 17 00:00:00 2001 From: Daniel Nicolai Date: Wed, 24 Feb 2021 16:16:00 +0100 Subject: [PATCH 3/4] Add new-(scheduled-)entry insert at point options Inserting journal style headlines easily can be useful in non-journal buffers too. Especially when using any 'org-notifications' package (e.g. [org-wild-notifier](https://github.com/akhramov/org-wild-notifier.el)). --- org-journal.el | 51 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/org-journal.el b/org-journal.el index a530cc5..8aaac35 100644 --- a/org-journal.el +++ b/org-journal.el @@ -716,7 +716,7 @@ This allows the use of `org-journal-tag-alist' and (run-hooks 'org-journal-after-entry-create-hook)) ;;;###autoload -(defun org-journal-new-entry (prefix &optional time todo) +(defun org-journal-new-entry (prefix &optional time todo insert-at-point) "Open today's journal file and start a new entry. With a PREFIX arg, open the today's file, create a heading if it doesn't exist yet, @@ -748,26 +748,27 @@ hook is run." (nth 8 now)))) (setq entry-path (org-journal--get-entry-path time)) - ;; Open journal file - (unless (string= entry-path (buffer-file-name)) - (funcall org-journal-find-file entry-path)) + (unless insert-at-point + ;; Open journal file + (unless (string= entry-path (buffer-file-name)) + (funcall org-journal-find-file entry-path)) - ;; Insure `view-mode' is not active - (view-mode -1) + ;; Insure `view-mode' is not active + (view-mode -1) - (org-journal--insert-header time) - (org-journal--insert-entry-header time) - (org-journal--decrypt) + (org-journal--insert-header time) + (org-journal--insert-entry-header time) + (org-journal--decrypt) - ;; Move TODOs from previous day to new entry - (when (and org-journal-carryover-items - (not (string-blank-p org-journal-carryover-items)) - (string= entry-path (org-journal--get-entry-path (current-time)))) - (org-journal--carryover)) + ;; Move TODOs from previous day to new entry + (when (and org-journal-carryover-items + (not (string-blank-p org-journal-carryover-items)) + (string= entry-path (org-journal--get-entry-path (current-time)))) + (org-journal--carryover)) - (if (org-journal--is-date-prefix-org-heading-p) - (outline-end-of-subtree) - (goto-char (point-max))) + (if (org-journal--is-date-prefix-org-heading-p) + (outline-end-of-subtree) + (goto-char (point-max)))) (when should-add-entry-p (org-journal--insert-entry time org-extend-today-until-active-p todo)) @@ -779,6 +780,12 @@ hook is run." (when should-add-entry-p (outline-show-entry)))) +(defun org-journal-new-entry-at-point (prefix &optional time todo) + "Insert a journal style entry at current cursor location." + (interactive "P") + (org-journal-new-entry prefix time todo t)) + + (defvar org-journal--kill-buffer nil "Will be set to the `t' if `org-journal--open-entry' is visiting a buffer not open already, otherwise `nil'.") @@ -1059,22 +1066,26 @@ arguments (C-u C-u) are given. In that case insert just the heading." (org-journal-new-scheduled-entry prefix time)))) ;;;###autoload -(defun org-journal-new-scheduled-entry (prefix &optional scheduled-time) +(defun org-journal-new-scheduled-entry (prefix &optional scheduled-time insert-at-point) "Create a new entry in the future with an active timestamp. - With non-nil prefix argument create a regular entry instead of a TODO entry." (interactive "P") (let ((time (or scheduled-time (org-time-string-to-time (org-read-date nil nil nil "Date:")))) org-journal-carryover-items) (when (time-less-p time (current-time)) (user-error "Scheduled time needs to be in the future")) - (org-journal-new-entry nil time (not prefix)) + (org-journal-new-entry nil time (not prefix) insert-at-point) (save-excursion (insert "\n") (insert "SCHEDULED: ") (org-insert-time-stamp time t) (org-cycle)))) +(defun org-journal-new-scheduled-entry-at-point (prefix &optional scheduled-time) + "Insert a journal style scheduled entry at current cursor location." + (interactive "P") + (org-journal-new-scheduled-entry prefix scheduled-time t)) + ;;;###autoload (defun org-journal-reschedule-scheduled-entry (&optional time) "Reschedule an entry in the future." From a021c6cd5aec7cf2aa04ebfa2a2923ddabbfe17f Mon Sep 17 00:00:00 2001 From: Daniel Nicolai Date: Tue, 13 Apr 2021 16:35:01 +0200 Subject: [PATCH 4/4] Make at-point functions autoloadable --- org-journal.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org-journal.el b/org-journal.el index 8aaac35..3bb1939 100644 --- a/org-journal.el +++ b/org-journal.el @@ -690,7 +690,7 @@ This allows the use of `org-journal-tag-alist' and (unless (member org-crypt-tag-matcher (org-get-tags)) (org-set-tags org-crypt-tag-matcher))) (run-hooks 'org-journal-after-header-create-hook)))) - +;;;###autoload (defun org-journal-insert-header-at-point () "Create journal style headline at point." (interactive) @@ -780,6 +780,7 @@ hook is run." (when should-add-entry-p (outline-show-entry)))) +;;;###autoload (defun org-journal-new-entry-at-point (prefix &optional time todo) "Insert a journal style entry at current cursor location." (interactive "P") @@ -1081,6 +1082,7 @@ With non-nil prefix argument create a regular entry instead of a TODO entry." (org-insert-time-stamp time t) (org-cycle)))) +;;;###autoload (defun org-journal-new-scheduled-entry-at-point (prefix &optional scheduled-time) "Insert a journal style scheduled entry at current cursor location." (interactive "P")