summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-03-17 11:32:40 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-03-17 11:49:16 +0100
commit5aaf3dfc7ed1b9fd0054fe4418c6f46befeaf1a8 (patch)
tree3a3531779d19d945cbfd9c852b0f75f5818981cb
parent00938bc98bb3ce7d14bdc400ad9f4e0ac9d04d8b (diff)
downloadorg-mode-5aaf3dfc7ed1b9fd0054fe4418c6f46befeaf1a8.tar.gz
Move `org-heading-delete-metadata' into "org-list.el"
* lisp/org.el (org-heading-delete-metadata): Move to... * lisp/org-list.el (org-list--delete-metadata): ... here. Refactor code. (org-toggle-item): Use new function. * testing/lisp/test-org-list.el (test-org-list/toggle-item): Add test. At the moment, this function is only used internally in "org-list.el", so it belongs there. Also refrain from removing log or clock drawers, because they may not contain all clocks or notes anyway. Besides, the information they contain may still make sense in a plain list.
-rw-r--r--lisp/org-list.el15
-rw-r--r--lisp/org.el22
-rw-r--r--testing/lisp/test-org-list.el20
3 files changed, 32 insertions, 25 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el
index d646e26..e233785 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -825,6 +825,17 @@ This function modifies STRUCT."
(t (cons pos (cdar ind-to-ori))))))
(cdr struct)))))
+(defun org-list--delete-metadata ()
+ "Delete metadata from the heading at point.
+Metadata are tags, planning information and properties drawers."
+ (save-match-data
+ (org-with-wide-buffer
+ (org-set-tags-to nil)
+ (delete-region (line-beginning-position 2)
+ (save-excursion
+ (org-end-of-meta-data)
+ (org-skip-whitespace)
+ (if (eobp) (point) (line-beginning-position)))))))
;;; Accessors
@@ -2994,7 +3005,7 @@ With a prefix argument ARG, change the region in a single item."
((org-at-heading-p)
;; Remove metadata
(let (org-loop-over-headlines-in-active-region)
- (org-heading-delete-metadata))
+ (org-list--delete-metadata))
(let* ((bul (org-list-bullet-string "-"))
(bul-len (length bul))
;; Indentation of the first heading. It should be
@@ -3017,7 +3028,7 @@ With a prefix argument ARG, change the region in a single item."
(when (< level ref-level) (setq ref-level level))
;; Remove metadata
(let (org-loop-over-headlines-in-active-region)
- (org-heading-delete-metadata))
+ (org-list--delete-metadata))
;; Remove stars and TODO keyword.
(let ((case-fold-search nil)) (looking-at org-todo-line-regexp))
(delete-region (point) (or (match-beginning 3)
diff --git a/lisp/org.el b/lisp/org.el
index 76bc60c..c905b5a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7674,28 +7674,6 @@ Set it to HEADING when provided."
(org-set-tags nil t)
(when (looking-at "[ \t]*$") (replace-match ""))))))))
-(defun org-heading-delete-metadata ()
- "Delete metadata from the heading at point.
-Metadata are tags, planning information and property/log/clock drawers."
- (org-back-to-heading t)
- (org-with-wide-buffer
- (save-match-data
- (let ((limit (save-excursion (outline-next-heading))))
- (org-set-tags-to nil)
- (save-excursion
- (when (re-search-forward
- (concat org-planning-line-re ".*$") limit t)
- (replace-match "")))
- (save-excursion
- (when (re-search-forward org-property-drawer-re limit t)
- (replace-match "")))
- (save-excursion
- (when (re-search-forward org-log-drawer-re limit t)
- (replace-match "")))
- (save-excursion
- (when (re-search-forward org-clock-drawer-re limit t)
- (replace-match "")))))))
-
(defun org-insert-heading-after-current ()
"Insert a new heading with same level as current, after current subtree."
(interactive)
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index e0c448c..93c6680 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -1,6 +1,6 @@
;;; test-org-list.el --- Tests for org-list.el
-;; Copyright (C) 2012, 2013, 2014 Nicolas Goaziou
+;; Copyright (C) 2012, 2013, 2014, 2018 Nicolas Goaziou
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
@@ -937,6 +937,24 @@
(org-test-with-temp-text "* TODO line"
(org-toggle-item nil)
(buffer-string))))
+ ;; When turning headlines into items, make sure planning info line
+ ;; and properties drawers are removed. This also includes empty
+ ;; lines following them.
+ (should
+ (equal "- H\n"
+ (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29 Thu>"
+ (org-toggle-item nil)
+ (buffer-string))))
+ (should
+ (equal "- H\n"
+ (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
+ (org-toggle-item nil)
+ (buffer-string))))
+ (should
+ (equal "- H\nText"
+ (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n\nText"
+ (org-toggle-item nil)
+ (buffer-string))))
;; When a region is marked and first line is a headline, all
;; headlines are turned into items.
(should