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