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