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

Aidan Kehoe kehoea at parhasard.net
Fri Aug 4 10:40:47 EDT 2006


 Ar an ceathrú lá de mí Lúnasa, scríobh Uwe Brauer: 

 > [..] 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.)

(defvar sms-buffer-max-length 155
  "How long the buffer can be before we stop accepting input. ")

(defun truncate-buffer-to-sms-max () 
  "Remove input in the buffer making it longer than `sms-buffer-max-length'"
  (when (> (point-max) (1+ sms-buffer-max-length)) 
    (delete-region (1+ sms-buffer-max-length) (point-max))))

;; You want to add a check that the buffer in question is one you want to
;; truncate to truncate-buffer-to-sms-max before doing this, otherwise every
;; buffer you type a command in will be truncated. 
;; (add-hook 'post-command-hook 'truncate-buffer-to-sms-max)

-- 
Santa Maradona, priez pour moi!




More information about the XEmacs-Beta mailing list