98
|
1 ;;; $Id: adapt.el,v 1.2 1997/02/15 22:21:03 steve Exp $
|
0
|
2 ;;;
|
70
|
3 ;;; Copyright (C) 1993, 1994, 1995 Heiko Muenkel
|
0
|
4 ;;; email: muenkel@tnt.uni-hannover.de
|
|
5 ;;;
|
|
6 ;;; This program is free software; you can redistribute it and/or modify
|
|
7 ;;; it under the terms of the GNU General Public License as published by
|
|
8 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
9 ;;; any later version.
|
|
10 ;;;
|
|
11 ;;; This program is distributed in the hope that it will be useful,
|
|
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 ;;; GNU General Public License for more details.
|
|
15 ;;;
|
|
16 ;;; You should have received a copy of the GNU General Public License
|
|
17 ;;; along with this program; if not, write to the Free Software
|
|
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19 ;;;
|
|
20 ;;;
|
|
21 ;;; Description:
|
|
22 ;;;
|
70
|
23 ;;; General functions to port Lucid Emacs to GNU Emacs 19.
|
0
|
24 ;;;
|
|
25 ;;; Installation:
|
|
26 ;;;
|
|
27 ;;; Put this file in one of your lisp load directories.
|
|
28 ;;;
|
|
29
|
|
30
|
|
31 (defun adapt-xemacsp ()
|
|
32 "Returns non nil if the editor is the XEmacs."
|
|
33 (or (string-match "Lucid" emacs-version)
|
|
34 (string-match "XEmacs" emacs-version)))
|
|
35
|
|
36
|
|
37 (defun adapt-lemacsp ()
|
|
38 "Returns non nil if the editor is the XEmacs.
|
|
39 Old version, use `adapt-xemacsp' instead of this."
|
|
40 (or (string-match "Lucid" emacs-version)
|
|
41 (string-match "XEmacs" emacs-version)))
|
|
42
|
|
43
|
|
44 (defun adapt-emacs19p ()
|
|
45 "Returns non nil if the editor is the GNU Emacs 19."
|
|
46 (and
|
|
47 (not (adapt-xemacsp))
|
|
48 (string= (substring emacs-version 0 2) "19")))
|
|
49
|
70
|
50 ;;; Functions, which doesn't exist in both emacses
|
0
|
51
|
|
52 (defun adapt-region-active-p ()
|
|
53 "Returns t, if a region is active."
|
|
54 (if (adapt-xemacsp)
|
|
55 (mark)
|
|
56 mark-active))
|
|
57
|
|
58
|
|
59 (if (adapt-emacs19p)
|
|
60 (progn
|
|
61 (load-library "lucid")
|
|
62
|
|
63 (load-library "lmenu")
|
|
64
|
|
65 (if window-system
|
|
66 (require 'font-lock)
|
|
67 )
|
|
68
|
|
69 (make-face 'font-lock-comment-face)
|
|
70
|
|
71 (defun read-number (prompt &optional integers-only)
|
|
72 "Reads a number from the minibuffer."
|
|
73 (interactive)
|
|
74 (let ((error t)
|
|
75 (number nil))
|
|
76 (if integers-only
|
|
77 (while error
|
|
78 (let ((input-string (read-string prompt)))
|
|
79 (setq number (if (string= "" input-string)
|
|
80 nil
|
|
81 (read input-string)))
|
|
82 (if (integerp number)
|
|
83 (setq error nil))))
|
|
84 (while error
|
|
85 (let ((input-string (read-string prompt)))
|
|
86 (setq number (if (string= "" input-string)
|
|
87 nil
|
|
88 (read input-string)))
|
|
89 (if (numberp number)
|
|
90 (setq error nil)))))
|
|
91 number))
|
|
92
|
|
93 (defvar original-read-string-function nil
|
|
94 "Points to the original Emacs 19 function read-string.")
|
|
95
|
|
96 (if (not original-read-string-function)
|
|
97 (fset 'original-read-string-function
|
|
98 (symbol-function 'read-string)))
|
|
99
|
|
100 (defun read-string (prompt &optional initial-contents history)
|
|
101 "Return a string from the minibuffer, prompting with string PROMPT.
|
|
102 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert
|
|
103 in the minibuffer before reading.
|
|
104 Third arg HISTORY, if non-nil, specifies a history list."
|
|
105 (read-from-minibuffer prompt initial-contents nil nil history))
|
|
106
|
|
107 (defun make-extent (beg end &optional buffer)
|
|
108 (make-overlay beg end buffer))
|
|
109
|
|
110 (defun set-extent-property (extent prop value)
|
|
111 (if (eq prop 'duplicable)
|
|
112 (cond ((and value (not (overlay-get extent prop)))
|
|
113 ;; If becoming duplicable,
|
|
114 ;; copy all overlay props to text props.
|
|
115 (add-text-properties (overlay-start extent)
|
|
116 (overlay-end extent)
|
|
117 (overlay-properties extent)
|
|
118 (overlay-buffer extent)))
|
|
119 ;; If becoming no longer duplicable, remove these text props.
|
|
120 ((and (not value) (overlay-get extent prop))
|
|
121 (remove-text-properties (overlay-start extent)
|
|
122 (overlay-end extent)
|
|
123 (overlay-properties extent)
|
|
124 (overlay-buffer extent))))
|
|
125 ;; If extent is already duplicable, put this property
|
|
126 ;; on the text as well as on the overlay.
|
|
127 (if (overlay-get extent 'duplicable)
|
|
128 (put-text-property (overlay-start extent)
|
|
129 (overlay-end extent)
|
|
130 prop value (overlay-buffer extent))))
|
|
131 (overlay-put extent prop value))
|
|
132
|
|
133 (defun set-extent-face (extent face)
|
|
134 (set-extent-property extent 'face face))
|
|
135
|
|
136 (defun delete-extent (extent)
|
|
137 (set-extent-property extent 'duplicable nil)
|
|
138 (delete-overlay extent))
|
|
139
|
|
140 ; (defun make-extent (from to &optional buffer)
|
|
141 ; "Make extent for range [FROM, TO) in BUFFER -- BUFFER defaults to
|
|
142 ;current buffer. Insertions at point TO will be outside of the extent;
|
|
143 ;insertions at FROM will be inside the extent (and the extent will grow.).
|
|
144 ;This is only a simple emulation of the Lucid Emacs extents !"
|
|
145 ; (list 'extent from to buffer))
|
|
146 ;
|
|
147 ; (defun set-extent-face (extent face)
|
|
148 ; "Make the given EXTENT have the graphic attributes specified by FACE.
|
|
149 ;This is only a simple emulation of the Lucid Emacs extents !"
|
|
150 ; (put-text-property (car (cdr extent))
|
|
151 ; (car (cdr (cdr extent)))
|
|
152 ; 'face
|
|
153 ; face
|
|
154 ; (car (cdr (cdr (cdr extent))))))
|
|
155 ;
|
|
156 ; (defun delete-extent (extent_obj)
|
|
157 ; "Remove EXTENT from its buffer; this does not modify the buffer's text,
|
|
158 ;only its display properties.
|
|
159 ;This is only a simple emulation of the Lucid Emacs extents !"
|
|
160 ; (remove-text-properties (car (cdr extent_obj))
|
|
161 ; (car (cdr (cdr extent_obj)))
|
|
162 ; (list 'face nil)
|
|
163 ; (car (cdr (cdr (cdr extent_obj))))))
|
|
164 ;
|
|
165
|
|
166 (if (not (fboundp 'emacs-pid))
|
|
167 (defun emacs-pid ()
|
|
168 "Return the process ID of Emacs, as an integer.
|
|
169 This is a dummy function for old versions of the Emacs 19.
|
|
170 You should install a new version, which has `emacs-pid' implemented."
|
|
171 0)
|
|
172 )
|
|
173
|
|
174 (if (not (fboundp 'facep))
|
|
175 (defun facep (object)
|
|
176 "Whether OBJECT is a FACE.
|
|
177 It's only a dummy function in the Emacs 19, which returns always nil."
|
|
178 nil))
|
|
179
|
|
180 ; (if (not (fboundp 'set-extent-property))
|
|
181 ; (defun set-extent-property (extent property value)
|
|
182 ; "Change a property of an extent.
|
|
183 ;Only a dummy version in Emacs 19."))
|
|
184
|
2
|
185 (if (not (fboundp 'region-active-p))
|
|
186 (defun region-active-p ()
|
|
187 "Non-nil iff the region is active.
|
|
188 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
|
|
189 Otherwise, this function always returns false."
|
|
190 (adapt-region-active-p)))
|
|
191
|
|
192 (if (not (fboundp 'next-command-event))
|
|
193 (defun next-command-event (&optional event prompt)
|
|
194 "Unlike the XEmacs version it reads the next event, if
|
|
195 it is a command event or not.
|
|
196
|
|
197 Return the next available \"user\" event.
|
|
198 Pass this object to `dispatch-event' to handle it.
|
|
199
|
|
200 If EVENT is non-nil, it should be an event object and will be filled in
|
|
201 and returned; otherwise a new event object will be created and returned.
|
|
202 If PROMPT is non-nil, it should be a string and will be displayed in the
|
|
203 echo area while this function is waiting for an event.
|
|
204
|
|
205 The event returned will be a keyboard, mouse press, or mouse release event.
|
|
206 If there are non-command events available (mouse motion, sub-process output,
|
|
207 etc) then these will be executed (with `dispatch-event') and discarded. This
|
|
208 function is provided as a convenience; it is equivalent to the lisp code
|
|
209
|
|
210 (while (progn
|
|
211 (next-event event prompt)
|
|
212 (not (or (key-press-event-p event)
|
|
213 (button-press-event-p event)
|
|
214 (button-release-event-p event)
|
|
215 (misc-user-event-p event))))
|
|
216 (dispatch-event event))"
|
|
217 (message prompt)
|
|
218 (or event
|
|
219 (read-event))))
|
|
220
|
|
221 (if (not (fboundp 'button-event-p))
|
|
222 (defun button-event-p (obj)
|
|
223 "True if OBJ is a button-press or button-release event object."
|
|
224 (and (eventp obj)
|
|
225 (or (eq 'mouse-1 (event-basic-type obj))
|
|
226 (eq 'mouse-2 (event-basic-type obj))
|
|
227 (eq 'mouse-3 (event-basic-type obj))))))
|
|
228
|
|
229 (if (not (fboundp 'button-press-event-p))
|
|
230 (defun button-press-event-p (obj)
|
|
231 "True if OBJ is a mouse-button-press event object."
|
|
232 (and (button-event-p obj)
|
|
233 (member 'down (event-modifiers obj)))))
|
|
234
|
|
235 (if (not (fboundp 'button-release-event-p))
|
|
236 (defun button-release-event-p (obj)
|
|
237 "True if OBJ is a mouse-button-release event object."
|
|
238 (and (button-event-p obj)
|
|
239 (not (button-press-event-p obj)))))
|
|
240
|
|
241 (if (not (fboundp 'event-window))
|
|
242 (defun event-window (event)
|
|
243 "Return the window of the given mouse event.
|
|
244 This may be nil if the event occurred in the border or over a toolbar.
|
|
245 The modeline is considered to be in the window it represents."
|
|
246 (and (eventp event)
|
|
247 (listp event)
|
|
248 (listp (cdr event))
|
|
249 (listp (car (cdr event)))
|
|
250 (car (car (cdr event))))))
|
|
251
|
|
252 (if (not (fboundp 'event-buffer))
|
|
253 (defun event-buffer (event)
|
|
254 "Given a mouse-motion, button-press, or button-release event, return
|
|
255 the buffer on which that event occurred. This will be nil for non-mouse
|
|
256 events. If event-over-text-area-p is nil, this will also be nil."
|
|
257 (if (button-event-p event)
|
|
258 (window-buffer (event-window event)))))
|
|
259
|
|
260
|
|
261 (if (not (fboundp 'event-closest-point))
|
|
262 (defun event-closest-point (event)
|
|
263 "Return the character position of the given mouse event.
|
|
264 If the event did not occur over a window or over text, return the
|
|
265 closest point to the location of the event. If the Y pixel position
|
|
266 overlaps a window and the X pixel position is to the left of that
|
|
267 window, the closest point is the beginning of the line containing the
|
|
268 Y position. If the Y pixel position overlaps a window and the X pixel
|
|
269 position is to the right of that window, the closest point is the end
|
|
270 of the line containing the Y position. If the Y pixel position is
|
|
271 above a window, return 0. If it is below a window, return the value
|
|
272 of (window-end)."
|
|
273 (posn-point (event-start event))))
|
|
274
|
|
275 (if (not (fboundp 'add-minor-mode))
|
|
276 (defun add-minor-mode (toggle
|
|
277 name
|
|
278 &optional
|
|
279 keymap
|
|
280 after
|
|
281 toggle-fun)
|
|
282 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
|
|
283 TOGGLE is a symbol whose value as a variable specifies whether the
|
|
284 minor mode is active. NAME is the name that should appear in the
|
|
285 modeline (it should be a string beginning with a space). KEYMAP is a
|
|
286 keymap to make active when the minor mode is active. AFTER is the
|
|
287 toggling symbol used for another minor mode. If AFTER is non-nil,
|
|
288 then it is used to position the new mode in the minor-mode alists.
|
|
289
|
|
290 TOGGLE-FUN is only a dummy variable in the Emacs 19. In the XEmacs
|
|
291 it has the following description:
|
|
292 TOGGLE-FUN specifies an interactive function that is called to toggle
|
|
293 the mode on and off; this affects what happens when button2 is pressed
|
|
294 on the mode, and when button3 is pressed somewhere in the list of
|
|
295 modes. If TOGGLE-FUN is nil and TOGGLE names an interactive function,
|
|
296 TOGGLE is used as the toggle function.
|
|
297
|
|
298 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)
|
|
299
|
|
300 WARNING: THIS FUNCTION ISN'T READ YET."
|
|
301 (if after
|
|
302 (add-minor-mode-1 toggle name keymap after)
|
|
303 (if (not (assq toggle minor-mode-alist))
|
|
304 (progn
|
|
305 (setq minor-mode-alist
|
|
306 (cons (list toggle name)
|
|
307 minor-mode-alist))))
|
|
308 (if (not (assq toggle minor-mode-map-alist))
|
|
309 (progn
|
|
310 (setq minor-mode-map-alist
|
|
311 (cons (cons toggle keymap)
|
|
312 minor-mode-map-alist))))
|
|
313 ))
|
|
314 )
|
98
|
315
|
|
316 (if (not (fboundp 'redraw-modeline))
|
|
317 (defalias 'redraw-modeline 'force-mode-line-update))
|
|
318
|
0
|
319 ))
|
2
|
320
|
0
|
321
|
|
322 (provide 'adapt)
|