0

Is there a way to delete the content under selected headers, but not the headers (and subheaders) themselves?

I.e.,

** TOC

*** PART 1: VECTORS AND GRAPHICS

[[https://livebook.manning.com/book/math-for-programmers/chapter-2?origin=product-toc][READ IN LIVEBOOK]]
**** [[https://livebook.manning.com/book/math-for-programmers/chapter-2?origin=product-toc][2DRAWING WITH 2D VECTORS]]

[[https://livebook.manning.com/book/math-for-programmers/chapter-3?origin=product-toc][READ IN LIVEBOOK]]

to

** TOC
*** PART 1: VECTORS AND GRAPHICS
**** [[https://livebook.manning.com/book/math-for-programmers/chapter-2?origin=product-toc][2DRAWING WITH 2D VECTORS]]
1

Here is a way to do that:

I collect each heading, then replace the buffer with just the headings. This also preserves properties on headlines:

(defun strip-headings ()
  (interactive)
  (setf (buffer-string)
    (string-join
     (cl-loop for headline in
          (org-element-map (org-element-parse-buffer) 'headline 'identity)
          collect
          (progn
            (goto-char (org-element-property :begin headline))
            (buffer-substring  (point) (progn (org-end-of-meta-data) (point)))))
     "\n")))
0

It just occurred to me that I can do this with PCRE easily:

perl -ne '/^(?!\*+).*\S+.*/ || print'

I'd still like to see a structural solution that uses org-mode's parse tree, and not regexes.

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.