post-command-hook vs after-change-functions (was: how to restrict the numbers of chars in a buffer/file)

Uwe Brauer oub at mat.ucm.es
Fri Aug 4 10:02:38 EDT 2006


>>>>> "sjt" == Stephen J Turnbull <stephen at xemacs.org> writes:

>>>>> "Uwe" == Uwe Brauer <oub at mat.ucm.es> writes:
   Uwe> Thanks did not know about that one. Lets see whether I can
   Uwe> manage.

   sjt> For your use case, David's suggestion is far better than mine (I
   sjt> focused on the "file" in "buffer/file").  Something very simple like

   sjt> (defvar uwe-message-limit 155)

   sjt> (lambda (&rest ignored)        ; you may need to have correct
   sjt>                                ; dummy arguments here
   sjt>   (when (> (buffer-size) uwe-message-limit)
   sjt>     (warn "The message buffer has %d characters.
   sjt> You should reduce it to %d characters or less."
   sjt>            (buffer-size) uwe-message-limit)))

Thanks for that. Right your suggestion only worked (as the name of the
hook indicated), when saving a file, while David's suggestion should
work when changes in buffer a performed. However somehow that hook did
not work for me, so I circumvent that difficulty by using the 
post-command-hook.

This reminds me that the old refill.el from Bob Glickstein also used
the after-change-functions hook and that made his code (at that time
some 10 years ago) quite slow. On the other hand Per Abrahamsen's
maniac.el uses post-command-hook and that code runs smoothly. Per even
stated that he should use the after-change-functions but he did not
get it to work.

Another point, as the function is now, only a warning is released when
more that 155 chars a typed. Is there any possibility that (X)Emacs
would just refuse any more char. (I thought of using the error
Funktion but even then I can continue typing.)

Thanks

Uwe 




More information about the XEmacs-Beta mailing list