added textile-mode and mmm-mode. xpath stuff
[emacs-init.git] / mmm-mode-0.4.8 / mmm-compat.el
1 ;;; mmm-compat.el --- MMM Hacks for compatibility with other Emacsen
2
3 ;; Copyright (C) 2000 by Michael Abraham Shulman
4
5 ;; Author: Michael Abraham Shulman <viritrilbia@users.sourceforge.net>
6 ;; Version: $Id: mmm-compat.el,v 1.9 2003/03/09 17:04:03 viritrilbia Exp $
7
8 ;;{{{ GPL
9
10 ;; This file 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 2, or (at your option)
13 ;; any later version.
14
15 ;; This file 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
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;}}}
26
27 ;;; Commentary:
28
29 ;; This file provides a number of hacks that are necessary for MMM
30 ;; Mode to function in different Emacsen.  MMM Mode is designed for
31 ;; FSF Emacs 20 and 21, but these hacks usually enable it to work
32 ;; almost perfectly in Emacs 19 and XEmacs 20 or 21.
33
34 ;;; Code:
35
36 (require 'cl)
37
38 ;;{{{ Emacsen Detection
39
40 (defvar mmm-xemacs (featurep 'xemacs)
41   "Whether we are running XEmacs.")
42
43 ;;}}}
44 ;;{{{ Keywords (Emacs 19)
45
46 ;; Emacs 19 doesn't automatically set keyword variables to themselves.
47 ;; We shouldn't have to do any more than these, since CL automatically
48 ;; defines all keywords used for function arguments.
49 (defvar mmm-keywords-used
50   '(:group :regexp :region :function :insert :classes :private)
51   "List of extra keywords used by MMM Mode.")
52
53 (dolist (keyword mmm-keywords-used)
54   (set keyword keyword))
55
56 ;;}}}
57 ;;{{{ Customization (Emacs 19)
58
59 (condition-case ()
60     (require 'custom)
61   (error nil))
62
63 (unless (and (featurep 'custom)
64              (fboundp 'custom-declare-variable))
65   (defmacro defgroup (&rest args)
66     nil)
67   (defmacro defface (var values doc &rest args)
68     (` (make-face (quote (, var)))))
69   (defmacro defcustom (var value doc &rest args) 
70     (` (defvar (, var) (, value) (, doc)))))
71
72 ;;}}}
73 ;;{{{ Regexp-Opt (Emacs 19)
74
75 (condition-case ()
76     (require 'regexp-opt)
77   (error nil))
78
79 (unless (and (featurep 'regexp-opt)
80              (fboundp 'regexp-opt))
81   ;; No regexp-opt; create one
82   (defun regexp-opt (strings &optional paren)
83     (concat (if paren "\\(" "")
84             (mapconcat 'regexp-quote strings "\\|")
85             (if paren "\\)" ""))))
86
87 ;;}}}
88 ;;{{{ Regexp-Opt (XEmacs)
89
90 (defmacro mmm-regexp-opt (strings paren)
91   "Act like FSF Emacs' `regexp-opt', whichever Emacs we're in.
92 XEmacs' `regexp-opt' requires an extra parameter to do grouping."
93   (if (featurep 'xemacs)
94       `(regexp-opt ,strings ,paren t)
95     `(regexp-opt ,strings ,paren)))
96
97 ;;}}}
98 ;;{{{ Overlays (XEmacs)
99
100 ;; The main thing we use from FSF Emacs that XEmacs doesn't support
101 ;; are overlays. XEmacs uses extents instead, but comes with a package
102 ;; to emulate overlays.
103 (when mmm-xemacs
104   ;; This does almost everything we need.
105   (require 'overlay))
106
107 ;; We also use a couple "special" overlay properties which have
108 ;; different names for XEmacs extents.
109 (defvar mmm-evaporate-property
110   (if (featurep 'xemacs) 'detachable 'evaporate)
111   "The name of the overlay property controlling evaporation.")
112
113 ;; We don't use this any more, since its behavior is different in FSF
114 ;; and XEmacs: in the one it replaces the buffer's local map, but in
115 ;; the other it gets stacked on top of it. Instead we just set the
116 ;; buffer's local map temporarily.
117 ;;;(defvar mmm-keymap-property
118 ;;;  (if (featurep 'xemacs) 'keymap 'local-map)
119 ;;;  "The name of the overlay property controlling keymaps.")
120
121 ;;}}}
122 ;;{{{ Keymaps and Events (XEmacs)
123
124 ;; In XEmacs, keymaps are a primitive type, while in FSF Emacs, they
125 ;; are a list whose car is the symbol `keymap'. Among other things,
126 ;; this means that they handle default bindings differently.
127 (defmacro mmm-set-keymap-default (keymap binding)
128   (if (featurep 'xemacs)
129       `(set-keymap-default-binding ,keymap ,binding)
130     `(define-key ,keymap [t] ,binding)))
131
132 ;; In XEmacs, events are a primitive type, while in FSF Emacs, they
133 ;; are represented by characters or vectors. We treat them as vectors.
134 ;; We can use `event-modifiers' in both Emacsen to extract the
135 ;; modifiers, but the function to extract the basic key is different.
136 (defmacro mmm-event-key (event)
137   (if (featurep 'xemacs)
138       `(event-key ,event)
139     `(event-basic-type ,event)))
140
141 ;;}}}
142 ;;{{{ Skeleton (XEmacs)
143
144 ;; XEmacs' `skeleton' package doesn't provide `@' to record positions.
145 (defvar skeleton-positions ())
146 (defun mmm-fixup-skeleton ()
147   "Add `@' to `skeleton-further-elements' if XEmacs and not there.
148 This makes `@' in skeletons act approximately like it does in FSF."
149   (and (featurep 'xemacs)
150        (defvar skeleton-further-elements ())
151        (not (assoc '@ skeleton-further-elements))
152        (add-to-list 'skeleton-further-elements
153                     '(@ ''(push (point) skeleton-positions)))))
154
155 ;;}}}
156 ;;{{{ Make Temp Buffers (XEmacs)
157
158 (defmacro mmm-make-temp-buffer (buffer name)
159   "Return a buffer called NAME including the text of BUFFER.
160 This text should not be modified."
161   (if (fboundp 'make-indirect-buffer)
162       `(make-indirect-buffer ,buffer ,name)
163     `(save-excursion
164        (set-buffer (get-buffer-create ,name))
165        (insert-buffer ,buffer)
166        (current-buffer))))
167
168 ;;}}}
169 ;;{{{ Font Lock Available (Emacs w/o X)
170
171 (defvar mmm-font-lock-available-p (or window-system mmm-xemacs)
172   "Whether font-locking is available.
173 Emacs 19 and 20 only provide font-lock with a window system in use.")
174
175 ;;}}}
176 ;;{{{ Font Lock Defaults (XEmacs)
177
178 (defmacro mmm-set-font-lock-defaults ()
179   "Set font-lock defaults without trying to turn font-lock on.
180 In XEmacs, `font-lock-set-defaults' calls `font-lock-set-defaults-1'
181 to do the real work but then `turn-on-font-lock', which in turn calls
182 `font-lock-mode', which unsets the defaults if running in a hidden
183 buffer \(name begins with a space).  So in XEmacs, we just call
184 `font-lock-set-defaults-1' directly."
185   (if mmm-xemacs
186       `(font-lock-set-defaults-1)
187     `(font-lock-set-defaults)))
188
189 ;;}}}
190
191 (provide 'mmm-compat)
192
193 ;;; mmm-compat.el ends here