From c6693e0299cec3e2466887b596e849790693276c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Sun, 17 May 2015 13:53:48 +0200 Subject: [PATCH] Use file in modes subdirectory for after-load The idea is to use a file named modes/after-load-lisp-mode.org as some thing to be automatically loaded after lisp-mode.el has been loaded. There are some code duplication with starter-kit.org. --- starter-kit-after-load.org | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 starter-kit-after-load.org diff --git a/starter-kit-after-load.org b/starter-kit-after-load.org new file mode 100644 index 000000000..6d78ccc18 --- /dev/null +++ b/starter-kit-after-load.org @@ -0,0 +1,30 @@ +#+TITLE: Starter Kit Automatic After Load +#+OPTIONS: toc:nil num:nil ^:nil + +* Automatic after load + +Use file named modes/after-load-*.org in after-load-mode: +modes/after-load-MODE.org will be load when MODE has been provided. + +#+begin_src emacs-lisp + (let ((modes-dir (expand-file-name "modes" starter-kit-dir))) + (cl-flet ((sk-after-load (base) + (eval-after-load base + (let* ((path (expand-file-name (concat "after-load-" base) modes-dir)) + (literate (concat path ".org")) + (encrypted-org (concat path ".org.gpg")) + (plain (concat path ".el")) + (encrypted-el (concat path ".el.gpg"))) + (cond + ((file-exists-p encrypted-org) `(org-babel-load-file ,encrypted-org)) + ((file-exists-p encrypted-el) `(load ,encrypted-el)) + ((file-exists-p literate) `(org-babel-load-file ,literate)) + ((file-exists-p plain) `(load ,plain)))))) + (base-name (name) + (string-match "after-load-\\(.*?\\)\.\\(org\\(\\.el\\)?\\|el\\)\\(\\.gpg\\)?$" name) + (match-string 1 name))) + (let* ((files (directory-files modes-dir () "after-load-.*\.\\(org\\|el\\)\\(\\.gpg\\)?$")) + (base-name (mapcar #'base-name files)) + (base-single (remove-duplicates base-name :test #'string=))) + (mapc #'sk-after-load base-single)))) +#+end_src