Add arch taglines
[gnus] / lisp / messagexmas.el
1 ;;; messagexmas.el --- XEmacs extensions to message
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2003
4 ;;      Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
8
9 ;; This file is part of GNU Emacs.
10
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)
14 ;; any later version.
15
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.
20
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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile (require 'cl))
31 (require 'nnheader)
32
33 (defvar message-xmas-dont-activate-region t
34   "If t, don't activate region after yanking.")
35
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
39 automatically.")
40
41 (defvar message-use-toolbar (if (featurep 'toolbar)
42                                 'default-toolbar
43                               nil)
44   "*If nil, do not use a toolbar.
45 If it is non-nil, it must be a toolbar.  The five valid values are
46 `default-toolbar', `top-toolbar', `bottom-toolbar',
47 `right-toolbar', and `left-toolbar'.")
48
49 (defvar message-toolbar
50   '([message-spell ispell-message t "Spell"]
51     [message-help (Info-goto-node "(Message)Top") t "Message help"])
52   "The message buffer toolbar.")
53
54 (defun message-xmas-find-glyph-directory (&optional package)
55   (setq package (or package "message"))
56   (let ((dir (symbol-value
57               (intern-soft (concat package "-xmas-glyph-directory")))))
58     (if (and (stringp dir) (file-directory-p dir))
59         dir
60       (nnheader-find-etc-directory package))))
61
62 (defun message-xmas-setup-toolbar (bar &optional force package)
63   (let ((dir (message-xmas-find-glyph-directory package))
64         (xpm (if (featurep 'xpm) "xpm" "xbm"))
65         icon up down disabled name)
66     (unless package
67       (setq message-xmas-glyph-directory dir))
68     (when dir
69       (while bar
70         (setq icon (aref (car bar) 0)
71               name (symbol-name icon)
72               bar (cdr bar))
73         (when (or force
74                   (not (boundp icon)))
75           (setq up (concat dir name "-up." xpm))
76           (setq down (concat dir name "-down." xpm))
77           (setq disabled (concat dir name "-disabled." xpm))
78           (if (not (file-exists-p up))
79               (setq bar nil
80                     dir nil)
81             (set icon (toolbar-make-button-list
82                        up (and (file-exists-p down) down)
83                        (and (file-exists-p disabled) disabled)))))))
84     dir))
85
86 (defun message-setup-toolbar ()
87   (and message-use-toolbar
88        (message-xmas-setup-toolbar message-toolbar)
89        (set-specifier (symbol-value message-use-toolbar)
90                       (cons (current-buffer) message-toolbar))))
91
92 (defun message-xmas-exchange-point-and-mark ()
93   "Exchange point and mark, but allow for XEmacs' optional argument."
94   (exchange-point-and-mark message-xmas-dont-activate-region))
95
96 (defun message-xmas-maybe-fontify ()
97   (when (featurep 'font-lock)
98     (font-lock-set-defaults)))
99
100 (defun message-xmas-make-caesar-translation-table (n)
101   "Create a rot table with offset N."
102   (let ((i -1)
103         (table (make-string 256 0))
104         (a (mm-char-int ?a))
105         (A (mm-char-int ?A)))
106     (while (< (incf i) 256)
107       (aset table i i))
108     (concat
109      (substring table 0 A)
110      (substring table (+ A n) (+ A n (- 26 n)))
111      (substring table A (+ A n))
112      (substring table (+ A 26) a)
113      (substring table (+ a n) (+ a n (- 26 n)))
114      (substring table a (+ a n))
115      (substring table (+ a 26) 255))))
116
117 (add-hook 'message-mode-hook 'message-xmas-maybe-fontify)
118
119 (defun message-xmas-redefine ()
120   "Redefine message functions for XEmacs."
121   (defalias 'message-exchange-point-and-mark
122     'message-xmas-exchange-point-and-mark)
123   (defalias 'message-mark-active-p
124     'region-exists-p)
125   (defalias 'message-make-caesar-translation-table
126     'message-xmas-make-caesar-translation-table)
127   (defalias 'message-make-overlay 'make-extent)
128   (defalias 'message-delete-overlay 'delete-extent)
129   (defalias 'message-overlay-put 'set-extent-property))
130
131 (message-xmas-redefine)
132
133 (provide 'messagexmas)
134
135 ;;; arch-tag: 0ece0484-8757-4641-b2d4-17147dd5c5b5
136 ;;; messagexmas.el ends here