5

I need to convert all nested lists present in buffer to org-mode headers using elisp. How can I do this?

1.2.7.2 Some Header Name -> **** Some Header Name

2
  • 2
    You might have to be more explicit about how the lists are labeled. Are they nested with period-separated numbers, and you want the org-mode indentation level to be the same amount as how many numbers there are in the input?
    – zck
    Dec 9, 2015 at 20:33
  • Yes, exactly like you explained. Dec 10, 2015 at 8:27

1 Answer 1

2

Here's a quick and dirty function to do the conversion - it just looks for lines starting with up to 4 numbers. Paste it into your *scratch* buffer, type C-x C-e after it, switch to the buffer to convert, then enter M-x convert-headers.

(defun convert-headers ()
  (interactive)
  (beginning-of-buffer)
  (replace-regexp "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+ " "**** ")
  (beginning-of-buffer)
  (replace-regexp "^[0-9]+\\.[0-9]+\\.[0-9]+ " "*** ")
  (beginning-of-buffer)
  (replace-regexp "^[0-9]+\\.[0-9]+ " "** ")
  (beginning-of-buffer)
  (replace-regexp "^[0-9]+ " "* "))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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