Xref: utzoo gnu.emacs:913 comp.emacs:6108 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bbn!jr@bbn.com From: jr@bbn.com (John Robinson) Newsgroups: gnu.emacs,comp.emacs Subject: Re: mail beep Message-ID: <40158@bbn.COM> Date: 18 May 89 21:06:10 GMT References: Sender: news@bbn.COM Reply-To: jr@bbn.com (John Robinson) Distribution: na Organization: BBN Systems and Technologies Corporation, Cambridge MA Lines: 59 In-reply-to: ghh@clarity.princeton.edu (Gilbert Harman) In article , ghh@clarity (Gilbert Harman) writes: >Is there a way to get (display-time) or some other process >to beep when mail first arrives, in addition to displaying >"Mail" in the mode-line? I replied to this once in gnu.emacs, with a buggy suggestion, then mentioned the bug in comp.emacs, which really confused things. The solution came from Dave Lawrence and Cesar Quiros in another context. First, you want the following macro definition; this is so useful you should have it around all the time. (require 'cl) (defmacro save-match-data (&rest body) "Execute the BODY forms, restoring the global value of the match data." (let ((original (gensym))) (list 'let (list (list original '(match-data))) (list 'unwind-protect (cons 'progn body) (list 'store-match-data original))))) (put 'save-match-data 'lisp-indent-hook 0) Given that, redefine display-time-filter in time.el as follows: (defun display-time-filter (proc string) ;; Desired data can't need more than the last 30 chars, ;; so save time by flushing the rest. ;; This way, if we have many different times all collected at once, ;; we can discard all but the last few very fast. (if (> (length string) 30) (setq string (substring string -30))) ;; Now discard all but the very last one. (while (and (> (length string) 4) (string-match "[0-9]+:[0-9][0-9].." string 4)) (setq string (substring string (match-beginning 0)))) (if (string-match "[^0-9][0-9]+:" string) (setq string (substring string 0 (1+ (match-beginning 0))))) ;; Append the date if desired. (if display-time-day-and-date (setq string (concat (substring (current-time-string) 0 11) string))) ;; Check if mail just arrived, and ring the bell (save-match-data (if (and (string-match "Mail" string) (not (string-match "Mail" display-time-string))) (ding t))) ;; Install the new time for display. (setq display-time-string string) ;; Force redisplay of all buffers' mode lines to be considered. (save-excursion (set-buffer (other-buffer))) (set-buffer-modified-p (buffer-modified-p)) ;; Do redisplay right now, if no input pending. (sit-for 0)) This time, I even tried it, and it seems to work. -- /jr, nee John Robinson What a waste it is to lose one's mind--or not jr@bbn.com or bbn!jr to have a mind. How true that is. -Dan Quayle