From: Denby Wong
Subject: elisp programming style advice needed (or come shoot fish in a barrel :-)
Date: 
Message-ID: <dnbwongznfqybhg4hmv@slip229.telnet1.QueensU.CA>
Hi, 

I need some advice on how to better/best implement a small change to mode
line updating in emacs.  I tried asking elsewhere but got no response.
Likely because its too dumb but heck I was doing integral calculus
right after they clipped off the afterbirth :) 

What I would like to know is if there is a better way to implement
this idea. I have no idea how to make efficient use of elisp objects
or whether there is a preferred style of programming, so any advice or
comments are appreciated. I'm sure there's something to be
improved/thrashed. Please feel free to comment and give reasons.

How the problem arose:

I was playing with mode lines in the beta (ding) gnus.  Since I have
display-time loaded, if I get mail and the mode line is updated, a
portion of the mode line is shifted off-screen. If I add the following
(from documentation)

          (add-hook 'display-time-hook
                  (lambda ()
                    (setq gnus-mode-non-string-length
                          (+ 21 (length display-time-string)))))

then the mode line will be corrected for the change from "Mail"
appearing but this is only corrected when an event internal to (ding)
gnus triggers an update to the mode line.  Internal mode line updating
appears to driven by "logical" events not temporal one, so if I'm
reading an article and mail comes in, the mode line will update to
include "Mail" but not shift correctly to compensate for the added
length of the display-time display until I leave the article/retrieve
a new one.

It's a small point but I would like the mode line to be correctly
updated when display-time is initiating the updates.  So I wrote this:


(defun gnus-external-mode-line-update (buffer)
"Function to externally update mode lines for gnus buffers."
(if (featurep 'gnus) 
    (condition-case ()
    (cond ((eq buffer 'article)
	   (if (bufferp (get-buffer gnus-article-buffer))
	       (save-excursion
	       (set-buffer gnus-article-buffer) 
	       (gnus-set-mode-line 'article))))
	  ((eq buffer 'summary)
	   (if (bufferp (get-buffer gnus-summary-buffer))
	       (save-excursion
	       (set-buffer gnus-summary-buffer) 
	       (gnus-set-mode-line 'summary))))
	  ((eq buffer 'group)
	   (if (bufferp (get-buffer gnus-group-buffer))
	       (save-excursion
	       (set-buffer gnus-group-buffer) 
	       (gnus-set-mode-line 'group)))))
    (error nil))))

and set the hook this way instead (to be as unobtrusive on (ding) gnus
as possible).

(add-hook 'display-time-hook
	  (lambda () 
	    (if (and (featurep 'gnus) (not (eq gnus-mode-non-string-length 
				   (+ 21 (length display-time-string)))))
		(progn 
		  (setq gnus-mode-non-string-length  
			(+ 21 (length display-time-string)))
		  (mapcar 'gnus-external-mode-line-update gnus-updated-mode-lines)))))


So how bad is this? What would have been the "lisp" way of doing this?
Is this a bad idea all around? If so why?

Thanks,

Denby

--
Denby Wong
c/o ·····@qlink.queensu.ca