Add 2012 to FSF copyright years for Emacs files.
[gnus] / lisp / messagexmas.el
1 ;;; messagexmas.el --- XEmacs extensions to message
2
3 ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, 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; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30 (require 'nnheader)
31
32 (defvar message-xmas-dont-activate-region t
33   "If t, don't activate region after yanking.")
34
35 (defvar message-xmas-glyph-directory nil
36   "*Directory where Message logos and icons are located.
37 If this variable is nil, Message will try to locate the directory
38 automatically.")
39
40 (defvar message-use-toolbar (if (featurep 'toolbar) 'default)
41   "*Position to display the toolbar.  Nil means do not use a toolbar.
42 If it is non-nil, it should be one of the symbols `default', `top',
43 `bottom', `right', and `left'.  `default' means to use the default
44 toolbar, the rest mean to display the toolbar on the place which those
45 names show.")
46
47 (defvar message-toolbar-thickness
48   (if (featurep 'toolbar)
49       (cons (specifier-instance default-toolbar-height)
50             (specifier-instance default-toolbar-width)))
51   "*Cons of the height and the width specifying the thickness of a toolbar.
52 The height is used for the toolbar displayed on the top or the bottom,
53 the width is used for the toolbar displayed on the right or the left.")
54
55 (defvar message-toolbar
56   '([message-spell ispell-message t "Spell"]
57     [message-help (Info-goto-node "(Message)Top") t "Message help"])
58   "The message buffer toolbar.")
59
60 (defun message-xmas-find-glyph-directory (&optional package)
61   (setq package (or package "message"))
62   (let ((dir (symbol-value
63               (intern-soft (concat package "-xmas-glyph-directory")))))
64     (if (and (stringp dir) (file-directory-p dir))
65         dir
66       (nnheader-find-etc-directory package))))
67
68 (defun message-xmas-setup-toolbar (bar &optional force package)
69   (let ((dir (or (message-xmas-find-glyph-directory package)
70                  (message-xmas-find-glyph-directory "gnus")))
71         (xpm (if (featurep 'xpm) "xpm" "xbm"))
72         icon up down disabled name)
73     (unless package
74       (setq message-xmas-glyph-directory dir))
75     (when dir
76       (while bar
77         (setq icon (aref (car bar) 0)
78               name (symbol-name icon)
79               bar (cdr bar))
80         (when (or force
81                   (not (boundp icon)))
82           (setq up (concat dir name "-up." xpm))
83           (setq down (concat dir name "-down." xpm))
84           (setq disabled (concat dir name "-disabled." xpm))
85           (if (not (file-exists-p up))
86               (setq bar nil
87                     dir nil)
88             (set icon (toolbar-make-button-list
89                        up (and (file-exists-p down) down)
90                        (and (file-exists-p disabled) disabled)))))))
91     dir))
92
93 (defun message-setup-toolbar ()
94   (when (featurep 'toolbar)
95     (if (and message-use-toolbar
96              (message-xmas-setup-toolbar message-toolbar))
97         (let ((bar (or (intern-soft (format "%s-toolbar" message-use-toolbar))
98                        'default-toolbar))
99               (height (car message-toolbar-thickness))
100               (width (cdr message-toolbar-thickness))
101               (cur (current-buffer))
102               bars)
103           (set-specifier (symbol-value bar) message-toolbar cur)
104           (set-specifier default-toolbar-height height cur)
105           (set-specifier default-toolbar-width width cur)
106           (set-specifier top-toolbar-height height cur)
107           (set-specifier bottom-toolbar-height height cur)
108           (set-specifier right-toolbar-width width cur)
109           (set-specifier left-toolbar-width width cur)
110           (if (eq bar 'default-toolbar)
111               (progn
112                 (remove-specifier default-toolbar-visible-p cur)
113                 (remove-specifier top-toolbar cur)
114                 (remove-specifier top-toolbar-visible-p cur)
115                 (remove-specifier bottom-toolbar cur)
116                 (remove-specifier bottom-toolbar-visible-p cur)
117                 (remove-specifier right-toolbar cur)
118                 (remove-specifier right-toolbar-visible-p cur)
119                 (remove-specifier left-toolbar cur)
120                 (remove-specifier left-toolbar-visible-p cur))
121             (set-specifier (symbol-value (intern (format "%s-visible-p" bar)))
122                            t cur)
123             (setq bars (delq bar (list 'default-toolbar
124                                        'bottom-toolbar 'top-toolbar
125                                        'right-toolbar 'left-toolbar)))
126             (while bars
127               (set-specifier (symbol-value (intern (format "%s-visible-p"
128                                                            (pop bars))))
129                              nil cur))))
130       (let ((cur (current-buffer)))
131         (set-specifier default-toolbar-visible-p nil cur)
132         (set-specifier top-toolbar-visible-p nil cur)
133         (set-specifier bottom-toolbar-visible-p nil cur)
134         (set-specifier right-toolbar-visible-p nil cur)
135         (set-specifier left-toolbar-visible-p nil cur)))))
136
137 (defun message-xmas-exchange-point-and-mark ()
138   "Exchange point and mark, but allow for XEmacs' optional argument."
139   (exchange-point-and-mark message-xmas-dont-activate-region))
140
141 (defun message-xmas-maybe-fontify ()
142   (when (featurep 'font-lock)
143     (font-lock-set-defaults)))
144
145 (defun message-xmas-make-caesar-translation-table (n)
146   "Create a rot table with offset N."
147   (let ((i -1)
148         (table (make-string 256 0))
149         (a (mm-char-int ?a))
150         (A (mm-char-int ?A)))
151     (while (< (incf i) 256)
152       (aset table i i))
153     (concat
154      (substring table 0 A)
155      (substring table (+ A n) (+ A n (- 26 n)))
156      (substring table A (+ A n))
157      (substring table (+ A 26) a)
158      (substring table (+ a n) (+ a n (- 26 n)))
159      (substring table a (+ a n))
160      (substring table (+ a 26) 255))))
161
162 (defun message-xmas-make-date (&optional now)
163   "Make a valid data header.
164 If NOW, use that time instead."
165   (let ((zone (car (current-time-zone)))
166         sign)
167     (if (>= zone 0)
168         (setq sign "+")
169       (setq sign "-"
170             zone (- zone)))
171     (format "%s %s%02d%02d"
172             (format-time-string "%a, %d %b %Y %T" now)
173             sign
174             (/ zone 3600)
175             (/ (% zone 3600) 60))))
176
177 (add-hook 'message-mode-hook 'message-xmas-maybe-fontify)
178
179 (defun message-xmas-redefine ()
180   "Redefine message functions for XEmacs."
181   (defalias 'message-exchange-point-and-mark
182     'message-xmas-exchange-point-and-mark)
183   (defalias 'message-mark-active-p
184     'region-exists-p)
185   (defalias 'message-make-caesar-translation-table
186     'message-xmas-make-caesar-translation-table)
187   (defalias 'message-make-overlay 'make-extent)
188   (defalias 'message-delete-overlay 'delete-extent)
189   (defalias 'message-overlay-put 'set-extent-property)
190   (defalias 'message-make-date 'message-xmas-make-date))
191
192 (message-xmas-redefine)
193
194 (provide 'messagexmas)
195
196 ;;; messagexmas.el ends here