Fix indentation when altering planning info

* lisp/org.el (org-add-planning-info): Do not remove too much
  indentation when removing a planning line.
* testing/lisp/test-org.el: Add tests.

Reported-by: George McNinch <gmcninch@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/100819>
This commit is contained in:
Nicolas Goaziou 2015-09-03 23:03:28 +02:00
parent 980aef2dfb
commit b0f6c3c251
2 changed files with 48 additions and 18 deletions

View File

@ -13533,25 +13533,33 @@ WHAT entry will also be removed."
(dolist (type (if what (cons what remove) remove))
(save-excursion
(when (re-search-forward
(concat
" *"
(case type
(closed org-closed-time-regexp)
(deadline org-deadline-time-regexp)
(scheduled org-scheduled-time-regexp)
(otherwise
(error "Invalid planning type: %s" type))))
(case type
(closed org-closed-time-regexp)
(deadline org-deadline-time-regexp)
(scheduled org-scheduled-time-regexp)
(otherwise
(error "Invalid planning type: %s" type)))
(line-end-position) t)
(replace-match "")
(when (looking-at "--+<[^>]+>") (replace-match ""))
(when (and (not what) (eq type 'closed))
(save-excursion
(beginning-of-line)
(when (looking-at "[ \t]*$")
(delete-region (point)
(line-beginning-position 2)))))))
;; Remove leading white spaces.
(when (looking-at "[ \t]+") (replace-match ""))))
;; Delete until next keyword or end of line.
(delete-region
(match-beginning 0)
(if (re-search-forward org-keyword-time-not-clock-regexp
(line-end-position)
t)
(match-beginning 0)
(line-end-position))))))
;; If there is nothing more to add and no more keyword
;; is left, remove the line completely.
(if (and (org-looking-at-p "[ \t]*$") (not what))
(delete-region (line-beginning-position)
(line-beginning-position 2))
;; If we removed last keyword, do not leave trailing
;; white space at the end of line.
(let ((p (point)))
(save-excursion
(end-of-line)
(unless (= (skip-chars-backward " \t" p) 0)
(delete-region (point) (line-end-position)))))))
((not what) (throw 'exit nil)) ; Nothing to do.
(t (insert-before-markers "\n")
(backward-char 1)

View File

@ -3062,12 +3062,34 @@ Paragraph<point>"
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
(should
(equal "* H\n Paragraph"
(org-test-with-temp-text "\
* H
CLOSED: [2015-06-25 Thu]
Paragraph<point>"
(let ((org-adapt-indentation t))
(org-add-planning-info nil nil 'closed))
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
;; Remove closed when `org-adapt-indentation' is nil.
(should
(equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
(org-test-with-temp-text "\
* H
CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
Paragraph<point>"
(let ((org-adapt-indentation nil))
(org-add-planning-info nil nil 'closed))
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
(should
(equal "* H\nParagraph"
(org-test-with-temp-text "\
* H
CLOSED: [2015-06-25 Thu]
Paragraph<point>"
(let ((org-adapt-indentation nil))
(org-add-planning-info nil nil 'closed))