Ignore unhandled errors in after-change-functions.

Close #184.

If an unhandled error happens in running these functions,
the variable’s value remains nil.  That prevents the error
from happening repeatedly and making Emacs nonfunctional.
This commit is contained in:
Vincent Zhang 2019-06-26 23:12:14 +08:00
parent 944148526f
commit 2360bd543c

View file

@ -264,6 +264,7 @@ Uses `all-the-icons-material' to fetch the icon."
(defun doom-modeline-update-buffer-file-state-icon (&rest _)
"Update the buffer or file state in mode-line."
(setq doom-modeline--buffer-file-state-icon
(ignore-errors
(cond (buffer-read-only
(doom-modeline-buffer-file-state-icon
"lock"
@ -288,7 +289,7 @@ Uses `all-the-icons-material' to fetch the icon."
"vertical_align_center"
"><"
'doom-modeline-warning))
(t ""))))
(t "")))))
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-state-icon)
(add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-state-icon)
(add-hook 'after-save-hook #'doom-modeline-update-buffer-file-state-icon)
@ -327,6 +328,7 @@ Uses `all-the-icons-material' to fetch the icon."
(defun doom-modeline-update-buffer-file-name (&rest _)
"Update buffer file name in mode-line."
(setq doom-modeline--buffer-file-name
(ignore-errors
(save-match-data
(if buffer-file-name
(doom-modeline-buffer-file-name)
@ -336,7 +338,7 @@ Uses `all-the-icons-material' to fetch the icon."
'mode-line-inactive)
'help-echo "Buffer name
mouse-1: Previous buffer\nmouse-3: Next buffer"
'local-map mode-line-buffer-identification-keymap)))))
'local-map mode-line-buffer-identification-keymap))))))
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-name)
(add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-name)
(add-hook 'after-save-hook #'doom-modeline-update-buffer-file-name)