From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jose Robins Subject: Re: opinion+suggestions: Check boxes on headlines and cookies to take care of this into account... Date: Fri, 04 Apr 2008 07:59:30 -0700 Message-ID: <47F64252.5040303@yahoo.com> References: <47F641C4.5010808@yahoo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1158343210==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JhnOC-00049q-OG for emacs-orgmode@gnu.org; Fri, 04 Apr 2008 10:59:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JhnOA-00047Z-IA for emacs-orgmode@gnu.org; Fri, 04 Apr 2008 10:59:36 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JhnOA-00047C-BI for emacs-orgmode@gnu.org; Fri, 04 Apr 2008 10:59:34 -0400 Received: from n54.bullet.mail.sp1.yahoo.com ([98.136.44.32]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JhnO9-00086u-K8 for emacs-orgmode@gnu.org; Fri, 04 Apr 2008 10:59:34 -0400 In-Reply-To: <47F641C4.5010808@yahoo.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Cc: org-mode This is a multi-part message in MIME format. --===============1158343210== Content-Type: multipart/alternative; boundary="------------080605090709000202010801" This is a multi-part message in MIME format. --------------080605090709000202010801 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Jose Robins wrote: > I like working with checkboxes, more than with headlines with a TODO > keyword. Unfortunately, right now checkboxes are lightweight and so > do not enjoy all the privileges enjoyed by headlines - especially > clocking in and out (which is very important for me). I wish that > regular checkboxes were also allowed to have the same privileges as > headlines. Has this idea been discussed before? Were there any > decisions one way or the other. > > Another option is to have checkboxes on headlines (which I find very > intuitive). On one of Sacha Chua's blogs I found a defun to allow > cookies to update checkbox count on a parent headline cookie if there > were checkboxes on it's subtree headlines. This was given in one of > her chapters in her new book that she had posted online > http://sachachua.com/notebook/wickedcoolemacs/wc-emacs-07-managing-your-notes.pdf > > > So I took that and modified it *slightly* - (it had a bug whereby if > the item after the subtree list was at the same level as it's parent's > parent, the checkbox count would get confused and still keep on > counting)... Still there are a few issues. > One more thing I did (to Sacha's code) was to also count headlines with TODO keywords and take that into account while updating the checkbox. > If anyone is interested, here is the code... > ;;;_. Update Checkbox count - to allow for checkboxes to be used in > headings > ;;; Based on code from Sacha Chua > (defun wicked/org-update-checkbox-count (&optional all) > "Update the checkbox statistics in the current section. > This will find all statistic cookies like [57%] and [6/12] and update > them with the current numbers. With optional prefix argument ALL, > do this for the whole buffer." > (interactive "P") > (save-excursion > ;;declaring and assigning values to a whole bunch of variables > (let* ((buffer-invisibility-spec (org-inhibit-invisibility)) > ;; assign point to the "beg" variable and > ;; returning an error in case of error > (beg (condition-case nil > (progn (outline-back-to-heading) (point)) > (error (point-min)))) > ;; make a marker which will point to the end of the current > outline region > (end (move-marker > (make-marker) > (progn (or (or (outline-get-next-sibling) (progn > (goto-char beg) nil)) > (progn (outline-end-of-subtree) (point)) > (goto-char (point-max))) > (point)))) > (re "\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)") > (re-box > "^[ \t]*\\(*+\\|[-+*]\\|[0-9]+[.)]\\) +\\(\\(\\[[- > X]\\]\\)\\|TODO\\|DOING\\|DONE\\)") > b1 e1 f1 c-on c-off lim (cstat 0)) > ;; if called with a prefix argument, "all" will be non-nil; in > which case count the checks in the whole buffer > (when all > (goto-char (point-min)) > (setq beg (point) end (point-max))) > (goto-char beg) > (while (re-search-forward re (marker-position end) t) > (setq cstat (1+ cstat) > b1 (match-beginning 0) ;set b1 to the beginning of the > recent search > e1 (match-end 0) ;set e1 to the end of the > recent re search > f1 (match-beginning 1) ;set f1 to the position of the > 1st paranthesized expression > lim (cond > ((org-on-heading-p) (or (outline-get-next-sibling) > (goto-char (point-max))) (point)) > ((org-at-item-p) (org-end-of-item) (point)) > (t nil)) > lim (marker-position end) ; right now setting lim to the > same as end - not sure what the above line is trying to do > c-on 0 c-off 0) > (goto-char e1) > (when lim > (while (re-search-forward re-box lim t) > (if (member (match-string 2) '("[ ]" "[-]" "TODO" "DOING")) > (setq c-off (1+ c-off)) > (setq c-on (1+ c-on)))) > (goto-char b1) > (insert (if f1 > (format "[%d%%]" (/ (* 100 c-on) > (max 1 (+ c-on c-off)))) > (format "[%d/%d]" c-on (+ c-on c-off)))) > (and (looking-at "\\[.*?\\]") > (replace-match "")))) > (when (interactive-p) > (message "Checkbox statistics updated %s (%d places)" > (if all "in entire file" "in current outline entry") > cstat))))) > (defadvice org-update-checkbox-count (around wicked activate) > "Fix the built-in checkbox count to understand headlines." > (setq ad-return-value > (wicked/org-update-checkbox-count (ad-get-arg 1)))) > > ------------------------------------------------------------------------ > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode > --------------080605090709000202010801 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit

Jose Robins wrote:
I like working with checkboxes, more than with headlines with a TODO keyword.  Unfortunately, right now checkboxes  are lightweight and so do not enjoy all the privileges enjoyed by headlines - especially clocking in and out (which is very important for me). I wish that regular checkboxes were also allowed to have the same privileges as headlines. Has this idea been discussed before? Were there any decisions one way or the other.

Another option is to have checkboxes on headlines (which I find very intuitive). On one of Sacha Chua's blogs I found a defun to allow cookies to update checkbox count on a parent headline cookie if there were checkboxes on it's subtree headlines. This was given in one of her chapters in her new book that she had posted online http://sachachua.com/notebook/wickedcoolemacs/wc-emacs-07-managing-your-notes.pdf

So I took that and modified it *slightly* - (it had a bug whereby if the item after the subtree list was at the same level as it's parent's parent, the checkbox count would get confused and still keep on counting)... Still there are a few issues.

One more thing I did (to Sacha's code) was to also count headlines with TODO keywords and take that into account while updating the checkbox.
If anyone is interested, here is the code...
;;;_. Update Checkbox count - to allow for checkboxes to be used in headings
;;; Based on code from Sacha Chua
(defun wicked/org-update-checkbox-count (&optional all)
 "Update the checkbox statistics in the current section.
This will find all statistic cookies like [57%] and [6/12] and update
them with the current numbers. With optional prefix argument ALL,
do this for the whole buffer."
 (interactive "P")
 (save-excursion
   ;;declaring and assigning values to a whole bunch of variables
   (let* ((buffer-invisibility-spec (org-inhibit-invisibility))
          ;; assign point to the "beg" variable and
          ;; returning an error in case of error
          (beg (condition-case nil
                   (progn (outline-back-to-heading) (point))
                 (error (point-min))))
          ;; make a marker which will point to the end of the current outline region
          (end   (move-marker
                (make-marker)
                (progn (or (or (outline-get-next-sibling) (progn (goto-char beg) nil))
                           (progn (outline-end-of-subtree) (point))
                           (goto-char (point-max)))
                       (point))))
          (re "\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)")
          (re-box
           "^[ \t]*\\(*+\\|[-+*]\\|[0-9]+[.)]\\) +\\(\\(\\[[- X]\\]\\)\\|TODO\\|DOING\\|DONE\\)")
          b1 e1 f1 c-on c-off lim (cstat 0))
     ;; if called with a prefix argument, "all" will be non-nil; in which case count the checks in the whole buffer
     (when all
       (goto-char (point-min))
       (setq beg (point) end (point-max)))
     (goto-char beg)
     (while (re-search-forward re (marker-position end) t)
       (setq cstat (1+ cstat)
             b1 (match-beginning 0)    ;set b1 to the beginning of the recent search
             e1 (match-end 0)            ;set e1 to the end of the recent re search
             f1 (match-beginning 1)    ;set f1 to the  position of the 1st paranthesized expression
             lim (cond
                  ((org-on-heading-p) (or (outline-get-next-sibling) (goto-char (point-max))) (point))
                  ((org-at-item-p) (org-end-of-item) (point))
                  (t nil))
             lim (marker-position end) ; right now setting lim to the same as end - not sure what the above line is trying to do
             c-on 0 c-off 0)
       (goto-char e1)
       (when lim
         (while (re-search-forward re-box lim t)
           (if (member (match-string 2) '("[ ]" "[-]" "TODO" "DOING"))
               (setq c-off (1+ c-off))
             (setq c-on (1+ c-on))))
         (goto-char b1)
         (insert (if f1
                     (format "[%d%%]" (/ (* 100 c-on)
                                         (max 1 (+ c-on c-off))))
                   (format "[%d/%d]" c-on (+ c-on c-off))))
         (and (looking-at "\\[.*?\\]")
              (replace-match ""))))
     (when (interactive-p)
       (message "Checkbox statistics updated %s (%d places)"
                (if all "in entire file" "in current outline entry")
                cstat)))))
(defadvice org-update-checkbox-count (around wicked activate)
 "Fix the built-in checkbox count to understand headlines."
 (setq ad-return-value
       (wicked/org-update-checkbox-count (ad-get-arg 1))))


_______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
--------------080605090709000202010801-- --===============1158343210== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============1158343210==--