Replace :electric with set-electric-rules!
And general refactor of the emacs/electric-indent module. Also updates (set! :electric ...) references in various :lang modules
This commit is contained in:
parent
f801939ce7
commit
9f0ebe42e8
9 changed files with 39 additions and 33 deletions
25
modules/emacs/electric-indent/autoload.el
Normal file
25
modules/emacs/electric-indent/autoload.el
Normal file
|
@ -0,0 +1,25 @@
|
|||
;;; emacs/electric-indent/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))
|
|
@ -2,37 +2,18 @@
|
|||
|
||||
;; Smarter, keyword-based electric-indent
|
||||
|
||||
(defvar doom-electric-indent-p nil
|
||||
"TODO")
|
||||
|
||||
(defvar-local doom-electric-indent-words '()
|
||||
"TODO")
|
||||
|
||||
(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 (doom-enlist (doom-unquote modes)))
|
||||
(chars (doom-unquote (plist-get plist :chars)))
|
||||
(words (doom-unquote (plist-get plist :words))))
|
||||
(when (or chars words)
|
||||
(let ((fn-name (intern (format "doom--init-electric-%s" (mapconcat #'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))))))
|
||||
(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) doom-electric-indent-words)
|
||||
(when (and (eolp) +electric-indent-words)
|
||||
(save-excursion
|
||||
(backward-word)
|
||||
(looking-at-p
|
||||
(concat "\\<" (regexp-opt doom-electric-indent-words))))))
|
||||
(looking-at-p (concat "\\<" (regexp-opt +electric-indent-words))))))
|
||||
(add-to-list 'electric-indent-functions #'+electric-indent|char nil #'eq))
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ compilation database is present in the project.")
|
|||
c-default-style "doom")
|
||||
|
||||
:config
|
||||
(set! :electric '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\}))
|
||||
(set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\}))
|
||||
|
||||
;;; Better fontification (also see `modern-cpp-font-lock')
|
||||
(add-hook 'c-mode-common-hook #'rainbow-delimiters-mode)
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
:config
|
||||
(when (featurep! :feature syntax-checker)
|
||||
(add-hook 'json-mode-hook #'flycheck-mode))
|
||||
(set! :electric 'json-mode :chars '(?\n ?: ?{ ?})))
|
||||
(set-electric! 'json-mode :chars '(?\n ?: ?{ ?})))
|
||||
|
||||
(def-package! vimrc-mode
|
||||
:mode "\\.?vimperatorrc\\'")
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
(add-hook! 'js2-mode-hook #'(flycheck-mode rainbow-delimiters-mode))
|
||||
|
||||
(set! :electric 'js2-mode :chars '(?\} ?\) ?. ?:))
|
||||
(set-electric! 'js2-mode :chars '(?\} ?\) ?. ?:))
|
||||
(set! :repl 'js2-mode #'+javascript/repl)
|
||||
|
||||
;; Conform switch-case indentation to js2 normal indent
|
||||
|
@ -48,7 +48,7 @@
|
|||
(not (sp-point-in-string-or-comment)))))
|
||||
(map-put magic-mode-alist #'+javascript-jsx-file-p 'rjsx-mode)
|
||||
:config
|
||||
(set! :electric 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
||||
(set-electric! 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
||||
(add-hook! 'rjsx-mode-hook
|
||||
;; jshint doesn't know how to deal with jsx
|
||||
(push 'javascript-jshint flycheck-disabled-checkers))
|
||||
|
@ -65,7 +65,7 @@
|
|||
|
||||
(after! typescript-mode
|
||||
(add-hook! 'typescript-mode-hook #'(flycheck-mode rainbow-delimiters-mode))
|
||||
(set! :electric 'typescript-mode
|
||||
(set-electric! 'typescript-mode
|
||||
:chars '(?\} ?\)) :words '("||" "&&")))
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
(add-hook 'lua-mode-hook #'flycheck-mode)
|
||||
|
||||
(set! :lookup 'lua-mode :documentation 'lua-search-documentation)
|
||||
(set! :electric 'lua-mode :words '("else" "end"))
|
||||
(set-electric! 'lua-mode :words '("else" "end"))
|
||||
(set! :repl 'lua-mode #'+lua/repl)
|
||||
(set-company-backend! 'lua-mode '(company-lua company-yasnippet))
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ is loaded.")
|
|||
(add-hook! 'python-mode-hook #'(flycheck-mode highlight-numbers-mode))
|
||||
|
||||
(set-env! "PYTHONPATH" "PYENV_ROOT")
|
||||
(set! :electric 'python-mode :chars '(?:))
|
||||
(set-electric! 'python-mode :chars '(?:))
|
||||
(set! :repl 'python-mode #'+python/repl)
|
||||
|
||||
(when (executable-find "ipython")
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
:mode "\\.\\(?:pry\\|irb\\)rc\\'"
|
||||
:config
|
||||
(set-company-backend! 'ruby-mode 'company-dabbrev-code)
|
||||
(set! :electric 'ruby-mode :words '("else" "end" "elseif"))
|
||||
(set-electric! 'ruby-mode :words '("else" "end" "elseif"))
|
||||
(set-env! "RBENV_ROOT")
|
||||
(set! :repl 'ruby-mode #'inf-ruby) ; `inf-ruby'
|
||||
(setq ruby-deep-indent-paren t)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
:mode ("/bspwmrc\\'" . sh-mode)
|
||||
:config
|
||||
(add-hook! sh-mode #'(flycheck-mode highlight-numbers-mode))
|
||||
(set! :electric 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;"))
|
||||
(set-electric! 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;"))
|
||||
(set! :repl 'sh-mode #'+sh/repl)
|
||||
|
||||
(setq sh-indent-after-continuation 'always)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue