Skip to content

Commit

Permalink
Improve new-scheduled-entry command
Browse files Browse the repository at this point in the history
Currently the command inserts the time preceding the TODO. This PR implements
fixes (non-desctructively), but it assumes that bastibe#335 and bastibe#337 get merged
first.
  • Loading branch information
dalanicolai committed Feb 24, 2021
1 parent 9d4151b commit 3fccdb1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions org-journal.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 &optional insert-at-point)
(defun org-journal--insert-entry-header (time &optional todo insert-at-point)
"Create new journal entry if there isn't one."
(let ((entry-header
(if (functionp org-journal-date-format)
Expand Down Expand Up @@ -694,9 +694,9 @@ This allows the use of `org-journal-tag-alist' and
(defun org-journal-insert-header-at-point ()
"Create journal style headline at point."
(interactive)
(org-journal--insert-entry-header (current-time) t))
(org-journal--insert-entry-header (current-time) nil 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)))
Expand All @@ -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,
Expand Down Expand Up @@ -756,7 +756,7 @@ hook is run."
(view-mode -1)

(org-journal--insert-header time)
(org-journal--insert-entry-header time)
(org-journal--insert-entry-header time todo)
(org-journal--decrypt)

;; Move TODOs from previous day to new entry
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3fccdb1

Please sign in to comment.