Add enhanced eval-after-load

This commit is contained in:
Tom Willemse 2013-05-31 17:58:07 +02:00
parent 607cc269c5
commit 856660ebda

View file

@ -36,6 +36,37 @@
"~/.emacs.d/vendor-lisp/org/contrib/lisp")) "~/.emacs.d/vendor-lisp/org/contrib/lisp"))
#+END_SRC #+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 * Load other functions
Including all the functions being used here would make this file Including all the functions being used here would make this file
@ -296,10 +327,9 @@
has been loaded. has been loaded.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(eval-after-load "flycheck" (stante-after flycheck
'(progn
(mapc (lambda (c) (delq c flycheck-checkers)) (mapc (lambda (c) (delq c flycheck-checkers))
'(python-pylint python-pyflakes)))) '(python-pylint python-pyflakes)))
#+END_SRC #+END_SRC
* Make ^L look pretty :ppcL: * Make ^L look pretty :ppcL:
@ -395,8 +425,8 @@
module loads. module loads.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(eval-after-load "em-term" (stante-after em-term
'(add-to-list 'eshell-visual-commands "unison")) (add-to-list 'eshell-visual-commands "unison"))
#+END_SRC #+END_SRC
* Disable prompt highlighting in eshell :eshell: * Disable prompt highlighting in eshell :eshell:
@ -537,8 +567,8 @@
only run it after that module has been loaded. only run it after that module has been loaded.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(eval-after-load "jabber" (stante-after jabber
'(remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo)) (remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo))
#+END_SRC #+END_SRC
* Use libnotify for jabber notifications :jabber: * Use libnotify for jabber notifications :jabber:
@ -630,21 +660,12 @@
execution until it is loaded. execution until it is loaded.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun oni:ido-init () (stante-after ido
"Initialization functionn for ido."
(setq ido-ignore-buffers (setq ido-ignore-buffers
(list "^\\` " "^irc\\." "^\\#" "^\\*Customize Option:" (list "^\\` " "^irc\\." "^\\#" "^\\*Customize Option:"
(eval-when-compile (rx (or "*-jabber-roster-*" "*Messages*" "*fsm-debug*"
(regexp-opt "*magit-process*" "*magit-edit-log*" "*Backtrace*"
'("*-jabber-roster-*" "*Ibuffer*")))))
"*Messages*"
"*fsm-debug*"
"*magit-process*"
"*magit-edit-log*"
"*Backtrace*"
"*Ibuffer*"))))))
(eval-after-load "ido" '(oni:ido-init))
#+END_SRC #+END_SRC
* Disable automatic merging in ido :ido: * Disable automatic merging in ido :ido:
@ -759,7 +780,7 @@
run =jedi:setup= when =python-mode= starts to enable it. run =jedi:setup= when =python-mode= starts to enable it.
#+BEGIN_SRC emacs-lisp #+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) (add-hook 'python-mode-hook 'jedi:setup)
#+END_SRC #+END_SRC
@ -1299,8 +1320,7 @@
absolute file names into something nicer. absolute file names into something nicer.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(eval-after-load "emms" (stante-after emms
`(progn
(emms-minimalistic) (emms-minimalistic)
(emms-default-players) (emms-default-players)
@ -1310,7 +1330,7 @@
(require 'emms-mode-line) (require 'emms-mode-line)
(setq emms-mode-line-mode-line-function 'oni:mode-line-current-song) (setq emms-mode-line-mode-line-function 'oni:mode-line-current-song)
(emms-mode-line 1))) (emms-mode-line 1))
#+END_SRC #+END_SRC
* Enable some smartparen keybindings in python :smartparens:python: * Enable some smartparen keybindings in python :smartparens:python:
@ -1382,7 +1402,9 @@
(setq eap-playlist-library "~/music/playlists") (setq eap-playlist-library "~/music/playlists")
#+END_SRC #+END_SRC
* Don't close some more buffers :desktop: * Desktop :desktop:
** Don't close some more buffers
Add some regular expressions to the "don't kill" list of the ~desktop~ Add some regular expressions to the "don't kill" list of the ~desktop~
module. module.
@ -1396,30 +1418,44 @@
- Don't close the IELM buffer. - Don't close the IELM buffer.
#+BEGIN_SRC emacs-lisp #+NAME: desktop-dont-clear
(eval-after-load 'desktop #+BEGIN_SRC emacs-lisp :tangle no
'(setq desktop-clear-preserve-buffers (setq desktop-clear-preserve-buffers
(append '("^++.*" "^dailies$" "^bookmarks.org$" "^contacts.org$" (append (list (rx (and bol (or (and "+" (1+ anything))
"^work$" "^tasks$" "\\*ielm\\*" "\\*magit.*\\*" "dailies" "work" "tasks"
"\\*-jabber-roster-\\*" "\\*scratch-.*\\*" (or "bookmarks.org"
"\\*eshell\\*") "contacts.org")) eol))
desktop-clear-preserve-buffers))) (rx (or "*ielm*" "*-jabber-roster-*" "*eshell*"))
(rx (and "*" (or "magit" "scratch-") (1+ anything)
"*")))
desktop-clear-preserve-buffers))
#+END_SRC #+END_SRC
* Don't save some more buffers :desktop: ** Don't save some more buffers
Add some regular expressions to the "don't save" list of the ~desktop~ Add some regular expressions to the "don't save" list of the ~desktop~
module. module.
#+BEGIN_SRC emacs-lisp #+NAME: desktop-dont-save
(eval-after-load 'desktop #+BEGIN_SRC emacs-lisp :tangle no
'(setq desktop-files-not-to-save (setq desktop-files-not-to-save
(rx (or (regexp "\\(^/[^/:]*:\\|(ftp)$\\)") (rx (or (regexp "\\(^/[^/:]*:\\|(ftp)$\\)")
(and "/" (or "dailies" "tasks" "bookmarks.org" (and "/" (or "dailies" "tasks" "bookmarks.org"
"contacts.org" "work") eol))))) "contacts.org" "work") eol))))
#+END_SRC #+END_SRC
* Add some desktop keybindings :desktop: ** Putting it together
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
<<desktop-dont-clear>>
<<desktop-dont-save>>)
#+END_SRC
** Add some desktop keybindings
As seen [[http://ericjmritz.wordpress.com/2013/05/28/emacs-desktops/][here]]. As seen [[http://ericjmritz.wordpress.com/2013/05/28/emacs-desktops/][here]].