Fix dtrt-indent errors in broken smie modes

Some smie modes throw errors when trying to guess their indentation,
like `nim-mode'. This prevents them from leaving Emacs in a broken
state.
This commit is contained in:
Henrik Lissner 2018-08-30 22:39:03 +02:00
parent bfe7b9f1c4
commit c1fa37245f
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395

View File

@ -216,7 +216,22 @@ savehist file."
#'doom|detect-indentation)
:config
(setq dtrt-indent-verbosity (if doom-debug-mode 2 0))
(add-to-list 'dtrt-indent-hook-generic-mapping-list '(t tab-width)))
(add-to-list 'dtrt-indent-hook-generic-mapping-list '(t tab-width))
(defun doom*fix-broken-smie-modes (orig-fn arg)
"Some smie modes throw errors when trying to guess their indentation, like
`nim-mode'. This prevents them from leaving Emacs in a broken state."
(let ((dtrt-indent-run-after-smie dtrt-indent-run-after-smie))
(cl-letf* ((old-smie-config-guess (symbol-function 'smie-config-guess))
((symbol-function 'smie-config-guess)
(lambda ()
(condition-case e (funcall old-smie-config-guess)
(error (setq dtrt-indent-run-after-smie t)
(message "[WARNING] Indent detection: %s"
(error-message-string e))
(message "")))))) ; warn silently
(funcall orig-fn arg))))
(advice-add #'dtrt-indent-mode :around #'doom*fix-broken-smie-modes))
;; Branching undo
(def-package! undo-tree