Move emacs/electric-indent to emacs/electric

This module will later be expanded to customize more of electric's
functionality.
This commit is contained in:
Henrik Lissner 2018-06-15 13:10:00 +02:00
parent 715167bec8
commit c22b3da9f9
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 4 additions and 3 deletions

View file

@ -0,0 +1,25 @@
;;; emacs/electric/autoload.el -*- lexical-binding: t; -*-
;;;###autodef
(defun set-electric! (modes &rest plist)
"Declare :words (list of strings) or :chars (lists of chars) in MODES that
trigger electric indentation."
(declare (indent 1))
(cl-destructuring-bind (&key char words) plist
(when (or chars words)
(let* ((name (mapconcat #'symbol-name modes "-"))
(fn (intern (format "+electric-indent--init-%s" name))))
(fset fn
(lambda () (electric-indent-local-mode +1)
(if chars (setq electric-indent-chars chars))
(if words (setq +electric-indent-words words))))
(dolist (mode modes)
(add-hook (intern (format "%s-hook" mode)) fn-name))))))
;; FIXME obsolete :electric
;;;###autoload
(def-setting! :electric (modes &rest plist)
"Declare :words (list of strings) or :chars (lists of chars) in MODES that
trigger electric indentation."
:obsolete set-electric!
`(set-electric! ,modes ,@plist))

View file

@ -0,0 +1,19 @@
;;; emacs/electric/config.el -*- lexical-binding: t; -*-
;; Smarter, keyword-based electric-indent
(defvar-local +electric-indent-words '()
"The list of electric words. Typing these will trigger reindentation of the
current line.")
;;
(after! electric
(setq-default electric-indent-chars '(?\n ?\^?))
(defun +electric-indent|char (_c)
(when (and (eolp) +electric-indent-words)
(save-excursion
(backward-word)
(looking-at-p (concat "\\<" (regexp-opt +electric-indent-words))))))
(add-to-list 'electric-indent-functions #'+electric-indent|char nil #'eq))