Browse Source

Lighten process when C-c C-c is called at a list item

* org.el (org-ctrl-c-ctrl-c): when called at a list item, replace
  usage `org-repair-list', forcing another reading of the list, with
  only needed subroutines.
Nicolas Goaziou 10 years ago
parent
commit
e223357743
1 changed files with 38 additions and 4 deletions
  1. 38 4
      lisp/org.el

+ 38 - 4
lisp/org.el

@@ -17398,12 +17398,46 @@ This command does many different things, depending on context:
 	  (org-footnote-at-definition-p))
       (call-interactively 'org-footnote-action))
      ((org-at-item-checkbox-p)
-      (call-interactively 'org-list-repair)
-      (call-interactively 'org-toggle-checkbox)
+      ;; Use a light version of `org-toggle-checkbox' to avoid
+      ;; computing list structure twice.
+      (let* ((cbox (match-string 1))
+	     (struct (org-list-struct))
+	     (old-struct (mapcar (lambda (e) (copy-alist e)) struct))
+	     (parents (org-list-struct-parent-alist struct))
+	     (prevs (org-list-struct-prev-alist struct))
+	     (orderedp (ignore-errors (org-entry-get nil "ORDERED")))
+	     block-item)
+	(org-list-set-checkbox (point-at-bol) struct
+			       (cond
+				((equal arg '(16)) "[-]")
+				((equal arg '(4)) nil)
+				((equal "[ ]" cbox) "[X]")
+				(t "[ ]")))
+	(org-list-struct-fix-ind struct parents)
+	(org-list-struct-fix-bul struct prevs)
+	(setq block-item
+	      (org-list-struct-fix-box struct parents prevs orderedp))
+	(when block-item
+	  (message
+	   "Checkboxes were removed due to unchecked box at line %d"
+	   (org-current-line block-item)))
+	(org-list-struct-apply-struct struct old-struct)
+	(org-update-checkbox-count-maybe))
       (org-list-send-list 'maybe))
      ((org-at-item-p)
-      (call-interactively 'org-list-repair)
-      (when arg (call-interactively 'org-toggle-checkbox))
+      ;; Do checkbox related actions only if function was called with
+      ;; an argument
+      (let* ((struct (org-list-struct))
+	     (old-struct (mapcar (lambda (e) (copy-alist e)) struct))
+	     (parents (org-list-struct-parent-alist struct))
+	     (prevs (org-list-struct-prev-alist struct)))
+	(org-list-struct-fix-ind struct parents)
+	(org-list-struct-fix-bul struct prevs)
+	(when arg
+	  (org-list-set-checkbox (point-at-bol) struct "[ ]")
+	  (org-list-struct-fix-box struct parents prevs))
+	(org-list-struct-apply-struct struct old-struct)
+	(when arg (org-update-checkbox-count-maybe)))
       (org-list-send-list 'maybe))
      ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
       ;; Dynamic block