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