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