I use org-mode for planning projects and tasks, etc. Say I am reading a book and I want to track my progress chapter by chapter. I want to create a list of repetitive elements with an incremented number like:

- [ ] chapter 1
- [ ] chapter 2
- [ ] chapter 3

Now, instead of typing out the incremented numbers each time, is there a way to just type the first entry, like - [ ] chapter 1 and then have org-mode complete n additional entries. So if a book has 10 chapters, then orgmode would increment the entry 10 times?

So I was just wondering if there is a way to do this in orgmode or a different package to use, etc? Note that I use Spacemacs.

  • Not that I know of: the text in a list item is arbitrary and I don't think that org mode makes any special effort to decipher it (e.g. the way that it does with table entries in org-table-copy-down). But it's easy enough to write a function that does that and it doesn't have to know anything about org: just insert the text in a counted loop. – NickD May 29 '19 at 22:54

This simple function will do that:

(defun insert-chapters-todo (count)
  (interactive "nChapters count: ")
  (dolist (n (number-sequence 1 count))
    (insert (format "- [ ] chapter %d\n" n))))
| improve this answer | |

I think the traditional way would be to use macros. I'm not a Spacemacs user, but I used to use Vim years ago and remember it has a way of incrementing the number at point (maybe it was C-a to increment and C-x to decrement, but I'm not sure). I'm sure Spacemacs either has the same functionality or there is an existing package that adds it. I would do something like this in Vim:

  • Type the first line - [ ] Chapter 1.
  • Record a macro that yanks and pastes the line and then increments the number: qayyp$<C-a>q (The <C-a> means control-a, I think that's the syntax Vim uses for keys, I don't if Spacemacs uses it or prefers Emacs syntax).
  • Run it as many times as you like.

In Emacs keyboard macros have a counter so this is easy. In vanilla Emacs keybindings you can use C-1 <f3> - [ ] Chapter <f3> <ret> C-5 <f4> to get five chapters. (The C-1 is to start the counter at one, it usually starts at 0.)

| improve this answer | |

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.