summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-09-03 23:03:28 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-09-03 23:03:28 +0200
commitb0f6c3c251414f9fb857bb54a309baba7d4cb17c (patch)
tree94c3d230067a213bc0865304ed5612df28a5d526
parent980aef2dfbef4ead2ed61a2fcf441c02e88a820c (diff)
downloadorg-mode-b0f6c3c251414f9fb857bb54a309baba7d4cb17c.tar.gz
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>
-rwxr-xr-xlisp/org.el44
-rw-r--r--testing/lisp/test-org.el22
2 files changed, 48 insertions, 18 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 161e851..0b80e79 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -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)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index d41e3a3..9ced3cf 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -3062,6 +3062,17 @@ 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"
@@ -3074,6 +3085,17 @@ Paragraph<point>"
(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))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
;; Remove closed entry and delete empty line.
(should
(equal "\