Skip to content

Instantly share code, notes, and snippets.

@kaz-yos
Created January 30, 2017 02:43
Show Gist options
  • Save kaz-yos/7c288e540f7aea838aa33d981eb33445 to your computer and use it in GitHub Desktop.
Save kaz-yos/7c288e540f7aea838aa33d981eb33445 to your computer and use it in GitHub Desktop.
Detect all languages used in org-babel src blocks in a file.
(defun org-babel-get-all-src-block-info ()
"Get information on all src blocks in an org file."
(interactive)
(let ((lst '()))
(save-excursion
;; Go to the beginning of buffer
(beginning-of-buffer)
(while (condition-case err
;; Try to move to the next src block.
(org-next-block nil nil org-babel-src-block-regexp)
;; If user-error is encountered, nil.
;; Otherwise, the evaluation result returns.
(user-error nil))
;; Add information to the list.
(add-to-list 'lst (org-babel-get-src-block-info)))
;; Return list
lst)))
(defun org-babel-extract-lang-from-src-block-info (info)
"Extract language name from src block information.
This is just the car of src block information.
Created to be clear about the intention of the code."
(car info))
(defun org-babel-get-all-src-langs ()
"Get all languages used src blocks."
(interactive)
(mapcar #'org-babel-extract-lang-from-src-block-info
(org-babel-get-all-src-block-info)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment