0

I'm implementing a (optional, de-activable) real-time syntax checker. Each time the user types/deletes anything, I want to run my spell-checking funtion :

I tried (add-hook 'post-self-insert-hook 'syntax-check-continuous) but now even when I type in the minibuffer, the function is run.

What would be the good practice for that? An advice after an insert function? An (add-to-list 'before-change-functions 'syntax-check-continuous)?

I'd really like to see existing real-time syntax checker implementations, I don't want to make Emacs behave in a weird way.

  • Take a look at flymake-mode. It can run a compiler or a linter on a buffer from time to time. There's also flyspell-mode (with a variant for prog-mode descendants as well) that runs a spell checker on what you type into a buffer. Both of them ship with Emacs. – DoMiNeLa10 Jul 20 '17 at 15:52
  • But how will those packages know about my language? Apparently (google.com/search?q=flyspell-mode+flymake-mode+faust) they don't. Furthermore, it's not just a syntax check, a build is launched in the background ; lots of things happen. I just want to know how to (message "type!") after each key press in the my-mode buffers. – yPhil Jul 20 '17 at 16:18
2

By default add-hook is global, but you can pass an optional argument to add the hook only for the current buffer. From the add-hook doc string:

(add-hook HOOK FUNCTION &optional APPEND LOCAL)

The optional fourth argument, LOCAL, if non-nil, says to modify the hook’s buffer-local value rather than its global value.

It sounds like you want your mode to add a buffer-local hook when it is enabled. Try:

(add-hook 'post-self-insert-hook 'syntax-check-continuous nil t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.