doom-emacs/modules/emacs/electric/autoload.el

27 lines
1 KiB
EmacsLisp
Raw Normal View History

;;; emacs/electric/autoload.el -*- lexical-binding: t; -*-
;;;###autodef
(defun set-electric! (modes &rest plist)
"Declare that WORDS (list of strings) or CHARS (lists of chars) should trigger
electric indentation.
Enables `electric-indent-local-mode' in MODES.
\(fn MODES &key WORDS CHARS)"
(declare (indent defun))
(dolist (mode (ensure-list modes))
2018-06-21 23:24:00 +00:00
(let ((hook (intern (format "%s-hook" mode)))
2020-10-06 00:52:02 +00:00
(fn (intern (format "+electric--init-%s-h" mode))))
2018-06-21 23:24:00 +00:00
(cond ((null (car-safe plist))
(remove-hook hook fn)
(unintern fn nil))
2020-10-06 00:52:02 +00:00
((fset
fn (lambda ()
(when (eq major-mode mode)
(setq-local electric-indent-inhibit nil)
(cl-destructuring-bind (&key chars words) plist
(electric-indent-local-mode +1)
(if chars (setq-local electric-indent-chars chars))
(if words (setq +electric-indent-words words))))))
2018-06-21 23:24:00 +00:00
(add-hook hook fn))))))