2

I want to export my org-mode document, but filter out all the actual content (well, ideally, just show it in the current buffer, but if that's harder to do, export is fine). That is, I want to only see the headlines. Except, the first paragraph after each headline should still be shown. Or, what would be even cooler, if I could use a demarcation such as a horizontal line ("-----") to indicate where it should end.

Basically, I intend these first paragraphs to be short summaries of what follows. (But I dont want to split it into two sub-headings 'summary' and 'content', which is what I've been doing so far.)

Could you help me, give some pointers, or maybe examples for something similar that I could modify? I am sadly not well-versed in emacs lisp.

Thank you!

4
  • You'd be fighting org-mode all the way. Your original sub-heading solution is much better IMO: you can tag the content subheadings as noexport and you are done. Why don't you like it?
    – NickD
    Apr 11, 2019 at 17:37
  • @NickD I didn't like it because it just cluttered my notes so much, each paragraph having two seperate subheadings that had no semantic value. For the export it worked fine though, yeah.
    – horst
    Apr 11, 2019 at 18:06
  • Why would each paragraph have two subheadings? The idea is to have headings for sections, each section consisting of multiple paragraphs: the first paragraph would be under ** Summary, all the subsequent ones in the section would be under ** Contents - or am I misunderstanding? Maybe you could augment your question with an example.
    – NickD
    Apr 11, 2019 at 18:35
  • Uh, yeah, sorry, I meant section, not paragraph.
    – horst
    Apr 12, 2019 at 20:32

1 Answer 1

1

Here are two solutions you can try. The first solution deletes the delimiter and anything after it at the beginning of the export process:

(add-hook 'org-export-before-processing-hook
          (lambda (_backend)
            (let ((hls (org-element-map (org-element-parse-buffer) 'headline
                         (lambda (hl)
                           (org-element-property :begin hl)))))
              (dolist (beg hls)
                (save-excursion
                  (save-restriction
                    (goto-char beg)
                    (org-narrow-to-subtree)
                    (when (re-search-forward "^---*" nil t)
                      (beginning-of-line)
                      (delete-region (point) (point-max)))))))))

In case you want to keep the subtree, change the delete-region expression to:

(delete-region (point) (save-excursion
                         (org-next-visible-heading 1)
                         (point)))

The second solution hides non-summary text from the Org buffer using overlay properties:

(defvar text-summary-overlay-p nil)

(defun toggle-text-summary ()
  (interactive)
  (if text-summary-overlay-p
      (progn (remove-overlays)
             (setq text-summary-overlay-p nil))
    (let ((hls (org-element-map (org-element-parse-buffer) 'headline
                 (lambda (hl)
                   (org-element-property :begin hl)))))
      (dolist (beg hls)
        (save-excursion
          (save-restriction
            (goto-char beg)
            (org-narrow-to-subtree)
            (when (re-search-forward "^---*" nil t)
              (beginning-of-line)
              (overlay-put (make-overlay (point) (point-max))
                           'invisible t)))))
      (setq text-summary-overlay-p t))))
2
  • Hey, thank you so much! The first solution worked well, but somehow only for the first section, it just ignored all the other ones.
    – horst
    Apr 14, 2019 at 15:28
  • And I can't get the overlay to work yet, it just does nothing at the moment. Thanks though! I don't have the time atm, but will look into your code in detail later. Much appreciated. @jagrg
    – horst
    Apr 14, 2019 at 15:29

Your Answer

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

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