I do not see direct access to this, which you can do: hook pre-command-hook , if the command is self-insert-command , you can check if the buffer-size does not match the length you need. Alternatively, you can intercept post-self-insert-hook to check if it has reached the size limit, cancel it and print the message. To do this, you need to write minor-mode , which is active in your buffer.
source share