Replace usages of eval-after-load with with-eval-after-load

`with-eval-after-load` was introduced in Emacs 24.4 and its
usage results in a cleaner code.

`eval-after-load` is considered ill-behaved because it is a function,
not a macro, and thus requires the code inside it to be quoted, which
means that it cannot be byte-compiled. It also accepts only one form,
so if you have more than one, you need to use `progn`.

More details - https://stackoverflow.com/questions/21880139/what-is-with-eval-after-load-in-emacs-lisp
This commit is contained in:
Bozhidar Batsov 2018-09-14 09:50:00 +03:00
parent 0ce648b699
commit cecae9ca19
15 changed files with 145 additions and 160 deletions

View file

@ -137,9 +137,9 @@ by Prelude.")
;; Patch security vulnerability in Emacs versions older than 25.3 ;; Patch security vulnerability in Emacs versions older than 25.3
(when (version< emacs-version "25.3") (when (version< emacs-version "25.3")
(eval-after-load "enriched" (with-eval-after-load "enriched"
'(defun enriched-decode-display-prop (start end &optional param) (defun enriched-decode-display-prop (start end &optional param)
(list start end)))) (list start end))))
(prelude-eval-after-init (prelude-eval-after-init
;; greet the use with some useful tip ;; greet the use with some useful tip

View file

@ -35,31 +35,29 @@
(require 'prelude-lisp) (require 'prelude-lisp)
(prelude-require-packages '(clojure-mode cider)) (prelude-require-packages '(clojure-mode cider))
(eval-after-load 'clojure-mode (with-eval-after-load 'clojure-mode
'(progn (defun prelude-clojure-mode-defaults ()
(defun prelude-clojure-mode-defaults () (subword-mode +1)
(subword-mode +1) (run-hooks 'prelude-lisp-coding-hook))
(run-hooks 'prelude-lisp-coding-hook))
(setq prelude-clojure-mode-hook 'prelude-clojure-mode-defaults) (setq prelude-clojure-mode-hook 'prelude-clojure-mode-defaults)
(add-hook 'clojure-mode-hook (lambda () (add-hook 'clojure-mode-hook (lambda ()
(run-hooks 'prelude-clojure-mode-hook))))) (run-hooks 'prelude-clojure-mode-hook))))
(eval-after-load 'cider (with-eval-after-load 'cider
'(progn (setq nrepl-log-messages t)
(setq nrepl-log-messages t)
(add-hook 'cider-mode-hook 'eldoc-mode) (add-hook 'cider-mode-hook 'eldoc-mode)
(defun prelude-cider-repl-mode-defaults () (defun prelude-cider-repl-mode-defaults ()
(subword-mode +1) (subword-mode +1)
(run-hooks 'prelude-interactive-lisp-coding-hook)) (run-hooks 'prelude-interactive-lisp-coding-hook))
(setq prelude-cider-repl-mode-hook 'prelude-cider-repl-mode-defaults) (setq prelude-cider-repl-mode-hook 'prelude-cider-repl-mode-defaults)
(add-hook 'cider-repl-mode-hook (lambda () (add-hook 'cider-repl-mode-hook (lambda ()
(run-hooks 'prelude-cider-repl-mode-hook))))) (run-hooks 'prelude-cider-repl-mode-hook))))
(provide 'prelude-clojure) (provide 'prelude-clojure)

View file

@ -35,26 +35,25 @@
(require 'prelude-programming) (require 'prelude-programming)
(prelude-require-package 'coffee-mode) (prelude-require-package 'coffee-mode)
(eval-after-load 'coffee-mode (with-eval-after-load 'coffee-mode
'(progn ;; CoffeeScript uses two spaces.
;; CoffeeScript uses two spaces. (setq coffee-tab-width 2)
(setq coffee-tab-width 2)
;; remove the "Generated by CoffeeScript" header ;; remove the "Generated by CoffeeScript" header
(add-to-list 'coffee-args-compile "--no-header") (add-to-list 'coffee-args-compile "--no-header")
(defun prelude-coffee-mode-defaults () (defun prelude-coffee-mode-defaults ()
;; Update the already compiled js on save ;; Update the already compiled js on save
(and (buffer-file-name) (and (buffer-file-name)
(file-exists-p (buffer-file-name)) (file-exists-p (buffer-file-name))
(file-exists-p (coffee-compiled-file-name (buffer-file-name))) (file-exists-p (coffee-compiled-file-name (buffer-file-name)))
(coffee-cos-mode t)) (coffee-cos-mode t))
(subword-mode +1)) (subword-mode +1))
(setq prelude-coffee-mode-hook 'prelude-coffee-mode-defaults) (setq prelude-coffee-mode-hook 'prelude-coffee-mode-defaults)
(add-hook 'coffee-mode-hook (lambda () (add-hook 'coffee-mode-hook (lambda ()
(run-hooks 'prelude-coffee-mode-hook))))) (run-hooks 'prelude-coffee-mode-hook))))
(provide 'prelude-coffee) (provide 'prelude-coffee)
;;; prelude-coffee.el ends here ;;; prelude-coffee.el ends here

View file

@ -71,14 +71,13 @@
(smartparens-strict-mode +1) (smartparens-strict-mode +1)
(whitespace-mode -1))) (whitespace-mode -1)))
(eval-after-load "slime" (with-eval-after-load "slime"
'(progn (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol slime-fuzzy-completion-in-place t
slime-fuzzy-completion-in-place t slime-enable-evaluate-in-emacs t
slime-enable-evaluate-in-emacs t slime-autodoc-use-multiline-p t
slime-autodoc-use-multiline-p t slime-auto-start 'always)
slime-auto-start 'always) (define-key slime-mode-map (kbd "C-c C-s") 'slime-selector))
(define-key slime-mode-map (kbd "C-c C-s") 'slime-selector)))
(provide 'prelude-common-lisp) (provide 'prelude-common-lisp)

View file

@ -32,20 +32,19 @@
;;; Code: ;;; Code:
(eval-after-load 'css-mode (with-eval-after-load 'css-mode
'(progn (prelude-require-packages '(rainbow-mode))
(prelude-require-packages '(rainbow-mode))
(setq css-indent-offset 2) (setq css-indent-offset 2)
(defun prelude-css-mode-defaults () (defun prelude-css-mode-defaults ()
(rainbow-mode +1) (rainbow-mode +1)
(run-hooks 'prelude-prog-mode-hook)) (run-hooks 'prelude-prog-mode-hook))
(setq prelude-css-mode-hook 'prelude-css-mode-defaults) (setq prelude-css-mode-hook 'prelude-css-mode-defaults)
(add-hook 'css-mode-hook (lambda () (add-hook 'css-mode-hook (lambda ()
(run-hooks 'prelude-css-mode-hook))))) (run-hooks 'prelude-css-mode-hook))))
(provide 'prelude-css) (provide 'prelude-css)
;;; prelude-css.el ends here ;;; prelude-css.el ends here

View file

@ -92,17 +92,16 @@ Start `ielm' if it's not already running."
(add-hook 'ielm-mode-hook (lambda () (add-hook 'ielm-mode-hook (lambda ()
(run-hooks 'prelude-ielm-mode-hook))) (run-hooks 'prelude-ielm-mode-hook)))
(eval-after-load "elisp-slime-nav" (with-eval-after-load "elisp-slime-nav"
'(diminish 'elisp-slime-nav-mode)) (diminish 'elisp-slime-nav-mode))
(eval-after-load "rainbow-mode" (with-eval-after-load "rainbow-mode"
'(diminish 'rainbow-mode)) (diminish 'rainbow-mode))
(eval-after-load "eldoc" (with-eval-after-load "eldoc"
'(diminish 'eldoc-mode)) (diminish 'eldoc-mode))
(eval-after-load "ielm" (with-eval-after-load "ielm"
'(progn (define-key ielm-map (kbd "M-(") (prelude-wrap-with "("))
(define-key ielm-map (kbd "M-(") (prelude-wrap-with "(")) (define-key ielm-map (kbd "M-\"") (prelude-wrap-with "\"")))
(define-key ielm-map (kbd "M-\"") (prelude-wrap-with "\""))))
;; enable elisp-slime-nav-mode ;; enable elisp-slime-nav-mode
(dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook)) (dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))

View file

@ -44,9 +44,8 @@
(when (require 'erlang-start nil t) (when (require 'erlang-start nil t)
(eval-after-load 'erlang-mode (with-eval-after-load 'erlang-mode
'(progn (flymake-mode))
(flymake-mode)))
(when (not (null wrangler-path)) (when (not (null wrangler-path))
(add-to-list 'load-path wrangler-path) (add-to-list 'load-path wrangler-path)

View file

@ -44,41 +44,40 @@
(define-key 'help-command (kbd "G") 'godoc) (define-key 'help-command (kbd "G") 'godoc)
(eval-after-load 'go-mode (with-eval-after-load 'go-mode
'(progn (defun prelude-go-mode-defaults ()
(defun prelude-go-mode-defaults () ;; Add to default go-mode key bindings
;; Add to default go-mode key bindings (let ((map go-mode-map))
(let ((map go-mode-map)) (define-key map (kbd "C-c a") 'go-test-current-project) ;; current package, really
(define-key map (kbd "C-c a") 'go-test-current-project) ;; current package, really (define-key map (kbd "C-c m") 'go-test-current-file)
(define-key map (kbd "C-c m") 'go-test-current-file) (define-key map (kbd "C-c .") 'go-test-current-test)
(define-key map (kbd "C-c .") 'go-test-current-test) (define-key map (kbd "C-c b") 'go-run)
(define-key map (kbd "C-c b") 'go-run) (define-key map (kbd "C-h f") 'godoc-at-point))
(define-key map (kbd "C-h f") 'godoc-at-point))
;; Prefer goimports to gofmt if installed ;; Prefer goimports to gofmt if installed
(let ((goimports (executable-find "goimports"))) (let ((goimports (executable-find "goimports")))
(when goimports (when goimports
(setq gofmt-command goimports))) (setq gofmt-command goimports)))
;; gofmt on save ;; gofmt on save
(add-hook 'before-save-hook 'gofmt-before-save nil t) (add-hook 'before-save-hook 'gofmt-before-save nil t)
;; stop whitespace being highlighted ;; stop whitespace being highlighted
(whitespace-toggle-options '(tabs)) (whitespace-toggle-options '(tabs))
;; Company mode settings ;; Company mode settings
(set (make-local-variable 'company-backends) '(company-go)) (set (make-local-variable 'company-backends) '(company-go))
;; El-doc for Go ;; El-doc for Go
(go-eldoc-setup) (go-eldoc-setup)
;; CamelCase aware editing operations ;; CamelCase aware editing operations
(subword-mode +1)) (subword-mode +1))
(setq prelude-go-mode-hook 'prelude-go-mode-defaults) (setq prelude-go-mode-hook 'prelude-go-mode-defaults)
(add-hook 'go-mode-hook (lambda () (add-hook 'go-mode-hook (lambda ()
(run-hooks 'prelude-go-mode-hook))))) (run-hooks 'prelude-go-mode-hook))))
(provide 'prelude-go) (provide 'prelude-go)
;;; prelude-go.el ends here ;;; prelude-go.el ends here

View file

@ -35,18 +35,17 @@
(require 'prelude-programming) (require 'prelude-programming)
(prelude-require-packages '(haskell-mode)) (prelude-require-packages '(haskell-mode))
(eval-after-load 'haskell-mode (with-eval-after-load 'haskell-mode
'(progn (defun prelude-haskell-mode-defaults ()
(defun prelude-haskell-mode-defaults () (subword-mode +1)
(subword-mode +1) (eldoc-mode +1)
(eldoc-mode +1) (haskell-indentation-mode +1)
(haskell-indentation-mode +1) (interactive-haskell-mode +1))
(interactive-haskell-mode +1))
(setq prelude-haskell-mode-hook 'prelude-haskell-mode-defaults) (setq prelude-haskell-mode-hook 'prelude-haskell-mode-defaults)
(add-hook 'haskell-mode-hook (lambda () (add-hook 'haskell-mode-hook (lambda ()
(run-hooks 'prelude-haskell-mode-hook))))) (run-hooks 'prelude-haskell-mode-hook))))
(provide 'prelude-haskell) (provide 'prelude-haskell)

View file

@ -41,17 +41,16 @@
(add-to-list 'auto-mode-alist '("\\.pac\\'" . js2-mode)) (add-to-list 'auto-mode-alist '("\\.pac\\'" . js2-mode))
(add-to-list 'interpreter-mode-alist '("node" . js2-mode)) (add-to-list 'interpreter-mode-alist '("node" . js2-mode))
(eval-after-load 'js2-mode (with-eval-after-load 'js2-mode
'(progn (defun prelude-js-mode-defaults ()
(defun prelude-js-mode-defaults () ;; electric-layout-mode doesn't play nice with smartparens
;; electric-layout-mode doesn't play nice with smartparens (setq-local electric-layout-rules '((?\; . after)))
(setq-local electric-layout-rules '((?\; . after))) (setq mode-name "JS2")
(setq mode-name "JS2") (js2-imenu-extras-mode +1))
(js2-imenu-extras-mode +1))
(setq prelude-js-mode-hook 'prelude-js-mode-defaults) (setq prelude-js-mode-hook 'prelude-js-mode-defaults)
(add-hook 'js2-mode-hook (lambda () (run-hooks 'prelude-js-mode-hook))))) (add-hook 'js2-mode-hook (lambda () (run-hooks 'prelude-js-mode-hook))))
(provide 'prelude-js) (provide 'prelude-js)

View file

@ -37,10 +37,9 @@
;; for case ;; for case
(require 'cl) (require 'cl)
(eval-after-load "company" (with-eval-after-load "company"
'(progn (prelude-require-packages '(company-auctex))
(prelude-require-packages '(company-auctex)) (company-auctex-init))
(company-auctex-init)))
(defcustom prelude-latex-fast-math-entry 'LaTeX-math-mode (defcustom prelude-latex-fast-math-entry 'LaTeX-math-mode
"Method used for fast math symbol entry in LaTeX." "Method used for fast math symbol entry in LaTeX."

View file

@ -41,17 +41,16 @@
(define-key 'help-command (kbd "R") 'yari) (define-key 'help-command (kbd "R") 'yari)
(eval-after-load 'ruby-mode (with-eval-after-load 'ruby-mode
'(progn (defun prelude-ruby-mode-defaults ()
(defun prelude-ruby-mode-defaults () (inf-ruby-minor-mode +1)
(inf-ruby-minor-mode +1) ;; CamelCase aware editing operations
;; CamelCase aware editing operations (subword-mode +1))
(subword-mode +1))
(setq prelude-ruby-mode-hook 'prelude-ruby-mode-defaults) (setq prelude-ruby-mode-hook 'prelude-ruby-mode-defaults)
(add-hook 'ruby-mode-hook (lambda () (add-hook 'ruby-mode-hook (lambda ()
(run-hooks 'prelude-ruby-mode-hook))))) (run-hooks 'prelude-ruby-mode-hook))))
(provide 'prelude-ruby) (provide 'prelude-ruby)
;;; prelude-ruby.el ends here ;;; prelude-ruby.el ends here

View file

@ -44,23 +44,22 @@
(setq rust-format-on-save t) (setq rust-format-on-save t)
(eval-after-load 'rust-mode (with-eval-after-load 'rust-mode
'(progn (add-hook 'rust-mode-hook 'racer-mode)
(add-hook 'rust-mode-hook 'racer-mode) (add-hook 'racer-mode-hook 'eldoc-mode)
(add-hook 'racer-mode-hook 'eldoc-mode) (add-hook 'rust-mode-hook 'cargo-minor-mode)
(add-hook 'rust-mode-hook 'cargo-minor-mode) (add-hook 'rust-mode-hook 'flycheck-rust-setup)
(add-hook 'rust-mode-hook 'flycheck-rust-setup) (add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
(add-hook 'flycheck-mode-hook 'flycheck-rust-setup)
(defun prelude-rust-mode-defaults () (defun prelude-rust-mode-defaults ()
(local-set-key (kbd "C-c C-d") 'racer-describe) (local-set-key (kbd "C-c C-d") 'racer-describe)
;; CamelCase aware editing operations ;; CamelCase aware editing operations
(subword-mode +1)) (subword-mode +1))
(setq prelude-rust-mode-hook 'prelude-rust-mode-defaults) (setq prelude-rust-mode-hook 'prelude-rust-mode-defaults)
(add-hook 'rust-mode-hook (lambda () (add-hook 'rust-mode-hook (lambda ()
(run-hooks 'prelude-rust-mode-hook))))) (run-hooks 'prelude-rust-mode-hook))))
(provide 'prelude-rust) (provide 'prelude-rust)
;;; prelude-rust.el ends here ;;; prelude-rust.el ends here

View file

@ -38,22 +38,21 @@
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode)) (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
(eval-after-load 'typescript-mode (with-eval-after-load 'typescript-mode
'(progn (defun prelude-ts-mode-defaults ()
(defun prelude-ts-mode-defaults () (interactive)
(interactive) (tide-setup)
(tide-setup) (flycheck-mode +1)
(flycheck-mode +1) (setq flycheck-check-syntax-automatically '(save mode-enabled))
(setq flycheck-check-syntax-automatically '(save mode-enabled)) (eldoc-mode +1)
(eldoc-mode +1) (tide-hl-identifier-mode +1))
(tide-hl-identifier-mode +1))
;; formats the buffer before saving ;; formats the buffer before saving
(add-hook 'before-save-hook 'tide-format-before-save) (add-hook 'before-save-hook 'tide-format-before-save)
(setq prelude-ts-mode-hook 'prelude-ts-mode-defaults) (setq prelude-ts-mode-hook 'prelude-ts-mode-defaults)
(add-hook 'typescript-mode-hook (lambda () (run-hooks 'prelude-ts-mode-hook))))) (add-hook 'typescript-mode-hook (lambda () (run-hooks 'prelude-ts-mode-hook))))
(provide 'prelude-ts) (provide 'prelude-ts)

View file

@ -61,13 +61,12 @@
(sp-local-tag "=" "<%= " " %>") (sp-local-tag "=" "<%= " " %>")
(sp-local-tag "#" "<%# " " %>")) (sp-local-tag "#" "<%# " " %>"))
(eval-after-load 'web-mode (with-eval-after-load 'web-mode
'(progn (defun prelude-web-mode-defaults ())
(defun prelude-web-mode-defaults ()) (setq prelude-web-mode-hook 'prelude-web-mode-defaults)
(setq prelude-web-mode-hook 'prelude-web-mode-defaults)
(add-hook 'web-mode-hook (lambda () (add-hook 'web-mode-hook (lambda ()
(run-hooks 'prelude-web-mode-hook))))) (run-hooks 'prelude-web-mode-hook))))
(provide 'prelude-web) (provide 'prelude-web)
;;; prelude-web.el ends here ;;; prelude-web.el ends here