Compare commits

...

2 Commits

1 changed files with 31 additions and 18 deletions

View File

@ -620,33 +620,46 @@ query for it."
(insert body) (insert body)
(org-update-statistics-cookies nil))) (org-update-statistics-cookies nil)))
(defun db/org-update-headline-log-note (new-headline) (defun db/org-update-headline-log-note (&optional new-headline)
"Replace headline of item at point with NEW-HEADLINE. "Replace headline of item at point with NEW-HEADLINE.
Interactively query for HEADLINE when not provided." Interactively query for HEADLINE when not provided."
(interactive "sNew Headline: ") (interactive)
;; We should check this before asking the user for the new headline, but how? (unless (derived-mode-p 'org-mode 'org-agenda-mode)
(unless (derived-mode-p 'org-mode) (user-error "Neither in an Org mode nor Org agenda buffer, aborting"))
(user-error "Not in an Org mode buffer, aborting"))
(unless new-headline
(setq new-headline (read-string "New Headline: ")))
(unless (stringp new-headline)
(user-error "New headline must be string"))
(when (string-match-p "\n" new-headline) (when (string-match-p "\n" new-headline)
(user-error "New headline contains newlines, aborting")) (user-error "New headline contains newlines, aborting"))
(when (org-before-first-heading-p) (save-window-excursion
(user-error "Point is before first headline, aborting")) (save-mark-and-excursion
(when (derived-mode-p 'org-agenda-mode)
(org-agenda-goto))
(let ((old-headline (org-entry-get (point) "ITEM"))) (when (org-before-first-heading-p)
(org-edit-headline new-headline) (user-error "Point is before first headline, aborting"))
;; This simulates adding a note by manually. It may also work by directly (let ((old-headline (org-entry-get (point) "ITEM")))
;; using `org-add-note', but this function makes use of `post-command-hook' (org-edit-headline new-headline)
;; in a way I do not understand. So let's try it that way.
(move-marker org-log-note-marker (point)) ;; This simulates manually adding a note. It may also work by directly
(let ((org-log-note-purpose 'note)) ;; using `org-add-note', but this function makes use of `post-command-hook'
(org-add-log-note nil) ;; in a way I do not understand. So let's try it that way.
(insert ; This goes into the *Org Note* buffer. (move-marker org-log-note-marker (point))
(format "Changed headline from: %s" old-headline)) (let ((org-log-note-purpose 'note))
(org-store-log-note)))) (org-add-log-note nil)
(insert ; This goes into the *Org Note* buffer.
(format "Changed headline from: %s" old-headline))
(org-store-log-note)))))
(when (derived-mode-p 'org-agenda-mode)
(org-agenda-redo)))
;;; Calendar ;;; Calendar