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

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 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 09 '15 at 20:33
  • Yes, exactly like you explained. – Kirill Dubovikov Dec 10 '15 at 08:27

1 Answers1

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]+ " "* "))
Brian Burns
  • 1,577
  • 14
  • 15