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