Search code examples
org-mode

Convert lines of text into Todos or Check boxes in org-mode


I'm trying to convert lines of text into Todos or check box items in org-mode. For example, if I have:

Line 1

Line 2

Line 3

I would like to convert that to either

*TODO Line 1

*TODO Line 2

*TODO Line 3

or

  • [ ] Line 1

  • [ ] Line 2

  • [ ] Line 3

I know that C-c - will convert the selected area into a list (source):

  • Line 1

  • Line 2

  • Line 3

But is there any way to convert it into a list with check boxes (or alternatively, lines of Todos?)

Thanks in advance!


Solution

  • You can use this function to make the current line(s) into checkbox(es):

    upd: works on regions too

    (defun org-set-line-checkbox (arg)
      (interactive "P")
      (let ((n (or arg 1)))
        (when (region-active-p)
          (setq n (count-lines (region-beginning)
                               (region-end)))
          (goto-char (region-beginning)))
        (dotimes (i n)
          (beginning-of-line)
          (insert "- [ ] ")
          (forward-line))
        (beginning-of-line)))
    

    So now, starting with:

    Line 1
    Line 2
    Line 3
    

    With C-3 C-c c you get:

    - [ ] Line 1
    - [ ] Line 2
    - [ ] Line 3
    

    Now with C-c C-* you can get:

    * TODO Line 1
    * TODO Line 2
    * TODO Line 3
    

    upd: the built-in way

    Starting with

    Line 1
    Line 2
    Line 3
    

    With C-x h C-u C-c - you get:

    - Line 1
    - Line 2
    - Line 3
    

    After, with C-x h C-u C-c C-x C-b you get:

    - [ ] Line 1
    - [ ] Line 2
    - [ ] Line 3
    

    But this is rather unwieldy, org-set-line-checkbox from above should be faster.