summaryrefslogtreecommitdiff
path: root/init.el
blob: c131d6b07c33cc172f465e05036dd85b326a9465 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;; This file is but bootstrapping. My real configuration file is
;; located at "jakob.org".

(defun eval-document (path)
  "Tangles and evaluates all Emacs lisp code in the org file
located at PATH."
  (let* ((body-list ())
         (src-block-regexp (concat
                            ;; (1) indentation                 (2) lang
                            "^\\([ \t]*\\)#\\+begin_src[ \t]+\\([^ \f\t\n\r\v]+\\)[ \t]*"
                            ;; (3) switches
                            "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)"
                            ;; (4) header arguments
                            "\\([^\n]*\\)\n"
                            ;; (5) body
                            "\\([^\000]*?\n\\)??[ \t]*#\\+end_src")))
    (with-temp-buffer
      (insert-file-contents path)
      (goto-char (point-min))
      (while (re-search-forward src-block-regexp nil t)
        (let ((lang (match-string 2))
              (args (match-string 4))
              (body (match-string 5)))
          (when (and (or (string= lang "emacs-lisp") (string= lang "elisp"))
                     (not (string-match-p ":tangle\\s-+no" args)))
              (add-to-list 'body-list body)))))
    (let ((buffer (generate-new-buffer "*jakob-tangle-temporary*")))
      (set-buffer buffer)
      (apply 'insert (reverse body-list))
      (eval-buffer)
      (kill-buffer)))
  (message "Successfully evaluated %s" path))

(eval-document "~/.emacs.d/jakob.org")

© 2015 - 2026 Jakob L. Kreuze