*** empty log message ***
[gnus] / lisp / messagexmas.el
1 ;;; messagexmas.el --- XEmacs extensions to message
2 ;; Copyright (C) 1996,97,98 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 (require 'nnheader)
29
30 (defvar message-xmas-dont-activate-region t
31   "If t, don't activate region after yanking.")
32
33 (defvar message-xmas-glyph-directory nil
34   "*Directory where Message logos and icons are located.
35 If this variable is nil, Message will try to locate the directory
36 automatically.")
37
38 (defvar message-use-toolbar (if (featurep 'toolbar)
39                                 'default-toolbar
40                               nil)
41   "*If nil, do not use a toolbar.
42 If it is non-nil, it must be a toolbar.  The five legal values are
43 `default-toolbar', `top-toolbar', `bottom-toolbar',
44 `right-toolbar', and `left-toolbar'.")
45
46 (defvar message-toolbar
47   '([message-spell ispell-message t "Spell"]
48     [message-help (Info-goto-node "(Message)Top") t "Message help"])
49   "The message buffer toolbar.")
50
51 (defun message-xmas-find-glyph-directory (&optional package)
52   (setq package (or package "message"))
53   (let ((dir (symbol-value
54               (intern-soft (concat package "-xmas-glyph-directory")))))
55     (if (and (stringp dir) (file-directory-p dir))
56         dir
57       (nnheader-find-etc-directory package))))
58
59 (defun message-xmas-setup-toolbar (bar &optional force package)
60   (let ((dir (message-xmas-find-glyph-directory package))
61         (xpm (if (featurep 'xpm) "xpm" "xbm"))
62         icon up down disabled name)
63     (unless package
64       (setq message-xmas-glyph-directory dir))
65     (when dir
66       (while bar
67         (setq icon (aref (car bar) 0)
68               name (symbol-name icon)
69               bar (cdr bar))
70         (when (or force
71                   (not (boundp icon)))
72           (setq up (concat dir name "-up." xpm))
73           (setq down (concat dir name "-down." xpm))
74           (setq disabled (concat dir name "-disabled." xpm))
75           (if (not (file-exists-p up))
76               (setq bar nil
77                     dir nil)
78             (set icon (toolbar-make-button-list
79                        up (and (file-exists-p down) down)
80                        (and (file-exists-p disabled) disabled)))))))
81     dir))
82
83 (defun message-setup-toolbar ()
84   (and message-use-toolbar
85        (message-xmas-setup-toolbar message-toolbar)
86        (set-specifier (symbol-value message-use-toolbar)
87                       (cons (current-buffer) message-toolbar))))
88
89 (defun message-xmas-exchange-point-and-mark ()
90   "Exchange point and mark, but allow for XEmacs' optional argument."
91   (exchange-point-and-mark message-xmas-dont-activate-region))
92
93 (fset 'message-exchange-point-and-mark 'message-xmas-exchange-point-and-mark)
94
95 (defun message-xmas-maybe-fontify ()
96   (when (featurep 'font-lock)
97     (font-lock-set-defaults)))
98
99 (defun message-xmas-make-caesar-translation-table (n)
100   "Create a rot table with offset N."
101   (let ((i -1)
102         (table (make-string 256 0))
103         (a (mm-char-int ?a))
104         (A (mm-char-int ?A)))
105     (while (< (incf i) 256)
106       (aset table i i))
107     (concat
108      (substring table 0 A)
109      (substring table (+ A n) (+ A n (- 26 n)))
110      (substring table A (+ A n))
111      (substring table (+ A 26) a)
112      (substring table (+ a n) (+ a n (- 26 n)))
113      (substring table a (+ a n))
114      (substring table (+ a 26) 255))))
115
116 (when (>= emacs-major-version 20)
117   (fset 'message-make-caesar-translation-table
118         'message-xmas-make-caesar-translation-table))
119
120 (add-hook 'message-mode-hook 'message-xmas-maybe-fontify)
121
122 (provide 'messagexmas)
123
124 ;;; messagexmas.el ends here