2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/emacs-lisp/config.el -*- lexical-binding: t; -*-
|
2015-06-15 09:06:10 +02:00
|
|
|
|
2018-07-31 03:48:45 +02:00
|
|
|
;;
|
|
|
|
;; elisp-mode deferral hack
|
|
|
|
;;
|
|
|
|
|
2018-07-29 17:58:15 +02:00
|
|
|
;; `elisp-mode' is loaded at startup. In order to lazy load its config we need
|
|
|
|
;; to pretend it isn't loaded
|
2018-06-27 22:52:46 +02:00
|
|
|
(delq 'elisp-mode features)
|
2018-07-29 17:58:15 +02:00
|
|
|
;; ...until the first time `emacs-lisp-mode' runs
|
|
|
|
(advice-add #'emacs-lisp-mode :before #'+emacs-lisp|init)
|
2017-02-21 00:46:44 -05:00
|
|
|
|
2018-06-27 18:48:01 +02:00
|
|
|
(defun +emacs-lisp|init (&rest _)
|
2018-07-29 17:58:15 +02:00
|
|
|
;; Some plugins (like yasnippet) run `emacs-lisp-mode' early, to parse some
|
|
|
|
;; elisp. This would prematurely trigger this function. In these cases,
|
|
|
|
;; `emacs-lisp-mode-hook' is let-bound to nil or its hooks are delayed, so if
|
|
|
|
;; we see either, keep pretending elisp-mode isn't loaded.
|
2018-06-27 18:48:01 +02:00
|
|
|
(when (and emacs-lisp-mode-hook (not delay-mode-hooks))
|
2018-07-29 17:58:15 +02:00
|
|
|
;; Otherwise, announce to the world elisp-mode has been loaded, so `after!'
|
|
|
|
;; handlers can respond and configure elisp-mode as expected.
|
2018-06-27 22:52:46 +02:00
|
|
|
(provide 'elisp-mode)
|
2018-06-27 18:48:01 +02:00
|
|
|
(advice-remove #'emacs-lisp-mode #'+emacs-lisp|init)))
|
2017-02-03 19:22:59 -05:00
|
|
|
|
2017-02-09 04:23:25 -05:00
|
|
|
|
2018-06-27 22:52:46 +02:00
|
|
|
;;
|
|
|
|
;; Config
|
|
|
|
;;
|
|
|
|
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.Cask\\'" . emacs-lisp-mode))
|
|
|
|
|
|
|
|
(after! elisp-mode
|
|
|
|
(set-repl-handler! 'emacs-lisp-mode #'+emacs-lisp/repl)
|
|
|
|
(set-eval-handler! 'emacs-lisp-mode #'+emacs-lisp-eval)
|
2018-08-19 00:13:18 +02:00
|
|
|
(set-lookup-handlers! 'emacs-lisp-mode
|
|
|
|
:definition #'elisp-def
|
|
|
|
:documentation #'info-lookup-symbol)
|
2018-07-29 18:23:49 +02:00
|
|
|
(set-docset! 'emacs-lisp-mode "Emacs Lisp")
|
2018-06-27 22:52:46 +02:00
|
|
|
(set-pretty-symbols! 'emacs-lisp-mode :lambda "lambda")
|
|
|
|
(set-rotate-patterns! 'emacs-lisp-mode
|
|
|
|
:symbols '(("t" "nil")
|
|
|
|
("let" "let*")
|
|
|
|
("when" "unless")
|
|
|
|
("append" "prepend")
|
|
|
|
("advice-add" "advice-remove")
|
|
|
|
("add-hook" "remove-hook")
|
|
|
|
("add-hook!" "remove-hook!")))
|
|
|
|
|
2018-07-29 02:54:19 +02:00
|
|
|
;; variable-width indentation is superior in elisp
|
|
|
|
(add-to-list 'doom-detect-indentation-excluded-modes 'emacs-lisp-mode nil #'eq)
|
|
|
|
|
2018-06-27 22:52:46 +02:00
|
|
|
(add-hook! 'emacs-lisp-mode-hook
|
|
|
|
#'(;; 3rd-party functionality
|
|
|
|
auto-compile-on-save-mode doom|enable-delete-trailing-whitespace
|
|
|
|
;; fontification
|
2018-07-29 18:24:14 +02:00
|
|
|
rainbow-delimiters-mode highlight-quoted-mode
|
2018-06-27 22:52:46 +02:00
|
|
|
;; initialization
|
2018-08-08 23:34:41 +02:00
|
|
|
+emacs-lisp|init-imenu))
|
2018-06-27 22:52:46 +02:00
|
|
|
|
2018-08-10 19:39:28 +02:00
|
|
|
(defvar +emacs-lisp--face nil)
|
|
|
|
(defun +emacs-lisp-highlight-vars-and-faces (end)
|
|
|
|
"Match defined variables and functions.
|
|
|
|
|
|
|
|
Functions are differentiated into special forms, built-in functions and
|
|
|
|
library/userland functions"
|
|
|
|
(catch 'matcher
|
|
|
|
(while (re-search-forward "\\_<.+?\\_>" end t)
|
2018-08-20 23:47:31 +02:00
|
|
|
(unless (save-excursion
|
|
|
|
(let ((ppss (syntax-ppss)))
|
|
|
|
(or (nth 3 ppss) (nth 4 ppss))))
|
|
|
|
(let ((symbol (intern-soft (match-string-no-properties 0))))
|
|
|
|
(and (cond ((null symbol) nil)
|
|
|
|
((eq symbol t) nil)
|
|
|
|
((special-variable-p symbol)
|
|
|
|
(setq +emacs-lisp--face 'font-lock-variable-name-face))
|
|
|
|
((and (fboundp symbol)
|
|
|
|
(eq (char-before (match-beginning 0)) ?\())
|
|
|
|
(let ((unaliased (indirect-function symbol t)))
|
|
|
|
(unless (or (macrop unaliased)
|
|
|
|
(special-form-p unaliased))
|
|
|
|
(let (unadvised)
|
|
|
|
(while (not (eq (setq unadvised (ad-get-orig-definition unaliased))
|
|
|
|
(setq unaliased (indirect-function unadvised t)))))
|
|
|
|
unaliased)
|
|
|
|
(setq +emacs-lisp--face
|
|
|
|
(if (subrp unaliased)
|
|
|
|
'font-lock-constant-face
|
|
|
|
'font-lock-function-name-face))))))
|
|
|
|
(throw 'matcher t)))))
|
2018-08-10 19:39:28 +02:00
|
|
|
nil))
|
|
|
|
(eval-when-compile
|
|
|
|
(byte-compile #'+emacs-lisp-highlight-vars-and-faces))
|
|
|
|
|
2018-07-31 03:48:45 +02:00
|
|
|
;; Special fontification for doom
|
2018-07-29 18:24:14 +02:00
|
|
|
(font-lock-add-keywords
|
|
|
|
'emacs-lisp-mode
|
2018-08-10 19:39:28 +02:00
|
|
|
(append `(;; custom Doom cookies
|
|
|
|
("^;;;###\\(autodef\\|if\\)[ \n]" (1 font-lock-warning-face t))
|
|
|
|
;; highlight defined, special variables & functions
|
|
|
|
(+emacs-lisp-highlight-vars-and-faces . +emacs-lisp--face))))
|
2018-06-27 22:52:46 +02:00
|
|
|
|
|
|
|
(defun +emacs-lisp|init-imenu ()
|
|
|
|
"Improve imenu support with better expression regexps and Doom-specific forms."
|
|
|
|
(setq imenu-generic-expression
|
|
|
|
'(("Evil Commands" "^\\s-*(evil-define-\\(?:command\\|operator\\|motion\\) +\\(\\_<[^ ()\n]+\\_>\\)" 1)
|
|
|
|
("Unit tests" "^\\s-*(\\(?:ert-deftest\\|describe\\) +\"\\([^\")]+\\)\"" 1)
|
|
|
|
("Package" "^\\s-*(\\(?:def-\\)?package! +\\(\\_<[^ ()\n]+\\_>\\)" 1)
|
|
|
|
("Settings" "^\\s-*(def-setting! +\\([^ ()\n]+\\)" 1)
|
|
|
|
("Major modes" "^\\s-*(define-derived-mode +\\([^ ()\n]+\\)" 1)
|
|
|
|
("Modelines" "^\\s-*(def-modeline! +\\([^ ()\n]+\\)" 1)
|
|
|
|
("Modeline Segments" "^\\s-*(def-modeline-segment! +\\([^ ()\n]+\\)" 1)
|
|
|
|
("Advice" "^\\s-*(def\\(?:\\(?:ine-\\)?advice\\))")
|
|
|
|
("Modes" "^\\s-*(define-\\(?:global\\(?:ized\\)?-minor\\|generic\\|minor\\)-mode +\\([^ ()\n]+\\)" 1)
|
|
|
|
("Macros" "^\\s-*(\\(?:cl-\\)?def\\(?:ine-compile-macro\\|macro\\) +\\([^ )\n]+\\)" 1)
|
|
|
|
("Inline Functions" "\\s-*(\\(?:cl-\\)?defsubst +\\([^ )\n]+\\)" 1)
|
|
|
|
("Functions" "^\\s-*(\\(?:cl-\\)?def\\(?:un\\|un\\*\\|method\\|generic\\|-memoized!\\) +\\([^ ,)\n]+\\)" 1)
|
2018-08-11 00:37:21 +02:00
|
|
|
("Variables" "^\\s-*(\\(def\\(?:c\\(?:onst\\(?:ant\\)?\\|ustom\\)\\|ine-symbol-macro\\|parameter\\|var\\(?:-local\\)?\\)\\)\\s-+\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)" 2)
|
2018-06-27 22:52:46 +02:00
|
|
|
("Types" "^\\s-*(\\(cl-def\\(?:struct\\|type\\)\\|def\\(?:class\\|face\\|group\\|ine-\\(?:condition\\|error\\|widget\\)\\|package\\|struct\\|t\\(?:\\(?:hem\\|yp\\)e\\)\\)\\)\\s-+'?\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)" 2))))
|
2017-07-17 12:01:05 +02:00
|
|
|
|
2018-06-27 22:52:46 +02:00
|
|
|
(defun +emacs-lisp|disable-flycheck-maybe ()
|
|
|
|
"Disable flycheck-mode if in emacs.d."
|
2018-08-08 23:34:41 +02:00
|
|
|
(when (and flycheck-mode
|
|
|
|
(eq major-mode 'emacs-lisp-mode)
|
|
|
|
(or (not buffer-file-name)
|
|
|
|
(cl-loop for dir in (list doom-emacs-dir doom-private-dir)
|
|
|
|
if (file-in-directory-p buffer-file-name dir)
|
|
|
|
return t)))
|
|
|
|
(flycheck-mode -1)))
|
2018-08-20 23:47:16 +02:00
|
|
|
(add-hook 'flycheck-mode-hook #'+emacs-lisp|disable-flycheck-maybe)
|
|
|
|
|
|
|
|
;; Recenter window after following definition
|
|
|
|
(advice-add #'elisp-def :after #'doom*recenter))
|
2018-06-25 15:43:23 +02:00
|
|
|
|
2017-02-08 02:23:06 -05:00
|
|
|
|
2017-02-03 19:22:59 -05:00
|
|
|
;;
|
|
|
|
;; Plugins
|
|
|
|
;;
|
|
|
|
|
2018-05-25 00:46:11 +02:00
|
|
|
;; `auto-compile'
|
|
|
|
(setq auto-compile-display-buffer nil
|
|
|
|
auto-compile-use-mode-line nil)
|
2017-02-03 19:22:59 -05:00
|
|
|
|
|
|
|
|
2018-05-29 16:00:51 +02:00
|
|
|
;; `macrostep'
|
2018-06-27 22:54:09 +02:00
|
|
|
(when (featurep! :feature evil)
|
|
|
|
(after! macrostep
|
|
|
|
(evil-define-key* 'normal macrostep-keymap
|
|
|
|
(kbd "RET") #'macrostep-expand
|
|
|
|
"e" #'macrostep-expand
|
|
|
|
"u" #'macrostep-collapse
|
|
|
|
"c" #'macrostep-collapse
|
|
|
|
|
|
|
|
[tab] #'macrostep-next-macro
|
|
|
|
"\C-n" #'macrostep-next-macro
|
|
|
|
"J" #'macrostep-next-macro
|
|
|
|
|
|
|
|
[backtab] #'macrostep-prev-macro
|
|
|
|
"K" #'macrostep-prev-macro
|
2018-06-30 02:55:45 +02:00
|
|
|
"\C-p" #'macrostep-prev-macro
|
2018-06-27 22:54:09 +02:00
|
|
|
|
|
|
|
"q" #'macrostep-collapse-all
|
|
|
|
"C" #'macrostep-collapse-all)
|
|
|
|
|
|
|
|
;; `evil-normalize-keymaps' seems to be required for macrostep or it won't
|
|
|
|
;; apply for the very first invocation
|
|
|
|
(add-hook 'macrostep-mode-hook #'evil-normalize-keymaps)))
|
2017-07-15 17:57:44 +02:00
|
|
|
|
2017-04-04 22:19:48 -04:00
|
|
|
|
2017-07-17 11:33:47 +02:00
|
|
|
(def-package! flycheck-cask
|
|
|
|
:when (featurep! :feature syntax-checker)
|
2018-05-25 00:46:11 +02:00
|
|
|
:defer t
|
2017-07-17 11:33:47 +02:00
|
|
|
:init
|
2018-02-19 14:37:32 -05:00
|
|
|
(add-hook! 'emacs-lisp-mode-hook
|
2017-07-17 11:33:47 +02:00
|
|
|
(add-hook 'flycheck-mode-hook #'flycheck-cask-setup nil t)))
|
|
|
|
|
|
|
|
|
2017-04-04 22:19:48 -04:00
|
|
|
;;
|
2018-05-25 00:46:11 +02:00
|
|
|
;; Project modes
|
2017-04-04 22:19:48 -04:00
|
|
|
;;
|
|
|
|
|
|
|
|
(def-project-mode! +emacs-lisp-ert-mode
|
|
|
|
:modes (emacs-lisp-mode)
|
2017-06-19 12:51:11 +02:00
|
|
|
:match "/test[/-].+\\.el$")
|
2018-06-15 03:31:54 +02:00
|
|
|
|
|
|
|
(associate! buttercup-minor-mode
|
|
|
|
:modes (emacs-lisp-mode)
|
|
|
|
:match "/test[/-].+\\.el$")
|
|
|
|
|
|
|
|
(after! buttercup
|
2018-06-15 18:03:11 +02:00
|
|
|
(set-yas-minor-mode! 'buttercup-minor-mode))
|
2018-06-15 03:31:54 +02:00
|
|
|
|