doomemacs/modules/tools/electric-indent/config.el
Henrik Lissner c7254e7bdc
Major optimization refactor, across the board
+ enable lexical-scope everywhere (lexical-binding = t): ~5-10% faster
  startup; ~5-20% general boost
+ reduce consing, function calls & garbage collection by preferring
  cl-loop & dolist over lambda closures (for mapc[ar], add-hook, and
  various cl-lib filter/map/reduce functions) -- where possible
+ prefer functions with dedicated opcodes, like assq (see byte-defop's
  in bytecomp.el for more)
+ prefer pcase & cond (faster) over cl-case
+ general refactor for code readability
+ ensure naming & style conventions are adhered to
+ appease byte-compiler by marking unused variables with underscore
+ defer minor mode activation to after-init, emacs-startup or
  window-setup hooks; a customization opportunity for users + ensures
  custom functionality won't interfere with startup.
2017-06-09 00:47:45 +02:00

37 lines
1.2 KiB
EmacsLisp

;;; tools/electric-indent/config.el -*- lexical-binding: t; -*-
;; Smarter, keyword-based electric-indent
(defvar doom-electric-indent-p nil
"TODO")
(defvar-local doom-electric-indent-words '()
"TODO")
(setq electric-indent-chars '(?\n ?\^?))
(defun +electric-indent|char (_c)
(when (and (eolp) doom-electric-indent-words)
(save-excursion
(backward-word)
(looking-at-p
(concat "\\<" (regexp-opt doom-electric-indent-words))))))
(cl-pushnew #'+electric-indent|char electric-indent-functions :test #'eq)
(def-setting! :electric (modes &rest plist)
"Declare :words (list of strings) or :chars (lists of chars) in MODES that
trigger electric indentation."
(declare (indent 1))
(let ((modes (if (listp modes) modes (list modes)))
(chars (plist-get plist :chars))
(words (plist-get plist :words)))
(when (or chars words)
(let ((fn-name (intern (format "doom--electric-%s" (string-join (mapcar #'symbol-name modes) "-")))))
`(progn
(defun ,fn-name ()
(electric-indent-local-mode +1)
,(if chars `(setq electric-indent-chars ',chars))
,(if words `(setq doom-electric-indent-words ',words)))
(add-hook! ,modes #',fn-name))))))