瀏覽代碼

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.
Bastien 7 年之前
父節點
當前提交
69c5b6c999
共有 2 個文件被更改,包括 49 次插入9 次删除
  1. 8 2
      lisp/org-list.el
  2. 41 7
      lisp/org.el

+ 8 - 2
lisp/org-list.el

@@ -1461,8 +1461,8 @@ This function returns, destructively, the new list structure."
 	 (org-M-RET-may-split-line nil)
 	 (org-M-RET-may-split-line nil)
 	 ;; Store inner overlays (to preserve visibility).
 	 ;; Store inner overlays (to preserve visibility).
 	 (overlays (cl-remove-if (lambda (o) (or (< (overlay-start o) item)
 	 (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
     (cond
      ((eq dest 'delete) (org-list-delete-item item struct))
      ((eq dest 'delete) (org-list-delete-item item struct))
      ((eq dest 'kill)
      ((eq dest 'kill)
@@ -2991,6 +2991,9 @@ With a prefix argument ARG, change the region in a single item."
 	   (forward-line)))
 	   (forward-line)))
 	;; Case 2. Start at an heading: convert to items.
 	;; Case 2. Start at an heading: convert to items.
 	((org-at-heading-p)
 	((org-at-heading-p)
+	 ;; Remove metadata
+	 (let (org-loop-over-headlines-in-active-region)
+	   (org-heading-delete-metadata))
 	 (let* ((bul (org-list-bullet-string "-"))
 	 (let* ((bul (org-list-bullet-string "-"))
 		(bul-len (length bul))
 		(bul-len (length bul))
 		;; Indentation of the first heading.  It should be
 		;; 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
 	       ;; one, set it as reference, in order to preserve
 	       ;; subtrees.
 	       ;; subtrees.
 	       (when (< level ref-level) (setq ref-level level))
 	       (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.
 	       ;; Remove stars and TODO keyword.
 	       (let ((case-fold-search nil)) (looking-at org-todo-line-regexp))
 	       (let ((case-fold-search nil)) (looking-at org-todo-line-regexp))
 	       (delete-region (point) (or (match-beginning 3)
 	       (delete-region (point) (or (match-beginning 3)

+ 41 - 7
lisp/org.el

@@ -7674,6 +7674,28 @@ Set it to HEADING when provided."
 	   (org-set-tags nil t)
 	   (org-set-tags nil t)
 	   (when (looking-at "[ \t]*$") (replace-match ""))))))))
 	   (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 ()
 (defun org-insert-heading-after-current ()
   "Insert a new heading with same level as current, after current subtree."
   "Insert a new heading with same level as current, after current subtree."
   (interactive)
   (interactive)
@@ -11016,7 +11038,7 @@ order.")
 					   (buffer-base-buffer))))
 					   (buffer-base-buffer))))
 				   (_ nil))
 				   (_ nil))
 				 (mapcar (lambda (s) (replace-regexp-in-string
 				 (mapcar (lambda (s) (replace-regexp-in-string
-						 "/" "\\/" s nil t))
+						      "/" "\\/" s nil t))
 					 (org-get-outline-path t t)))
 					 (org-get-outline-path t t)))
 				"/"))))
 				"/"))))
 			(push (list target f re (org-refile-marker (point)))
 			(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
 If the last change removed the TODO tag or switched to DONE, then
 this is nil.")
 this is nil.")
 
 
-(defvar org-setting-tags nil) ; dynamically skipped
+(defvar org-setting-tags nil) ; dynamically scoped
 
 
 (defvar org-todo-setup-filter-hook nil
 (defvar org-todo-setup-filter-hook nil
   "Hook for functions that pre-filter todo specs.
   "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."
   "Return string to be used as color value for an RGB component."
   (format "%g" (/ value 65535.0)))
   (format "%g" (/ value 65535.0)))
 
 
-
 
 
 ;; Image display
 ;; Image display
 
 
@@ -22628,9 +22649,7 @@ it has a `diary' type."
 		    (org-timestamp-format timestamp fmt t))
 		    (org-timestamp-format timestamp fmt t))
 	  (org-timestamp-format timestamp fmt (eq boundary 'end)))))))
 	  (org-timestamp-format timestamp fmt (eq boundary 'end)))))))
 
 
-
-
-;;; Other stuff.
+;;; Other stuff
 
 
 (defvar reftex-docstruct-symbol)
 (defvar reftex-docstruct-symbol)
 (defvar org--rds)
 (defvar org--rds)
@@ -23646,12 +23665,27 @@ when non-nil, is a regexp matching keywords names."
 	  (and extra (concat (and kwds "\\|") extra))
 	  (and extra (concat (and kwds "\\|") extra))
 	  "\\):[ \t]*\\(.*\\)"))
 	  "\\):[ \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
 ;;; Finish up
 
 
 (add-hook 'org-mode-hook     ;remove overlays when changing major mode
 (add-hook 'org-mode-hook     ;remove overlays when changing major mode
 	  (lambda () (add-hook 'change-major-mode-hook
 	  (lambda () (add-hook 'change-major-mode-hook
-			  'org-show-all 'append 'local)))
+			       'org-show-all 'append 'local)))
 
 
 (provide 'org)
 (provide 'org)