1 ;;; messagexmas.el --- XEmacs extensions to message
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2003, 2004
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
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)
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.
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.
30 (eval-when-compile (require 'cl))
33 (defvar message-xmas-dont-activate-region t
34 "If t, don't activate region after yanking.")
36 (defvar message-xmas-glyph-directory nil
37 "*Directory where Message logos and icons are located.
38 If this variable is nil, Message will try to locate the directory
41 (defvar message-use-toolbar (if (featurep 'toolbar) 'default)
42 "*Position to display the toolbar. Nil means do not use a toolbar.
43 If it is non-nil, it should be one of the symbols `default', `top',
44 `bottom', `right', and `left'. `default' means to use the default
45 toolbar, the rest mean to display the toolbar on the place which those
48 (defvar message-toolbar-thickness
49 (if (featurep 'toolbar)
50 (cons (specifier-instance default-toolbar-height)
51 (specifier-instance default-toolbar-width)))
52 "*Cons of the height and the width specifying the thickness of a toolbar.
53 The height is used for the toolbar displayed on the top or the bottom,
54 the width is used for the toolbar displayed on the right or the left.")
56 (defvar message-toolbar
57 '([message-spell ispell-message t "Spell"]
58 [message-help (Info-goto-node "(Message)Top") t "Message help"])
59 "The message buffer toolbar.")
61 (defun message-xmas-find-glyph-directory (&optional package)
62 (setq package (or package "message"))
63 (let ((dir (symbol-value
64 (intern-soft (concat package "-xmas-glyph-directory")))))
65 (if (and (stringp dir) (file-directory-p dir))
67 (nnheader-find-etc-directory package))))
69 (defun message-xmas-setup-toolbar (bar &optional force package)
70 (let ((dir (or (message-xmas-find-glyph-directory package)
71 (message-xmas-find-glyph-directory "gnus")))
72 (xpm (if (featurep 'xpm) "xpm" "xbm"))
73 icon up down disabled name)
75 (setq message-xmas-glyph-directory dir))
78 (setq icon (aref (car bar) 0)
79 name (symbol-name icon)
83 (setq up (concat dir name "-up." xpm))
84 (setq down (concat dir name "-down." xpm))
85 (setq disabled (concat dir name "-disabled." xpm))
86 (if (not (file-exists-p up))
89 (set icon (toolbar-make-button-list
90 up (and (file-exists-p down) down)
91 (and (file-exists-p disabled) disabled)))))))
94 (defun message-setup-toolbar ()
95 (when (featurep 'toolbar)
96 (if (and message-use-toolbar
97 (message-xmas-setup-toolbar message-toolbar))
98 (let ((bar (or (intern-soft (format "%s-toolbar" message-use-toolbar))
100 (height (car message-toolbar-thickness))
101 (width (cdr message-toolbar-thickness))
102 (cur (current-buffer))
104 (set-specifier (symbol-value bar) message-toolbar cur)
105 (set-specifier default-toolbar-height height cur)
106 (set-specifier default-toolbar-width width cur)
107 (set-specifier top-toolbar-height height cur)
108 (set-specifier bottom-toolbar-height height cur)
109 (set-specifier right-toolbar-width width cur)
110 (set-specifier left-toolbar-width width cur)
111 (if (eq bar 'default-toolbar)
113 (remove-specifier default-toolbar-visible-p cur)
114 (remove-specifier top-toolbar cur)
115 (remove-specifier top-toolbar-visible-p cur)
116 (remove-specifier bottom-toolbar cur)
117 (remove-specifier bottom-toolbar-visible-p cur)
118 (remove-specifier right-toolbar cur)
119 (remove-specifier right-toolbar-visible-p cur)
120 (remove-specifier left-toolbar cur)
121 (remove-specifier left-toolbar-visible-p cur))
122 (set-specifier (symbol-value (intern (format "%s-visible-p" bar)))
124 (setq bars (delq bar (list 'default-toolbar
125 'bottom-toolbar 'top-toolbar
126 'right-toolbar 'left-toolbar)))
128 (set-specifier (symbol-value (intern (format "%s-visible-p"
131 (let ((cur (current-buffer)))
132 (set-specifier default-toolbar-visible-p nil cur)
133 (set-specifier top-toolbar-visible-p nil cur)
134 (set-specifier bottom-toolbar-visible-p nil cur)
135 (set-specifier right-toolbar-visible-p nil cur)
136 (set-specifier left-toolbar-visible-p nil cur)))))
138 (defun message-xmas-exchange-point-and-mark ()
139 "Exchange point and mark, but allow for XEmacs' optional argument."
140 (exchange-point-and-mark message-xmas-dont-activate-region))
142 (defun message-xmas-maybe-fontify ()
143 (when (featurep 'font-lock)
144 (font-lock-set-defaults)))
146 (defun message-xmas-make-caesar-translation-table (n)
147 "Create a rot table with offset N."
149 (table (make-string 256 0))
152 (while (< (incf i) 256)
155 (substring table 0 A)
156 (substring table (+ A n) (+ A n (- 26 n)))
157 (substring table A (+ A n))
158 (substring table (+ A 26) a)
159 (substring table (+ a n) (+ a n (- 26 n)))
160 (substring table a (+ a n))
161 (substring table (+ a 26) 255))))
163 (defun message-xmas-make-date (&optional now)
164 "Make a valid data header.
165 If NOW, use that time instead."
166 (let ((zone (car (current-time-zone)))
172 (format "%s %s%02d%02d"
173 (format-time-string "%a, %d %b %Y %T" now)
176 (/ (% zone 3600) 60))))
178 (add-hook 'message-mode-hook 'message-xmas-maybe-fontify)
180 (defun message-xmas-redefine ()
181 "Redefine message functions for XEmacs."
182 (defalias 'message-exchange-point-and-mark
183 'message-xmas-exchange-point-and-mark)
184 (defalias 'message-mark-active-p
186 (defalias 'message-make-caesar-translation-table
187 'message-xmas-make-caesar-translation-table)
188 (defalias 'message-make-overlay 'make-extent)
189 (defalias 'message-delete-overlay 'delete-extent)
190 (defalias 'message-overlay-put 'set-extent-property)
191 (defalias 'message-make-date 'message-xmas-make-date))
193 (message-xmas-redefine)
195 (provide 'messagexmas)
197 ;;; messagexmas.el ends here