2020672e410b732b5c3fa959a524f6863b306a42
[gnus] / lisp / gnus-xmas.el
1 ;;; gnus-xmas.el --- Gnus functions for XEmacs
2
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 ;;        Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (autoload 'gnus-active "gnus" nil nil 'macro)
32   (autoload 'gnus-group-entry "gnus" nil nil 'macro)
33   (autoload 'gnus-info-level "gnus" nil nil 'macro)
34   (autoload 'gnus-info-marks "gnus" nil nil 'macro)
35   (autoload 'gnus-info-method "gnus" nil nil 'macro)
36   (autoload 'gnus-info-score "gnus" nil nil 'macro))
37
38 (require 'text-props)
39 (defvar menu-bar-mode (featurep 'menubar))
40 (require 'messagexmas)
41 (require 'wid-edit)
42
43 (defgroup gnus-xmas nil
44   "XEmacsoid support for Gnus"
45   :group 'gnus)
46
47 (defcustom gnus-xmas-glyph-directory nil
48   "Directory where Gnus logos and icons are located.
49 If this variable is nil, Gnus will try to locate the directory
50 automatically."
51   :type '(choice (const :tag "autodetect" nil)
52                  directory)
53   :group 'gnus-xmas)
54
55 (unless gnus-xmas-glyph-directory
56   (unless (setq gnus-xmas-glyph-directory
57                 (message-xmas-find-glyph-directory "gnus"))
58     (error "Can't find glyph directory. \
59 Possibly the `etc' directory has not been installed.")))
60
61 ;;; Internal variables.
62
63 ;; Don't warn about these undefined variables.
64
65 ;;defined in gnus.el
66 (defvar gnus-active-hashtb)
67 (defvar gnus-article-buffer)
68 (defvar gnus-auto-center-summary)
69 (defvar gnus-current-headers)
70 (defvar gnus-level-killed)
71 (defvar gnus-level-zombie)
72 (defvar gnus-newsgroup-bookmarks)
73 (defvar gnus-newsgroup-dependencies)
74 (defvar gnus-newsgroup-selected-overlay)
75 (defvar gnus-newsrc-hashtb)
76 (defvar gnus-read-mark)
77 (defvar gnus-refer-article-method)
78 (defvar gnus-reffed-article-number)
79 (defvar gnus-unread-mark)
80 (defvar gnus-version)
81 (defvar gnus-view-pseudos)
82 (defvar gnus-view-pseudos-separately)
83 (defvar gnus-visual)
84 (defvar gnus-zombie-list)
85 ;;defined in gnus-msg.el
86 (defvar gnus-article-copy)
87 (defvar gnus-check-before-posting)
88 ;;defined in gnus-vis.el
89 (defvar gnus-article-button-face)
90 (defvar gnus-article-mouse-face)
91 (defvar gnus-summary-selected-face)
92 (defvar gnus-group-reading-menu)
93 (defvar gnus-group-group-menu)
94 (defvar gnus-group-misc-menu)
95 (defvar gnus-summary-article-menu)
96 (defvar gnus-summary-thread-menu)
97 (defvar gnus-summary-misc-menu)
98 (defvar gnus-summary-post-menu)
99 (defvar gnus-summary-kill-menu)
100 (defvar gnus-article-article-menu)
101 (defvar gnus-article-treatment-menu)
102 (defvar gnus-mouse-2)
103 (defvar standard-display-table)
104 (defvar gnus-tree-minimize-window)
105
106 (defun gnus-xmas-set-text-properties (start end props &optional buffer)
107   "You should NEVER use this function.  It is ideologically blasphemous.
108 It is provided only to ease porting of broken FSF Emacs programs."
109   (if (stringp buffer)
110       nil
111     (map-extents (lambda (extent ignored)
112                    (remove-text-properties
113                     start end
114                     (list (extent-property extent 'text-prop) nil)
115                     buffer)
116                    nil)
117                  buffer start end nil nil 'text-prop)
118     (gnus-add-text-properties start end props buffer)))
119
120 (defun gnus-xmas-highlight-selected-summary ()
121   ;; Highlight selected article in summary buffer
122   (when gnus-summary-selected-face
123     (when gnus-newsgroup-selected-overlay
124       (delete-extent gnus-newsgroup-selected-overlay))
125     (setq gnus-newsgroup-selected-overlay
126           (make-extent (point-at-bol) (point-at-eol)))
127     (set-extent-face gnus-newsgroup-selected-overlay
128                      gnus-summary-selected-face)))
129
130 (defcustom gnus-xmas-force-redisplay nil
131   "*If non-nil, force a redisplay before recentering the summary buffer.
132 This is ugly, but it works around a bug in `window-displayed-height'."
133   :type 'boolean
134   :group 'gnus-xmas)
135
136 (defun gnus-xmas-switch-horizontal-scrollbar-off ()
137   (when (featurep 'scrollbar)
138     (set-specifier scrollbar-height (cons (current-buffer) 0))))
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   ;; Force redisplay to get properly computed window height.
147   (when gnus-xmas-force-redisplay
148     (sit-for 0))
149   (when gnus-auto-center-summary
150     (let* ((height (if (fboundp 'window-displayed-height)
151                        (window-displayed-height)
152                      (- (window-height) 2)))
153            (top (cond ((< height 4) 0)
154                       ((< height 7) 1)
155                       (t (if (numberp gnus-auto-center-summary)
156                              gnus-auto-center-summary
157                            2))))
158            (bottom (save-excursion (goto-char (point-max))
159                                    (forward-line (- height))
160                                    (point)))
161            (window (get-buffer-window (current-buffer))))
162       (when (get-buffer-window gnus-article-buffer)
163         ;; Only do recentering when the article buffer is displayed,
164         ;; Set the window start to either `bottom', which is the biggest
165         ;; possible valid number, or the second line from the top,
166         ;; whichever is the least.
167         ;; NOFORCE parameter suggested by Daniel Pittman <daniel@danann.net>.
168         (set-window-start
169          window (min bottom (save-excursion (forward-line (- top)) (point)))
170          t))
171       ;; Do horizontal recentering while we're at it.
172       (when (and (get-buffer-window (current-buffer) t)
173                  (not (eq gnus-auto-center-summary 'vertical)))
174         (let ((selected (selected-window)))
175           (select-window (get-buffer-window (current-buffer) t))
176           (gnus-summary-position-point)
177           (gnus-horizontal-recenter)
178           (select-window selected))))))
179
180 (defun gnus-xmas-summary-set-display-table ()
181   ;; Setup the display table -- like `gnus-summary-setup-display-table',
182   ;; but done in an XEmacsish way.
183   (let ((table (make-display-table))
184         (i 32))
185     ;; Nix out all the control chars...
186     (while (>= (setq i (1- i)) 0)
187       (aset table i [??]))
188     ;; ... but not newline and cr, of course.  (cr is necessary for the
189     ;; selective display).
190     (aset table ?\n nil)
191     (aset table ?\r nil)
192     ;; We keep TAB as well.
193     (aset table ?\t nil)
194     ;; We nix out any glyphs over 126 below ctl-arrow.
195     (let ((i (if (integerp ctl-arrow) ctl-arrow 160)))
196       (while (>= (setq i (1- i)) 127)
197         (unless (aref table i)
198           (aset table i [??]))))
199     ;; Can't use `set-specifier' because of a bug in 19.14 and earlier
200     (add-spec-to-specifier current-display-table table (current-buffer) nil)))
201
202 (defun gnus-xmas-add-text-properties (start end props &optional object)
203   (add-text-properties start end props object)
204   (put-text-property start end 'start-closed nil object))
205
206 (defun gnus-xmas-put-text-property (start end prop value &optional object)
207   (put-text-property start end prop value object)
208   (put-text-property start end 'start-closed nil object))
209
210 (defun gnus-xmas-extent-start-open (point)
211   (map-extents (lambda (extent arg)
212                  (set-extent-property extent 'start-open t))
213                nil point (min (1+ (point)) (point-max))))
214
215 (defun gnus-xmas-article-push-button (event)
216   "Check text under the mouse pointer for a callback function.
217 If the text under the mouse pointer has a `gnus-callback' property,
218 call it with the value of the `gnus-data' text property."
219   (interactive "e")
220   (set-buffer (window-buffer (event-window event)))
221   (let* ((pos (event-closest-point event))
222          (data (get-text-property pos 'gnus-data))
223          (fun (get-text-property pos 'gnus-callback)))
224     (goto-char pos)
225     (when fun
226       (funcall fun data))))
227
228 (defun gnus-xmas-move-overlay (extent start end &optional buffer)
229   (set-extent-endpoints extent start end buffer))
230
231 (defun gnus-xmas-kill-all-overlays ()
232   "Delete all extents in the current buffer."
233   (map-extents (lambda (extent ignore)
234                  (delete-extent extent)
235                  nil)))
236
237 (defun gnus-xmas-window-top-edge (&optional window)
238   (nth 1 (window-pixel-edges window)))
239
240 (defun gnus-xmas-tree-minimize ()
241   (when (and gnus-tree-minimize-window
242              (not (one-window-p)))
243     (let* ((window-min-height 2)
244            (height (1+ (count-lines (point-min) (point-max))))
245            (min (max (1- window-min-height) height))
246            (tot (if (numberp gnus-tree-minimize-window)
247                     (min gnus-tree-minimize-window min)
248                   min))
249            (win (get-buffer-window (current-buffer)))
250            (wh (and win (1- (window-height win)))))
251       (when (and win
252                  (not (eq tot wh)))
253         (let ((selected (selected-window)))
254           (select-window win)
255           (enlarge-window (- tot wh))
256           (select-window selected))))))
257
258 ;; Select the lowest window on the frame.
259 (defun gnus-xmas-appt-select-lowest-window ()
260   (let* ((lowest-window (selected-window))
261          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
262          (last-window (previous-window))
263          (window-search t))
264     (while window-search
265       (let* ((this-window (next-window))
266              (next-bottom-edge (car (cdr (cdr (cdr
267                                                (window-pixel-edges
268                                                 this-window)))))))
269         (when (< bottom-edge next-bottom-edge)
270           (setq bottom-edge next-bottom-edge)
271           (setq lowest-window this-window))
272
273         (select-window this-window)
274         (when (eq last-window this-window)
275           (select-window lowest-window)
276           (setq window-search nil))))))
277
278 (defmacro gnus-xmas-menu-add (type &rest menus)
279   `(gnus-xmas-menu-add-1 ',type ',menus))
280 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
281
282 (defun gnus-xmas-menu-add-1 (type menus)
283   (when (and menu-bar-mode
284              (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
285     (while menus
286       (easy-menu-add (symbol-value (pop menus))))))
287
288 (defun gnus-xmas-group-menu-add ()
289   (gnus-xmas-menu-add group
290     gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
291
292 (defun gnus-xmas-summary-menu-add ()
293   (gnus-xmas-menu-add summary
294     gnus-summary-misc-menu gnus-summary-kill-menu
295     gnus-summary-article-menu gnus-summary-thread-menu
296     gnus-summary-post-menu ))
297
298 (defun gnus-xmas-article-menu-add ()
299   (gnus-xmas-menu-add article
300     gnus-article-article-menu gnus-article-treatment-menu
301     gnus-article-post-menu gnus-article-commands-menu))
302
303 (defun gnus-xmas-score-menu-add ()
304   (gnus-xmas-menu-add score
305     gnus-score-menu))
306
307 (defun gnus-xmas-pick-menu-add ()
308   (gnus-xmas-menu-add pick
309     gnus-pick-menu))
310
311 (defun gnus-xmas-topic-menu-add ()
312   (gnus-xmas-menu-add topic
313     gnus-topic-menu))
314
315 (defun gnus-xmas-binary-menu-add ()
316   (gnus-xmas-menu-add binary
317     gnus-binary-menu))
318
319 (defun gnus-xmas-agent-summary-menu-add ()
320   (gnus-xmas-menu-add agent-summary
321     gnus-agent-summary-menu))
322
323 (defun gnus-xmas-agent-group-menu-add ()
324   (gnus-xmas-menu-add agent-group
325     gnus-agent-group-menu))
326
327 (defun gnus-xmas-agent-server-menu-add ()
328   (gnus-xmas-menu-add agent-server
329     gnus-agent-server-menu))
330
331 (defun gnus-xmas-tree-menu-add ()
332   (gnus-xmas-menu-add tree
333     gnus-tree-menu))
334
335 (defun gnus-xmas-draft-menu-add ()
336   (gnus-xmas-menu-add draft
337     gnus-draft-menu))
338
339 (defun gnus-xmas-server-menu-add ()
340   (gnus-xmas-menu-add menu
341     gnus-server-server-menu gnus-server-connections-menu))
342
343 (defun gnus-xmas-browse-menu-add ()
344   (gnus-xmas-menu-add browse
345     gnus-browse-menu))
346
347 (defun gnus-xmas-grouplens-menu-add ()
348   (gnus-xmas-menu-add grouplens
349     gnus-grouplens-menu))
350
351 (defun gnus-xmas-read-event-char (&optional prompt)
352   "Get the next event."
353   (when prompt
354     (message "%s" prompt))
355   (let ((event (next-command-event)))
356     (sit-for 0)
357     ;; We junk all non-key events.  Is this naughty?
358     (while (not (or (key-press-event-p event)
359                     (button-press-event-p event)))
360       (dispatch-event event)
361       (setq event (next-command-event)))
362     (cons (and (key-press-event-p event)
363                (event-to-character event))
364           event)))
365
366 (defun gnus-xmas-define ()
367   (setq gnus-mouse-2 [button2])
368   (setq gnus-mouse-3 [button3])
369   (setq gnus-widget-button-keymap widget-button-keymap)
370
371   (unless (memq 'underline (face-list))
372     (and (fboundp 'make-face)
373          (funcall (intern "make-face") 'underline)))
374   ;; Must avoid calling set-face-underline-p directly, because it
375   ;; is a defsubst in emacs19, and will make the .elc files non
376   ;; portable!
377   (unless (face-differs-from-default-p 'underline)
378     (funcall (intern "set-face-underline-p") 'underline t))
379
380   (cond
381    ((fboundp 'char-or-char-int-p)
382     ;; Handle both types of marks for XEmacs-20.x.
383     (defalias 'gnus-characterp 'char-or-char-int-p))
384    ;; V19 of XEmacs, probably.
385    (t
386     (defalias 'gnus-characterp 'characterp)))
387
388   (defalias 'gnus-make-overlay 'make-extent)
389   (defalias 'gnus-delete-overlay 'delete-extent)
390   (defalias 'gnus-overlay-put 'set-extent-property)
391   (defalias 'gnus-move-overlay 'gnus-xmas-move-overlay)
392   (defalias 'gnus-overlay-buffer 'extent-object)
393   (defalias 'gnus-overlay-start 'extent-start-position)
394   (defalias 'gnus-overlay-end 'extent-end-position)
395   (defalias 'gnus-kill-all-overlays 'gnus-xmas-kill-all-overlays)
396   (defalias 'gnus-extent-detached-p 'extent-detached-p)
397   (defalias 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
398   (defalias 'gnus-put-text-property 'gnus-xmas-put-text-property)
399   (defalias 'gnus-deactivate-mark 'ignore)
400   (defalias 'gnus-window-edges 'window-pixel-edges)
401   (defalias 'gnus-assq-delete-all 'gnus-xmas-assq-delete-all)
402
403   (if (and (<= emacs-major-version 19)
404            (< emacs-minor-version 14))
405       (defalias 'gnus-set-text-properties 'gnus-xmas-set-text-properties))
406
407   (unless (boundp 'standard-display-table)
408     (setq standard-display-table nil))
409
410   (defvar gnus-mouse-face-prop 'highlight)
411
412   (defun gnus-byte-code (func)
413     "Return a form that can be `eval'ed based on FUNC."
414     (let ((fval (indirect-function func)))
415       (if (compiled-function-p fval)
416           (list 'funcall fval)
417         (cons 'progn (cdr (cdr fval))))))
418
419   (unless (fboundp 'match-string-no-properties)
420     (defalias 'match-string-no-properties 'match-string))
421
422   (defalias 'gnus-x-color-values
423         (if (fboundp 'x-color-values)
424             'x-color-values
425           (lambda (color)
426             (color-instance-rgb-components
427              (make-color-instance color)))))
428
429   (unless (fboundp 'char-width)
430     (defalias 'char-width (lambda (ch) 1))))
431
432 (defun gnus-xmas-redefine ()
433   "Redefine lots of Gnus functions for XEmacs."
434   (defalias 'gnus-summary-set-display-table 'gnus-xmas-summary-set-display-table)
435   (defalias 'gnus-visual-turn-off-edit-menu 'identity)
436   (defalias 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
437   (defalias 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
438   (defalias 'gnus-article-push-button 'gnus-xmas-article-push-button)
439   (defalias 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
440   (defalias 'gnus-read-event-char 'gnus-xmas-read-event-char)
441   (defalias 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
442   (defalias 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
443   (defalias 'gnus-appt-select-lowest-window
444     'gnus-xmas-appt-select-lowest-window)
445   (defalias 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
446   (defalias 'gnus-character-to-event 'character-to-event)
447   (defalias 'gnus-mode-line-buffer-identification
448     'gnus-xmas-mode-line-buffer-identification)
449   (defalias 'gnus-key-press-event-p 'key-press-event-p)
450   (defalias 'gnus-region-active-p 'region-active-p)
451   (defalias 'gnus-mark-active-p 'region-exists-p)
452   (defalias 'gnus-annotation-in-region-p 'gnus-xmas-annotation-in-region-p)
453   (defalias 'gnus-mime-button-menu 'gnus-xmas-mime-button-menu)
454   (defalias 'gnus-image-type-available-p 'gnus-xmas-image-type-available-p)
455   (defalias 'gnus-put-image 'gnus-xmas-put-image)
456   (defalias 'gnus-create-image 'gnus-xmas-create-image)
457   (defalias 'gnus-remove-image 'gnus-xmas-remove-image)
458
459   (when (or (< emacs-major-version 21)
460             (and (= emacs-major-version 21)
461                  (< emacs-minor-version 3)))
462     (defalias 'gnus-completing-read 'gnus-xmas-completing-read))
463
464   ;; These ones are not defcutom'ed, sometimes not even defvar'ed. They
465   ;; probably should. If that is done, the code below should then be moved
466   ;; where each variable is defined, in order not to mess with user settings.
467   ;; -- didier
468   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
469   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
470   (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
471   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
472   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
473   (add-hook 'gnus-draft-mode-hook 'gnus-xmas-draft-menu-add)
474   (add-hook 'gnus-mailing-list-mode-hook 'gnus-xmas-mailing-list-menu-add))
475
476
477 ;;; XEmacs logo and toolbar.
478
479 (defun gnus-xmas-group-startup-message (&optional x y)
480   "Insert startup message in current buffer."
481   ;; Insert the message.
482   (erase-buffer)
483   (cond
484    ((and (console-on-window-system-p)
485          (or (featurep 'xpm)
486              (featurep 'xbm)))
487     (let* ((logo-xpm (expand-file-name "gnus.xpm" gnus-xmas-glyph-directory))
488            (logo-xbm (expand-file-name "gnus.xbm" gnus-xmas-glyph-directory))
489            (glyph (make-glyph
490                    (cond ((featurep 'xpm)
491                           `[xpm
492                             :file ,logo-xpm
493                             :color-symbols
494                             (("thing" . ,(car gnus-logo-colors))
495                              ("shadow" . ,(cadr gnus-logo-colors))
496                              ("oort" . "#eeeeee")
497                              ("background" . ,(face-background 'default)))])
498                          ((featurep 'xbm)
499                           `[xbm :file ,logo-xbm])
500                          (t [nothing])))))
501       (insert " ")
502       (set-extent-begin-glyph (make-extent (point) (point)) glyph)
503       (goto-char (point-min))
504       (while (not (eobp))
505         (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
506                              ?\ ))
507         (forward-line 1))
508       (setq gnus-simple-splash nil))
509     (goto-char (point-min))
510     (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
511            (wheight (window-height))
512            (rest (- wheight pheight)))
513       (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
514    (t
515     (insert
516      (format "              %s
517           _    ___ _             _
518           _ ___ __ ___  __    _ ___
519           __   _     ___    __  ___
520               _           ___     _
521              _  _ __             _
522              ___   __            _
523                    __           _
524                     _      _   _
525                    _      _    _
526                       _  _    _
527                   __  ___
528                  _   _ _     _
529                 _   _
530               _    _
531              _    _
532             _
533           __
534
535 "
536              ""))
537     ;; And then hack it.
538     (gnus-indent-rigidly (point-min) (point-max)
539                          (/ (max (- (window-width) (or x 46)) 0) 2))
540     (goto-char (point-min))
541     (forward-line 1)
542     (let* ((pheight (count-lines (point-min) (point-max)))
543            (wheight (window-height))
544            (rest (- wheight pheight)))
545       (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
546     ;; Paint it.
547     (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)))
548   (setq modeline-buffer-identification
549         (list (concat gnus-version ": *Group*")))
550   (set-buffer-modified-p t))
551
552
553 ;;; The toolbar.
554
555 (defcustom gnus-use-toolbar (if (featurep 'toolbar)
556                                 'default-toolbar
557                               nil)
558   "*If nil, do not use a toolbar.
559 If it is non-nil, it must be a toolbar.  The five valid values are
560 `default-toolbar', `top-toolbar', `bottom-toolbar',
561 `right-toolbar', and `left-toolbar'."
562   :type '(choice (const default-toolbar)
563                  (const top-toolbar) (const bottom-toolbar)
564                  (const left-toolbar) (const right-toolbar)
565                  (const :tag "no toolbar" nil))
566   :group 'gnus-xmas)
567
568 (defvar gnus-group-toolbar
569   '([gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
570     [gnus-group-get-new-news-this-group
571      gnus-group-get-new-news-this-group t "Get new news in this group"]
572     [gnus-group-catchup-current
573      gnus-group-catchup-current t "Catchup group"]
574     [gnus-group-describe-group
575      gnus-group-describe-group t "Describe group"]
576     [gnus-group-unsubscribe gnus-group-unsubscribe t "Unsubscribe group"]
577     [gnus-group-subscribe gnus-group-subscribe t "Subscribe group"]
578     [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
579     [gnus-summary-mail-save
580      gnus-group-save-newsrc t "Save .newsrc files"] ; borrowed icon.
581     [gnus-group-exit gnus-group-exit t "Exit Gnus"])
582   "The group buffer toolbar.")
583
584 (defvar gnus-summary-toolbar
585   '([gnus-summary-prev-unread
586      gnus-summary-prev-page-or-article t "Page up"]
587     [gnus-summary-next-unread
588      gnus-summary-next-page t "Page down"]
589     [gnus-summary-post-news
590      gnus-summary-post-news t "Post an article"]
591     [gnus-summary-followup-with-original
592      gnus-summary-followup-with-original t
593      "Post a followup and yank the original"]
594     [gnus-summary-followup
595      gnus-summary-followup t "Post a followup"]
596     [gnus-summary-reply-with-original
597      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
598     [gnus-summary-reply
599      gnus-summary-reply t "Mail a reply"]
600     [gnus-summary-caesar-message
601      gnus-summary-caesar-message t "Rot 13"]
602     [gnus-uu-decode-uu
603      gnus-uu-decode-uu t "Decode uuencoded articles"]
604     [gnus-summary-save-article-file
605      gnus-summary-save-article-file t "Save article in file"]
606     [gnus-summary-save-article
607      gnus-summary-save-article t "Save article"]
608     [gnus-uu-post-news
609      gnus-uu-post-news t "Post a uuencoded article"]
610     [gnus-summary-cancel-article
611      gnus-summary-cancel-article t "Cancel article"]
612     [gnus-summary-catchup
613      gnus-summary-catchup t "Catchup"]
614     [gnus-summary-catchup-and-exit
615      gnus-summary-catchup-and-exit t "Catchup and exit"]
616     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
617   "The summary buffer toolbar.")
618
619 (defvar gnus-summary-mail-toolbar
620   '(
621     [gnus-summary-prev-unread
622      gnus-summary-prev-unread-article t "Prev unread article"]
623     [gnus-summary-next-unread
624      gnus-summary-next-unread-article t "Next unread article"]
625     [gnus-summary-mail-reply gnus-summary-reply t "Reply"]
626     [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
627     [gnus-summary-mail-save gnus-summary-save-article t "Save"]
628     [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
629     [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
630     [gnus-summary-caesar-message
631      gnus-summary-caesar-message t "Rot 13"]
632     [gnus-uu-decode-uu
633      gnus-uu-decode-uu t "Decode uuencoded articles"]
634     [gnus-summary-save-article-file
635      gnus-summary-save-article-file t "Save article in file"]
636     [gnus-summary-save-article
637      gnus-summary-save-article t "Save article"]
638     [gnus-summary-cancel-article ; usenet : cancellation :: mail : deletion.
639      gnus-summary-delete-article t "Delete message"]
640     [gnus-summary-catchup
641      gnus-summary-catchup t "Catchup"]
642     [gnus-summary-catchup-and-exit
643      gnus-summary-catchup-and-exit t "Catchup and exit"]
644     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
645   "The summary buffer mail toolbar.")
646
647 (defun gnus-xmas-setup-group-toolbar ()
648   (and gnus-use-toolbar
649        (message-xmas-setup-toolbar gnus-group-toolbar nil "gnus")
650        (set-specifier (symbol-value gnus-use-toolbar)
651                       (cons (current-buffer) gnus-group-toolbar))))
652
653 (defun gnus-xmas-setup-summary-toolbar ()
654   (let ((bar (if (gnus-news-group-p gnus-newsgroup-name)
655                  gnus-summary-toolbar gnus-summary-mail-toolbar)))
656     (and gnus-use-toolbar
657          (message-xmas-setup-toolbar bar nil "gnus")
658          (set-specifier (symbol-value gnus-use-toolbar)
659                         (cons (current-buffer) bar)))))
660
661 (defun gnus-xmas-mail-strip-quoted-names (address)
662   "Protect mail-strip-quoted-names from nil input.
663 XEmacs compatibility workaround."
664   (if (null address)
665       nil
666     (mail-strip-quoted-names address)))
667
668 (defun gnus-xmas-call-region (command &rest args)
669   (apply
670    'call-process-region (point-min) (point-max) command t '(t nil) nil
671    args))
672
673 (defvar gnus-xmas-modeline-left-extent
674   (let ((ext (copy-extent modeline-buffer-id-left-extent)))
675     ext))
676
677 (defvar gnus-xmas-modeline-right-extent
678   (let ((ext (copy-extent modeline-buffer-id-right-extent)))
679     ext))
680
681 (defvar gnus-xmas-modeline-glyph
682   (progn
683     (let* ((file-xpm (expand-file-name "gnus-pointer.xpm"
684                                        gnus-xmas-glyph-directory))
685            (file-xbm (expand-file-name "gnus-pointer.xbm"
686                                        gnus-xmas-glyph-directory))
687            (glyph (make-glyph
688                    ;; Gag gag gag.
689                    (cond ((featurep 'xpm)
690                           ;; Let's try a nifty XPM
691                           `[xpm :file ,file-xpm])
692                          ((featurep 'xbm)
693                           ;; Then a not-so-nifty XBM
694                           `[xbm :file ,file-xbm])
695                          ;; Then the simple string
696                          (t [string :data "Gnus:"])))))
697       (set-glyph-face glyph 'modeline-buffer-id)
698       glyph)))
699
700 (defun gnus-xmas-mode-line-buffer-identification (line)
701   (let ((line (car line))
702         chop)
703     (cond
704      ;; This is some weird type of id.
705      ((not (stringp line))
706       (list line))
707      ;; This is non-standard, so we just pass it through.
708      ((not (string-match "^Gnus:" line))
709       (list line))
710      ;; We have a standard line, so we colorize and glyphize it a bit.
711      (t
712       (setq chop (match-end 0))
713       (list
714        (if gnus-xmas-modeline-glyph
715            (cons gnus-xmas-modeline-left-extent gnus-xmas-modeline-glyph)
716          (cons gnus-xmas-modeline-left-extent (substring line 0 chop)))
717        (cons gnus-xmas-modeline-right-extent (substring line chop)))))))
718
719 (defun gnus-xmas-splash ()
720   (when (eq (device-type) 'x)
721     (gnus-splash)))
722
723 (defun gnus-xmas-annotation-in-region-p (b e)
724   (or (map-extents (lambda (e u) t) nil b e nil nil 'mm t)
725       (if (= b e)
726           (eq (cadr (memq 'gnus-undeletable (text-properties-at b))) t)
727         (text-property-any b e 'gnus-undeletable t))))
728
729 (defun gnus-xmas-mime-button-menu (event prefix)
730   "Construct a context-sensitive menu of MIME commands."
731   (interactive "e\nP")
732   (let ((response (get-popup-menu-response
733                    `("MIME Part"
734                      ,@(mapcar (lambda (c) `[,(caddr c) ,(car c) t])
735                                gnus-mime-button-commands)))))
736     (set-buffer (event-buffer event))
737     (goto-char (event-point event))
738     (funcall (event-function response) (event-object response))))
739
740 (defun gnus-group-add-icon ()
741   "Add an icon to the current line according to `gnus-group-icon-list'."
742   (let* ((p (point))
743          (end (point-at-eol))
744          ;; now find out where the line starts and leave point there.
745          (beg (progn (beginning-of-line) (point))))
746     (save-restriction
747       (narrow-to-region beg end)
748       (goto-char beg)
749       (when (search-forward "==&&==" nil t)
750         (let* ((group (gnus-group-group-name))
751                (entry (gnus-group-entry group))
752                (unread (if (numberp (car entry)) (car entry) 0))
753                (active (gnus-active group))
754                (total (if active (1+ (- (cdr active) (car active))) 0))
755                (info (nth 2 entry))
756                (method (gnus-server-get-method group (gnus-info-method info)))
757                (marked (gnus-info-marks info))
758                (mailp (memq 'mail (assoc (symbol-name
759                                           (car (or method gnus-select-method)))
760                                          gnus-valid-select-methods)))
761                (level (or (gnus-info-level info) gnus-level-killed))
762                (score (or (gnus-info-score info) 0))
763                (ticked (gnus-range-length (cdr (assq 'tick marked))))
764                (group-age (gnus-group-timestamp-delta group))
765                (inhibit-read-only t)
766                (list gnus-group-icon-list)
767                (mystart (match-beginning 0))
768                (myend (match-end 0)))
769           (goto-char (point-min))
770           (while (and list
771                       (not (eval (caar list))))
772             (setq list (cdr list)))
773           (if list
774               (let* ((file (cdar list))
775                      (glyph (gnus-group-icon-create-glyph
776                              (buffer-substring mystart myend)
777                              file)))
778                 (if glyph
779                     (progn
780                       (mapcar 'delete-annotation (annotations-at myend))
781                       (let ((ext (make-extent mystart myend))
782                             (ant (make-annotation glyph myend 'text)))
783                         ;; set text extent params
784                         (set-extent-property ext 'end-open t)
785                         (set-extent-property ext 'start-open t)
786                         (set-extent-property ext 'invisible t)))
787                   (delete-region mystart myend)))
788             (delete-region mystart myend))))
789       (widen))
790     (goto-char p)))
791
792 (defun gnus-group-icon-create-glyph (substring pixmap)
793   "Create a glyph for insertion into a group line."
794   (or
795    (cdr-safe (assoc pixmap gnus-group-icon-cache))
796    (let* ((glyph (make-glyph
797                   (list
798                    (cons 'x
799                          (expand-file-name pixmap gnus-xmas-glyph-directory))
800                    (cons 'mswindows
801                          (expand-file-name pixmap gnus-xmas-glyph-directory))
802                    (cons 'tty substring)))))
803      (setq gnus-group-icon-cache
804            (cons (cons pixmap glyph) gnus-group-icon-cache))
805      (set-glyph-face glyph 'default)
806      glyph)))
807
808 (defun gnus-xmas-mailing-list-menu-add ()
809   (gnus-xmas-menu-add mailing-list
810                       gnus-mailing-list-menu))
811
812 (defun gnus-xmas-image-type-available-p (type)
813   (and window-system
814        (featurep (if (eq type 'pbm) 'xbm type))))
815
816 (defun gnus-xmas-create-image (file &optional type data-p &rest props)
817   (let ((type (if type
818                   (symbol-name type)
819                 (car (last (split-string file "[.]")))))
820         (face (plist-get props :face))
821         glyph)
822     (when (equal type "pbm")
823       (with-temp-buffer
824         (if data-p
825             (insert file)
826           (insert-file-contents-literally file))
827         (shell-command-on-region (point-min) (point-max)
828                                  "ppmtoxpm 2>/dev/null" t)
829         (setq file (buffer-string)
830               type "xpm"
831               data-p t)))
832     (setq glyph
833           (if (equal type "xbm")
834               (make-glyph (list (cons 'x file)))
835             (with-temp-buffer
836               (if data-p
837                   (insert file)
838                 (insert-file-contents-literally file))
839               (make-glyph
840                (vector
841                 (or (intern type)
842                     (mm-image-type-from-buffer))
843                 :data (buffer-string))))))
844     (when face
845       (set-glyph-face glyph face))
846     glyph))
847
848 (defun gnus-xmas-put-image (glyph &optional string category)
849   "Insert STRING, but display GLYPH.
850 Warning: Don't insert text immediately after the image."
851   (let ((begin (point))
852         extent)
853     (if (and (bobp) (not string))
854         (setq string " "))
855     (if string
856         (insert string)
857       (setq begin (1- begin)))
858     (setq extent (make-extent begin (point)))
859     (set-extent-property extent 'gnus-image category)
860     (set-extent-property extent 'duplicable t)
861     (if string
862         (set-extent-property extent 'invisible t))
863     (set-extent-property extent 'end-glyph glyph))
864   glyph)
865
866 (defun gnus-xmas-remove-image (image &optional category)
867   (map-extents
868    (lambda (ext unused)
869      (when (equal (extent-end-glyph ext) image)
870        (set-extent-property ext 'invisible nil)
871        (set-extent-property ext 'end-glyph nil))
872      nil)
873    nil nil nil nil nil 'gnus-image category))
874
875 (defun gnus-xmas-completing-read (prompt table &optional
876                                          predicate require-match history)
877   (when (and history
878              (not (boundp history)))
879     (set history nil))
880   (completing-read
881    (if (symbol-value history)
882        (concat prompt " (" (car (symbol-value history)) "): ")
883      (concat prompt ": "))
884    table
885    predicate
886    require-match
887    nil
888    history))
889
890 ;; This macro is because XEmacs versions prior to 21.2 do not have the
891 ;; PROTOCOL argument to `open-network-stream'.
892 (defmacro gnus-xmas-open-network-stream (name buffer host service &optional protocol)
893   "Like `open-network-stream' but take into account older XEmacs versions."
894   (if (and (featurep 'xemacs)
895            (fboundp 'open-network-stream)
896            (emacs-version>= 21 2))
897       `(open-network-stream ,name ,buffer ,host ,service ,protocol)
898     `(open-network-stream ,name ,buffer ,host ,service)))
899
900 (defun gnus-xmas-assq-delete-all (key alist)
901   (let ((elem nil))
902     (while (setq elem (assq key alist))
903       (setq alist (delq elem alist)))
904     alist))
905
906 (provide 'gnus-xmas)
907
908 ;;; gnus-xmas.el ends here