0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-12 08:39:56 +00:00

Bugfix: Avoid unnecessary empty line inserted by changing TODO entry.

This commit fixes the bug discussed in:

   http://thread.gmane.org/gmane.emacs.orgmode/11106

The reason for the empty line being inserted is subtle:

The function `org-add-planning-info' is used to add and remove planning
info time stamps (deadline, scheduled, closed) from the second line in
an entry.  Usually, the function is called to add something, with an
optional argument to also remove something.  In doing so, it assumes
that the second line must be there, and if it is not there, it creates
it.

Now, sometimes `org-add-planning-info' is called only to remove a time
stamp.  In this particular case it was to remove the CLOSED time
stamp.  This happens when the state is changed from a DONE or nil
state to a not-done state.  The idea behind this is that maybe to
entry was marked earlier as DONE, but the user has changed his mind,
so the timestamp recording when it was finished should be removed.

So in this case, an empty line was created, assuming that there would
be something to add - only nothing was added.

This commit arranges for checking if there is something to add before
creating an empty line.
This commit is contained in:
Carsten Dominik 2009-02-22 13:44:01 +01:00
parent 9989e5f030
commit 4138be27ba
2 changed files with 84 additions and 76 deletions

View file

@ -7,6 +7,9 @@
(orgstruct-make-binding): Detect if item-body context should be
seen.
(orgstruct-is-++): New variable.
(org-add-planning-info): Catch the case when there is no planning
info yet and the call does not want to add anything, only maybe
tries to remove something.
2009-02-21 Carsten Dominik <carsten.dominik@gmail.com>

View file

@ -9177,84 +9177,89 @@ be removed."
(let (org-time-was-given org-end-time-was-given ts
end default-time default-input)
(when (and (not time) (memq what '(scheduled deadline)))
;; Try to get a default date/time from existing timestamp
(save-excursion
(org-back-to-heading t)
(setq end (save-excursion (outline-next-heading) (point)))
(when (re-search-forward (if (eq what 'scheduled)
org-scheduled-time-regexp
org-deadline-time-regexp)
end t)
(setq ts (match-string 1)
default-time
(apply 'encode-time (org-parse-time-string ts))
default-input (and ts (org-get-compact-tod ts))))))
(when what
;; If necessary, get the time from the user
(setq time (or time (org-read-date nil 'to-time nil nil
default-time default-input))))
(when (and org-insert-labeled-timestamps-at-point
(member what '(scheduled deadline)))
(insert
(if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
(org-insert-time-stamp time org-time-was-given
nil nil nil (list org-end-time-was-given))
(setq what nil))
(save-excursion
(save-restriction
(let (col list elt ts buffer-invisibility-spec)
(catch 'exit
(when (and (not time) (memq what '(scheduled deadline)))
;; Try to get a default date/time from existing timestamp
(save-excursion
(org-back-to-heading t)
(looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
(goto-char (match-end 1))
(setq col (current-column))
(goto-char (match-end 0))
(if (eobp) (insert "\n") (forward-char 1))
(if (and (not (looking-at outline-regexp))
(looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
"[^\r\n]*"))
(not (equal (match-string 1) org-clock-string)))
(narrow-to-region (match-beginning 0) (match-end 0))
(insert-before-markers "\n")
(backward-char 1)
(narrow-to-region (point) (point))
(and org-adapt-indentation (org-indent-to-column col)))
;; Check if we have to remove something.
(setq list (cons what remove))
(while list
(setq elt (pop list))
(setq end (save-excursion (outline-next-heading) (point)))
(when (re-search-forward (if (eq what 'scheduled)
org-scheduled-time-regexp
org-deadline-time-regexp)
end t)
(setq ts (match-string 1)
default-time
(apply 'encode-time (org-parse-time-string ts))
default-input (and ts (org-get-compact-tod ts))))))
(when what
;; If necessary, get the time from the user
(setq time (or time (org-read-date nil 'to-time nil nil
default-time default-input))))
(when (and org-insert-labeled-timestamps-at-point
(member what '(scheduled deadline)))
(insert
(if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
(org-insert-time-stamp time org-time-was-given
nil nil nil (list org-end-time-was-given))
(setq what nil))
(save-excursion
(save-restriction
(let (col list elt ts buffer-invisibility-spec)
(org-back-to-heading t)
(looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
(goto-char (match-end 1))
(setq col (current-column))
(goto-char (match-end 0))
(if (eobp) (insert "\n") (forward-char 1))
(when (and (not what)
(not (looking-at org-keyword-time-not-clock-regexp)))
;; Nothing to add, nothing to remove...... :-)
(throw 'exit nil))
(if (and (not (looking-at outline-regexp))
(looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
"[^\r\n]*"))
(not (equal (match-string 1) org-clock-string)))
(narrow-to-region (match-beginning 0) (match-end 0))
(insert-before-markers "\n")
(backward-char 1)
(narrow-to-region (point) (point))
(and org-adapt-indentation (org-indent-to-column col)))
;; Check if we have to remove something.
(setq list (cons what remove))
(while list
(setq elt (pop list))
(goto-char (point-min))
(when (or (and (eq elt 'scheduled)
(re-search-forward org-scheduled-time-regexp nil t))
(and (eq elt 'deadline)
(re-search-forward org-deadline-time-regexp nil t))
(and (eq elt 'closed)
(re-search-forward org-closed-time-regexp nil t)))
(replace-match "")
(if (looking-at "--+<[^>]+>") (replace-match ""))
(if (looking-at " +") (replace-match ""))))
(goto-char (point-max))
(when what
(insert
(if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
(cond ((eq what 'scheduled) org-scheduled-string)
((eq what 'deadline) org-deadline-string)
((eq what 'closed) org-closed-string))
" ")
(setq ts (org-insert-time-stamp
time
(or org-time-was-given
(and (eq what 'closed) org-log-done-with-time))
(eq what 'closed)
nil nil (list org-end-time-was-given)))
(end-of-line 1))
(goto-char (point-min))
(when (or (and (eq elt 'scheduled)
(re-search-forward org-scheduled-time-regexp nil t))
(and (eq elt 'deadline)
(re-search-forward org-deadline-time-regexp nil t))
(and (eq elt 'closed)
(re-search-forward org-closed-time-regexp nil t)))
(replace-match "")
(if (looking-at "--+<[^>]+>") (replace-match ""))
(if (looking-at " +") (replace-match ""))))
(goto-char (point-max))
(when what
(insert
(if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
(cond ((eq what 'scheduled) org-scheduled-string)
((eq what 'deadline) org-deadline-string)
((eq what 'closed) org-closed-string))
" ")
(setq ts (org-insert-time-stamp
time
(or org-time-was-given
(and (eq what 'closed) org-log-done-with-time))
(eq what 'closed)
nil nil (list org-end-time-was-given)))
(end-of-line 1))
(goto-char (point-min))
(widen)
(if (and (looking-at "[ \t]+\n")
(equal (char-before) ?\n))
(delete-region (1- (point)) (point-at-eol)))
ts)))))
(widen)
(if (and (looking-at "[ \t]+\n")
(equal (char-before) ?\n))
(delete-region (1- (point)) (point-at-eol)))
ts))))))
(defvar org-log-note-marker (make-marker))
(defvar org-log-note-purpose nil)