Advertisement
CftfKees2x

Emacs config tangling bootstrapper

Jul 26th, 2023 (edited)
1,580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.80 KB | Software | 0 0
  1. #+PROPERTY: header-args:emacs-lisp :tangle ./tangled.el
  2.  
  3. Welcome to tangling elisp out of org files! I swear it's easier than it sounds.
  4.  
  5. Save this as an org file in your .emacs.d directory, put point in the first block, and use =C-c C-c= to evaluate it.
  6.  
  7. Then you can put your entire init.el in the second code block, and saving this file should create a new file, =tangled.el= with the provided code and your current config. Now break your config up into blocks and sort them with org headlines and text descriptions!
  8.  
  9. Make sure you test that the generated file can be evaluated (=M-x eval-buffer=) and then change the output target in the PROPERTY line at the top to be =./init.el=.
  10.  
  11. #+begin_src emacs-lisp
  12.  
  13.   (org-babel-do-load-languages
  14.    'org-babel-load-languages '((emacs-lisp . t))) ;; have babel highlight elisp
  15.  
  16.   (setq org-confirm-babel-evaluate nil)           ;; C-c C-c to evaluate code blocks without requesting confirmation
  17.  
  18.   ;; string expander for code blocks
  19.   (require 'org-tempo)
  20.  
  21.   ;; Type <el TAB to automatically insert an elisp code block
  22.   ;; it will look like "#+begin_src emacs-lisp" and "#+end_src"
  23.   (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
  24.  
  25.   (defun my/org-babel-tangle-config ()
  26.   "When saving the org file, automatically tangle it into an elisp file without prompting for confirmation."
  27.     (when (string-equal (buffer-file-name)
  28.                         (expand-file-name "~/.emacs.d/config.org")) ; Change this to be whatever you name your org file
  29.       (let ((org-confirm-babel-evaluate nil))
  30.         (org-babel-tangle))))
  31.  
  32.   (add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook #'my/org-babel-tangle-config)))
  33.  
  34. #+end_src
  35.  
  36. You can put your current configuration in here:
  37.  
  38. #+begin_src emacs-lisp
  39.  
  40.   ;; Right here!
  41.  
  42. #+end_src
Tags: emacs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement