Add a function to extract headlines by tags

This commit is contained in:
Marcus Kammer 2024-02-28 21:09:09 +01:00
parent b3766d804a
commit 5fb99b5180

View file

@ -535,3 +535,18 @@
;; :after org
;; :config
;; (append '((restclient . t)) org-babel-load-languages))
(defun mk/extract-headlines-by-tag (tag)
"Extract headlines from current buffer by TAG."
(interactive "sEnter tag: ")
(save-excursion
(let ((result-buffer (generate-new-buffer (concat "*Extracted Headlines " tag "*"))))
(with-current-buffer result-buffer
(org-mode)
(insert "* Extracted Headlines by Tag: " tag " *\n\n"))
(goto-char (point-min))
(while (re-search-forward (concat "^\\*+\\s-+\\(.*?\\)\\s-+:\\(" tag "\\):") nil t)
(let ((headline (match-string 0)))
(with-current-buffer result-buffer
(insert headline "\n\n"))))
(switch-to-buffer result-buffer))))