summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien <bzg@gnu.org>2018-03-05 10:57:43 +0100
committerBastien <bzg@gnu.org>2018-03-05 10:57:43 +0100
commit69c5b6c999523ff80bd1c7ca6b3935c1dca97ac2 (patch)
treeb90a6f0cf5cd66c0b166c6c40f617fef670a848d
parentdd99ed74430a8b6a48f6b63fac71a0bede3e772f (diff)
downloadorg-mode-69c5b6c999523ff80bd1c7ca6b3935c1dca97ac2.tar.gz
Remove headings' metadata when turning them into list items
* lisp/org-list.el (org-toggle-item): Delete headings' metadata before turning them into list items. * lisp/org.el (org-log-drawer-start-re): New variable. (org-log-drawer-end-re, org-log-drawer-re): New constants. (org-heading-delete-metadata): New function. (org-setting-tags): Fix comment.
-rw-r--r--lisp/org-list.el10
-rw-r--r--lisp/org.el48
2 files changed, 49 insertions, 9 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el
index c61634c..9e015cd 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1461,8 +1461,8 @@ This function returns, destructively, the new list structure."
(org-M-RET-may-split-line nil)
;; Store inner overlays (to preserve visibility).
(overlays (cl-remove-if (lambda (o) (or (< (overlay-start o) item)
- (> (overlay-end o) item)))
- (overlays-in item item-end))))
+ (> (overlay-end o) item)))
+ (overlays-in item item-end))))
(cond
((eq dest 'delete) (org-list-delete-item item struct))
((eq dest 'kill)
@@ -2991,6 +2991,9 @@ With a prefix argument ARG, change the region in a single item."
(forward-line)))
;; Case 2. Start at an heading: convert to items.
((org-at-heading-p)
+ ;; Remove metadata
+ (let (org-loop-over-headlines-in-active-region)
+ (org-heading-delete-metadata))
(let* ((bul (org-list-bullet-string "-"))
(bul-len (length bul))
;; Indentation of the first heading. It should be
@@ -3011,6 +3014,9 @@ With a prefix argument ARG, change the region in a single item."
;; one, set it as reference, in order to preserve
;; subtrees.
(when (< level ref-level) (setq ref-level level))
+ ;; Remove metadata
+ (let (org-loop-over-headlines-in-active-region)
+ (org-heading-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 f0cc311..a221725 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7674,6 +7674,28 @@ 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)
@@ -11016,7 +11038,7 @@ order.")
(buffer-base-buffer))))
(_ nil))
(mapcar (lambda (s) (replace-regexp-in-string
- "/" "\\/" s nil t))
+ "/" "\\/" s nil t))
(org-get-outline-path t t)))
"/"))))
(push (list target f re (org-refile-marker (point)))
@@ -11739,7 +11761,7 @@ in the block. Otherwise, insert an empty block."
If the last change removed the TODO tag or switched to DONE, then
this is nil.")
-(defvar org-setting-tags nil) ; dynamically skipped
+(defvar org-setting-tags nil) ; dynamically scoped
(defvar org-todo-setup-filter-hook nil
"Hook for functions that pre-filter todo specs.
@@ -18660,7 +18682,6 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
"Return string to be used as color value for an RGB component."
(format "%g" (/ value 65535.0)))
-
;; Image display
@@ -22628,9 +22649,7 @@ it has a `diary' type."
(org-timestamp-format timestamp fmt t))
(org-timestamp-format timestamp fmt (eq boundary 'end)))))))
-
-
-;;; Other stuff.
+;;; Other stuff
(defvar reftex-docstruct-symbol)
(defvar org--rds)
@@ -23646,12 +23665,27 @@ when non-nil, is a regexp matching keywords names."
(and extra (concat (and kwds "\\|") extra))
"\\):[ \t]*\\(.*\\)"))
+;;; Log drawer regular expressions
+
+(defvar org-log-drawer-start-re
+ (concat "^[ ]*:%s:[ ]*$" (org-log-into-drawer))
+ "Regular expression matching the first line of a clock drawer.")
+
+(defconst org-log-drawer-end-re
+ org-clock-drawer-end-re
+ "Regular expression matching the last line of a log drawer.")
+
+(defconst org-log-drawer-re
+ (concat "\\(" org-log-drawer-start-re "\\)[^\000]*?\\("
+ org-log-drawer-end-re "\\)\n?")
+ "Matches an entire log drawer.")
+
;;; Finish up
(add-hook 'org-mode-hook ;remove overlays when changing major mode
(lambda () (add-hook 'change-major-mode-hook
- 'org-show-all 'append 'local)))
+ 'org-show-all 'append 'local)))
(provide 'org)