reddit / emacs

TOC for tangled files

bartalemous ยท 2022-10-06 00:34
Hello, There is most likely another better way of accomplishing this, but I made the function below. In case if it is useful to anyone, it goes over an org file and builds and outputs a list of all tangled directives. Like clickable links: https://preview.redd.it/xvek5leyy2s91.png?width=516&format=png&auto=webp&s=2454daf16d8890b3c1f0912c311dda35522a589b It can be used as a poor man's toc. (defun mb/org-insert-tangle-toc () "inserts a list of all the files tangled or about to be tangled." (interactive) (let ((toc nil)) (save-excursion (org-babel-map-src-blocks nil (if-let* ((args (nth 2 (org-babel-get-src-block-info))) (tangle (alist-get :tangle args))) (when (not (equal tangle "no")) (add-to-list 'toc tangle)))) (insert "#+results:\n") (if (not (equal toc nil)) (cl-loop for index from 1 for item in toc do (insert (format "+ [[%s][%s]] \n" (s-replace "/sudo::" "" item) (file-name-nondirectory item)))) (insert ": and there was nothing\n")))))