Browse Source

org.el (org-toggle-item): Handle TODO and DONE keywords

* org.el (org-toggle-item): When an entry has a TODO or a DONE
keyword, add an empty or a checked checkbox.
Bastien Guerry 4 years ago
parent
commit
213c2a6aa0
1 changed files with 10 additions and 0 deletions
  1. 10 0
      lisp/org.el

+ 10 - 0
lisp/org.el

@@ -20662,6 +20662,8 @@ With a prefix argument ARG, change the region in a single item."
 	((org-at-heading-p)
 	 (let* ((bul (org-list-bullet-string "-"))
 		(bul-len (length bul))
+		(done (org-entry-is-done-p))
+		(todo (org-entry-is-todo-p))
 		;; Indentation of the first heading.  It should be
 		;; relative to the indentation of its parent, if any.
 		(start-ind (save-excursion
@@ -20672,6 +20674,7 @@ With a prefix argument ARG, change the region in a single item."
 		;; Level of first heading.  Further headings will be
 		;; compared to it to determine hierarchy in the list.
 		(ref-level (org-reduced-level (org-outline-level))))
+	   (when (or done todo) (org-todo ""))
 	   (while (< (point) end)
 	     (let* ((level (org-reduced-level (org-outline-level)))
 		    (delta (max 0 (- level ref-level))))
@@ -20681,6 +20684,13 @@ With a prefix argument ARG, change the region in a single item."
 	       (when (< level ref-level) (setq ref-level level))
 	       (replace-match bul t t)
 	       (org-indent-line-to (+ start-ind (* delta bul-len)))
+	       (if (or done todo)
+		   (let* ((struct0 (org-list-struct))
+			  (struct (org-list-struct))
+			  (parents (org-list-parents-alist struct))
+			  (item (car (assoc (point) struct))))
+		     (org-list-set-checkbox item struct (if done "[X]" "[ ]"))
+		     (org-list-struct-apply-struct struct struct0)))
 	       ;; Ensure all text down to END (or SECTION-END) belongs
 	       ;; to the newly created item.
 	       (let ((section-end (save-excursion