Fix doc.
[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-window-top-edge (&optional window)
228   (nth 1 (window-pixel-edges window)))
229
230 (defun gnus-xmas-tree-minimize ()
231   (when (and gnus-tree-minimize-window
232              (not (one-window-p)))
233     (let* ((window-min-height 2)
234            (height (1+ (count-lines (point-min) (point-max))))
235            (min (max (1- window-min-height) height))
236            (tot (if (numberp gnus-tree-minimize-window)
237                     (min gnus-tree-minimize-window min)
238                   min))
239            (win (get-buffer-window (current-buffer)))
240            (wh (and win (1- (window-height win)))))
241       (when (and win
242                  (not (eq tot wh)))
243         (let ((selected (selected-window)))
244           (select-window win)
245           (enlarge-window (- tot wh))
246           (select-window selected))))))
247
248 ;; Select the lowest window on the frame.
249 (defun gnus-xmas-select-lowest-window ()
250   (let* ((lowest-window (selected-window))
251          (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
252          (last-window (previous-window))
253          (window-search t))
254     (while window-search
255       (let* ((this-window (next-window))
256              (next-bottom-edge (car (cdr (cdr (cdr
257                                                (window-pixel-edges
258                                                 this-window)))))))
259         (when (< bottom-edge next-bottom-edge)
260           (setq bottom-edge next-bottom-edge)
261           (setq lowest-window this-window))
262
263         (select-window this-window)
264         (when (eq last-window this-window)
265           (select-window lowest-window)
266           (setq window-search nil))))))
267
268 (defmacro gnus-xmas-menu-add (type &rest menus)
269   `(gnus-xmas-menu-add-1 ',type ',menus))
270 (put 'gnus-xmas-menu-add 'lisp-indent-function 1)
271
272 (defun gnus-xmas-menu-add-1 (type menus)
273   (when (and menu-bar-mode
274              (gnus-visual-p (intern (format "%s-menu" type)) 'menu))
275     (while menus
276       (easy-menu-add (symbol-value (pop menus))))))
277
278 (defun gnus-xmas-group-menu-add ()
279   (gnus-xmas-menu-add group
280     gnus-group-reading-menu gnus-group-group-menu gnus-group-misc-menu))
281
282 (defun gnus-xmas-summary-menu-add ()
283   (gnus-xmas-menu-add summary
284     gnus-summary-misc-menu gnus-summary-kill-menu
285     gnus-summary-article-menu gnus-summary-thread-menu
286     gnus-summary-post-menu ))
287
288 (defun gnus-xmas-article-menu-add ()
289   (gnus-xmas-menu-add article
290     gnus-article-article-menu gnus-article-treatment-menu
291     gnus-article-post-menu gnus-article-commands-menu))
292
293 (defun gnus-xmas-score-menu-add ()
294   (gnus-xmas-menu-add score
295     gnus-score-menu))
296
297 (defun gnus-xmas-pick-menu-add ()
298   (gnus-xmas-menu-add pick
299     gnus-pick-menu))
300
301 (defun gnus-xmas-topic-menu-add ()
302   (gnus-xmas-menu-add topic
303     gnus-topic-menu))
304
305 (defun gnus-xmas-binary-menu-add ()
306   (gnus-xmas-menu-add binary
307     gnus-binary-menu))
308
309 (defun gnus-xmas-agent-summary-menu-add ()
310   (gnus-xmas-menu-add agent-summary
311     gnus-agent-summary-menu))
312
313 (defun gnus-xmas-agent-group-menu-add ()
314   (gnus-xmas-menu-add agent-group
315     gnus-agent-group-menu))
316
317 (defun gnus-xmas-agent-server-menu-add ()
318   (gnus-xmas-menu-add agent-server
319     gnus-agent-server-menu))
320
321 (defun gnus-xmas-tree-menu-add ()
322   (gnus-xmas-menu-add tree
323     gnus-tree-menu))
324
325 (defun gnus-xmas-draft-menu-add ()
326   (gnus-xmas-menu-add draft
327     gnus-draft-menu))
328
329 (defun gnus-xmas-server-menu-add ()
330   (gnus-xmas-menu-add menu
331     gnus-server-server-menu gnus-server-connections-menu))
332
333 (defun gnus-xmas-browse-menu-add ()
334   (gnus-xmas-menu-add browse
335     gnus-browse-menu))
336
337 (defun gnus-xmas-read-event-char (&optional prompt)
338   "Get the next event."
339   (when prompt
340     (message "%s" prompt))
341   (let ((event (next-command-event)))
342     (sit-for 0)
343     ;; We junk all non-key events.  Is this naughty?
344     (while (not (or (key-press-event-p event)
345                     (button-press-event-p event)))
346       (dispatch-event event)
347       (setq event (next-command-event)))
348     (cons (and (key-press-event-p event)
349                (event-to-character event))
350           event)))
351
352 (defun gnus-xmas-article-describe-bindings (&optional prefix)
353   "Show a list of all defined keys, and their definitions.
354 The optional argument PREFIX, if non-nil, should be a key sequence;
355 then we display only bindings that start with that prefix."
356   (interactive)
357   (gnus-article-check-buffer)
358   (let ((keymap (copy-keymap gnus-article-mode-map))
359         (map (copy-keymap gnus-article-send-map))
360         (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
361         agent draft)
362     (define-key keymap "S" map)
363     (set-keymap-default-binding map nil)
364     (with-current-buffer gnus-article-current-summary
365       (let ((def (key-binding "S"))
366             gnus-pick-mode)
367         (set-keymap-parent map (if (symbolp def)
368                                    (symbol-value def)
369                                  def))
370         (dolist (key sumkeys)
371           (when (setq def (key-binding key))
372             (define-key keymap key def))))
373       (when (boundp 'gnus-agent-summary-mode)
374         (setq agent gnus-agent-summary-mode))
375       (when (boundp 'gnus-draft-mode)
376         (setq draft gnus-draft-mode)))
377     (with-temp-buffer
378       (setq major-mode 'gnus-article-mode)
379       (use-local-map keymap)
380       (set (make-local-variable 'gnus-agent-summary-mode) agent)
381       (set (make-local-variable 'gnus-draft-mode) draft)
382       (describe-bindings prefix))))
383
384 (defun gnus-xmas-define ()
385   (setq gnus-mouse-2 [button2])
386   (setq gnus-mouse-3 [button3])
387   (setq gnus-widget-button-keymap widget-button-keymap)
388
389   (unless (memq 'underline (face-list))
390     (and (fboundp 'make-face)
391          (funcall (intern "make-face") 'underline)))
392   ;; Must avoid calling set-face-underline-p directly, because it
393   ;; is a defsubst in emacs19, and will make the .elc files non
394   ;; portable!
395   (unless (face-differs-from-default-p 'underline)
396     (funcall (intern "set-face-underline-p") 'underline t))
397
398   (cond
399    ((fboundp 'char-or-char-int-p)
400     ;; Handle both types of marks for XEmacs-20.x.
401     (defalias 'gnus-characterp 'char-or-char-int-p))
402    ;; V19 of XEmacs, probably.
403    (t
404     (defalias 'gnus-characterp 'characterp)))
405
406   (defalias 'gnus-make-overlay
407     (lambda (beg end &optional buffer front-advance rear-advance)
408       "Create a new overlay with range BEG to END in BUFFER.
409 FRONT-ADVANCE and REAR-ADVANCE are ignored."
410       (make-extent beg end buffer)))
411
412   (defalias 'gnus-delete-overlay 'delete-extent)
413   (defalias 'gnus-overlay-put 'set-extent-property)
414   (defalias 'gnus-move-overlay 'gnus-xmas-move-overlay)
415   (defalias 'gnus-overlay-buffer 'extent-object)
416   (defalias 'gnus-overlay-start 'extent-start-position)
417   (defalias 'gnus-overlay-end 'extent-end-position)
418   (defalias 'gnus-kill-all-overlays 'gnus-xmas-kill-all-overlays)
419   (defalias 'gnus-extent-detached-p 'extent-detached-p)
420   (defalias 'gnus-add-text-properties 'gnus-xmas-add-text-properties)
421   (defalias 'gnus-put-text-property 'gnus-xmas-put-text-property)
422   (defalias 'gnus-deactivate-mark 'ignore)
423   (defalias 'gnus-window-edges 'window-pixel-edges)
424   (defalias 'gnus-assq-delete-all 'gnus-xmas-assq-delete-all)
425
426   (unless (boundp 'standard-display-table)
427     (setq standard-display-table nil))
428
429   (defvar gnus-mouse-face-prop 'highlight)
430
431   (defun gnus-byte-code (func)
432     "Return a form that can be `eval'ed based on FUNC."
433     (let ((fval (indirect-function func)))
434       (if (compiled-function-p fval)
435           (list 'funcall fval)
436         (cons 'progn (cdr (cdr fval))))))
437
438   (unless (fboundp 'match-string-no-properties)
439     (defalias 'match-string-no-properties 'match-string))
440
441   (defalias 'gnus-x-color-values
442         (if (fboundp 'x-color-values)
443             'x-color-values
444           (lambda (color)
445             (color-instance-rgb-components
446              (make-color-instance color)))))
447
448   (unless (fboundp 'char-width)
449     (defalias 'char-width (lambda (ch) 1))))
450
451 (defun gnus-xmas-redefine ()
452   "Redefine lots of Gnus functions for XEmacs."
453   (defalias 'gnus-summary-set-display-table 'gnus-xmas-summary-set-display-table)
454   (defalias 'gnus-visual-turn-off-edit-menu 'identity)
455   (defalias 'gnus-summary-recenter 'gnus-xmas-summary-recenter)
456   (defalias 'gnus-extent-start-open 'gnus-xmas-extent-start-open)
457   (defalias 'gnus-article-push-button 'gnus-xmas-article-push-button)
458   (defalias 'gnus-window-top-edge 'gnus-xmas-window-top-edge)
459   (defalias 'gnus-read-event-char 'gnus-xmas-read-event-char)
460   (defalias 'gnus-group-startup-message 'gnus-xmas-group-startup-message)
461   (defalias 'gnus-tree-minimize 'gnus-xmas-tree-minimize)
462   (defalias 'gnus-select-lowest-window
463     'gnus-xmas-select-lowest-window)
464   (defalias 'gnus-mail-strip-quoted-names 'gnus-xmas-mail-strip-quoted-names)
465   (defalias 'gnus-character-to-event 'character-to-event)
466   (defalias 'gnus-mode-line-buffer-identification
467     'gnus-xmas-mode-line-buffer-identification)
468   (defalias 'gnus-key-press-event-p 'key-press-event-p)
469   (defalias 'gnus-region-active-p 'region-active-p)
470   (defalias 'gnus-mark-active-p 'region-exists-p)
471   (defalias 'gnus-annotation-in-region-p 'gnus-xmas-annotation-in-region-p)
472   (defalias 'gnus-mime-button-menu 'gnus-xmas-mime-button-menu)
473   (defalias 'gnus-mime-security-button-menu
474     'gnus-xmas-mime-security-button-menu)
475   (defalias 'gnus-image-type-available-p 'gnus-xmas-image-type-available-p)
476   (defalias 'gnus-put-image 'gnus-xmas-put-image)
477   (defalias 'gnus-create-image 'gnus-xmas-create-image)
478   (defalias 'gnus-remove-image 'gnus-xmas-remove-image)
479   (defalias 'gnus-article-describe-bindings
480     'gnus-xmas-article-describe-bindings)
481
482   ;; These ones are not defcutom'ed, sometimes not even defvar'ed. They
483   ;; probably should. If that is done, the code below should then be moved
484   ;; where each variable is defined, in order not to mess with user settings.
485   ;; -- didier
486   (add-hook 'gnus-score-mode-hook 'gnus-xmas-score-menu-add)
487   (add-hook 'gnus-binary-mode-hook 'gnus-xmas-binary-menu-add)
488   (add-hook 'gnus-server-mode-hook 'gnus-xmas-server-menu-add)
489   (add-hook 'gnus-browse-mode-hook 'gnus-xmas-browse-menu-add)
490   (add-hook 'gnus-draft-mode-hook 'gnus-xmas-draft-menu-add)
491   (add-hook 'gnus-mailing-list-mode-hook 'gnus-xmas-mailing-list-menu-add))
492
493
494 ;;; XEmacs logo and toolbar.
495
496 (defun gnus-xmas-group-startup-message (&optional x y)
497   "Insert startup message in current buffer."
498   ;; Insert the message.
499   (erase-buffer)
500   (cond
501    ((and (console-on-window-system-p)
502          (or (featurep 'xpm)
503              (featurep 'xbm)))
504     (let* ((logo-xpm (expand-file-name "gnus.xpm" gnus-xmas-glyph-directory))
505            (logo-xbm (expand-file-name "gnus.xbm" gnus-xmas-glyph-directory))
506            (glyph (make-glyph
507                    (cond ((featurep 'xpm)
508                           `[xpm
509                             :file ,logo-xpm
510                             :color-symbols
511                             (("thing" . ,(car gnus-logo-colors))
512                              ("shadow" . ,(cadr gnus-logo-colors))
513                              ("oort" . "#eeeeee")
514                              ("background" . ,(face-background 'default)))])
515                          ((featurep 'xbm)
516                           `[xbm :file ,logo-xbm])
517                          (t [nothing])))))
518       (insert " ")
519       (set-extent-begin-glyph (make-extent (point) (point)) glyph)
520       (goto-char (point-min))
521       (while (not (eobp))
522         (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
523                              ?\ ))
524         (forward-line 1))
525       (setq gnus-simple-splash nil))
526     (goto-char (point-min))
527     (let* ((pheight (+ 20 (count-lines (point-min) (point-max))))
528            (wheight (window-height))
529            (rest (- wheight pheight)))
530       (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))))
531    (t
532     (insert
533      (format "              %s
534           _    ___ _             _
535           _ ___ __ ___  __    _ ___
536           __   _     ___    __  ___
537               _           ___     _
538              _  _ __             _
539              ___   __            _
540                    __           _
541                     _      _   _
542                    _      _    _
543                       _  _    _
544                   __  ___
545                  _   _ _     _
546                 _   _
547               _    _
548              _    _
549             _
550           __
551
552 "
553              ""))
554     ;; And then hack it.
555     (gnus-indent-rigidly (point-min) (point-max)
556                          (/ (max (- (window-width) (or x 46)) 0) 2))
557     (goto-char (point-min))
558     (forward-line 1)
559     (let* ((pheight (count-lines (point-min) (point-max)))
560            (wheight (window-height))
561            (rest (- wheight pheight)))
562       (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
563     ;; Paint it.
564     (put-text-property (point-min) (point-max) 'face 'gnus-splash)))
565   (setq modeline-buffer-identification
566         (list (concat gnus-version ": *Group*")))
567   (set-buffer-modified-p t))
568
569
570 ;;; The toolbar.
571
572 (defun gnus-xmas-update-toolbars ()
573   "Update the toolbars' appearance."
574   (when (and (not noninteractive)
575              (featurep 'gnus-xmas))
576     (save-excursion
577       (dolist (buffer (buffer-list))
578         (set-buffer buffer)
579         (cond ((eq major-mode 'gnus-group-mode)
580                (gnus-xmas-setup-group-toolbar))
581               ((eq major-mode 'gnus-summary-mode)
582                (gnus-xmas-setup-summary-toolbar)))))))
583
584 (defcustom gnus-use-toolbar (if (featurep 'toolbar) 'default)
585   "*Position to display the toolbar.  Nil means do not use a toolbar.
586 If it is non-nil, it should be one of the symbols `default', `top',
587 `bottom', `right', and `left'.  `default' means to use the default
588 toolbar, the rest mean to display the toolbar on the place which those
589 names show."
590   :type '(choice (const default)
591                  (const top) (const bottom) (const left) (const right)
592                  (const :tag "no toolbar" nil))
593   :set (lambda (symbol value)
594          (set-default
595           symbol
596           (if (or (not value)
597                   (memq value (list 'default 'top 'bottom 'right 'left)))
598               value
599             'default))
600          (gnus-xmas-update-toolbars))
601   :group 'gnus-xmas)
602
603 (defcustom gnus-toolbar-thickness
604   (if (featurep 'toolbar)
605       (cons (specifier-instance default-toolbar-height)
606             (specifier-instance default-toolbar-width)))
607   "*Cons of the height and the width specifying the thickness of a toolbar.
608 The height is used for the toolbar displayed on the top or the bottom,
609 the width is used for the toolbar displayed on the right or the left."
610   :type '(cons :tag "height & width"
611                (integer :tag "height") (integer :tag "width"))
612   :set (lambda (symbol value)
613          (set-default
614           symbol
615           (if (and (consp value) (natnump (car value)) (natnump (cdr value)))
616               value
617             '(37 . 40)))
618          (gnus-xmas-update-toolbars))
619   :group 'gnus-xmas)
620
621 (defvar gnus-group-toolbar
622   '([gnus-group-get-new-news gnus-group-get-new-news t "Get new news"]
623     [gnus-group-get-new-news-this-group
624      gnus-group-get-new-news-this-group t "Get new news in this group"]
625     [gnus-group-catchup-current
626      gnus-group-catchup-current t "Catchup group"]
627     [gnus-group-describe-group
628      gnus-group-describe-group t "Describe group"]
629     [gnus-group-unsubscribe gnus-group-unsubscribe t "Unsubscribe group"]
630     [gnus-group-subscribe gnus-group-subscribe t "Subscribe group"]
631     [gnus-group-kill-group gnus-group-kill-group t "Kill group"]
632     [gnus-summary-mail-save
633      gnus-group-save-newsrc t "Save .newsrc files"] ; borrowed icon.
634     [gnus-group-exit gnus-group-exit t "Exit Gnus"])
635   "The group buffer toolbar.")
636
637 (defvar gnus-summary-toolbar
638   '([gnus-summary-prev-unread
639      gnus-summary-prev-page-or-article t "Page up"]
640     [gnus-summary-next-unread
641      gnus-summary-next-page t "Page down"]
642     [gnus-summary-post-news
643      gnus-summary-post-news t "Post an article"]
644     [gnus-summary-followup-with-original
645      gnus-summary-followup-with-original t
646      "Post a followup and yank the original"]
647     [gnus-summary-followup
648      gnus-summary-followup t "Post a followup"]
649     [gnus-summary-reply-with-original
650      gnus-summary-reply-with-original t "Mail a reply and yank the original"]
651     [gnus-summary-reply
652      gnus-summary-reply t "Mail a reply"]
653     [gnus-summary-caesar-message
654      gnus-summary-caesar-message t "Rot 13"]
655     [gnus-uu-decode-uu
656      gnus-uu-decode-uu t "Decode uuencoded articles"]
657     [gnus-summary-save-article-file
658      gnus-summary-save-article-file t "Save article in file"]
659     [gnus-summary-save-article
660      gnus-summary-save-article t "Save article"]
661     [gnus-uu-post-news
662      gnus-uu-post-news t "Post a uuencoded article"]
663     [gnus-summary-cancel-article
664      gnus-summary-cancel-article t "Cancel article"]
665     [gnus-summary-catchup
666      gnus-summary-catchup t "Catchup"]
667     [gnus-summary-catchup-and-exit
668      gnus-summary-catchup-and-exit t "Catchup and exit"]
669     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
670   "The summary buffer toolbar.")
671
672 (defvar gnus-summary-mail-toolbar
673   '(
674     [gnus-summary-prev-unread
675      gnus-summary-prev-unread-article t "Prev unread article"]
676     [gnus-summary-next-unread
677      gnus-summary-next-unread-article t "Next unread article"]
678     [gnus-summary-mail-reply gnus-summary-reply t "Reply"]
679     [gnus-summary-mail-originate gnus-summary-post-news t "Originate"]
680     [gnus-summary-mail-save gnus-summary-save-article t "Save"]
681     [gnus-summary-mail-copy gnus-summary-copy-article t "Copy message"]
682     [gnus-summary-mail-forward gnus-summary-mail-forward t "Forward message"]
683     [gnus-summary-caesar-message
684      gnus-summary-caesar-message t "Rot 13"]
685     [gnus-uu-decode-uu
686      gnus-uu-decode-uu t "Decode uuencoded articles"]
687     [gnus-summary-save-article-file
688      gnus-summary-save-article-file t "Save article in file"]
689     [gnus-summary-save-article
690      gnus-summary-save-article t "Save article"]
691     [gnus-summary-cancel-article ; usenet : cancellation :: mail : deletion.
692      gnus-summary-delete-article t "Delete message"]
693     [gnus-summary-catchup
694      gnus-summary-catchup t "Catchup"]
695     [gnus-summary-catchup-and-exit
696      gnus-summary-catchup-and-exit t "Catchup and exit"]
697     [gnus-summary-exit gnus-summary-exit t "Exit this summary"])
698   "The summary buffer mail toolbar.")
699
700 (defun gnus-xmas-setup-toolbar (toolbar)
701   (when (featurep 'toolbar)
702     (if (and gnus-use-toolbar
703              (message-xmas-setup-toolbar toolbar nil "gnus"))
704         (let ((bar (or (intern-soft (format "%s-toolbar" gnus-use-toolbar))
705                        'default-toolbar))
706               (height (car gnus-toolbar-thickness))
707               (width (cdr gnus-toolbar-thickness))
708               (cur (current-buffer))
709               bars)
710           (set-specifier (symbol-value bar) toolbar cur)
711           (set-specifier default-toolbar-height height cur)
712           (set-specifier default-toolbar-width width cur)
713           (set-specifier top-toolbar-height height cur)
714           (set-specifier bottom-toolbar-height height cur)
715           (set-specifier right-toolbar-width width cur)
716           (set-specifier left-toolbar-width width cur)
717           (if (eq bar 'default-toolbar)
718               (progn
719                 (remove-specifier default-toolbar-visible-p cur)
720                 (remove-specifier top-toolbar cur)
721                 (remove-specifier top-toolbar-visible-p cur)
722                 (remove-specifier bottom-toolbar cur)
723                 (remove-specifier bottom-toolbar-visible-p cur)
724                 (remove-specifier right-toolbar cur)
725                 (remove-specifier right-toolbar-visible-p cur)
726                 (remove-specifier left-toolbar cur)
727                 (remove-specifier left-toolbar-visible-p cur))
728             (set-specifier (symbol-value (intern (format "%s-visible-p" bar)))
729                            t cur)
730             (setq bars (delq bar (list 'default-toolbar
731                                        'bottom-toolbar 'top-toolbar
732                                        'right-toolbar 'left-toolbar)))
733             (while bars
734               (set-specifier (symbol-value (intern (format "%s-visible-p"
735                                                            (pop bars))))
736                              nil cur))))
737       (let ((cur (current-buffer)))
738         (set-specifier default-toolbar-visible-p nil cur)
739         (set-specifier top-toolbar-visible-p nil cur)
740         (set-specifier bottom-toolbar-visible-p nil cur)
741         (set-specifier right-toolbar-visible-p nil cur)
742         (set-specifier left-toolbar-visible-p nil cur)))))
743
744 (defun gnus-xmas-setup-group-toolbar ()
745   (gnus-xmas-setup-toolbar gnus-group-toolbar))
746
747 (defun gnus-xmas-setup-summary-toolbar ()
748   (gnus-xmas-setup-toolbar (if (gnus-news-group-p gnus-newsgroup-name)
749                                gnus-summary-toolbar
750                              gnus-summary-mail-toolbar)))
751
752 (defun gnus-xmas-mail-strip-quoted-names (address)
753   "Protect mail-strip-quoted-names from nil input.
754 XEmacs compatibility workaround."
755   (if (null address)
756       nil
757     (mail-strip-quoted-names address)))
758
759 (defun gnus-xmas-call-region (command &rest args)
760   (apply
761    'call-process-region (point-min) (point-max) command t '(t nil) nil
762    args))
763
764 (defvar gnus-xmas-modeline-left-extent
765   (let ((ext (copy-extent modeline-buffer-id-left-extent)))
766     ext))
767
768 (defvar gnus-xmas-modeline-right-extent
769   (let ((ext (copy-extent modeline-buffer-id-right-extent)))
770     ext))
771
772 (defvar gnus-xmas-modeline-glyph
773   (progn
774     (let* ((file-xpm (expand-file-name "gnus-pointer.xpm"
775                                        gnus-xmas-glyph-directory))
776            (file-xbm (expand-file-name "gnus-pointer.xbm"
777                                        gnus-xmas-glyph-directory))
778            (glyph (make-glyph
779                    ;; Gag gag gag.
780                    (cond ((featurep 'xpm)
781                           ;; Let's try a nifty XPM
782                           `[xpm :file ,file-xpm])
783                          ((featurep 'xbm)
784                           ;; Then a not-so-nifty XBM
785                           `[xbm :file ,file-xbm])
786                          ;; Then the simple string
787                          (t [string :data "Gnus:"])))))
788       (set-glyph-face glyph 'modeline-buffer-id)
789       glyph)))
790
791 (defun gnus-xmas-mode-line-buffer-identification (line)
792   (let ((line (car line))
793         chop)
794     (cond
795      ;; This is some weird type of id.
796      ((not (stringp line))
797       (list line))
798      ;; This is non-standard, so we just pass it through.
799      ((not (string-match "^Gnus:" line))
800       (list line))
801      ;; We have a standard line, so we colorize and glyphize it a bit.
802      (t
803       (setq chop (match-end 0))
804       (list
805        (if gnus-xmas-modeline-glyph
806            (cons gnus-xmas-modeline-left-extent gnus-xmas-modeline-glyph)
807          (cons gnus-xmas-modeline-left-extent (substring line 0 chop)))
808        (cons gnus-xmas-modeline-right-extent (substring line chop)))))))
809
810 (defun gnus-xmas-splash ()
811   (when (eq (device-type) 'x)
812     (gnus-splash)))
813
814 (defun gnus-xmas-annotation-in-region-p (b e)
815   (or (map-extents (lambda (e u) t) nil b e nil nil 'mm t)
816       (if (= b e)
817           (eq (cadr (memq 'gnus-undeletable (text-properties-at b))) t)
818         (text-property-any b e 'gnus-undeletable t))))
819
820 (defun gnus-xmas-mime-button-menu (event prefix)
821   "Construct a context-sensitive menu of MIME commands."
822   (interactive "e\nP")
823   (let ((response (get-popup-menu-response
824                    `("MIME Part"
825                      ,@(mapcar (lambda (c) `[,(caddr c) ,(car c) t])
826                                gnus-mime-button-commands)))))
827     (set-buffer (event-buffer event))
828     (goto-char (event-point event))
829     (funcall (event-function response) (event-object response))))
830
831 (defun gnus-xmas-mime-security-button-menu (event prefix)
832   "Construct a context-sensitive menu of security commands."
833   (interactive "e\nP")
834   (let ((response
835          (get-popup-menu-response
836           `("Security Part"
837             ,@(delq nil
838                     (mapcar (lambda (c)
839                               (unless (eq (car c) 'undefined)
840                                 `[,(caddr c) ,(car c) t]))
841                             gnus-mime-security-button-commands))))))
842     (set-buffer (event-buffer event))
843     (goto-char (event-point event))
844     (funcall (event-function response) (event-object response))))
845
846 (defun gnus-group-add-icon ()
847   "Add an icon to the current line according to `gnus-group-icon-list'."
848   (let* ((p (point))
849          (end (point-at-eol))
850          ;; now find out where the line starts and leave point there.
851          (beg (progn (beginning-of-line) (point))))
852     (save-restriction
853       (narrow-to-region beg end)
854       (goto-char beg)
855       (when (search-forward "==&&==" nil t)
856         (let* ((group (gnus-group-group-name))
857                (entry (gnus-group-entry group))
858                (unread (if (numberp (car entry)) (car entry) 0))
859                (active (gnus-active group))
860                (total (if active (1+ (- (cdr active) (car active))) 0))
861                (info (nth 2 entry))
862                (method (gnus-server-get-method group (gnus-info-method info)))
863                (marked (gnus-info-marks info))
864                (mailp (memq 'mail (assoc (symbol-name
865                                           (car (or method gnus-select-method)))
866                                          gnus-valid-select-methods)))
867                (level (or (gnus-info-level info) gnus-level-killed))
868                (score (or (gnus-info-score info) 0))
869                (ticked (gnus-range-length (cdr (assq 'tick marked))))
870                (group-age (gnus-group-timestamp-delta group))
871                (inhibit-read-only t)
872                (list gnus-group-icon-list)
873                (mystart (match-beginning 0))
874                (myend (match-end 0)))
875           (goto-char (point-min))
876           (while (and list
877                       (not (eval (caar list))))
878             (setq list (cdr list)))
879           (if list
880               (let* ((file (cdar list))
881                      (glyph (gnus-group-icon-create-glyph
882                              (buffer-substring mystart myend)
883                              file)))
884                 (if glyph
885                     (progn
886                       (mapc 'delete-annotation (annotations-at myend))
887                       (let ((ext (make-extent mystart myend))
888                             (ant (make-annotation glyph myend 'text)))
889                         ;; set text extent params
890                         (set-extent-property ext 'end-open t)
891                         (set-extent-property ext 'start-open t)
892                         (set-extent-property ext 'invisible t)))
893                   (delete-region mystart myend)))
894             (delete-region mystart myend))))
895       (widen))
896     (goto-char p)))
897
898 (defun gnus-group-icon-create-glyph (substring pixmap)
899   "Create a glyph for insertion into a group line."
900   (or
901    (cdr-safe (assoc pixmap gnus-group-icon-cache))
902    (let* ((glyph (make-glyph
903                   (list
904                    (cons 'x
905                          (expand-file-name pixmap gnus-xmas-glyph-directory))
906                    (cons 'mswindows
907                          (expand-file-name pixmap gnus-xmas-glyph-directory))
908                    (cons 'tty substring)))))
909      (setq gnus-group-icon-cache
910            (cons (cons pixmap glyph) gnus-group-icon-cache))
911      (set-glyph-face glyph 'default)
912      glyph)))
913
914 (defun gnus-xmas-mailing-list-menu-add ()
915   (gnus-xmas-menu-add mailing-list
916                       gnus-mailing-list-menu))
917
918 (defun gnus-xmas-image-type-available-p (type)
919   (and (if (fboundp 'display-images-p)
920            (display-images-p)
921          window-system)
922        (featurep (if (eq type 'pbm) 'xbm type))))
923
924 (defun gnus-xmas-create-image (file &optional type data-p &rest props)
925   (let ((type (if type
926                   (symbol-name type)
927                 (car (last (split-string file "[.]")))))
928         (face (plist-get props :face))
929         glyph)
930     (when (equal type "pbm")
931       (with-temp-buffer
932         (if data-p
933             (insert file)
934           (insert-file-contents-literally file))
935         (shell-command-on-region (point-min) (point-max)
936                                  "ppmtoxpm 2>/dev/null" t)
937         (setq file (buffer-string)
938               type "xpm"
939               data-p t)))
940     (setq glyph
941           (if (equal type "xbm")
942               (make-glyph (list (cons 'x file)))
943             (with-temp-buffer
944               (if data-p
945                   (insert file)
946                 (insert-file-contents-literally file))
947               (make-glyph
948                (vector
949                 (or (intern type)
950                     (mm-image-type-from-buffer))
951                 :data (buffer-string))))))
952     (when face
953       (set-glyph-face glyph face))
954     glyph))
955
956 (defun gnus-xmas-put-image (glyph &optional string category)
957   "Insert STRING, but display GLYPH.
958 Warning: Don't insert text immediately after the image."
959   (let ((begin (point))
960         extent)
961     (if (and (bobp) (not string))
962         (setq string " "))
963     (if string
964         (insert string)
965       (setq begin (1- begin)))
966     (setq extent (make-extent begin (point)))
967     (set-extent-property extent 'gnus-image category)
968     (set-extent-property extent 'duplicable t)
969     (if string
970         (set-extent-property extent 'invisible t))
971     (set-extent-property extent 'end-glyph glyph))
972   glyph)
973
974 (defun gnus-xmas-remove-image (image &optional category)
975   "Remove the image matching IMAGE and CATEGORY found first."
976   (map-extents
977    (lambda (ext unused)
978      (when (equal (extent-end-glyph ext) image)
979        (set-extent-property ext 'invisible nil)
980        (set-extent-property ext 'end-glyph nil)
981        t))
982    nil nil nil nil nil 'gnus-image category))
983
984 (defun gnus-xmas-assq-delete-all (key alist)
985   (let ((elem nil))
986     (while (setq elem (assq key alist))
987       (setq alist (delq elem alist)))
988     alist))
989
990 (provide 'gnus-xmas)
991
992 ;;; arch-tag: 4e84de3f-ea0a-4ee3-bfeb-e03d46fcacef
993 ;;; gnus-xmas.el ends here