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