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