1

This question already has an answer here:

I'd like to be able to do the following:

* A story about airplanes
** Chapter one
*** # Introduce the main character
Billy was a nice boy etc ...
*** # Set the scene
One day Billy stumbled upon a paper airplane..

In other words, I want to be able to write prose and use headings with their expand/collapse capability to give hints to myself about what I'm trying to say in a given paragraph/section, but when exporting I don't want these to be treated as headings that should be part of the text.

Is this possible?

According to this page[1] lines starting with # are treated as comments. But when they are headings they are still exported.

[1] https://orgmode.org/manual/Comment-lines.html

marked as duplicate by Stefan, Drew, zck, erikstokes, JeanPierre Oct 7 '18 at 9:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Okay, I figured it out:

(defun strip-comment-line (str)
  ; <space> <star>* <space> <hash> <anything> <eol>
  (replace-regexp-in-string "[ ]*[*]*[ ]*#.*$" "" str))

(defun org-remove-comment-headlines (backend)
  "Remove headlines that are comments starting with '#'."
  ; traverse all headings
  (org-map-entries 
    ; call this lambda on each heading
    (lambda ()
      ; re-insert it into the buffer at the current position
      (insert
        ; if it's a comment line strip it
        (strip-comment-line
          ; extract current line from buffer
          (delete-and-extract-region (point-at-bol) (point-at-eol)))))
    nil))

(add-hook 'org-export-before-processing-hook #'org-remove-comment-headlines)
  • Any reason you use delete-and-extract-region instead of just replace-regexp limited to (point-at-bol) (point-at-eol) ? – rpluim Sep 19 '18 at 12:01
  • I didn't know about replace-regexp. All the search/replace type functions I could find operate on strings, so I had to use delete-and-extract-region as a way to obtain the string I needed. – numerodix Sep 20 '18 at 12:04

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