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