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