set-electric!: fix & improve error handling

This commit is contained in:
Henrik Lissner 2018-06-15 13:29:25 +02:00
parent 3c7c5d5120
commit cccccbb3fd
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -5,16 +5,18 @@
"Declare :words (list of strings) or :chars (lists of chars) in MODES that "Declare :words (list of strings) or :chars (lists of chars) in MODES that
trigger electric indentation." trigger electric indentation."
(declare (indent 1)) (declare (indent 1))
(unless plist
(signal 'wrong-number-of-arguments
(list '(:char :words) plist)))
(cl-destructuring-bind (&key char words) plist (cl-destructuring-bind (&key char words) plist
(when (or chars words) (dolist (mode (doom-enlist modes))
(let* ((name (mapconcat #'symbol-name modes "-")) (let ((fn (intern (format "+electric-indent--init-%s" mode))))
(fn (intern (format "+electric-indent--init-%s" name))))
(fset fn (fset fn
(lambda () (electric-indent-local-mode +1) (lambda ()
(electric-indent-local-mode +1)
(if chars (setq electric-indent-chars chars)) (if chars (setq electric-indent-chars chars))
(if words (setq +electric-indent-words words)))) (if words (setq +electric-indent-words words))))
(dolist (mode modes) (add-hook (intern (format "%s-hook" mode)) fn)))))
(add-hook (intern (format "%s-hook" mode)) fn-name))))))
;; FIXME obsolete :electric ;; FIXME obsolete :electric
;;;###autoload ;;;###autoload