From 856660ebdaddd2e71ef52f69d3fab28e2fb3a166 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 31 May 2013 17:58:07 +0200 Subject: [PATCH] Add enhanced eval-after-load --- emacs/init.org | 168 ++++++++++++++++++++++++++++++------------------- 1 file changed, 102 insertions(+), 66 deletions(-) diff --git a/emacs/init.org b/emacs/init.org index 4e1199e..bd4b1d8 100644 --- a/emacs/init.org +++ b/emacs/init.org @@ -36,6 +36,37 @@ "~/.emacs.d/vendor-lisp/org/contrib/lisp")) #+END_SRC +* Enhanced eval-after-load + + [[http://lunaryorn.com/blog/2013/05/31/byte-compiling-eval-after-load/][This post]] has brought to my attention that =eval-after-load= does not + byte compile its contents. It makes sense, but I'd never thought + about it before. + + It offers a better wrapper around it that should speed things up. + + I've modified it a little to suit my stylistic preferences. + + #+BEGIN_SRC emacs-lisp + (defmacro stante-after (feature &rest forms) + "After FEATURE is loaded, evaluate FORMS. + + FEATURE may be an unquoted feature symbol or a file name, see + `eval-after-load'." + (declare (indent 1) (debug t)) + ;; Byte compile the body. If the feature is not available, ignore + ;; warnings. Taken from + ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2012-11/msg01262.html + (let ((loaded (if (symbolp feature) + (require feature nil :no-error) + (load feature :no-error :no-message)))) + `(,(if loaded + 'progn + (message "stante-after: cannot find %s" feature) + 'with-no-warnings) + (eval-after-load ',feature + `(funcall (function ,(lambda () ,@forms))))))) + #+END_SRC + * Load other functions Including all the functions being used here would make this file @@ -296,10 +327,9 @@ has been loaded. #+BEGIN_SRC emacs-lisp - (eval-after-load "flycheck" - '(progn - (mapc (lambda (c) (delq c flycheck-checkers)) - '(python-pylint python-pyflakes)))) + (stante-after flycheck + (mapc (lambda (c) (delq c flycheck-checkers)) + '(python-pylint python-pyflakes))) #+END_SRC * Make ^L look pretty :ppcL: @@ -395,8 +425,8 @@ module loads. #+BEGIN_SRC emacs-lisp - (eval-after-load "em-term" - '(add-to-list 'eshell-visual-commands "unison")) + (stante-after em-term + (add-to-list 'eshell-visual-commands "unison")) #+END_SRC * Disable prompt highlighting in eshell :eshell: @@ -537,8 +567,8 @@ only run it after that module has been loaded. #+BEGIN_SRC emacs-lisp - (eval-after-load "jabber" - '(remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo)) + (stante-after jabber + (remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo)) #+END_SRC * Use libnotify for jabber notifications :jabber: @@ -630,21 +660,12 @@ execution until it is loaded. #+BEGIN_SRC emacs-lisp - (defun oni:ido-init () - "Initialization functionn for ido." + (stante-after ido (setq ido-ignore-buffers (list "^\\` " "^irc\\." "^\\#" "^\\*Customize Option:" - (eval-when-compile - (regexp-opt - '("*-jabber-roster-*" - "*Messages*" - "*fsm-debug*" - "*magit-process*" - "*magit-edit-log*" - "*Backtrace*" - "*Ibuffer*")))))) - - (eval-after-load "ido" '(oni:ido-init)) + (rx (or "*-jabber-roster-*" "*Messages*" "*fsm-debug*" + "*magit-process*" "*magit-edit-log*" "*Backtrace*" + "*Ibuffer*"))))) #+END_SRC * Disable automatic merging in ido :ido: @@ -759,7 +780,7 @@ run =jedi:setup= when =python-mode= starts to enable it. #+BEGIN_SRC emacs-lisp - (eval-after-load "jedi" '(setcar jedi:server-command "python2")) + (stante-after jedi (setcar jedi:server-command "python2")) (add-hook 'python-mode-hook 'jedi:setup) #+END_SRC @@ -1299,18 +1320,17 @@ absolute file names into something nicer. #+BEGIN_SRC emacs-lisp - (eval-after-load "emms" - `(progn - (emms-minimalistic) - (emms-default-players) + (stante-after emms + (emms-minimalistic) + (emms-default-players) - (require 'emms-player-mpd) - (add-to-list 'emms-player-list 'emms-player-mpd) - (setq emms-player-mpd-music-directory "/mnt/music/mp3") + (require 'emms-player-mpd) + (add-to-list 'emms-player-list 'emms-player-mpd) + (setq emms-player-mpd-music-directory "/mnt/music/mp3") - (require 'emms-mode-line) - (setq emms-mode-line-mode-line-function 'oni:mode-line-current-song) - (emms-mode-line 1))) + (require 'emms-mode-line) + (setq emms-mode-line-mode-line-function 'oni:mode-line-current-song) + (emms-mode-line 1)) #+END_SRC * Enable some smartparen keybindings in python :smartparens:python: @@ -1382,52 +1402,68 @@ (setq eap-playlist-library "~/music/playlists") #+END_SRC -* Don't close some more buffers :desktop: +* Desktop :desktop: - Add some regular expressions to the "don't kill" list of the ~desktop~ - module. +** Don't close some more buffers - - Don't close my open jabber buffers, they start with ~+~. Don't - close the jabber roster buffer either. + Add some regular expressions to the "don't kill" list of the ~desktop~ + module. - - Don't close my org tasks files. + - Don't close my open jabber buffers, they start with ~+~. Don't + close the jabber roster buffer either. - - Don't close any of my other ~*scratch-MODE*~ buffers. + - Don't close my org tasks files. - - Don't close the IELM buffer. + - Don't close any of my other ~*scratch-MODE*~ buffers. - #+BEGIN_SRC emacs-lisp - (eval-after-load 'desktop - '(setq desktop-clear-preserve-buffers - (append '("^++.*" "^dailies$" "^bookmarks.org$" "^contacts.org$" - "^work$" "^tasks$" "\\*ielm\\*" "\\*magit.*\\*" - "\\*-jabber-roster-\\*" "\\*scratch-.*\\*" - "\\*eshell\\*") - desktop-clear-preserve-buffers))) - #+END_SRC + - Don't close the IELM buffer. -* Don't save some more buffers :desktop: + #+NAME: desktop-dont-clear + #+BEGIN_SRC emacs-lisp :tangle no + (setq desktop-clear-preserve-buffers + (append (list (rx (and bol (or (and "+" (1+ anything)) + "dailies" "work" "tasks" + (or "bookmarks.org" + "contacts.org")) eol)) + (rx (or "*ielm*" "*-jabber-roster-*" "*eshell*")) + (rx (and "*" (or "magit" "scratch-") (1+ anything) + "*"))) + desktop-clear-preserve-buffers)) + #+END_SRC - Add some regular expressions to the "don't save" list of the ~desktop~ - module. +** Don't save some more buffers - #+BEGIN_SRC emacs-lisp - (eval-after-load 'desktop - '(setq desktop-files-not-to-save - (rx (or (regexp "\\(^/[^/:]*:\\|(ftp)$\\)") - (and "/" (or "dailies" "tasks" "bookmarks.org" - "contacts.org" "work") eol))))) - #+END_SRC + Add some regular expressions to the "don't save" list of the ~desktop~ + module. -* Add some desktop keybindings :desktop: + #+NAME: desktop-dont-save + #+BEGIN_SRC emacs-lisp :tangle no + (setq desktop-files-not-to-save + (rx (or (regexp "\\(^/[^/:]*:\\|(ftp)$\\)") + (and "/" (or "dailies" "tasks" "bookmarks.org" + "contacts.org" "work") eol)))) + #+END_SRC - As seen [[http://ericjmritz.wordpress.com/2013/05/28/emacs-desktops/][here]]. +** Putting it together - #+BEGIN_SRC emacs-lisp - (global-set-key (kbd "C-c d c") 'desktop-clear) - (global-set-key (kbd "C-c d d") 'desktop-change-dir) - (global-set-key (kbd "C-c d s") 'desktop-save) - #+END_SRC + Put it in a =stante-after= call so they only evaluate after ~desktop~ + has been loaded. + + #+BEGIN_SRC emacs-lisp :noweb no-export + (stante-after desktop + <> + <>) + #+END_SRC + +** Add some desktop keybindings + + As seen [[http://ericjmritz.wordpress.com/2013/05/28/emacs-desktops/][here]]. + + #+BEGIN_SRC emacs-lisp + (global-set-key (kbd "C-c d c") 'desktop-clear) + (global-set-key (kbd "C-c d d") 'desktop-change-dir) + (global-set-key (kbd "C-c d s") 'desktop-save) + #+END_SRC * Improve eol and bol navigation in org-mode :org:navigation: