I write a lot of text in German and English and I'm getting tired of switching the dictionary of my spell-checker all the time. In true Emacs spirit, I decided to do something about this and dusted off my grandpa's parentheses. The code I wrote guesses the language of the current paragraph and then changes the language in ispell and typo-mode. It also reruns flyspell on the current paragraph, but only on that paragraph because sometimes I also write documents in multiple languages.
All this is working really nicely and I will publish this code after some more testing, so other people can use it, too. However, I want the process of switching languages to be fully automatic so I don't have to think about it at all. This means that my function should run every once in a while during text editing. Perhaps it's overkill to run it on every key stroke but I thought it might be good to run it every time I start a new word, i.e., when I enter a space or newline. Alternatively, it might also be enough to run it only when I enter punctuation marks.
My question: How can I fire off the function when certain characters are inserted in the buffer? Is there a hook for that? Thanks for your help.
FYI: Here is my code: https://github.com/tmalsburg/guess-language.el
post-self-insert-hook
fires after every insert, but could be made to work by doing the check for the character in the hook. – wasamasa Jan 31 '17 at 21:03run-with-idle-timer
andrun-with-timer
. – glucas Jan 31 '17 at 21:19