*** empty log message ***
[gnus] / lisp / gnus-xmas.el
1 ;;; gnus-xmas.el --- Gnus functions for XEmacs
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'text-props)
29 (eval-when-compile (require 'cl))
30 (defvar menu-bar-mode t)
31
32 (defvar gnus-xmas-glyph-directory nil
33   "*Directory where Gnus logos and icons are located.
34 If this variable is nil, Gnus will try to locate the directory
35 automatically.")
36
37 ;;; Internal variables.
38
39 (defvar gnus-xmas-logo (make-glyph (make-specifier 'image)))
40
41 ;; Don't warn about these undefined variables.
42
43 (defvar gnus-group-mode-hook)
44 (defvar gnus-summary-mode-hook)
45 (defvar gnus-article-mode-hook)
46
47 ;;defined in gnus.el
48 (defvar gnus-active-hashtb)
49 (defvar gnus-article-buffer)
50 (defvar gnus-auto-center-summary)
51 (defvar gnus-buffer-list)
52 (defvar gnus-current-headers)
53 (defvar gnus-level-killed)
54 (defvar gnus-level-zombie)
55 (defvar gnus-newsgroup-bookmarks)
56 (defvar gnus-newsgroup-dependencies)
57 (defvar gnus-newsgroup-selected-overlay)
58 (defvar gnus-newsrc-hashtb)
59 (defvar gnus-read-mark)
60 (defvar gnus-refer-article-method)
61 (defvar gnus-reffed-article-number)
62 (defvar gnus-unread-mark)
63 (defvar gnus-version)
64 (defvar gnus-view-pseudos)
65 (defvar gnus-view-pseudos-separately)
66 (defvar gnus-visual)
67 (defvar gnus-zombie-list)
68 ;;defined in gnus-msg.el
69 (defvar gnus-article-copy)
70 (defvar gnus-check-before-posting)
71 ;;defined in gnus-vis.el
72 (defvar gnus-article-button-face)
73 (defvar gnus-article-mouse-face)
74 (defvar gnus-summary-selected-face)
75 (defvar gnus-group-reading-menu)
76 (defvar gnus-group-group-menu)
77 (defvar gnus-group-misc-menu)
78 (defvar gnus-summary-article-menu)
79 (defvar gnus-summary-thread-menu)
80 (defvar gnus-summary-misc-menu)
81 (defvar gnus-summary-post-menu)
82 (defvar gnus-summary-kill-menu)
83 (defvar gnus-article-article-menu)
84 (defvar gnus-article-treatment-menu)
85 (defvar gnus-mouse-2)
86 (defvar standard-display-table)
87
88 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
89   "You should NEVER use this function.  It is ideologically blasphemous.
90 It is provided only to ease porting of broken FSF Emacs programs."
91   (if (stringp buffer) 
92       nil
93     (map-extents (lambda (extent ignored)
94                    (remove-text-properties 
95                     start end
96                     (list (extent-property extent 'text-prop) nil)
97                     buffer))
98                  buffer start end nil nil 'text-prop)
99     (add-text-properties start end props buffer)))
100
101 (defun gnus-xmas-highlight-selected-summary ()
102   ;; Highlight selected article in summary buffer
103   (if gnus-summary-selected-face
104       (progn
105         (if gnus-newsgroup-selected-overlay
106             (delete-extent gnus-newsgroup-selected-overlay))
107         (setq gnus-newsgroup-selected-overlay 
108               (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
109         (set-extent-face gnus-newsgroup-selected-overlay
110                          gnus-summary-selected-face))))
111
112 (defun gnus-xmas-summary-recenter ()
113   (let* ((top (cond ((< (window-height) 4) 0)
114                     ((< (window-height) 7) 1)
115                     (t 2)))
116          (height (- (window-height) 2))
117          (bottom (save-excursion (goto-char (point-max))
118                                  (forward-line (- height))
119                                  (point)))
120          (window (get-buffer-window (current-buffer))))
121     (and 
122      ;; The user has to want it,
123      gnus-auto-center-summary 
124      ;; the article buffer must be displayed,
125      (get-buffer-window gnus-article-buffer)
126      ;; Set the window start to either `bottom', which is the biggest
127      ;; possible valid number, or the second line from the top,
128      ;; whichever is the least.
129      (set-window-start
130       window (min bottom (save-excursion
131                            (forward-line (- top)) (point)))))))
132
133 (defun gnus-xmas-group-remove-excess-properties ()
134   (let ((end (point))
135         (beg (progn (forward-line -1) (point))))
136     (remove-text-properties (1+ beg) end '(gnus-group nil))
137     (remove-text-properties 
138      beg end 
139      '(gnus-topic nil gnus-topic-level nil gnus-topic-visible nil))
140     (goto-char end)))
141                   
142 (defun gnus-xmas-topic-remove-excess-properties ()
143   (let ((end (point))
144         (beg (progn (forward-line -1) (point))))
145     (remove-text-properties beg end '(gnus-group nil))
146     (goto-char end)))
147
148 (defun gnus-xmas-extent-start-open (point)
149   (map-extents (lambda (extent arg)
150                  (set-extent-property extent 'start-open t))
151                nil point (min (1+ (point)) (point-max))))
152                   
153 (defun gnus-xmas-copy-article-buffer (&optional article-buffer)
154   (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
155   (buffer-disable-undo gnus-article-copy)
156   (or (memq gnus-article-copy gnus-buffer-list)
157       (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
158   (let ((article-buffer (or article-buffer gnus-article-buffer))
159         buf)
160     (if (and (get-buffer article-buffer)
161              (buffer-name (get-buffer article-buffer)))
162         (save-excursion
163           (set-buffer article-buffer)
164           (widen)
165           (setq buf (buffer-substring (point-min) (point-max)))
166           (set-buffer gnus-article-copy)
167           (erase-buffer)
168           (insert (format "%s" buf))))
169     gnus-article-copy))
170
171 (defun gnus-xmas-article-push-button (event)
172   "Check text under the mouse pointer for a callback function.
173 If the text under the mouse pointer has a `gnus-callback' property,
174 call it with the value of the `gnus-data' text property."
175   (interactive "e")
176   (set-buffer (window-buffer (event-window event)))
177   (let* ((pos (event-closest-point event))
178          (data (get-text-property pos 'gnus-data))
179          (fun (get-text-property pos 'gnus-callback)))
180     (if fun (funcall fun data))))
181
182 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
183   (set-extent-endpoints extent start end))
184
185 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
186 (defun gnus-xmas-article-add-button (from to fun &optional data)
187   "Create a button between FROM and TO with callback FUN and data DATA."
188   (and gnus-article-button-face
189        (gnus-overlay-put (gnus-make-overlay from to) 
190                          'face gnus-article-button-face))
191   (add-text-properties 
192    from to
193    (nconc
194     (and gnus-article-mouse-face
195          (list 'mouse-face gnus-article-mouse-face))
196     (list 'gnus-callback fun)
197     (and data (list 'gnus-data data))
198     (list 'highlight t))))
199
200 (defun gnus-xmas-window-top-edge (&optional window)
201   (nth 1 (window-pixel-edges window)))
202
203 (defun gnus-xmas-tree-minimize ()
204   (when (and gnus-tree-minimize-window
205              (not (one-window-p)))
206     (let* ((window-min-height 2)
207            (height (1+ (count-lines (point-min) (point-max))))
208            (min (max (1- window-min-height) height))
209            (tot (if (numberp gnus-tree-minimize-window)
210                     (min gnus-tree-minimize-window min)
211                   min))
212            (win (get-buffer-window (current-buffer)))
213            (wh (and win (1- (window-height win)))))
214       (when (and win
215                  (not (eq tot wh)))
216         (let ((selected (selected-window)))
217           (select-window win)
218           (enlarge-window (- tot wh))
219           (select-window selected))))))
220
221 ;; Select the lowest window on the frame.
222 (defun gnus-xmas-appt-select-lowest-window ()
223   (let* ((lowest-window (selected-window))
224          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
225          (last-window (previous-window))
226          (window-search t))
227     (while window-search
228       (let* ((this-window (next-window))
229              (next-bottom-edge (car (cdr (cdr (cdr 
230                                                (window-pixel-edges 
231                                                 this-window)))))))
232         (if (< bottom-edge next-bottom-edge)
233             (progn
234               (setq bottom-edge next-bottom-edge)
235               (setq lowest-window this-window)))
236
237         (select-window this-window)
238         (if (eq last-window this-window)
239             (progn
240               (select-window lowest-window)
241               (setq window-search nil)))))))
242
243 (defmacro gnus-xmas-menu-add (type &rest menus)
244   `(gnus-xmas-menu-add-1 ',type ',menus))
245 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
246 (put 'gnus-xmas-menu-add 'lisp-indent-hook 1)
247
248 (defun gnus-xmas-menu-add-1 (type menus)
249   (when (and menu-bar-mode
250              (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
251     (while menus
252       (easy-menu-add (symbol-value (pop menus))))))
253
254 (defun gnus-xmas-group-menu-add ()
255   (gnus-xmas-menu-add group
256     gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
257
258 (defun gnus-xmas-summary-menu-add ()
259   (gnus-xmas-menu-add summary
260     gnus-summary-article-menu gnus-summary-thread-menu
261     gnus-summary-misc-menu gnus-summary-post-menu gnus-summary-kill-menu))
262
263 (defun gnus-xmas-article-menu-add ()
264   (gnus-xmas-menu-add article
265     gnus-article-article-menu gnus-article-treatment-menu))
266
267 (defun gnus-xmas-pick-menu-add ()
268   (gnus-xmas-menu-add pick
269     gnus-pick-menu))
270
271 (defun gnus-xmas-binary-menu-add ()
272   (gnus-xmas-menu-add binary
273     gnus-binary-menu))
274
275 (defun gnus-xmas-tree-menu-add ()
276   (gnus-xmas-menu-add tree
277     gnus-tree-menu))
278
279 (defun gnus-xmas-grouplens-menu-add ()
280   (gnus-xmas-menu-add grouplens
281     gnus-grouplens-menu))
282
283 (defun gnus-xmas-read-event-char ()
284   "Get the next event."
285   (let ((event (next-event)))
286     ;; We junk all non-key events.  Is this naughty?
287     (while (not (key-press-event-p event))
288       (setq event (next-event)))
289     (cons (and (key-press-event-p event) 
290               ; (numberp (event-key event))
291                (event-to-character event)) 
292           event)))
293
294 (defun gnus-xmas-seconds-since-epoch (date)
295   "Return a floating point number that says how many seconds have lapsed between Jan 1 12:00:00 1970 and DATE."
296   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
297                         (timezone-parse-date date)))
298          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
299                         (timezone-parse-time
300                          (aref (timezone-parse-date date) 3))))
301          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
302                         (timezone-parse-date "Jan 1 12:00:00 1970")))
303          (tday (- (timezone-absolute-from-gregorian 
304                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
305                   (timezone-absolute-from-gregorian 
306                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
307     (+ (nth 2 ttime)
308        (* (nth 1 ttime) 60)
309        (* (float (nth 0 ttime)) 60 60)
310        (* (float tday) 60 60 24))))
311
312 (defun gnus-xmas-define ()
313   (setq gnus-mouse-2 [button2])
314
315   (or (memq 'underline (list-faces))
316       (and (fboundp 'make-face)
317            (funcall (intern "make-face") 'underline)))
318   ;; Must avoid calling set-face-underline-p directly, because it
319   ;; is a defsubst in emacs19, and will make the .elc files non
320   ;; portable!
321   (or (face-differs-from-default-p 'underline)
322       (funcall (intern "set-face-underline-p") 'underline t))
323
324   (fset 'gnus-make-overlay 'make-extent)
325   (fset 'gnus-overlay-put 'set-extent-property)
326   (fset 'gnus-move-overlay 'gnus-xmas-move-overlay)
327   (fset 'gnus-overlay-end 'extent-end-position)
328   (fset 'gnus-extent-detached-p 'extent-detached-p)
329       
330   (require 'text-props)
331   (if (< emacs-minor-version 14)
332       (fset 'gnus-set-text-properties 'gnus-xmas-set-text-properties))
333
334   (fset 'nnheader-find-file-noselect 'gnus-xmas-find-file-noselect)
335
336   (or (boundp 'standard-display-table) (setq standard-display-table nil))
337
338   (defvar gnus-mouse-face-prop 'highlight)
339
340   (unless (fboundp 'encode-time)
341     (defun encode-time (sec minute hour day month year &optional zone)
342       (let ((seconds
343              (gnus-xmas-seconds-since-epoch
344               (timezone-make-arpa-date 
345                year month day (timezone-make-time-string hour minute sec)
346                zone))))
347         (list (floor (/ seconds (expt 2 16)))
348               (round (mod seconds (expt 2 16)))))))
349       
350   (defun gnus-byte-code (func)
351     "Return a form that can be `eval'ed based on FUNC."
352     (let ((fval (symbol-function func)))
353       (if (byte-code-function-p fval)
354           (list 'funcall fval)
355         (cons 'progn (cdr (cdr fval))))))
356       
357   ;; Fix by "jeff (j.d.) sparkes" <jsparkes@bnr.ca>.
358   (defvar gnus-display-type (device-class)
359     "A symbol indicating the display Emacs is running under.
360 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
361 guesses this display attribute wrongly, either set this variable in
362 your `~/.emacs' or set the resource `Emacs.displayType' in your
363 `~/.Xdefaults'. See also `gnus-background-mode'.
364
365 This is a meta-variable that will affect what default values other
366 variables get.  You would normally not change this variable, but
367 pounce directly on the real variables themselves.")
368
369
370   (fset 'gnus-x-color-values 
371         (if (fboundp 'x-color-values)
372             'x-color-values
373           (lambda (color)
374             (color-instance-rgb-components
375              (make-color-instance color)))))
376     
377   (defvar gnus-background-mode 
378     (let ((bg-resource 
379            (condition-case ()
380                (x-get-resource ".backgroundMode" "BackgroundMode" 'string)
381              (error nil)))
382           (params (frame-parameters)))
383       (cond (bg-resource (intern (downcase bg-resource)))
384             ((and (assq 'background-color params)
385                   (< (apply '+ (gnus-x-color-values
386                                 (cdr (assq 'background-color params))))
387                      (/ (apply '+ (gnus-x-color-values "white")) 3)))
388              'dark)
389             (t 'light)))
390     "A symbol indicating the Emacs background brightness.
391 The symbol should be one of `light' or `dark'.
392 If Emacs guesses this frame attribute wrongly, either set this variable in
393 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
394 `~/.Xdefaults'.
395 See also `gnus-display-type'.
396
397 This is a meta-variable that will affect what default values other
398 variables get.  You would normally not change this variable, but
399 pounce directly on the real variables themselves.")
400   )
401
402
403
404 (defun gnus-xmas-redefine ()
405   "Redefine lots of Gnus functions for XEmacs."
406   (fset 'gnus-summary-make-display-table (lambda () nil))
407   (fset 'gnus-visual-turn-off-edit-menu 'identity)
408   (fset 'gnus-highlight-selected-summary
409         'gnus-xmas-highlight-selected-summary)
410   (fset 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
411   (fset 'gnus-group-remove-excess-properties
412         'gnus-xmas-group-remove-excess-properties)
413   (fset 'gnus-topic-remove-excess-properties
414         'gnus-xmas-topic-remove-excess-properties)
415   (fset 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
416   (fset 'gnus-copy-article-buffer 'gnus-xmas-copy-article-buffer)
417   (fset 'gnus-article-push-button 'gnus-xmas-article-push-button)
418   (fset 'gnus-article-add-button 'gnus-xmas-article-add-button)
419   (fset 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
420   (fset 'gnus-read-event-char 'gnus-xmas-read-event-char)
421   (fset 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
422   (fset 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
423   (fset 'gnus-appt-select-lowest-window 
424         'gnus-xmas-appt-select-lowest-window)
425   (fset 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
426   (fset 'gnus-make-local-hook 'make-local-variable)
427
428   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
429   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
430   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)
431
432   (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add)
433   (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
434   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
435   (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
436
437   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar)
438   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar))
439
440
441 ;;; XEmacs logo and toolbar.
442
443 (defun gnus-xmas-find-glyph-directory ()
444   (or gnus-xmas-glyph-directory ; We have a dir already...
445       (let ((path load-path)
446             dir)
447         ;; We try to find the dir by looking at the load path,
448         ;; stripping away the last component and adding "etc/".
449         (while path
450           (setq dir (concat
451                      (file-name-directory (directory-file-name (car path)))
452                      "etc/gnus/"))
453           (if (and (file-exists-p dir)
454                    (file-directory-p dir)
455                    (file-exists-p (concat dir "gnus-group-exit-icon-up.xpm")))
456               (setq gnus-xmas-glyph-directory dir
457                     path nil)
458             (setq path (cdr path))))
459         gnus-xmas-glyph-directory)))
460
461 (defun gnus-xmas-group-startup-message (&optional x y)
462   "Insert startup message in current buffer."
463   ;; Insert the message.
464   (gnus-xmas-find-glyph-directory)
465   (erase-buffer)
466   (let ((file (and gnus-xmas-glyph-directory
467                    (concat 
468                     (file-name-as-directory gnus-xmas-glyph-directory)
469                     "gnus.xpm"))))
470     (if (and (featurep 'xpm)
471              (not (equal (device-type) 'tty))
472              file (file-exists-p file))
473         (progn
474           (set-glyph-property gnus-xmas-logo 'image file)
475           (set-glyph-image gnus-xmas-logo file 'global 'x)
476
477           (insert " ")
478           (set-extent-begin-glyph (make-extent (point) (point)) gnus-xmas-logo)
479           (goto-char (point-min))
480           (while (not (eobp))
481             (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
482                                  ? ))
483             (forward-line 1))
484           (goto-char (point-min))
485           (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
486                  (wheight (window-height))
487                  (rest (- wheight pheight)))
488             (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
489
490       (insert
491        (format "              %s
492           _    ___ _             _      
493           _ ___ __ ___  __    _ ___     
494           __   _     ___    __  ___     
495               _           ___     _     
496              _  _ __             _      
497              ___   __            _      
498                    __           _       
499                     _      _   _        
500                    _      _    _        
501                       _  _    _         
502                   __  ___               
503                  _   _ _     _          
504                 _   _                   
505               _    _                    
506              _    _                     
507             _                         
508           __                             
509
510
511                ""))
512       ;; And then hack it.
513       (gnus-indent-rigidly (point-min) (point-max) 
514                            (/ (max (- (window-width) (or x 46)) 0) 2))
515       (goto-char (point-min))
516       (forward-line 1)
517       (let* ((pheight (count-lines (point-min) (point-max)))
518              (wheight (window-height))
519              (rest (- wheight pheight)))
520         (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
521     ;; Fontify some.
522     (goto-char (point-min))
523     (and (search-forward "Praxis" nil t)
524          (put-text-property (match-beginning 0) (match-end 0) 'face 'bold))
525     (goto-char (point-min))
526     (let* ((mode-string (gnus-group-set-mode-line)))
527       (setq mode-line-buffer-identification 
528             (list (concat gnus-version (substring (car mode-string) 4))))
529       (set-buffer-modified-p t))))
530
531
532 ;;; The toolbar.
533
534 (defvar gnus-use-toolbar 'default-toolbar
535   "*If nil, do not use a toolbar.
536 If it is non-nil, it must be a toolbar.  The five legal values are
537 `default-toolbar', `top-toolbar', `bottom-toolbar',
538 `right-toolbar', and `left-toolbar'.")
539
540 (defvar gnus-group-toolbar 
541   '([gnus-group-exit-icon gnus-group-exit t "Exit Gnus"]
542     [gnus-group-kill-group-icon gnus-group-kill-group t "Kill group"]
543     [gnus-group-get-new-news-icon gnus-group-get-new-news t "Get new news"]
544     [gnus-group-get-new-news-this-group-icon 
545      gnus-group-get-new-news-this-group t "Get new news in this group"]
546     [gnus-group-catchup-current-icon 
547      gnus-group-catchup-current t "Catchup group"]
548     [gnus-group-describe-group-icon 
549      gnus-group-describe-group t "Describe group"])
550   "The group buffer toolbar.")
551
552 (defvar gnus-summary-toolbar 
553   '([gnus-summary-post-news-icon 
554      gnus-summary-post-news t "Post an article"]
555     [gnus-summary-save-article-file-icon
556      gnus-summary-save-article-file t "Save article in file"]
557     [gnus-summary-save-article-icon
558      gnus-summary-save-article t "Save article"]
559     [gnus-summary-reply-icon 
560      gnus-summary-reply t "Mail a reply"]
561     [gnus-summary-reply-with-original-icon
562      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
563     [gnus-summary-followup-icon 
564      gnus-summary-followup t "Post a followup"]
565     [gnus-summary-followup-with-original-icon
566      gnus-summary-followup-with-original t 
567      "Post a followup and yank the original"]
568     [gnus-uu-decode-uu-icon
569      gnus-uu-decode-uu t "Decode uuencoded articles"]
570     [gnus-uu-post-news-icon 
571      gnus-uu-post-news t "Post an uuencoded article"]
572     [gnus-summary-caesar-message-icon
573      gnus-summary-caesar-message t "Rot 13"]
574     [gnus-summary-cancel-article-icon
575      gnus-summary-cancel-article t "Cancel article"])
576   "The summary buffer toolbar.")
577
578 (defun gnus-xmas-setup-toolbar (bar &optional force)
579   (let ((dir (gnus-xmas-find-glyph-directory))
580         icon up down disabled name)
581     (if (not dir)
582         ()
583       (if (and (not force)
584                (boundp (aref (car bar) 0)))
585           dir
586         (while bar
587           (setq icon (aref (car bar) 0)
588                 name (symbol-name icon)
589                 bar (cdr bar))
590           (setq up (concat dir name "-up.xpm"))
591           (setq down (concat dir name "-down.xpm"))
592           (setq disabled (concat dir name "-disabled.xpm"))
593           (if (not (file-exists-p up))
594               (set icon nil)
595             (set icon (toolbar-make-button-list
596                        up (and (file-exists-p down) down)
597                        (and (file-exists-p disabled) disabled)))))
598         dir))))
599
600 (defun gnus-xmas-setup-group-toolbar ()
601   (and gnus-use-toolbar
602        (gnus-xmas-setup-toolbar gnus-group-toolbar)
603        (set-specifier (symbol-value gnus-use-toolbar)
604                       (cons (current-buffer) gnus-group-toolbar))))
605
606 (defun gnus-xmas-setup-summary-toolbar ()
607   (and gnus-use-toolbar
608        (gnus-xmas-setup-toolbar gnus-summary-toolbar)
609        (set-specifier (symbol-value gnus-use-toolbar)
610                       (cons (current-buffer) gnus-summary-toolbar))))
611
612 ;; Written by Erik Naggum <erik@naggum.no>.
613 ;; Saved by Steve Baur <steve@miranova.com>.
614 (or (fboundp 'insert-file-contents-literally)
615 (defun insert-file-contents-literally (filename &optional visit beg end replace)
616   "Like `insert-file-contents', q.v., but only reads in the file.
617 A buffer may be modified in several ways after reading into the buffer due
618 to advanced Emacs features, such as file-name-handlers, format decoding,
619 find-file-hooks, etc.
620   This function ensures that none of these modifications will take place."
621   (let (                                ; (file-name-handler-alist nil)
622         (format-alist nil)
623         (after-insert-file-functions nil)
624         (find-buffer-file-type-function 
625          (if (fboundp 'find-buffer-file-type)
626              (symbol-function 'find-buffer-file-type)
627            nil)))
628     (unwind-protect
629         (progn
630           (fset 'find-buffer-file-type (lambda (filename) t))
631           (insert-file-contents filename visit beg end replace))
632       (if find-buffer-file-type-function
633           (fset 'find-buffer-file-type find-buffer-file-type-function)
634         (fmakunbound 'find-buffer-file-type))))))
635
636 (defun gnus-xmas-find-file-noselect (filename &optional nowarn rawfile)
637   "Read file FILENAME into a buffer and return the buffer.
638 If a buffer exists visiting FILENAME, return that one, but
639 verify that the file has not changed since visited or saved.
640 The buffer is not selected, just returned to the caller."
641   (setq filename
642         (abbreviate-file-name
643          (expand-file-name filename)))
644   (if (file-directory-p filename)
645       (if find-file-run-dired
646           (dired-noselect filename)
647         (error "%s is a directory." filename))
648     (let* ((buf (get-file-buffer filename))
649            (truename (abbreviate-file-name (file-truename filename)))
650            (number (nthcdr 10 (file-attributes truename)))
651            ;; Find any buffer for a file which has same truename.
652            (other (and (not buf) 
653                        (if (fboundp 'find-buffer-visiting)
654                            (find-buffer-visiting filename)
655                          (get-file-buffer filename))))
656            error)
657       ;; Let user know if there is a buffer with the same truename.
658       (if other
659           (progn
660             (or nowarn
661                 (string-equal filename (buffer-file-name other))
662                 (message "%s and %s are the same file"
663                          filename (buffer-file-name other)))
664             ;; Optionally also find that buffer.
665             (if (or (and (boundp 'find-file-existing-other-name)
666                          find-file-existing-other-name)
667                     find-file-visit-truename)
668                 (setq buf other))))
669       (if buf
670           (or nowarn
671               (verify-visited-file-modtime buf)
672               (cond ((not (file-exists-p filename))
673                      (error "File %s no longer exists!" filename))
674                     ((yes-or-no-p
675                       (if (string= (file-name-nondirectory filename)
676                                    (buffer-name buf))
677                           (format
678                            (if (buffer-modified-p buf)
679                                "File %s changed on disk.  Discard your edits? "
680                              "File %s changed on disk.  Reread from disk? ")
681                            (file-name-nondirectory filename))
682                         (format
683                          (if (buffer-modified-p buf)
684                              "File %s changed on disk.  Discard your edits in %s? "
685                            "File %s changed on disk.  Reread from disk into %s? ")
686                          (file-name-nondirectory filename)
687                          (buffer-name buf))))
688                      (save-excursion
689                        (set-buffer buf)
690                        (revert-buffer t t)))))
691         (save-excursion
692 ;;; The truename stuff makes this obsolete.
693 ;;;       (let* ((link-name (car (file-attributes filename)))
694 ;;;              (linked-buf (and (stringp link-name)
695 ;;;                               (get-file-buffer link-name))))
696 ;;;         (if (bufferp linked-buf)
697 ;;;             (message "Symbolic link to file in buffer %s"
698 ;;;                      (buffer-name linked-buf))))
699           (setq buf (create-file-buffer filename))
700           ;;      (set-buffer-major-mode buf)
701           (set-buffer buf)
702           (erase-buffer)
703           (if rawfile
704               (condition-case ()
705                   (insert-file-contents-literally filename t)
706                 (file-error
707                  ;; Unconditionally set error
708                  (setq error t)))
709             (condition-case ()
710                 (insert-file-contents filename t)
711               (file-error
712                ;; Run find-file-not-found-hooks until one returns non-nil.
713                (or t                    ; (run-hook-with-args-until-success 'find-file-not-found-hooks)
714                    ;; If they fail too, set error.
715                    (setq error t)))))
716           ;; Find the file's truename, and maybe use that as visited name.
717           (setq buffer-file-truename truename)
718           (setq buffer-file-number number)
719           ;; On VMS, we may want to remember which directory in a search list
720           ;; the file was found in.
721           (and (eq system-type 'vax-vms)
722                (let (logical)
723                  (if (string-match ":" (file-name-directory filename))
724                      (setq logical (substring (file-name-directory filename)
725                                               0 (match-beginning 0))))
726                  (not (member logical find-file-not-true-dirname-list)))
727                (setq buffer-file-name buffer-file-truename))
728           (if find-file-visit-truename
729               (setq buffer-file-name
730                     (setq filename
731                           (expand-file-name buffer-file-truename))))
732           ;; Set buffer's default directory to that of the file.
733           (setq default-directory (file-name-directory filename))
734           ;; Turn off backup files for certain file names.  Since
735           ;; this is a permanent local, the major mode won't eliminate it.
736           (and (not (funcall backup-enable-predicate buffer-file-name))
737                (progn
738                  (make-local-variable 'backup-inhibited)
739                  (setq backup-inhibited t)))
740           (if rawfile
741               nil
742             (after-find-file error (not nowarn)))))
743       buf)))
744
745 (defun gnus-xmas-mail-strip-quoted-names (address)
746   "Protect mail-strip-quoted-names from NIL input.
747 XEmacs compatibility workaround."
748   (if (null address)
749       nil
750     (mail-strip-quoted-names address)))
751
752 ;;; gnus-xmas.el ends here