I am trying to implement the auto-indentation snippet posted by @Malabarba in one of the emacs SE questions.
From that post, below is the function that I am trying to add to the post-command-hook
:
(require 'cl-lib) (defun endless/indent-defun () "Indent current defun. Do nothing if mark is active (to avoid deactivaing it), or if buffer is not modified (to avoid creating accidental modifications)." (interactive) (unless (or (region-active-p) buffer-read-only (null (buffer-modified-p))) (let ((l (save-excursion (beginning-of-defun 1) (point))) (r (save-excursion (end-of-defun 1) (point)))) (cl-letf (((symbol-function 'message) #'ignore)) (indent-region l r)))))
But emacs is removing it from that hook as it seems to be causing some error.
If I call the function using M-x, it runs fine and doesn't throw any error; it just doesn't run when executed via the post-command-hook
.
Question: How can I find what's causing the removal of that function from the hook?
I am using the following code to add that function to the hook only for elisp mode:
(defun endless/activate-aggressive-indent () "Locally add `endless/indent-defun' to `post-command-hook'." (add-hook 'post-command-hook #'endless/indent-defun nil 'local)) (add-hook 'emacs-lisp-mode-hook #'endless/activate-aggressive-indent)
post-command-hook
? After you run that code and you inspect the contents ofpost-command-hook
, is the command listed?ignore-errors
. :-)