0efa3285a3f4f12c1ab624ccb62c2d2d701369e6
[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 (defvar menu-bar-mode (featurep 'menubar))
30 (require 'messagexmas)
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 (defvar gnus-xmas-logo-color-alist
38   '((flame "#cc3300" "#ff2200")
39     (pine "#c0cc93" "#f8ffb8")
40     (moss "#a1cc93" "#d2ffb8")
41     (irish "#04cc90" "#05ff97")
42     (sky "#049acc" "#05deff")
43     (tin "#6886cc" "#82b6ff")
44     (velvet "#7c68cc" "#8c82ff")
45     (grape "#b264cc" "#cf7df")
46     (labia "#cc64c2" "#fd7dff")
47     (berry "#cc6485" "#ff7db5")
48     (neutral "#b4b4b4" "#878787")
49     (september "#bf9900" "#ffcc00"))
50   "Color alist used for the Gnus logo.")
51
52 (defvar gnus-xmas-logo-color-style 'flame
53   "Color styles used for the Gnus logo.")
54
55 (defvar gnus-xmas-logo-colors
56   (cdr (assq gnus-xmas-logo-color-style gnus-xmas-logo-color-alist))
57   "Colors used for the Gnus logo.")
58
59 (defvar gnus-article-x-face-command
60   (if (featurep 'xface)
61       'gnus-xmas-article-display-xface
62     "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -")
63   "String or function to be executed to display an X-Face header.
64 If it is a string, the command will be executed in a sub-shell
65 asynchronously.  The compressed face will be piped to this command.")
66
67 ;;; Internal variables.
68
69 ;; Don't warn about these undefined variables.
70
71 (defvar gnus-group-mode-hook)
72 (defvar gnus-summary-mode-hook)
73 (defvar gnus-article-mode-hook)
74
75 ;;defined in gnus.el
76 (defvar gnus-active-hashtb)
77 (defvar gnus-article-buffer)
78 (defvar gnus-auto-center-summary)
79 (defvar gnus-buffer-list)
80 (defvar gnus-current-headers)
81 (defvar gnus-level-killed)
82 (defvar gnus-level-zombie)
83 (defvar gnus-newsgroup-bookmarks)
84 (defvar gnus-newsgroup-dependencies)
85 (defvar gnus-newsgroup-selected-overlay)
86 (defvar gnus-newsrc-hashtb)
87 (defvar gnus-read-mark)
88 (defvar gnus-refer-article-method)
89 (defvar gnus-reffed-article-number)
90 (defvar gnus-unread-mark)
91 (defvar gnus-version)
92 (defvar gnus-view-pseudos)
93 (defvar gnus-view-pseudos-separately)
94 (defvar gnus-visual)
95 (defvar gnus-zombie-list)
96 ;;defined in gnus-msg.el
97 (defvar gnus-article-copy)
98 (defvar gnus-check-before-posting)
99 ;;defined in gnus-vis.el
100 (defvar gnus-article-button-face)
101 (defvar gnus-article-mouse-face)
102 (defvar gnus-summary-selected-face)
103 (defvar gnus-group-reading-menu)
104 (defvar gnus-group-group-menu)
105 (defvar gnus-group-misc-menu)
106 (defvar gnus-summary-article-menu)
107 (defvar gnus-summary-thread-menu)
108 (defvar gnus-summary-misc-menu)
109 (defvar gnus-summary-post-menu)
110 (defvar gnus-summary-kill-menu)
111 (defvar gnus-article-article-menu)
112 (defvar gnus-article-treatment-menu)
113 (defvar gnus-mouse-2)
114 (defvar standard-display-table)
115 (defvar gnus-tree-minimize-window)
116
117 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
118   "You should NEVER use this function.  It is ideologically blasphemous.
119 It is provided only to ease porting of broken FSF Emacs programs."
120   (if (stringp buffer)
121       nil
122     (map-extents (lambda (extent ignored)
123                    (remove-text-properties 
124                     start end
125                     (list (extent-property extent 'text-prop) nil)
126                     buffer))
127                  buffer start end nil nil 'text-prop)
128     (gnus-add-text-properties start end props buffer)))
129
130 (defun gnus-xmas-highlight-selected-summary ()
131   ;; Highlight selected article in summary buffer
132   (when gnus-summary-selected-face
133     (when gnus-newsgroup-selected-overlay
134       (delete-extent gnus-newsgroup-selected-overlay))
135     (setq gnus-newsgroup-selected-overlay 
136           (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
137     (set-extent-face gnus-newsgroup-selected-overlay
138                      gnus-summary-selected-face)))
139
140 (defun gnus-xmas-summary-recenter ()
141   "\"Center\" point in the summary window.
142 If `gnus-auto-center-summary' is nil, or the article buffer isn't
143 displayed, no centering will be performed."
144   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
145   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
146   (when gnus-auto-center-summary
147     (let* ((height (if (fboundp 'window-displayed-height)
148                        (window-displayed-height)
149                      (- (window-height) 2)))
150            (top (cond ((< height 4) 0)
151                       ((< height 7) 1)
152                       (t 2)))
153            (bottom (save-excursion (goto-char (point-max))
154                                    (forward-line (- height))
155                                    (point)))
156            (window (get-buffer-window (current-buffer))))
157       (when (get-buffer-window gnus-article-buffer)
158         ;; Only do recentering when the article buffer is displayed,
159         ;; Set the window start to either `bottom', which is the biggest
160         ;; possible valid number, or the second line from the top,
161         ;; whichever is the least.
162         (set-window-start
163          window (min bottom (save-excursion (forward-line (- top)) (point)))))
164       ;; Do horizontal recentering while we're at it.
165       (when (and (get-buffer-window (current-buffer) t)
166                  (not (eq gnus-auto-center-summary 'vertical)))
167         (let ((selected (selected-window)))
168           (select-window (get-buffer-window (current-buffer) t))
169           (gnus-summary-position-point)
170           (gnus-horizontal-recenter)
171           (select-window selected))))))
172
173 (defun gnus-xmas-add-hook (hook function &optional append local)
174   (add-hook hook function))
175
176 (defun gnus-xmas-add-text-properties (start end props &optional object)
177   (add-text-properties start end props object)
178   (put-text-property start end 'start-closed nil object))
179
180 (defun gnus-xmas-put-text-property (start end prop value &optional object)
181   (put-text-property start end prop value object)
182   (put-text-property start end 'start-closed nil object))
183
184 (defun gnus-xmas-extent-start-open (point)
185   (map-extents (lambda (extent arg)
186                  (set-extent-property extent 'start-open t))
187                nil point (min (1+ (point)) (point-max))))
188                   
189 (defun gnus-xmas-article-push-button (event)
190   "Check text under the mouse pointer for a callback function.
191 If the text under the mouse pointer has a `gnus-callback' property,
192 call it with the value of the `gnus-data' text property."
193   (interactive "e")
194   (set-buffer (window-buffer (event-window event)))
195   (let* ((pos (event-closest-point event))
196          (data (get-text-property pos 'gnus-data))
197          (fun (get-text-property pos 'gnus-callback)))
198     (when fun
199       (funcall fun data))))
200
201 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
202   (set-extent-endpoints extent start end))
203
204 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
205 (defun gnus-xmas-article-add-button (from to fun &optional data)
206   "Create a button between FROM and TO with callback FUN and data DATA."
207   (when gnus-article-button-face
208     (gnus-overlay-put (gnus-make-overlay from to)
209                       'face gnus-article-button-face))
210   (gnus-add-text-properties 
211    from to
212    (nconc
213     (and gnus-article-mouse-face
214          (list 'mouse-face gnus-article-mouse-face))
215     (list 'gnus-callback fun)
216     (and data (list 'gnus-data data))
217     (list 'highlight t))))
218
219 (defun gnus-xmas-window-top-edge (&optional window)
220   (nth 1 (window-pixel-edges window)))
221
222 (defun gnus-xmas-tree-minimize ()
223   (when (and gnus-tree-minimize-window
224              (not (one-window-p)))
225     (let* ((window-min-height 2)
226            (height (1+ (count-lines (point-min) (point-max))))
227            (min (max (1- window-min-height) height))
228            (tot (if (numberp gnus-tree-minimize-window)
229                     (min gnus-tree-minimize-window min)
230                   min))
231            (win (get-buffer-window (current-buffer)))
232            (wh (and win (1- (window-height win)))))
233       (when (and win
234                  (not (eq tot wh)))
235         (let ((selected (selected-window)))
236           (select-window win)
237           (enlarge-window (- tot wh))
238           (select-window selected))))))
239
240 ;; Select the lowest window on the frame.
241 (defun gnus-xmas-appt-select-lowest-window ()
242   (let* ((lowest-window (selected-window))
243          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
244          (last-window (previous-window))
245          (window-search t))
246     (while window-search
247       (let* ((this-window (next-window))
248              (next-bottom-edge (car (cdr (cdr (cdr 
249                                                (window-pixel-edges 
250                                                 this-window)))))))
251         (when (< bottom-edge next-bottom-edge)
252           (setq bottom-edge next-bottom-edge)
253           (setq lowest-window this-window))
254
255         (select-window this-window)
256         (when (eq last-window this-window)
257           (select-window lowest-window)
258           (setq window-search nil))))))
259
260 (defmacro gnus-xmas-menu-add (type &rest menus)
261   `(gnus-xmas-menu-add-1 ',type ',menus))
262 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
263
264 (defun gnus-xmas-menu-add-1 (type menus)
265   (when (and menu-bar-mode
266              (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
267     (while menus
268       (easy-menu-add (symbol-value (pop menus))))))
269
270 (defun gnus-xmas-group-menu-add ()
271   (gnus-xmas-menu-add group
272     gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
273
274 (defun gnus-xmas-summary-menu-add ()
275   (gnus-xmas-menu-add summary
276     gnus-summary-misc-menu gnus-summary-kill-menu
277     gnus-summary-article-menu gnus-summary-thread-menu
278     gnus-summary-post-menu ))
279
280 (defun gnus-xmas-article-menu-add ()
281   (gnus-xmas-menu-add article
282     gnus-article-article-menu gnus-article-treatment-menu))
283
284 (defun gnus-xmas-score-menu-add ()
285   (gnus-xmas-menu-add score
286     gnus-score-menu))
287
288 (defun gnus-xmas-pick-menu-add ()
289   (gnus-xmas-menu-add pick
290     gnus-pick-menu))
291
292 (defun gnus-xmas-topic-menu-add ()
293   (gnus-xmas-menu-add topic
294     gnus-topic-menu))
295
296 (defun gnus-xmas-binary-menu-add ()
297   (gnus-xmas-menu-add binary
298     gnus-binary-menu))
299
300 (defun gnus-xmas-tree-menu-add ()
301   (gnus-xmas-menu-add tree
302     gnus-tree-menu))
303
304 (defun gnus-xmas-server-menu-add ()
305   (gnus-xmas-menu-add menu
306     gnus-server-server-menu gnus-server-connections-menu))
307
308 (defun gnus-xmas-browse-menu-add ()
309   (gnus-xmas-menu-add browse
310     gnus-browse-menu))
311
312 (defun gnus-xmas-grouplens-menu-add ()
313   (gnus-xmas-menu-add grouplens
314     gnus-grouplens-menu))
315
316 (defun gnus-xmas-read-event-char ()
317   "Get the next event."
318   (let ((event (next-command-event)))
319     ;; We junk all non-key events.  Is this naughty?
320     (while (not (key-press-event-p event))
321       (setq event (next-command-event)))
322     (cons (and (key-press-event-p event) 
323                (event-to-character event)) 
324           event)))
325
326 (defun gnus-xmas-group-remove-excess-properties ()
327   (let ((end (point))
328         (beg (progn (forward-line -1) (point))))
329     (remove-text-properties (1+ beg) end '(gnus-group nil))
330     (remove-text-properties 
331      beg end 
332      '(gnus-topic nil gnus-topic-level nil gnus-topic-visible nil))
333     (goto-char end)
334     (map-extents 
335      (lambda (e ma)
336        (set-extent-property e 'start-closed t))
337      (current-buffer) beg end)))
338                   
339 (defun gnus-xmas-topic-remove-excess-properties ()
340   (let ((end (point))
341         (beg (progn (forward-line -1) (point))))
342     (remove-text-properties beg end '(gnus-group nil gnus-unread nil))
343     (remove-text-properties (1+ beg) end '(gnus-topic nil))
344     (goto-char end)))
345
346 (defun gnus-xmas-seconds-since-epoch (date)
347   "Return a floating point number that says how many seconds have lapsed between Jan 1 12:00:00 1970 and DATE."
348   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
349                         (timezone-parse-date date)))
350          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
351                         (timezone-parse-time
352                          (aref (timezone-parse-date date) 3))))
353          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
354                         (timezone-parse-date "Jan 1 12:00:00 1970")))
355          (tday (- (timezone-absolute-from-gregorian 
356                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
357                   (timezone-absolute-from-gregorian 
358                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
359     (+ (nth 2 ttime)
360        (* (nth 1 ttime) 60)
361        (* (float (nth 0 ttime)) 60 60)
362        (* (float tday) 60 60 24))))
363
364 (defun gnus-xmas-define ()
365   (setq gnus-mouse-2 [button2])
366
367   (unless (memq 'underline (face-list))
368     (and (fboundp 'make-face)
369          (funcall (intern "make-face") 'underline)))
370   ;; Must avoid calling set-face-underline-p directly, because it
371   ;; is a defsubst in emacs19, and will make the .elc files non
372   ;; portable!
373   (unless (face-differs-from-default-p 'underline)
374     (funcall (intern "set-face-underline-p") 'underline t))
375
376   (fset 'gnus-make-overlay 'make-extent)
377   (fset 'gnus-overlay-put 'set-extent-property)
378   (fset 'gnus-move-overlay 'gnus-xmas-move-overlay)
379   (fset 'gnus-overlay-end 'extent-end-position)
380   (fset 'gnus-extent-detached-p 'extent-detached-p)
381   (fset 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
382   (fset 'gnus-put-text-property 'gnus-xmas-put-text-property)
383       
384   (require 'text-props)
385   (when (< emacs-minor-version 14)
386     (fset 'gnus-set-text-properties 'gnus-xmas-set-text-properties))
387
388   (unless (boundp 'standard-display-table)
389     (setq standard-display-table nil))
390
391   (defvar gnus-mouse-face-prop 'highlight)
392
393   (unless (fboundp 'encode-time)
394     (defun encode-time (sec minute hour day month year &optional zone)
395       (let ((seconds
396              (gnus-xmas-seconds-since-epoch
397               (timezone-make-arpa-date 
398                year month day (timezone-make-time-string hour minute sec)
399                zone))))
400         (list (floor (/ seconds (expt 2 16)))
401               (round (mod seconds (expt 2 16)))))))
402       
403   (defun gnus-byte-code (func)
404     "Return a form that can be `eval'ed based on FUNC."
405     (let ((fval (symbol-function func)))
406       (if (compiled-function-p fval)
407           (list 'funcall fval)
408         (cons 'progn (cdr (cdr fval))))))
409
410   (fset 'gnus-x-color-values 
411         (if (fboundp 'x-color-values)
412             'x-color-values
413           (lambda (color)
414             (color-instance-rgb-components
415              (make-color-instance color))))))
416
417
418 (defun gnus-xmas-redefine ()
419   "Redefine lots of Gnus functions for XEmacs."
420   (fset 'gnus-summary-make-display-table 'ignore)
421   (fset 'gnus-visual-turn-off-edit-menu 'identity)
422   (fset 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
423   (fset 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
424   (fset 'gnus-article-push-button 'gnus-xmas-article-push-button)
425   (fset 'gnus-article-add-button 'gnus-xmas-article-add-button)
426   (fset 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
427   (fset 'gnus-read-event-char 'gnus-xmas-read-event-char)
428   (fset 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
429   (fset 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
430   (fset 'gnus-appt-select-lowest-window 
431         'gnus-xmas-appt-select-lowest-window)
432   (fset 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
433   (fset 'gnus-make-local-hook 'make-local-variable)
434   (fset 'gnus-add-hook 'gnus-xmas-add-hook)
435   (fset 'gnus-character-to-event 'character-to-event)
436   (fset 'gnus-article-show-hidden-text 'gnus-xmas-article-show-hidden-text)
437   (fset 'gnus-mode-line-buffer-identification
438         'gnus-xmas-mode-line-buffer-identification)
439
440   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
441   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
442   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)
443   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
444
445   (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add)
446   (add-hook 'gnus-topic-mode-hook 'gnus-xmas-topic-menu-add)
447   (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
448   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
449   (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
450   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
451   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
452
453   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar)
454   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
455
456   (when (and (<= emacs-major-version 19)
457              (<= emacs-minor-version 13))
458     (setq gnus-article-x-face-too-ugly (when (eq (device-type) 'tty)
459                                          "."))
460     (fset 'gnus-highlight-selected-summary
461           'gnus-xmas-highlight-selected-summary)
462     (fset 'gnus-group-remove-excess-properties
463           'gnus-xmas-group-remove-excess-properties)
464     (fset 'gnus-topic-remove-excess-properties
465           'gnus-xmas-topic-remove-excess-properties)
466     (fset 'gnus-mode-line-buffer-identification 'identity)
467     (unless (boundp 'shell-command-switch)
468       (setq shell-command-switch "-c"))
469     ))
470
471
472 ;;; XEmacs logo and toolbar.
473
474 (defun gnus-xmas-group-startup-message (&optional x y)
475   "Insert startup message in current buffer."
476   ;; Insert the message.
477   (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
478   (erase-buffer)
479   (let ((logo (and gnus-xmas-glyph-directory
480                    (concat 
481                     (file-name-as-directory gnus-xmas-glyph-directory)
482                     "gnus."
483                     (if (featurep 'xpm) "xpm" "xbm"))))
484         (xpm-color-symbols 
485          (and (featurep 'xpm)
486               (append `(("thing" ,(car gnus-xmas-logo-colors))
487                         ("shadow" ,(cadr gnus-xmas-logo-colors)))
488                       xpm-color-symbols))))
489     (if (and (featurep 'xpm)
490              (not (equal (device-type) 'tty))
491              logo
492              (file-exists-p logo))
493         (progn
494           (setq logo (make-glyph logo))
495           (insert " ")
496           (set-extent-begin-glyph (make-extent (point) (point)) logo)
497           (goto-char (point-min))
498           (while (not (eobp))
499             (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
500                                  ? ))
501             (forward-line 1))
502           (goto-char (point-min))
503           (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
504                  (wheight (window-height))
505                  (rest (- wheight pheight)))
506             (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
507
508       (insert
509        (format "              %s
510           _    ___ _             _      
511           _ ___ __ ___  __    _ ___     
512           __   _     ___    __  ___     
513               _           ___     _     
514              _  _ __             _      
515              ___   __            _      
516                    __           _       
517                     _      _   _        
518                    _      _    _        
519                       _  _    _         
520                   __  ___               
521                  _   _ _     _          
522                 _   _                   
523               _    _                    
524              _    _                     
525             _                         
526           __                             
527
528
529                ""))
530       ;; And then hack it.
531       (gnus-indent-rigidly (point-min) (point-max)
532                            (/ (max (- (window-width) (or x 46)) 0) 2))
533       (goto-char (point-min))
534       (forward-line 1)
535       (let* ((pheight (count-lines (point-min) (point-max)))
536              (wheight (window-height))
537              (rest (- wheight pheight)))
538         (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
539     ;; Fontify some.
540     (goto-char (point-min))
541     (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)
542     (goto-char (point-min))
543     (setq modeline-buffer-identification 
544           (list (concat gnus-version ": *Group*")))
545     (set-buffer-modified-p t)))
546
547
548 ;;; The toolbar.
549
550 (defvar gnus-use-toolbar (if (featurep 'toolbar)
551                              'default-toolbar
552                            nil)
553   "*If nil, do not use a toolbar.
554 If it is non-nil, it must be a toolbar.  The five legal values are
555 `default-toolbar', `top-toolbar', `bottom-toolbar',
556 `right-toolbar', and `left-toolbar'.")
557
558 (defvar gnus-group-toolbar 
559   '([gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
560     [gnus-group-get-new-news-this-group 
561      gnus-group-get-new-news-this-group t "Get new news in this group"]
562     [gnus-group-catchup-current 
563      gnus-group-catchup-current t "Catchup group"]
564     [gnus-group-describe-group 
565      gnus-group-describe-group t "Describe group"]
566     [gnus-group-unsubscribe gnus-group-unsubscribe t "Unsubscribe group"]
567     [gnus-group-subscribe gnus-group-subscribe t "Subscribe group"]
568     [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
569     [gnus-group-exit gnus-group-exit t "Exit Gnus"]
570     )
571   "The group buffer toolbar.")
572
573 (defvar gnus-summary-toolbar 
574   '([gnus-summary-prev-unread 
575      gnus-summary-prev-unread-article t "Prev unread article"]
576     [gnus-summary-next-unread 
577      gnus-summary-next-unread-article t "Next unread article"]
578     [gnus-summary-post-news 
579      gnus-summary-post-news t "Post an article"]
580     [gnus-summary-followup-with-original
581      gnus-summary-followup-with-original t 
582      "Post a followup and yank the original"]
583     [gnus-summary-followup 
584      gnus-summary-followup t "Post a followup"]
585     [gnus-summary-reply-with-original
586      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
587     [gnus-summary-reply 
588      gnus-summary-reply t "Mail a reply"]
589     [gnus-summary-caesar-message
590      gnus-summary-caesar-message t "Rot 13"]
591     [gnus-uu-decode-uu
592      gnus-uu-decode-uu t "Decode uuencoded articles"]
593     [gnus-summary-save-article-file
594      gnus-summary-save-article-file t "Save article in file"]
595     [gnus-summary-save-article
596      gnus-summary-save-article t "Save article"]
597     [gnus-uu-post-news 
598      gnus-uu-post-news t "Post an uuencoded article"]
599     [gnus-summary-cancel-article
600      gnus-summary-cancel-article t "Cancel article"]
601     [gnus-summary-catchup
602      gnus-summary-catchup t "Catchup"]
603     [gnus-summary-catchup-and-exit
604      gnus-summary-catchup-and-exit t "Catchup and exit"]
605     [gnus-summary-exit gnus-summary-exit t "Exit this summary"]
606     )
607   "The summary buffer toolbar.")
608
609 (defvar gnus-summary-mail-toolbar
610   '(
611     [gnus-summary-prev-unread 
612      gnus-summary-prev-unread-article t "Prev unread article"]
613     [gnus-summary-next-unread 
614      gnus-summary-next-unread-article t "Next unread article"]
615     [gnus-summary-mail-reply gnus-summary-reply t "Reply"]
616 ;    [gnus-summary-mail-get gnus-mail-get t "Message get"]
617     [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
618     [gnus-summary-mail-save gnus-summary-save-article t "Save"]
619     [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
620 ;    [gnus-summary-mail-delete gnus-summary-delete-article t "Delete message"]
621     [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
622 ;    [gnus-summary-mail-spell gnus-mail-spell t "Spell"]
623 ;    [gnus-summary-mail-help gnus-mail-help  t "Message help"]
624     [gnus-summary-caesar-message
625      gnus-summary-caesar-message t "Rot 13"]
626     [gnus-uu-decode-uu
627      gnus-uu-decode-uu t "Decode uuencoded articles"]
628     [gnus-summary-save-article-file
629      gnus-summary-save-article-file t "Save article in file"]
630     [gnus-summary-save-article
631      gnus-summary-save-article t "Save article"]
632     [gnus-summary-catchup-and-exit
633      gnus-summary-catchup-and-exit t "Catchup and exit"]
634     [gnus-summary-catchup
635      gnus-summary-catchup t "Catchup"]
636     [gnus-summary-exit gnus-summary-exit t "Exit this summary"]
637     )
638   "The summary buffer mail toolbar.")
639
640 (defun gnus-xmas-setup-group-toolbar ()
641   (and gnus-use-toolbar
642        (message-xmas-setup-toolbar gnus-group-toolbar nil "gnus")
643        (set-specifier (symbol-value gnus-use-toolbar)
644                       (cons (current-buffer) gnus-group-toolbar))))
645
646 (defun gnus-xmas-setup-summary-toolbar ()
647   (let ((bar (if (gnus-news-group-p gnus-newsgroup-name)
648                  gnus-summary-toolbar gnus-summary-mail-toolbar)))
649     (and gnus-use-toolbar
650          (message-xmas-setup-toolbar bar nil "gnus")
651          (set-specifier (symbol-value gnus-use-toolbar)
652                         (cons (current-buffer) bar)))))
653
654 (defun gnus-xmas-mail-strip-quoted-names (address)
655   "Protect mail-strip-quoted-names from NIL input.
656 XEmacs compatibility workaround."
657   (if (null address)
658       nil
659     (mail-strip-quoted-names address)))
660
661 (defun gnus-xmas-call-region (command &rest args)
662   (apply
663    'call-process-region (point-min) (point-max) command t '(t nil) nil
664    args))
665
666 (unless (find-face 'gnus-x-face)
667   (copy-face 'default 'gnus-x-face)
668   (set-face-foreground 'gnus-x-face "black")
669   (set-face-background 'gnus-x-face "white"))
670
671 (defun gnus-xmas-article-display-xface (beg end)
672   "Display any XFace headers in the current article."
673   (save-excursion
674     (let (xface-glyph)
675       (if (featurep 'xface)
676           (setq xface-glyph
677                 (make-glyph (vector 'xface :data 
678                                     (concat "X-Face: "
679                                             (buffer-substring beg end)))))
680         (let ((cur (current-buffer)))
681           (save-excursion
682             (gnus-set-work-buffer)
683             (insert (format "%s" (buffer-substring beg end cur)))
684             (gnus-xmas-call-region "uncompface")
685             (goto-char (point-min))
686             (insert "/* Width=48, Height=48 */\n")
687             (gnus-xmas-call-region "icontopbm")
688             (gnus-xmas-call-region "ppmtoxpm")
689             (setq xface-glyph
690                   (make-glyph
691                    (vector 'xpm :data (buffer-string )))))))
692       (set-glyph-face xface-glyph 'gnus-x-face)
693       (goto-char (point-min))
694       (re-search-forward "^From:" nil t)
695       (set-extent-begin-glyph 
696        (make-extent (point) (1+ (point))) xface-glyph))))
697
698 (defun gnus-xmas-article-show-hidden-text (type &optional hide)
699   "Show all hidden text of type TYPE.
700 If HIDE, hide the text instead."
701   (save-excursion
702     (set-buffer gnus-article-buffer)
703     (let ((buffer-read-only nil)
704           (inhibit-point-motion-hooks t)
705           (beg (point-min)))
706       (while (gnus-goto-char (text-property-any
707                               beg (point-max) 'gnus-type type))
708         (setq beg (point))
709         (forward-char)
710         (if hide
711             (article-hide-text beg (point) gnus-hidden-properties)
712           (article-unhide-text beg (point)))
713         (setq beg (point)))
714       (save-window-excursion
715         (select-window (get-buffer-window (current-buffer)))
716         (recenter))
717       t)))
718
719 (defvar gnus-xmas-pointer-glyph 
720   (progn
721     (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
722     (make-pointer-glyph (concat gnus-xmas-glyph-directory "gnus-pointer."
723                                 (if (featurep 'xpm) "xpm" "xbm")))))
724
725 (defvar gnus-xmas-modeline-left-extent 
726   (let ((ext (copy-extent modeline-buffer-id-left-extent)))
727     ;(set-extent-property ext 'pointer gnus-xmas-pointer-glyph)
728     ext))
729       
730 (defvar gnus-xmas-modeline-right-extent 
731   (let ((ext (copy-extent modeline-buffer-id-right-extent)))
732     ;(set-extent-property ext 'pointer gnus-xmas-pointer-glyph)
733     ext))
734
735 (defvar gnus-xmas-modeline-glyph
736   (progn
737     (setq gnus-xmas-glyph-directory (message-xmas-find-glyph-directory "gnus"))
738     (let* ((file (concat gnus-xmas-glyph-directory "gnus-pointer."
739                          (if (featurep 'xpm) "xpm" "xbm")))
740            (glyph (make-glyph file)))
741       (when (and (featurep 'x)
742                  (file-exists-p file))
743         (set-glyph-face glyph 'modeline-buffer-id))
744       (set-glyph-property glyph 'image (cons 'tty "Gnus:"))
745       glyph)))
746
747 (defun gnus-xmas-mode-line-buffer-identification (line)
748   (let ((line (car line))
749         chop)
750     (if (not (stringp line))
751         (list line)
752       (when (string-match "^Gnus:" line)
753         (setq chop (match-end 0))
754         (list 
755          (if gnus-xmas-modeline-glyph
756              (cons gnus-xmas-modeline-left-extent gnus-xmas-modeline-glyph)
757            (cons gnus-xmas-modeline-left-extent (substring line 0 chop)))
758          (cons gnus-xmas-modeline-right-extent (substring line chop)))))))
759
760 (defun gnus-xmas-splash ()
761   (when (eq (device-type) 'x)
762     (gnus-splash)))
763
764 (provide 'gnus-xmas)
765
766 ;;; gnus-xmas.el ends here