*** empty log message ***
[gnus] / lisp / messagexmas.el
1 ;;; messagexmas.el --- XEmacs extensions to message
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: mail, news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29 (require 'nnheader)
30
31 (defvar message-xmas-dont-activate-region t
32   "If t, don't activate region after yanking.")
33
34 (defvar message-xmas-glyph-directory nil
35   "*Directory where Message logos and icons are located.
36 If this variable is nil, Message will try to locate the directory
37 automatically.")
38
39 (defvar message-use-toolbar (if (featurep 'toolbar)
40                                 'default-toolbar
41                               nil)
42   "*If nil, do not use a toolbar.
43 If it is non-nil, it must be a toolbar.  The five valid values are
44 `default-toolbar', `top-toolbar', `bottom-toolbar',
45 `right-toolbar', and `left-toolbar'.")
46
47 (defvar message-toolbar
48   '([message-spell ispell-message t "Spell"]
49     [message-help (Info-goto-node "(Message)Top") t "Message help"])
50   "The message buffer toolbar.")
51
52 (defun message-xmas-find-glyph-directory (&optional package)
53   (setq package (or package "message"))
54   (let ((dir (symbol-value
55               (intern-soft (concat package "-xmas-glyph-directory")))))
56     (if (and (stringp dir) (file-directory-p dir))
57         dir
58       (nnheader-find-etc-directory package))))
59
60 (defun message-xmas-setup-toolbar (bar &optional force package)
61   (let ((dir (message-xmas-find-glyph-directory package))
62         (xpm (if (featurep 'xpm) "xpm" "xbm"))
63         icon up down disabled name)
64     (unless package
65       (setq message-xmas-glyph-directory dir))
66     (when dir
67       (while bar
68         (setq icon (aref (car bar) 0)
69               name (symbol-name icon)
70               bar (cdr bar))
71         (when (or force
72                   (not (boundp icon)))
73           (setq up (concat dir name "-up." xpm))
74           (setq down (concat dir name "-down." xpm))
75           (setq disabled (concat dir name "-disabled." xpm))
76           (if (not (file-exists-p up))
77               (setq bar nil
78                     dir nil)
79             (set icon (toolbar-make-button-list
80                        up (and (file-exists-p down) down)
81                        (and (file-exists-p disabled) disabled)))))))
82     dir))
83
84 (defun message-setup-toolbar ()
85   (and message-use-toolbar
86        (message-xmas-setup-toolbar message-toolbar)
87        (set-specifier (symbol-value message-use-toolbar)
88                       (cons (current-buffer) message-toolbar))))
89
90 (defun message-xmas-exchange-point-and-mark ()
91   "Exchange point and mark, but allow for XEmacs' optional argument."
92   (exchange-point-and-mark message-xmas-dont-activate-region))
93
94 (defalias 'message-exchange-point-and-mark 
95   'message-xmas-exchange-point-and-mark)
96
97 (defun message-xmas-maybe-fontify ()
98   (when (featurep 'font-lock)
99     (font-lock-set-defaults)))
100
101 (defun message-xmas-make-caesar-translation-table (n)
102   "Create a rot table with offset N."
103   (let ((i -1)
104         (table (make-string 256 0))
105         (a (mm-char-int ?a))
106         (A (mm-char-int ?A)))
107     (while (< (incf i) 256)
108       (aset table i i))
109     (concat
110      (substring table 0 A)
111      (substring table (+ A n) (+ A n (- 26 n)))
112      (substring table A (+ A n))
113      (substring table (+ A 26) a)
114      (substring table (+ a n) (+ a n (- 26 n)))
115      (substring table a (+ a n))
116      (substring table (+ a 26) 255))))
117
118 (when (>= emacs-major-version 20)
119   (defalias 'message-make-caesar-translation-table
120     'message-xmas-make-caesar-translation-table))
121
122 (add-hook 'message-mode-hook 'message-xmas-maybe-fontify)
123
124 (provide 'messagexmas)
125
126 ;;; messagexmas.el ends here