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