2017-06-08 11:47:56 +02:00
|
|
|
;;; tools/electric-indent/config.el -*- lexical-binding: t; -*-
|
2017-02-20 20:42:37 -05:00
|
|
|
|
|
|
|
;; Smarter, keyword-based electric-indent
|
|
|
|
|
|
|
|
(defvar doom-electric-indent-p nil
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
(defvar-local doom-electric-indent-words '()
|
|
|
|
"TODO")
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-setting! :electric (modes &rest plist)
|
2017-02-20 20:42:37 -05:00
|
|
|
"Declare :words (list of strings) or :chars (lists of chars) in MODES that
|
|
|
|
trigger electric indentation."
|
|
|
|
(declare (indent 1))
|
2017-06-19 00:22:04 +02:00
|
|
|
(let ((modes (doom-enlist (doom-unquote modes)))
|
|
|
|
(chars (doom-unquote (plist-get plist :chars)))
|
|
|
|
(words (doom-unquote (plist-get plist :words))))
|
2017-02-20 20:42:37 -05:00
|
|
|
(when (or chars words)
|
2017-06-19 00:22:04 +02:00
|
|
|
(let ((fn-name (intern (format "doom--init-electric-%s" (mapconcat #'symbol-name modes "-")))))
|
2017-02-20 20:42:37 -05:00
|
|
|
`(progn
|
|
|
|
(defun ,fn-name ()
|
|
|
|
(electric-indent-local-mode +1)
|
2017-06-19 00:22:04 +02:00
|
|
|
,@(if chars `((setq electric-indent-chars ',chars)))
|
|
|
|
,@(if words `((setq doom-electric-indent-words ',words))))
|
2017-04-17 02:17:10 -04:00
|
|
|
(add-hook! ,modes #',fn-name))))))
|
2017-02-20 20:42:37 -05:00
|
|
|
|
2018-05-25 00:46:11 +02:00
|
|
|
;;
|
|
|
|
(after! electric
|
|
|
|
(setq-default 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))))))
|
|
|
|
(add-to-list 'electric-indent-functions #'+electric-indent|char))
|
|
|
|
|