54b8e8866a905078feedcc1ccf9cd4a667a58414
[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 (gnus-point-at-bol) (gnus-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 (defun gnus-xmas-redefine ()
430   "Redefine lots of Gnus functions for XEmacs."
431   (defalias 'gnus-summary-set-display-table 'gnus-xmas-summary-set-display-table)
432   (defalias 'gnus-visual-turn-off-edit-menu 'identity)
433   (defalias 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
434   (defalias 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
435   (defalias 'gnus-article-push-button 'gnus-xmas-article-push-button)
436   (defalias 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
437   (defalias 'gnus-read-event-char 'gnus-xmas-read-event-char)
438   (defalias 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
439   (defalias 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
440   (defalias 'gnus-appt-select-lowest-window
441     'gnus-xmas-appt-select-lowest-window)
442   (defalias 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
443   (defalias 'gnus-character-to-event 'character-to-event)
444   (defalias 'gnus-mode-line-buffer-identification
445     'gnus-xmas-mode-line-buffer-identification)
446   (defalias 'gnus-key-press-event-p 'key-press-event-p)
447   (defalias 'gnus-region-active-p 'region-active-p)
448   (defalias 'gnus-mark-active-p 'region-exists-p)
449   (defalias 'gnus-annotation-in-region-p 'gnus-xmas-annotation-in-region-p)
450   (defalias 'gnus-mime-button-menu 'gnus-xmas-mime-button-menu)
451   (defalias 'gnus-image-type-available-p 'gnus-xmas-image-type-available-p)
452   (defalias 'gnus-put-image 'gnus-xmas-put-image)
453   (defalias 'gnus-create-image 'gnus-xmas-create-image)
454   (defalias 'gnus-remove-image 'gnus-xmas-remove-image)
455
456   (when (or (< emacs-major-version 21)
457             (and (= emacs-major-version 21)
458                  (< emacs-minor-version 3)))
459     (defalias 'gnus-completing-read 'gnus-xmas-completing-read))
460
461   ;; These ones are not defcutom'ed, sometimes not even defvar'ed. They
462   ;; probably should. If that is done, the code below should then be moved
463   ;; where each variable is defined, in order not to mess with user settings.
464   ;; -- didier
465   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
466   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
467   (add-hook 'gnus-grouplens-mode-hook 'gnus-xmas-grouplens-menu-add)
468   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
469   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
470   (add-hook 'gnus-draft-mode-hook 'gnus-xmas-draft-menu-add)
471   (add-hook 'gnus-mailing-list-mode-hook 'gnus-xmas-mailing-list-menu-add))
472
473
474 ;;; XEmacs logo and toolbar.
475
476 (defun gnus-xmas-group-startup-message (&optional x y)
477   "Insert startup message in current buffer."
478   ;; Insert the message.
479   (erase-buffer)
480   (cond
481    ((and (console-on-window-system-p)
482          (or (featurep 'xpm)
483              (featurep 'xbm)))
484     (let* ((logo-xpm (expand-file-name "gnus.xpm" gnus-xmas-glyph-directory))
485            (logo-xbm (expand-file-name "gnus.xbm" gnus-xmas-glyph-directory))
486            (glyph (make-glyph
487                    (cond ((featurep 'xpm)
488                           `[xpm
489                             :file ,logo-xpm
490                             :color-symbols
491                             (("thing" . ,(car gnus-logo-colors))
492                              ("shadow" . ,(cadr gnus-logo-colors))
493                              ("oort" . "#eeeeee")
494                              ("background" . ,(face-background 'default)))])
495                          ((featurep 'xbm)
496                           `[xbm :file ,logo-xbm])
497                          (t [nothing])))))
498       (insert " ")
499       (set-extent-begin-glyph (make-extent (point) (point)) glyph)
500       (goto-char (point-min))
501       (while (not (eobp))
502         (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
503                              ?\ ))
504         (forward-line 1))
505       (setq gnus-simple-splash nil))
506     (goto-char (point-min))
507     (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
508            (wheight (window-height))
509            (rest (- wheight pheight)))
510       (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
511    (t
512     (insert
513      (format "              %s
514           _    ___ _             _
515           _ ___ __ ___  __    _ ___
516           __   _     ___    __  ___
517               _           ___     _
518              _  _ __             _
519              ___   __            _
520                    __           _
521                     _      _   _
522                    _      _    _
523                       _  _    _
524                   __  ___
525                  _   _ _     _
526                 _   _
527               _    _
528              _    _
529             _
530           __
531
532 "
533              ""))
534     ;; And then hack it.
535     (gnus-indent-rigidly (point-min) (point-max)
536                          (/ (max (- (window-width) (or x 46)) 0) 2))
537     (goto-char (point-min))
538     (forward-line 1)
539     (let* ((pheight (count-lines (point-min) (point-max)))
540            (wheight (window-height))
541            (rest (- wheight pheight)))
542       (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
543     ;; Paint it.
544     (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)))
545   (setq modeline-buffer-identification
546         (list (concat gnus-version ": *Group*")))
547   (set-buffer-modified-p t))
548
549
550 ;;; The toolbar.
551
552 (defcustom gnus-use-toolbar (if (featurep 'toolbar)
553                                 'default-toolbar
554                               nil)
555   "*If nil, do not use a toolbar.
556 If it is non-nil, it must be a toolbar.  The five valid values are
557 `default-toolbar', `top-toolbar', `bottom-toolbar',
558 `right-toolbar', and `left-toolbar'."
559   :type '(choice (const default-toolbar)
560                  (const top-toolbar) (const bottom-toolbar)
561                  (const left-toolbar) (const right-toolbar)
562                  (const :tag "no toolbar" nil))
563   :group 'gnus-xmas)
564
565 (defvar gnus-group-toolbar
566   '([gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
567     [gnus-group-get-new-news-this-group
568      gnus-group-get-new-news-this-group t "Get new news in this group"]
569     [gnus-group-catchup-current
570      gnus-group-catchup-current t "Catchup group"]
571     [gnus-group-describe-group
572      gnus-group-describe-group t "Describe group"]
573     [gnus-group-unsubscribe gnus-group-unsubscribe t "Unsubscribe group"]
574     [gnus-group-subscribe gnus-group-subscribe t "Subscribe group"]
575     [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
576     [gnus-summary-mail-save
577      gnus-group-save-newsrc t "Save .newsrc files"] ; borrowed icon.
578     [gnus-group-exit gnus-group-exit t "Exit Gnus"])
579   "The group buffer toolbar.")
580
581 (defvar gnus-summary-toolbar
582   '([gnus-summary-prev-unread
583      gnus-summary-prev-page-or-article t "Page up"]
584     [gnus-summary-next-unread
585      gnus-summary-next-page t "Page down"]
586     [gnus-summary-post-news
587      gnus-summary-post-news t "Post an article"]
588     [gnus-summary-followup-with-original
589      gnus-summary-followup-with-original t
590      "Post a followup and yank the original"]
591     [gnus-summary-followup
592      gnus-summary-followup t "Post a followup"]
593     [gnus-summary-reply-with-original
594      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
595     [gnus-summary-reply
596      gnus-summary-reply t "Mail a reply"]
597     [gnus-summary-caesar-message
598      gnus-summary-caesar-message t "Rot 13"]
599     [gnus-uu-decode-uu
600      gnus-uu-decode-uu t "Decode uuencoded articles"]
601     [gnus-summary-save-article-file
602      gnus-summary-save-article-file t "Save article in file"]
603     [gnus-summary-save-article
604      gnus-summary-save-article t "Save article"]
605     [gnus-uu-post-news
606      gnus-uu-post-news t "Post a uuencoded article"]
607     [gnus-summary-cancel-article
608      gnus-summary-cancel-article t "Cancel article"]
609     [gnus-summary-catchup
610      gnus-summary-catchup t "Catchup"]
611     [gnus-summary-catchup-and-exit
612      gnus-summary-catchup-and-exit t "Catchup and exit"]
613     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
614   "The summary buffer toolbar.")
615
616 (defvar gnus-summary-mail-toolbar
617   '(
618     [gnus-summary-prev-unread
619      gnus-summary-prev-unread-article t "Prev unread article"]
620     [gnus-summary-next-unread
621      gnus-summary-next-unread-article t "Next unread article"]
622     [gnus-summary-mail-reply gnus-summary-reply t "Reply"]
623     [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
624     [gnus-summary-mail-save gnus-summary-save-article t "Save"]
625     [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
626     [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
627     [gnus-summary-caesar-message
628      gnus-summary-caesar-message t "Rot 13"]
629     [gnus-uu-decode-uu
630      gnus-uu-decode-uu t "Decode uuencoded articles"]
631     [gnus-summary-save-article-file
632      gnus-summary-save-article-file t "Save article in file"]
633     [gnus-summary-save-article
634      gnus-summary-save-article t "Save article"]
635     [gnus-summary-cancel-article ; usenet : cancellation :: mail : deletion.
636      gnus-summary-delete-article t "Delete message"]
637     [gnus-summary-catchup
638      gnus-summary-catchup t "Catchup"]
639     [gnus-summary-catchup-and-exit
640      gnus-summary-catchup-and-exit t "Catchup and exit"]
641     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
642   "The summary buffer mail toolbar.")
643
644 (defun gnus-xmas-setup-group-toolbar ()
645   (and gnus-use-toolbar
646        (message-xmas-setup-toolbar gnus-group-toolbar nil "gnus")
647        (set-specifier (symbol-value gnus-use-toolbar)
648                       (cons (current-buffer) gnus-group-toolbar))))
649
650 (defun gnus-xmas-setup-summary-toolbar ()
651   (let ((bar (if (gnus-news-group-p gnus-newsgroup-name)
652                  gnus-summary-toolbar gnus-summary-mail-toolbar)))
653     (and gnus-use-toolbar
654          (message-xmas-setup-toolbar bar nil "gnus")
655          (set-specifier (symbol-value gnus-use-toolbar)
656                         (cons (current-buffer) bar)))))
657
658 (defun gnus-xmas-mail-strip-quoted-names (address)
659   "Protect mail-strip-quoted-names from nil input.
660 XEmacs compatibility workaround."
661   (if (null address)
662       nil
663     (mail-strip-quoted-names address)))
664
665 (defun gnus-xmas-call-region (command &rest args)
666   (apply
667    'call-process-region (point-min) (point-max) command t '(t nil) nil
668    args))
669
670 (defvar gnus-xmas-modeline-left-extent
671   (let ((ext (copy-extent modeline-buffer-id-left-extent)))
672     ext))
673
674 (defvar gnus-xmas-modeline-right-extent
675   (let ((ext (copy-extent modeline-buffer-id-right-extent)))
676     ext))
677
678 (defvar gnus-xmas-modeline-glyph
679   (progn
680     (let* ((file-xpm (expand-file-name "gnus-pointer.xpm"
681                                        gnus-xmas-glyph-directory))
682            (file-xbm (expand-file-name "gnus-pointer.xbm"
683                                        gnus-xmas-glyph-directory))
684            (glyph (make-glyph
685                    ;; Gag gag gag.
686                    (cond ((featurep 'xpm)
687                           ;; Let's try a nifty XPM
688                           `[xpm :file ,file-xpm])
689                          ((featurep 'xbm)
690                           ;; Then a not-so-nifty XBM
691                           `[xbm :file ,file-xbm])
692                          ;; Then the simple string
693                          (t [string :data "Gnus:"])))))
694       (set-glyph-face glyph 'modeline-buffer-id)
695       glyph)))
696
697 (defun gnus-xmas-mode-line-buffer-identification (line)
698   (let ((line (car line))
699         chop)
700     (cond
701      ;; This is some weird type of id.
702      ((not (stringp line))
703       (list line))
704      ;; This is non-standard, so we just pass it through.
705      ((not (string-match "^Gnus:" line))
706       (list line))
707      ;; We have a standard line, so we colorize and glyphize it a bit.
708      (t
709       (setq chop (match-end 0))
710       (list
711        (if gnus-xmas-modeline-glyph
712            (cons gnus-xmas-modeline-left-extent gnus-xmas-modeline-glyph)
713          (cons gnus-xmas-modeline-left-extent (substring line 0 chop)))
714        (cons gnus-xmas-modeline-right-extent (substring line chop)))))))
715
716 (defun gnus-xmas-splash ()
717   (when (eq (device-type) 'x)
718     (gnus-splash)))
719
720 (defun gnus-xmas-annotation-in-region-p (b e)
721   (or (map-extents (lambda (e u) t) nil b e nil nil 'mm t)
722       (if (= b e)
723           (eq (cadr (memq 'gnus-undeletable (text-properties-at b))) t)
724         (text-property-any b e 'gnus-undeletable t))))
725
726 (defun gnus-xmas-mime-button-menu (event prefix)
727   "Construct a context-sensitive menu of MIME commands."
728   (interactive "e\nP")
729   (let ((response (get-popup-menu-response
730                    `("MIME Part"
731                      ,@(mapcar (lambda (c) `[,(caddr c) ,(car c) t])
732                                gnus-mime-button-commands)))))
733     (set-buffer (event-buffer event))
734     (goto-char (event-point event))
735     (funcall (event-function response) (event-object response))))
736
737 (defun gnus-group-add-icon ()
738   "Add an icon to the current line according to `gnus-group-icon-list'."
739   (let* ((p (point))
740          (end (gnus-point-at-eol))
741          ;; now find out where the line starts and leave point there.
742          (beg (progn (beginning-of-line) (point))))
743     (save-restriction
744       (narrow-to-region beg end)
745       (goto-char beg)
746       (when (search-forward "==&&==" nil t)
747         (let* ((group (gnus-group-group-name))
748                (entry (gnus-group-entry group))
749                (unread (if (numberp (car entry)) (car entry) 0))
750                (active (gnus-active group))
751                (total (if active (1+ (- (cdr active) (car active))) 0))
752                (info (nth 2 entry))
753                (method (gnus-server-get-method group (gnus-info-method info)))
754                (marked (gnus-info-marks info))
755                (mailp (memq 'mail (assoc (symbol-name
756                                           (car (or method gnus-select-method)))
757                                          gnus-valid-select-methods)))
758                (level (or (gnus-info-level info) gnus-level-killed))
759                (score (or (gnus-info-score info) 0))
760                (ticked (gnus-range-length (cdr (assq 'tick marked))))
761                (group-age (gnus-group-timestamp-delta group))
762                (inhibit-read-only t)
763                (list gnus-group-icon-list)
764                (mystart (match-beginning 0))
765                (myend (match-end 0)))
766           (goto-char (point-min))
767           (while (and list
768                       (not (eval (caar list))))
769             (setq list (cdr list)))
770           (if list
771               (let* ((file (cdar list))
772                      (glyph (gnus-group-icon-create-glyph
773                              (buffer-substring mystart myend)
774                              file)))
775                 (if glyph
776                     (progn
777                       (mapcar 'delete-annotation (annotations-at myend))
778                       (let ((ext (make-extent mystart myend))
779                             (ant (make-annotation glyph myend 'text)))
780                         ;; set text extent params
781                         (set-extent-property ext 'end-open t)
782                         (set-extent-property ext 'start-open t)
783                         (set-extent-property ext 'invisible t)))
784                   (delete-region mystart myend)))
785             (delete-region mystart myend))))
786       (widen))
787     (goto-char p)))
788
789 (defun gnus-group-icon-create-glyph (substring pixmap)
790   "Create a glyph for insertion into a group line."
791   (or
792    (cdr-safe (assoc pixmap gnus-group-icon-cache))
793    (let* ((glyph (make-glyph
794                   (list
795                    (cons 'x
796                          (expand-file-name pixmap gnus-xmas-glyph-directory))
797                    (cons 'mswindows
798                          (expand-file-name pixmap gnus-xmas-glyph-directory))
799                    (cons 'tty substring)))))
800      (setq gnus-group-icon-cache
801            (cons (cons pixmap glyph) gnus-group-icon-cache))
802      (set-glyph-face glyph 'default)
803      glyph)))
804
805 (defun gnus-xmas-mailing-list-menu-add ()
806   (gnus-xmas-menu-add mailing-list
807                       gnus-mailing-list-menu))
808
809 (defun gnus-xmas-image-type-available-p (type)
810   (and window-system
811        (featurep (if (eq type 'pbm) 'xbm type))))
812
813 (defun gnus-xmas-create-image (file &optional type data-p &rest props)
814   (let ((type (if type
815                   (symbol-name type)
816                 (car (last (split-string file "[.]")))))
817         (face (plist-get props :face))
818         glyph)
819     (when (equal type "pbm")
820       (with-temp-buffer
821         (if data-p
822             (insert file)
823           (insert-file-contents-literally file))
824         (shell-command-on-region (point-min) (point-max)
825                                  "ppmtoxpm 2>/dev/null" t)
826         (setq file (buffer-string)
827               type "xpm"
828               data-p t)))
829     (setq glyph
830           (if (equal type "xbm")
831               (make-glyph (list (cons 'x file)))
832             (with-temp-buffer
833               (if data-p
834                   (insert file)
835                 (insert-file-contents-literally file))
836               (make-glyph
837                (vector
838                 (or (intern type)
839                     (mm-image-type-from-buffer))
840                 :data (buffer-string))))))
841     (when face
842       (set-glyph-face glyph face))
843     glyph))
844
845 (defun gnus-xmas-put-image (glyph &optional string category)
846   "Insert STRING, but display GLYPH.
847 Warning: Don't insert text immediately after the image."
848   (let ((begin (point))
849         extent)
850     (if (and (bobp) (not string))
851         (setq string " "))
852     (if string
853         (insert string)
854       (setq begin (1- begin)))
855     (setq extent (make-extent begin (point)))
856     (set-extent-property extent 'gnus-image category)
857     (set-extent-property extent 'duplicable t)
858     (if string
859         (set-extent-property extent 'invisible t))
860     (set-extent-property extent 'end-glyph glyph))
861   glyph)
862
863 (defun gnus-xmas-remove-image (image &optional category)
864   (map-extents
865    (lambda (ext unused)
866      (when (equal (extent-end-glyph ext) image)
867        (set-extent-property ext 'invisible nil)
868        (set-extent-property ext 'end-glyph nil))
869      nil)
870    nil nil nil nil nil 'gnus-image category))
871
872 (defun gnus-xmas-completing-read (prompt table &optional
873                                          predicate require-match history)
874   (when (and history
875              (not (boundp history)))
876     (set history nil))
877   (completing-read
878    (if (symbol-value history)
879        (concat prompt " (" (car (symbol-value history)) "): ")
880      (concat prompt ": "))
881    table
882    predicate
883    require-match
884    nil
885    history))
886
887 ;; This macro is because XEmacs versions prior to 21.2 do not have the
888 ;; PROTOCOL argument to `open-network-stream'.
889 (defmacro gnus-xmas-open-network-stream (name buffer host service &optional protocol)
890   "Like `open-network-stream' but take into account older XEmacs versions."
891   (if (and (featurep 'xemacs)
892            (fboundp 'open-network-stream)
893            (emacs-version>= 21 2))
894       `(open-network-stream ,name ,buffer ,host ,service ,protocol)
895     `(open-network-stream ,name ,buffer ,host ,service)))
896
897 (defun gnus-xmas-assq-delete-all (key alist)
898   (let ((elem nil))
899     (while (setq elem (assq key alist))
900       (setq alist (delq elem alist)))
901     alist))
902
903 (provide 'gnus-xmas)
904
905 ;;; gnus-xmas.el ends here