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