0
|
1 ;;; sysdep.el --- consolidate Emacs-version dependencies in one file.
|
|
2
|
82
|
3 ;; Copyright (c) 1995 - 1997 Ben Wing.
|
0
|
4
|
82
|
5 ;; Author: Ben Wing <wing@666.com>, William Perry <wmperry@cs.indiana.edu>
|
0
|
6 ;; Keywords: lisp, tools
|
80
|
7 ;; Version: 0.003
|
0
|
8
|
|
9 ;; The purpose of this file is to eliminate the cruftiness that
|
|
10 ;; would otherwise be required of packages that want to run on multiple
|
|
11 ;; versions of Emacs. The idea is that we make it look like we're running
|
|
12 ;; the latest version of XEmacs (currently 19.12) by emulating all the
|
|
13 ;; missing functions.
|
|
14
|
|
15 ;; #### This file does not currently do any advising but should.
|
|
16 ;; Unfortunately, advice.el is a hugely big package. Is any such
|
|
17 ;; thing as `advice-lite' possible?
|
|
18
|
|
19 ;; #### - This package is great, but its role needs to be thought out a bit
|
|
20 ;; more. Sysdep will not permit programs written for the old XEmacs API to
|
|
21 ;; run on new versions of XEmacs. Sysdep is a backward-compatibility
|
|
22 ;; package for the latest and greatest XEmacs API. It permits programmers
|
|
23 ;; to use the latest XEmacs functionality and still have their programs run
|
|
24 ;; on older versions of XEmacs...perhaps even on FSF Emacs. It should NEVER
|
|
25 ;; ever need to be loaded in the newest XEmacs. It doesn't even make sense
|
|
26 ;; to put it in the lisp/utils part of the XEmacs distribution because it's
|
|
27 ;; real purpose is to be distributed with packages like w3 which take
|
|
28 ;; advantage of the latest and greatest features of XEmacs but still need to
|
|
29 ;; be run on older versions. --Stig
|
|
30
|
|
31 ;; Any packages that wish to use this file should load it using
|
|
32 ;; `load-library'. It will not load itself if a version of sysdep.el
|
|
33 ;; that is at least as recent has already been loaded, but will
|
|
34 ;; load over an older version of sysdep.el. It will attempt to
|
|
35 ;; not redefine functions that have already been custom-redefined,
|
|
36 ;; but will redefine a function if the supplied definition came from
|
|
37 ;; an older version of sysdep.el.
|
|
38
|
|
39 ;; Packages such as w3 that wish to include this file with the package
|
|
40 ;; should rename it to something unique, such as `w3-sysdep.el', and
|
|
41 ;; load it with `load-library'. That will ensure that no conflicts
|
|
42 ;; arise if more than one package in the load path provides a version
|
|
43 ;; of sysdep.el. If multiple packages load sysdep.el, the most recent
|
|
44 ;; version will end up loaded; as long as I'm careful not to
|
|
45 ;; introduce bugs in previously working definitions, this should work
|
|
46 ;; fine.
|
|
47
|
|
48 ;; You may well discover deficiencies in this file as you use it.
|
|
49 ;; The preferable way of dealing with this is to send me a patch
|
|
50 ;; to sysdep.el; that way, the collective body of knowledge gets
|
|
51 ;; increased.
|
|
52
|
|
53 ;; IMPORTANT: leave the version string in the format X.XXX (e.g. 1.001)
|
|
54 ;; so that string comparisons to other versions work properly.
|
|
55
|
80
|
56 (defconst sysdep-potential-version "0.003")
|
0
|
57
|
|
58 ;; this macro means: define the function, but only if either it
|
|
59 ;; wasn't bound before, or the supplied binding comes from an older
|
|
60 ;; version of sysdep.el. That way, user-supplied bindings don't
|
|
61 ;; get overridden.
|
|
62
|
|
63 ;; note: sysdep-defalias is often more useful than this function,
|
|
64 ;; esp. since you can do load-time conditionalizing and can
|
|
65 ;; optionally leave the function undefined. (e.g. frame functions
|
|
66 ;; in v18.)
|
|
67
|
|
68 (defmacro sysdep-defun (function &rest everything-else)
|
80
|
69 (` (cond ((and (not (fboundp (quote (, function))))
|
|
70 (or
|
|
71 (not
|
|
72 (stringp (get (quote (, function)) 'sysdep-defined-this)))
|
|
73 (and (get (quote (, function)) 'sysdep-defined-this)
|
|
74 (string-lessp
|
|
75 (get (quote (, function)) 'sysdep-defined-this)
|
|
76 sysdep-potential-version))))
|
|
77 (put (quote (, function)) 'sysdep-defined-this
|
|
78 sysdep-potential-version)
|
0
|
79 (defun (, function) (,@ everything-else))))))
|
|
80
|
|
81 (defmacro sysdep-defvar (function &rest everything-else)
|
80
|
82 (` (cond ((and (not (boundp (quote (, function))))
|
|
83 (or
|
|
84 (not
|
|
85 (stringp (get (quote (, function)) 'sysdep-defined-this)))
|
|
86 (and (get (quote (, function)) 'sysdep-defined-this)
|
|
87 (string-lessp
|
|
88 (get (quote (, function)) 'sysdep-defined-this)
|
|
89 sysdep-potential-version))))
|
0
|
90 (put (quote (, function)) 'sysdep-defined-this t)
|
|
91 (defvar (, function) (,@ everything-else))))))
|
|
92
|
|
93 (defmacro sysdep-defconst (function &rest everything-else)
|
80
|
94 (` (cond ((and (not (boundp (quote (, function))))
|
|
95 (or
|
|
96 (not
|
|
97 (stringp (get (quote (, function)) 'sysdep-defined-this)))
|
|
98 (and (get (quote (, function)) 'sysdep-defined-this)
|
|
99 (string-lessp
|
|
100 (get (quote (, function)) 'sysdep-defined-this)
|
|
101 sysdep-potential-version))))
|
0
|
102 (put (quote (, function)) 'sysdep-defined-this t)
|
|
103 (defconst (, function) (,@ everything-else))))))
|
|
104
|
|
105 ;; similar for fset and defalias. No need to quote as the argument
|
|
106 ;; is already quoted.
|
|
107
|
|
108 (defmacro sysdep-fset (function def)
|
80
|
109 (` (cond ((and (not (fboundp (, function)))
|
|
110 (or (not (stringp
|
|
111 (get (, function) 'sysdep-defined-this)))
|
|
112 (and (get (, function) 'sysdep-defined-this)
|
|
113 (string-lessp
|
|
114 (get (, function) 'sysdep-defined-this)
|
|
115 sysdep-potential-version)))
|
0
|
116 (, def))
|
|
117 (put (, function) 'sysdep-defined-this t)
|
|
118 (fset (, function) (, def))))))
|
|
119
|
|
120 (defmacro sysdep-defalias (function def)
|
80
|
121 (` (cond ((and (not (fboundp (, function)))
|
|
122 (or (not (stringp
|
|
123 (get (, function) 'sysdep-defined-this)))
|
|
124 (and (get (, function) 'sysdep-defined-this)
|
|
125 (string-lessp
|
|
126 (get (, function) 'sysdep-defined-this)
|
|
127 sysdep-potential-version)))
|
0
|
128 (, def)
|
|
129 (or (listp (, def))
|
|
130 (and (symbolp (, def))
|
|
131 (fboundp (, def)))))
|
|
132 (put (, function) 'sysdep-defined-this t)
|
|
133 (defalias (, function) (, def))))))
|
|
134
|
|
135 ;; bootstrapping: defalias and define-function don't exist
|
|
136 ;; in older versions of lemacs
|
|
137
|
|
138 (sysdep-fset 'defalias 'fset)
|
|
139 (sysdep-defalias 'define-function 'defalias)
|
|
140
|
|
141 ;; useful ways of determining what version is running
|
|
142 ;; emacs-major-version and emacs-minor-version are
|
|
143 ;; already defined in recent versions of FSF Emacs and XEmacs
|
|
144
|
|
145 (sysdep-defconst emacs-major-version
|
|
146 ;; will string-match ever fail? If so, assume 19.0.
|
|
147 ;; (should we assume 18.something?)
|
|
148 (if (string-match "^[0-9]+" emacs-version)
|
|
149 (string-to-int
|
|
150 (substring emacs-version
|
|
151 (match-beginning 0) (match-end 0)))
|
|
152 19))
|
|
153
|
|
154 (sysdep-defconst emacs-minor-version
|
|
155 (if (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version)
|
|
156 (string-to-int
|
|
157 (substring emacs-version
|
|
158 (match-beginning 1) (match-end 1)))
|
|
159 0))
|
|
160
|
|
161 (sysdep-defconst sysdep-running-xemacs
|
|
162 (or (string-match "Lucid" emacs-version)
|
|
163 (string-match "XEmacs" emacs-version)))
|
|
164
|
|
165 (sysdep-defconst window-system nil)
|
|
166 (sysdep-defconst window-system-version 0)
|
|
167
|
|
168 (sysdep-defvar list-buffers-directory nil)
|
2
|
169 (sysdep-defvar x-library-search-path (`
|
|
170 ("/usr/X11R6/lib/X11/"
|
0
|
171 "/usr/X11R5/lib/X11/"
|
|
172 "/usr/lib/X11R6/X11/"
|
|
173 "/usr/lib/X11R5/X11/"
|
|
174 "/usr/local/X11R6/lib/X11/"
|
|
175 "/usr/local/X11R5/lib/X11/"
|
|
176 "/usr/local/lib/X11R6/X11/"
|
|
177 "/usr/local/lib/X11R5/X11/"
|
|
178 "/usr/X11/lib/X11/"
|
|
179 "/usr/lib/X11/"
|
|
180 "/usr/local/lib/X11/"
|
|
181 "/usr/X386/lib/X11/"
|
|
182 "/usr/x386/lib/X11/"
|
|
183 "/usr/XFree86/lib/X11/"
|
|
184 "/usr/unsupported/lib/X11/"
|
|
185 "/usr/athena/lib/X11/"
|
|
186 "/usr/local/x11r5/lib/X11/"
|
|
187 "/usr/lpp/Xamples/lib/X11/"
|
|
188 "/usr/openwin/lib/X11/"
|
2
|
189 "/usr/openwin/share/lib/X11/"
|
|
190 (, data-directory)
|
|
191 )
|
|
192 )
|
0
|
193 "Search path used for X11 libraries.")
|
|
194
|
|
195 ;; frame-related stuff.
|
|
196
|
|
197 (sysdep-defalias 'buffer-dedicated-frame 'buffer-dedicated-screen)
|
|
198 (sysdep-defalias 'deiconify-frame
|
|
199 (cond ((fboundp 'deiconify-screen) 'deiconify-screen)
|
|
200 ;; make-frame-visible will be defined as necessary
|
|
201 (t 'make-frame-visible)))
|
|
202 (sysdep-defalias 'delete-frame 'delete-screen)
|
|
203 (sysdep-defalias 'event-frame 'event-screen)
|
|
204 (sysdep-defalias 'event-glyph-extent 'event-glyph)
|
|
205 (sysdep-defalias 'find-file-other-frame 'find-file-other-screen)
|
|
206 (sysdep-defalias 'find-file-read-only-other-frame
|
|
207 'find-file-read-only-other-screen)
|
|
208 (sysdep-defalias 'frame-height 'screen-height)
|
|
209 (sysdep-defalias 'frame-iconified-p 'screen-iconified-p)
|
|
210 (sysdep-defalias 'frame-left-margin-width 'screen-left-margin-width)
|
|
211 (sysdep-defalias 'frame-list 'screen-list)
|
|
212 (sysdep-defalias 'frame-live-p
|
|
213 (cond ((fboundp 'screen-live-p) 'screen-live-p)
|
|
214 ((fboundp 'live-screen-p) 'live-screen-p)
|
|
215 ;; #### not sure if this is correct (this is for Epoch)
|
|
216 ;; but gnuserv.el uses it this way
|
|
217 ((fboundp 'screenp) 'screenp)))
|
|
218 (sysdep-defalias 'frame-name 'screen-name)
|
|
219 (sysdep-defalias 'frame-parameters 'screen-parameters)
|
|
220 (sysdep-defalias 'frame-pixel-height 'screen-pixel-height)
|
|
221 (sysdep-defalias 'frame-pixel-width 'screen-pixel-width)
|
|
222 (sysdep-defalias 'frame-right-margin-width 'screen-right-margin-width)
|
|
223 (sysdep-defalias 'frame-root-window 'screen-root-window)
|
|
224 (sysdep-defalias 'frame-selected-window 'screen-selected-window)
|
|
225 (sysdep-defalias 'frame-totally-visible-p 'screen-totally-visible-p)
|
|
226 (sysdep-defalias 'frame-visible-p 'screen-visible-p)
|
|
227 (sysdep-defalias 'frame-width 'screen-width)
|
|
228 (sysdep-defalias 'framep 'screenp)
|
|
229 (sysdep-defalias 'get-frame-for-buffer 'get-screen-for-buffer)
|
|
230 (sysdep-defalias 'get-frame-for-buffer-noselect 'get-screen-for-buffer-noselect)
|
|
231 (sysdep-defalias 'get-other-frame 'get-other-screen)
|
|
232 (sysdep-defalias 'iconify-frame 'iconify-screen)
|
|
233 (sysdep-defalias 'lower-frame 'lower-screen)
|
70
|
234 (sysdep-defalias 'mail-other-frame 'mail-other-screen)
|
0
|
235
|
|
236 (sysdep-defalias 'make-frame
|
|
237 (cond ((fboundp 'make-screen)
|
|
238 (function (lambda (&optional parameters device)
|
|
239 (make-screen parameters))))
|
|
240 ((fboundp 'x-create-screen)
|
|
241 (function (lambda (&optional parameters device)
|
|
242 (x-create-screen parameters))))))
|
|
243
|
|
244 (sysdep-defalias 'make-frame-invisible 'make-screen-invisible)
|
|
245 (sysdep-defalias 'make-frame-visible
|
|
246 (cond ((fboundp 'make-screen-visible) 'make-screen-visible)
|
|
247 ((fboundp 'mapraised-screen) 'mapraised-screen)
|
|
248 ((fboundp 'x-remap-window)
|
|
249 (lambda (&optional x)
|
|
250 (x-remap-window)
|
|
251 (accept-process-output)))))
|
|
252 (sysdep-defalias 'modify-frame-parameters 'modify-screen-parameters)
|
|
253 (sysdep-defalias 'new-frame 'new-screen)
|
|
254 (sysdep-defalias 'next-frame 'next-screen)
|
|
255 (sysdep-defalias 'next-multiframe-window 'next-multiscreen-window)
|
|
256 (sysdep-defalias 'other-frame 'other-screen)
|
|
257 (sysdep-defalias 'previous-frame 'previous-screen)
|
|
258 (sysdep-defalias 'previous-multiframe-window 'previous-multiscreen-window)
|
|
259 (sysdep-defalias 'raise-frame
|
|
260 (cond ((fboundp 'raise-screen) 'raise-screen)
|
|
261 ((fboundp 'mapraise-screen) 'mapraise-screen)))
|
|
262 (sysdep-defalias 'redraw-frame 'redraw-screen)
|
|
263 (sysdep-defalias 'select-frame 'select-screen)
|
|
264 (sysdep-defalias 'selected-frame 'selected-screen)
|
|
265 (sysdep-defalias 'set-buffer-dedicated-frame 'set-buffer-dedicated-screen)
|
|
266 (sysdep-defalias 'set-frame-height 'set-screen-height)
|
|
267 (sysdep-defalias 'set-frame-left-margin-width 'set-screen-left-margin-width)
|
|
268 (sysdep-defalias 'set-frame-position 'set-screen-position)
|
|
269 (sysdep-defalias 'set-frame-right-margin-width 'set-screen-right-margin-width)
|
|
270 (sysdep-defalias 'set-frame-size 'set-screen-size)
|
|
271 (sysdep-defalias 'set-frame-width 'set-screen-width)
|
|
272 (sysdep-defalias 'show-temp-buffer-in-current-frame 'show-temp-buffer-in-current-screen)
|
|
273 (sysdep-defalias 'switch-to-buffer-other-frame 'switch-to-buffer-other-screen)
|
|
274 (sysdep-defalias 'visible-frame-list 'visible-screen-list)
|
|
275 (sysdep-defalias 'window-frame 'window-screen)
|
|
276 (sysdep-defalias 'x-create-frame 'x-create-screen)
|
|
277 (sysdep-defalias 'x-set-frame-icon-pixmap 'x-set-screen-icon-pixmap)
|
|
278 (sysdep-defalias 'x-set-frame-pointer 'x-set-screen-pointer)
|
|
279 (sysdep-defalias 'x-display-color-p 'x-color-display-p)
|
|
280 (sysdep-defalias 'x-display-grayscale-p 'x-grayscale-display-p)
|
|
281 (sysdep-defalias 'menu-event-p 'misc-user-event-p)
|
|
282
|
144
|
283 (sysdep-defun event-point (event)
|
|
284 (let ((posn (event-end event)))
|
|
285 (if posn
|
|
286 (posn-point posn))))
|
|
287
|
|
288 ;; WMP - commenting these out so that Emacs 19 doesn't get screwed by them.
|
80
|
289 ;; In particular, this makes the 'custom' package blow up quite well.
|
|
290 ;;(sysdep-defun add-submenu (menu-path submenu &optional before)
|
|
291 ;; "Add a menu to the menubar or one of its submenus.
|
|
292 ;;If the named menu exists already, it is changed.
|
|
293 ;;MENU-PATH identifies the menu under which the new menu should be inserted.
|
|
294 ;; It is a list of strings; for example, (\"File\") names the top-level \"File\"
|
|
295 ;; menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
|
|
296 ;; If MENU-PATH is nil, then the menu will be added to the menubar itself.
|
|
297 ;;SUBMENU is the new menu to add.
|
|
298 ;; See the documentation of `current-menubar' for the syntax.
|
|
299 ;;BEFORE, if provided, is the name of a menu before which this menu should
|
|
300 ;; be added, if this menu is not on its parent already. If the menu is already
|
|
301 ;; present, it will not be moved."
|
|
302 ;; (add-menu menu-path (car submenu) (cdr submenu) before))
|
0
|
303
|
80
|
304 ;;(sysdep-defun add-menu-button (menu-path menu-leaf &optional before)
|
|
305 ;; "Add a menu item to some menu, creating the menu first if necessary.
|
|
306 ;;If the named item exists already, it is changed.
|
|
307 ;;MENU-PATH identifies the menu under which the new menu item should be inserted.
|
|
308 ;; It is a list of strings; for example, (\"File\") names the top-level \"File\"
|
|
309 ;; menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
|
|
310 ;;MENU-LEAF is a menubar leaf node. See the documentation of `current-menubar'.
|
|
311 ;;BEFORE, if provided, is the name of a menu item before which this item should
|
|
312 ;; be added, if this item is not on the menu already. If the item is already
|
|
313 ;; present, it will not be moved."
|
|
314 ;; (add-menu-item menu-path (aref menu-leaf 0) (aref menu-leaf 1)
|
|
315 ;; (aref menu-leaf 2) before))
|
0
|
316
|
|
317 (sysdep-defun make-glyph (&optional spec-list)
|
|
318 (if (and spec-list (cdr-safe (assq 'x spec-list)))
|
|
319 (make-pixmap (cdr-safe (assq 'x spec-list)))))
|
|
320
|
|
321 (sysdep-defalias 'face-list 'list-faces)
|
|
322
|
80
|
323 (sysdep-defun set-keymap-parent (keymap new-parent)
|
|
324 (let ((tail keymap))
|
|
325 (while (and tail (cdr tail) (not (eq (car (cdr tail)) 'keymap)))
|
|
326 (setq tail (cdr tail)))
|
|
327 (if tail
|
|
328 (setcdr tail new-parent))))
|
|
329
|
114
|
330 (sysdep-defun buffer-substring-no-properties (st nd)
|
|
331 "Return the characters of part of the buffer, without the text properties.
|
|
332 The two arguments START and END are character positions;
|
|
333 they can be in either order."
|
|
334 (buffer-substring st nd))
|
|
335
|
2
|
336 ;; Property list functions
|
|
337 ;;
|
|
338 (sysdep-defun plist-put (plist prop val)
|
|
339 "Change value in PLIST of PROP to VAL.
|
|
340 PLIST is a property list, which is a list of the form
|
|
341 (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol and VAL is any object.
|
|
342 If PROP is already a property on the list, its value is set to VAL,
|
|
343 otherwise the new PROP VAL pair is added. The new plist is returned;
|
|
344 use `(setq x (plist-put x prop val))' to be sure to use the new value.
|
|
345 The PLIST is modified by side effects."
|
|
346 (let ((node (memq prop plist)))
|
|
347 (if node
|
|
348 (setcar (cdr node) val)
|
|
349 (setq plist (cons prop (cons val plist))))
|
|
350 plist))
|
|
351
|
|
352 (sysdep-defun plist-get (plist prop)
|
|
353 "Extract a value from a property list.
|
|
354 PLIST is a property list, which is a list of the form
|
|
355 (PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
|
|
356 corresponding to the given PROP, or nil if PROP is not
|
|
357 one of the properties on the list."
|
80
|
358 (while (and plist (not (eq (car plist) prop)))
|
|
359 (setq plist (cdr (cdr plist))))
|
|
360 (and plist (car (cdr plist))))
|
2
|
361
|
0
|
362 ;; Extent stuff
|
|
363 (sysdep-fset 'delete-extent 'delete-overlay)
|
|
364 (sysdep-fset 'extent-end-position 'overlay-end)
|
|
365 (sysdep-fset 'extent-start-position 'overlay-start)
|
|
366 (sysdep-fset 'set-extent-endpoints 'move-overlay)
|
2
|
367 (sysdep-fset 'set-extent-property 'overlay-put)
|
|
368 (sysdep-fset 'make-extent 'make-overlay)
|
0
|
369
|
|
370 (sysdep-defun extent-property (extent property &optional default)
|
|
371 (or (overlay-get extent property) default))
|
|
372
|
|
373 (sysdep-defun extent-at (pos &optional object property before at-flag)
|
|
374 (let ((tmp (overlays-at (point)))
|
|
375 ovls)
|
|
376 (if property
|
|
377 (while tmp
|
|
378 (if (extent-property (car tmp) property)
|
|
379 (setq ovls (cons (car tmp) ovls)))
|
|
380 (setq tmp (cdr tmp)))
|
|
381 (setq ovls tmp
|
|
382 tmp nil))
|
|
383 (car-safe
|
|
384 (sort ovls
|
|
385 (function
|
|
386 (lambda (a b)
|
|
387 (< (- (extent-end-position a) (extent-start-position a))
|
|
388 (- (extent-end-position b) (extent-start-position b)))))))))
|
|
389
|
|
390 (sysdep-defun overlays-in (beg end)
|
|
391 "Return a list of the overlays that overlap the region BEG ... END.
|
|
392 Overlap means that at least one character is contained within the overlay
|
|
393 and also contained within the specified region.
|
|
394 Empty overlays are included in the result if they are located at BEG
|
|
395 or between BEG and END."
|
|
396 (let ((ovls (overlay-lists))
|
|
397 tmp retval)
|
|
398 (if (< end beg)
|
|
399 (setq tmp end
|
|
400 end beg
|
|
401 beg tmp))
|
|
402 (setq ovls (nconc (car ovls) (cdr ovls)))
|
|
403 (while ovls
|
|
404 (setq tmp (car ovls)
|
|
405 ovls (cdr ovls))
|
|
406 (if (or (and (<= (overlay-start tmp) end)
|
|
407 (>= (overlay-start tmp) beg))
|
|
408 (and (<= (overlay-end tmp) end)
|
|
409 (>= (overlay-end tmp) beg)))
|
|
410 (setq retval (cons tmp retval))))
|
|
411 retval))
|
|
412
|
|
413 (sysdep-defun map-extents (function &optional object from to
|
|
414 maparg flags property value)
|
|
415 (let ((tmp (overlays-in (or from (point-min))
|
|
416 (or to (point-max))))
|
|
417 ovls)
|
|
418 (if property
|
|
419 (while tmp
|
|
420 (if (extent-property (car tmp) property)
|
|
421 (setq ovls (cons (car tmp) ovls)))
|
|
422 (setq tmp (cdr tmp)))
|
|
423 (setq ovls tmp
|
|
424 tmp nil))
|
|
425 (catch 'done
|
|
426 (while ovls
|
|
427 (setq tmp (funcall function (car ovls) maparg)
|
|
428 ovls (cdr ovls))
|
|
429 (if tmp
|
|
430 (throw 'done tmp))))))
|
|
431
|
|
432 ;; misc
|
2
|
433 (sysdep-fset 'make-local-hook 'make-local-variable)
|
|
434
|
|
435 (sysdep-defun buffer-substring-no-properties (beg end)
|
|
436 "Return the text from BEG to END, without text properties, as a string."
|
|
437 (format "%s" (buffer-substring beg end)))
|
|
438
|
0
|
439 (sysdep-defun symbol-value-in-buffer (symbol buffer &optional unbound-value)
|
|
440 "Return the value of SYMBOL in BUFFER, or UNBOUND-VALUE if it is unbound."
|
|
441 (save-excursion
|
|
442 (set-buffer buffer)
|
|
443 (if (not (boundp symbol))
|
|
444 unbound-value
|
|
445 (symbol-value symbol))))
|
|
446
|
|
447 (sysdep-defun insert-file-contents-literally
|
|
448 (file &optional visit beg end replace)
|
|
449 "Like `insert-file-contents', q.v., but only reads in the file.
|
|
450 A buffer may be modified in several ways after reading into the buffer due
|
|
451 to advanced Emacs features, such as file-name-handlers, format decoding,
|
|
452 find-file-hooks, etc.
|
|
453 This function ensures that none of these modifications will take place."
|
|
454 (let ((file-name-handler-alist nil)
|
|
455 (find-file-hooks nil))
|
|
456 (insert-file-contents file visit beg end replace)))
|
|
457
|
|
458 (sysdep-defun alist-to-plist (alist)
|
|
459 "Convert association list ALIST into the equivalent property-list form.
|
|
460 The plist is returned. This converts from
|
|
461
|
|
462 \((a . 1) (b . 2) (c . 3))
|
|
463
|
|
464 into
|
|
465
|
|
466 \(a 1 b 2 c 3)
|
|
467
|
|
468 The original alist is not modified. See also `destructive-alist-to-plist'."
|
|
469 (let (plist)
|
|
470 (while alist
|
|
471 (let ((el (car alist)))
|
|
472 (setq plist (cons (cdr el) (cons (car el) plist))))
|
|
473 (setq alist (cdr alist)))
|
|
474 (nreverse plist)))
|
|
475
|
|
476 (sysdep-defun add-minor-mode (toggle name &optional keymap after toggle-fun)
|
|
477 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
|
|
478 TOGGLE is a symbol which is used as the variable which toggle the minor mode,
|
|
479 NAME is the name that should appear in the modeline (it should be a string
|
|
480 beginning with a space), KEYMAP is a keymap to make active when the minor
|
|
481 mode is active, and AFTER is the toggling symbol used for another minor
|
|
482 mode. If AFTER is non-nil, then it is used to position the new mode in the
|
|
483 minor-mode alists. TOGGLE-FUN specifies an interactive function that
|
|
484 is called to toggle the mode on and off; this affects what appens when
|
|
485 button2 is pressed on the mode, and when button3 is pressed somewhere
|
|
486 in the list of modes. If TOGGLE-FUN is nil and TOGGLE names an
|
|
487 interactive function, TOGGLE is used as the toggle function.
|
|
488
|
|
489 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)"
|
|
490 (if (not (assq toggle minor-mode-alist))
|
|
491 (setq minor-mode-alist (cons (list toggle name) minor-mode-alist)))
|
|
492 (if (and keymap (not (assq toggle minor-mode-map-alist)))
|
|
493 (setq minor-mode-map-alist (cons (cons toggle keymap)
|
|
494 minor-mode-map-alist))))
|
|
495
|
|
496 (sysdep-defvar x-font-regexp-foundry-and-family
|
|
497 (let ((- "[-?]")
|
|
498 (foundry "[^-]+")
|
|
499 (family "[^-]+")
|
|
500 )
|
|
501 (concat "\\`[-?*]" foundry - "\\(" family "\\)" -)))
|
|
502
|
|
503 (sysdep-defun match-string (num &optional string)
|
|
504 "Return string of text matched by last search.
|
|
505 NUM specifies which parenthesized expression in the last regexp.
|
|
506 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
|
|
507 Zero means the entire text matched by the whole regexp or whole string.
|
|
508 STRING should be given if the last search was by `string-match' on STRING."
|
|
509 (if (match-beginning num)
|
|
510 (if string
|
|
511 (substring string (match-beginning num) (match-end num))
|
|
512 (buffer-substring (match-beginning num) (match-end num)))))
|
|
513
|
|
514 (sysdep-defun add-hook (hook-var function &optional at-end)
|
|
515 "Add a function to a hook.
|
|
516 First argument HOOK-VAR (a symbol) is the name of a hook, second
|
|
517 argument FUNCTION is the function to add.
|
|
518 Third (optional) argument AT-END means to add the function at the end
|
|
519 of the hook list instead of the beginning. If the function is already
|
|
520 present, this has no effect.
|
|
521 Returns nil if FUNCTION was already present in HOOK-VAR, else new
|
|
522 value of HOOK-VAR."
|
|
523 (if (not (boundp hook-var)) (set hook-var nil))
|
|
524 (let ((old (symbol-value hook-var)))
|
|
525 (if (or (not (listp old)) (eq (car old) 'lambda))
|
|
526 (setq old (list old)))
|
|
527 (if (member function old)
|
|
528 nil
|
|
529 (set hook-var
|
|
530 (if at-end
|
|
531 (append old (list function)) ; don't nconc
|
|
532 (cons function old))))))
|
|
533
|
|
534 (sysdep-defalias 'valid-color-name-p
|
|
535 (cond
|
|
536 ((fboundp 'x-valid-color-name-p) ; XEmacs/Lucid
|
|
537 'x-valid-color-name-p)
|
|
538 ((and window-system
|
|
539 (fboundp 'color-defined-p)) ; NS/Emacs 19
|
|
540 'color-defined-p)
|
|
541 ((and window-system
|
2
|
542 (fboundp 'pm-color-defined-p))
|
|
543 'pm-color-defined-p)
|
|
544 ((and window-system
|
0
|
545 (fboundp 'x-color-defined-p)) ; Emacs 19
|
|
546 'x-color-defined-p)
|
|
547 ((fboundp 'get-color) ; Epoch
|
|
548 (function (lambda (color)
|
|
549 (let ((x (get-color color)))
|
|
550 (if x
|
|
551 (setq x (progn
|
|
552 (free-color x)
|
|
553 t)))
|
|
554 x))))
|
|
555 (t 'identity))) ; All others
|
|
556
|
|
557 ;; Misc.
|
108
|
558 ;; NT doesn't have make-symbolic-link
|
|
559 (sysdep-defalias 'make-symbolic-link 'copy-file)
|
|
560
|
122
|
561 (sysdep-defun run-hook-with-args-until-success (hook &rest args)
|
|
562 "Run HOOK with the specified arguments ARGS.
|
|
563 HOOK should be a symbol, a hook variable. Its value should
|
|
564 be a list of functions. We call those functions, one by one,
|
|
565 passing arguments ARGS to each of them, until one of them
|
|
566 returns a non-nil value. Then we return that value.
|
|
567 If all the functions return nil, we return nil."
|
|
568 (let ((rval nil)
|
|
569 (todo (and (boundp hook) (symbol-value hook)))
|
|
570 (global (and (boundp hook) (default-value hook)))
|
|
571 (cur nil))
|
|
572 (while (and (setq cur (car todo)) (not rval))
|
|
573 (setq todo (cdr todo))
|
|
574 (if (eq cur t)
|
|
575 (if global
|
|
576 (setq todo (append global todo)))
|
|
577 (setq rval (apply cur args))))))
|
|
578
|
0
|
579 (sysdep-defun split-string (string pattern)
|
|
580 "Return a list of substrings of STRING which are separated by PATTERN."
|
|
581 (let (parts (start 0))
|
|
582 (while (string-match pattern string start)
|
|
583 (setq parts (cons (substring string start (match-beginning 0)) parts)
|
|
584 start (match-end 0)))
|
|
585 (nreverse (cons (substring string start) parts))
|
|
586 ))
|
|
587
|
|
588 (sysdep-defun member (elt list)
|
|
589 (while (and list (not (equal elt (car list))))
|
|
590 (setq list (cdr list)))
|
|
591 list)
|
|
592
|
|
593 (sysdep-defun rassoc (key list)
|
|
594 (let ((found nil))
|
|
595 (while (and list (not found))
|
|
596 (if (equal (cdr (car list)) key) (setq found (car list)))
|
|
597 (setq list (cdr list)))
|
|
598 found))
|
|
599
|
|
600 (sysdep-defun display-error (error-object stream)
|
|
601 "Display `error-object' on `stream' in a user-friendly way."
|
|
602 (funcall (or (let ((type (car-safe error-object)))
|
|
603 (catch 'error
|
|
604 (and (consp error-object)
|
|
605 (symbolp type)
|
|
606 ;;(stringp (get type 'error-message))
|
|
607 (consp (get type 'error-conditions))
|
|
608 (let ((tail (cdr error-object)))
|
|
609 (while (not (null tail))
|
|
610 (if (consp tail)
|
|
611 (setq tail (cdr tail))
|
|
612 (throw 'error nil)))
|
|
613 t)
|
|
614 ;; (check-type condition condition)
|
|
615 (get type 'error-conditions)
|
|
616 ;; Search class hierarchy
|
|
617 (let ((tail (get type 'error-conditions)))
|
|
618 (while (not (null tail))
|
|
619 (cond ((not (and (consp tail)
|
|
620 (symbolp (car tail))))
|
|
621 (throw 'error nil))
|
|
622 ((get (car tail) 'display-error)
|
|
623 (throw 'error (get (car tail)
|
|
624 'display-error)))
|
|
625 (t
|
|
626 (setq tail (cdr tail)))))
|
|
627 ;; Default method
|
|
628 (function
|
|
629 (lambda (error-object stream)
|
|
630 (let ((type (car error-object))
|
|
631 (tail (cdr error-object))
|
|
632 (first t))
|
|
633 (if (eq type 'error)
|
|
634 (progn (princ (car tail) stream)
|
|
635 (setq tail (cdr tail)))
|
|
636 (princ (or (get type 'error-message) type)
|
|
637 stream))
|
|
638 (while tail
|
|
639 (princ (if first ": " ", ") stream)
|
|
640 (prin1 (car tail) stream)
|
|
641 (setq tail (cdr tail)
|
|
642 first nil)))))))))
|
|
643 (function
|
|
644 (lambda (error-object stream)
|
|
645 (princ "Peculiar error " stream)
|
|
646 (prin1 error-object stream))))
|
|
647 error-object stream))
|
|
648
|
80
|
649 (sysdep-defun decode-time (&optional specified-time)
|
|
650 (let* ((date (current-time-string specified-time))
|
|
651 (dateinfo (and date (timezone-parse-date date)))
|
|
652 (timeinfo (and dateinfo (timezone-parse-time (aref dateinfo 3)))))
|
|
653 (list (aref timeinfo 2) (aref timeinfo 1)
|
|
654 (aref timeinfo 0) (aref dateinfo 2)
|
|
655 (aref dateinfo 1) (aref dateinfo 0)
|
|
656 "unknown" nil 0)))
|
|
657
|
0
|
658 (sysdep-defun find-face (face)
|
|
659 (car-safe (memq face (face-list))))
|
|
660
|
2
|
661 (sysdep-defun set-marker-insertion-type (marker type)
|
|
662 "Set the insertion-type of MARKER to TYPE.
|
|
663 If TYPE is t, it means the marker advances when you insert text at it.
|
|
664 If TYPE is nil, it means the marker stays behind when you insert text at it."
|
|
665 nil)
|
|
666
|
0
|
667 ;; window functions
|
|
668
|
|
669 ;; not defined in v18
|
|
670 (sysdep-defun eval-buffer (bufname &optional printflag)
|
80
|
671 (interactive)
|
0
|
672 (save-excursion
|
|
673 (set-buffer bufname)
|
|
674 (eval-current-buffer)))
|
|
675
|
|
676 (sysdep-defun window-minibuffer-p (window)
|
|
677 "Returns non-nil if WINDOW is a minibuffer window."
|
|
678 (eq window (minibuffer-window)))
|
|
679
|
|
680 (sysdep-defun window-live-p (window)
|
|
681 "Returns t if OBJ is a window which is currently visible."
|
|
682 (and (windowp window)
|
|
683 (window-point window)))
|
|
684
|
80
|
685 (provide 'w3-sysdp)
|
0
|
686 ;;; sysdep.el ends here
|
|
687
|
|
688 ;;;(sysdep.el) Local Variables:
|
|
689 ;;;(sysdep.el) eval: (put 'sysdep-defun 'lisp-indent-function 'defun)
|
|
690 ;;;(sysdep.el) eval: (put 'sysdep-defalias 'lisp-indent-function 'defun)
|
|
691 ;;;(sysdep.el) eval: (put 'sysdep-defconst 'lisp-indent-function 'defun)
|
|
692 ;;;(sysdep.el) eval: (put 'sysdep-defvar 'lisp-indent-function 'defun)
|
|
693 ;;;(sysdep.el) End:
|