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