Reputation: 29534
I have added a function to after-change-functions
list using this code
(defun test-func ()
(message "foo"))
(add-hook 'after-change-functions 'test-func nil t)
Now whenever i change buffer manually, test-func
is getting called. But when i programatically modify the buffer using insert
, the contents of buffer are getting updated, but test-func
is not getting called.
Any pointers on how to activate test-func
everytime buffer is updated?
Update:
I am trying to convert markdown to html and serve that on browser, so that whenever user types some markdown, html will be updated automatically.
Here is original implementation of test-func
(defun impatient-markup-update (&rest args)
"Update html buffer if markup buffer updates."
(save-buffer impatient-markup-buffer)
(with-current-buffer (get-buffer impatient-markup-html-buffer)
(erase-buffer)
(insert (shell-command-to-string
(format "%s %s" impatient-markup-pandoc impatient-markup-buffer)))))
Upvotes: 3
Views: 877
Reputation: 30699
Use sleep-for
after the call to message
, as a test, to see whether you see the message then.
after-change-functions
does not necessarily run your hook in the buffer you expect. And as the doc says:
*Buffer changes made while executing the
after-change-functions
don't call any before-change or after-change functions. That's becauseinhibit-modification-hooks
is temporarily set non-nil.
Check what else is on that hook, etc. IOW, do a little debugging.
Upvotes: 2