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,18 +1320,17 @@
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)
(require 'emms-player-mpd) (require 'emms-player-mpd)
(add-to-list 'emms-player-list 'emms-player-mpd) (add-to-list 'emms-player-list 'emms-player-mpd)
(setq emms-player-mpd-music-directory "/mnt/music/mp3") (setq emms-player-mpd-music-directory "/mnt/music/mp3")
(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,52 +1402,68 @@
(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:
Add some regular expressions to the "don't kill" list of the ~desktop~ ** Don't close some more buffers
module.
- Don't close my open jabber buffers, they start with ~+~. Don't Add some regular expressions to the "don't kill" list of the ~desktop~
close the jabber roster buffer either. 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 - Don't close the IELM buffer.
(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 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~ ** Don't save some more buffers
module.
#+BEGIN_SRC emacs-lisp Add some regular expressions to the "don't save" list of the ~desktop~
(eval-after-load 'desktop module.
'(setq desktop-files-not-to-save
(rx (or (regexp "\\(^/[^/:]*:\\|(ftp)$\\)")
(and "/" (or "dailies" "tasks" "bookmarks.org"
"contacts.org" "work") eol)))))
#+END_SRC
* 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 Put it in a =stante-after= call so they only evaluate after ~desktop~
(global-set-key (kbd "C-c d c") 'desktop-clear) has been loaded.
(global-set-key (kbd "C-c d d") 'desktop-change-dir)
(global-set-key (kbd "C-c d s") 'desktop-save) #+BEGIN_SRC emacs-lisp :noweb no-export
#+END_SRC (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]].
#+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: * Improve eol and bol navigation in org-mode :org:navigation: