3
$\begingroup$

I love using org-mode to organize my to-do lists, the functionality is amazing, but it suffers from being stuck inside the emacs terminal...

I'm hoping to replicate some basic features into a notebook, specially checklists. I'm looking for something like this, where the cell dingbats are checkboxes and subitems get dynamically tallied:

enter image description here

So my question is:

How to make counters in cells that update based on the count of the checkboxes of their subitems?

$\endgroup$
5
$\begingroup$

It is unclear whether the checklist reflects the total number of boxes checked or the position of the boxes. For example if you only has the second box checked do you want to see [1/2] or [2/2]?

Having said that here is something quick to try:

x = {False, False};

CellPrint@
 TextCell["Tasks", "Subsection", ShowStringCharacters -> False]
CellPrint@
 TextCell[Text@
   Row[{Dynamic@Row[{"[", Total@Boole@x, "/", Length[x], "]"}], 
     "Checklist"}, Spacer[5]], "Item", ShowStringCharacters -> False]
CellPrint@
 TextCell[Text@Row[{Checkbox[Dynamic[x[[1]]]], "task a"}, Spacer[5]], 
  "Subitem", ShowStringCharacters -> False]
CellPrint@
 TextCell[Text@Row[{Checkbox[Dynamic[x[[2]]]], "task b"}, Spacer[5]], 
  "Subitem", ShowStringCharacters -> False]

enter image description here

If you want to make this part of the cell dingbat rather than in the actual cell then:

CellPrint@
 TextCell[Text@Row[{"Checklist"}, Spacer[5]], "Item", 
  ShowStringCharacters -> False, 
  CellDingbat -> 
   ToBoxes@Text@
     Row[{Style["\[FilledSmallSquare]", Alignment -> Baseline, 
        RGBColor[0.8, 0.043, 0.008]], 
       Dynamic@Row[{"[", Total@Boole@x, "/", Length[x], "]"}]}]]

...but I think it is formatted better as is.

Edit

chewFood[numberOfCheckBoxes_] := Module[{x},
  x = ConstantArray[False, numberOfCheckBoxes];
  CellPrint@
   TextCell["Tasks", "Subsection", ShowStringCharacters -> False]; 
  CellPrint@
   TextCell[
    Text@Row[{Dynamic@Row[{"[", Total@Boole@x, "/", Length[x], "]"}], 
       "Checklist"}, Spacer[5]], "Item", 
    ShowStringCharacters -> False];
  CellPrint@
     TextCell[
      Text@Row[{Checkbox[Dynamic[x[[#]]]], 
         "task " <> CharacterRange["a", "z"][[#]]}, Spacer[5]], 
      "Subitem", ShowStringCharacters -> False, 
      ShowGroupOpener -> False] & /@ Range[numberOfCheckBoxes];
  ]

enter image description here

$\endgroup$
  • $\begingroup$ The ordering doesn't matter, if you only have the second box checked, it's still 1/2 total. Also, if one wants to quickly add more item cells the label would change to 1/n... $\endgroup$ – M.R. Jan 13 '15 at 22:06
  • $\begingroup$ if the ordering doesn't matter then the above is ok? $\endgroup$ – Mike Honeychurch Jan 13 '15 at 22:13
  • $\begingroup$ Yes, but it's not dynamically counting the cells underneath... so if i copy past task b into a task c, the Checklist should have [x/3] not [x/2]... $\endgroup$ – M.R. Jan 14 '15 at 0:31
  • $\begingroup$ Did you change x from {False,False} to {False,False,False}`? No offense but you have a 4K rep and need to contribute as well! The answer was intended to get you started. $\endgroup$ – Mike Honeychurch Jan 14 '15 at 0:48
  • $\begingroup$ Thanks! I honestly don't know how to achieve what I want - and it might not be possible... I'm not looking for a function that I have to re-execute, but a "dynamic cell style" for which option+return would duplicate and update everything appropriately. Sorry if the question was too vague! $\endgroup$ – M.R. Jan 14 '15 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.