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

  • 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 '15 at 20:33
  • Yes, exactly like you explained. – Kirill Dubovikov Dec 10 '15 at 8:27

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 ()
  (replace-regexp "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+ " "**** ")
  (replace-regexp "^[0-9]+\\.[0-9]+\\.[0-9]+ " "*** ")
  (replace-regexp "^[0-9]+\\.[0-9]+ " "** ")
  (replace-regexp "^[0-9]+ " "* "))

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.