minibuffer

Do you know how to list org-mode source blocks with Emacs Lisp?

September 28, 2023
(org-element-parse-buffer)
(org-element-map (org-element-parse-buffer) 'src-block #'identity)
(org-element-map (org-element-parse-buffer) 'src-block
  (lambda (sb) (org-element-property :language sb)))
;; ("bash" "emacs-lisp")

(org-element-property
 :language
 '(src-block (:language "bash" :value "ls -al")))
;; "bash"

;; (lambda (sb) (org-element-property :language sb))
#+title: Do you know how to list org-mode source blocks with Emacs Lisp?

* foo
** foo level 2

- item 1
- item 2
- item 3

* bar

#+BEGIN_SRC bash
echo foo bar baz
#+END_SRC

* baz

#+BEGIN_SRC emacs-lisp
;; org-element-parse-buffer
;; org-element-map
;; org-element-property
#+END_SRC
(org-data
 nil
 (section ...)
 (headline
  ...
  (headline ...))
 (headline
  ...
  (section
   ...
   (src-block
    (:language "bash"
     :switches nil
     :parameters nil
     :begin 132
     :end 176
     :number-lines nil
     :preserve-indent nil
     :retain-labels t
     :use-labels t
     :label-fmt nil
     :value "echo foo bar baz\n"
     :post-blank 0
     :post-affiliated 132
     :parent #2))))
 (headline
  ...
  (section
   ...
   (src-block
    (:language "emacs-lisp"
     :switches nil
     :parameters nil
     :begin 184
     :end 288
     :number-lines nil
     :preserve-indent nil
     :retain-labels t
     :use-labels t
     :label-fmt nil
     :value ";; org-element-parse-buffer\n;; org-element-map\n;; org-element-property\n"
     :post-blank 0
     :post-affiliated 184
     :parent #2)))))
((src-block
  (:language "bash"
   :switches nil
   :parameters nil
   :begin 132
   :end 176
   :number-lines nil
   :preserve-indent nil
   :retain-labels t
   :use-labels t
   :label-fmt nil
   :value "echo foo bar baz\n"
   :post-blank 0
   :post-affiliated 132
   :parent ...))
 (src-block
  (:language "emacs-lisp"
   :switches nil
   :parameters nil
   :begin 184
   :end 288
   :number-lines nil
   :preserve-indent nil
   :retain-labels t
   :use-labels t
   :label-fmt nil
   :value ";; org-element-parse-buffer\n;; org-element-map\n;; org-element-property\n"
   :post-blank 0
   :post-affiliated 184
   :parent ...)))