From b0f6c3c251414f9fb857bb54a309baba7d4cb17c Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 3 Sep 2015 23:03:28 +0200 Subject: [PATCH] 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 --- lisp/org.el | 44 ++++++++++++++++++++++++++------------------ testing/lisp/test-org.el | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 161e85185..0b80e79f0 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 d41e3a349..9ced3cf95 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -3062,6 +3062,17 @@ Paragraph" (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" + (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" (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" + (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 "\ -- 2.11.4.GIT