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
|
80
|
283 ;; WMP - commention these out so that Emacs 19 doesn't get screwed by them.
|
|
284 ;; In particular, this makes the 'custom' package blow up quite well.
|
|
285 ;;(sysdep-defun add-submenu (menu-path submenu &optional before)
|
|
286 ;; "Add a menu to the menubar or one of its submenus.
|
|
287 ;;If the named menu exists already, it is changed.
|
|
288 ;;MENU-PATH identifies the menu under which the new menu should be inserted.
|
|
289 ;; It is a list of strings; for example, (\"File\") names the top-level \"File\"
|
|
290 ;; menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
|
|
291 ;; If MENU-PATH is nil, then the menu will be added to the menubar itself.
|
|
292 ;;SUBMENU is the new menu to add.
|
|
293 ;; See the documentation of `current-menubar' for the syntax.
|
|
294 ;;BEFORE, if provided, is the name of a menu before which this menu should
|
|
295 ;; be added, if this menu is not on its parent already. If the menu is already
|
|
296 ;; present, it will not be moved."
|
|
297 ;; (add-menu menu-path (car submenu) (cdr submenu) before))
|
0
|
298
|
80
|
299 ;;(sysdep-defun add-menu-button (menu-path menu-leaf &optional before)
|
|
300 ;; "Add a menu item to some menu, creating the menu first if necessary.
|
|
301 ;;If the named item exists already, it is changed.
|
|
302 ;;MENU-PATH identifies the menu under which the new menu item should be inserted.
|
|
303 ;; It is a list of strings; for example, (\"File\") names the top-level \"File\"
|
|
304 ;; menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
|
|
305 ;;MENU-LEAF is a menubar leaf node. See the documentation of `current-menubar'.
|
|
306 ;;BEFORE, if provided, is the name of a menu item before which this item should
|
|
307 ;; be added, if this item is not on the menu already. If the item is already
|
|
308 ;; present, it will not be moved."
|
|
309 ;; (add-menu-item menu-path (aref menu-leaf 0) (aref menu-leaf 1)
|
|
310 ;; (aref menu-leaf 2) before))
|
0
|
311
|
|
312 (sysdep-defun make-glyph (&optional spec-list)
|
|
313 (if (and spec-list (cdr-safe (assq 'x spec-list)))
|
|
314 (make-pixmap (cdr-safe (assq 'x spec-list)))))
|
|
315
|
|
316 (sysdep-defalias 'face-list 'list-faces)
|
|
317
|
80
|
318 (sysdep-defun set-keymap-parent (keymap new-parent)
|
|
319 (let ((tail keymap))
|
|
320 (while (and tail (cdr tail) (not (eq (car (cdr tail)) 'keymap)))
|
|
321 (setq tail (cdr tail)))
|
|
322 (if tail
|
|
323 (setcdr tail new-parent))))
|
|
324
|
114
|
325 (sysdep-defun buffer-substring-no-properties (st nd)
|
|
326 "Return the characters of part of the buffer, without the text properties.
|
|
327 The two arguments START and END are character positions;
|
|
328 they can be in either order."
|
|
329 (buffer-substring st nd))
|
|
330
|
2
|
331 ;; Property list functions
|
|
332 ;;
|
|
333 (sysdep-defun plist-put (plist prop val)
|
|
334 "Change value in PLIST of PROP to VAL.
|
|
335 PLIST is a property list, which is a list of the form
|
|
336 (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol and VAL is any object.
|
|
337 If PROP is already a property on the list, its value is set to VAL,
|
|
338 otherwise the new PROP VAL pair is added. The new plist is returned;
|
|
339 use `(setq x (plist-put x prop val))' to be sure to use the new value.
|
|
340 The PLIST is modified by side effects."
|
|
341 (let ((node (memq prop plist)))
|
|
342 (if node
|
|
343 (setcar (cdr node) val)
|
|
344 (setq plist (cons prop (cons val plist))))
|
|
345 plist))
|
|
346
|
|
347 (sysdep-defun plist-get (plist prop)
|
|
348 "Extract a value from a property list.
|
|
349 PLIST is a property list, which is a list of the form
|
|
350 (PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
|
|
351 corresponding to the given PROP, or nil if PROP is not
|
|
352 one of the properties on the list."
|
80
|
353 (while (and plist (not (eq (car plist) prop)))
|
|
354 (setq plist (cdr (cdr plist))))
|
|
355 (and plist (car (cdr plist))))
|
2
|
356
|
0
|
357 ;; Extent stuff
|
|
358 (sysdep-fset 'delete-extent 'delete-overlay)
|
|
359 (sysdep-fset 'extent-end-position 'overlay-end)
|
|
360 (sysdep-fset 'extent-start-position 'overlay-start)
|
|
361 (sysdep-fset 'set-extent-endpoints 'move-overlay)
|
2
|
362 (sysdep-fset 'set-extent-property 'overlay-put)
|
|
363 (sysdep-fset 'make-extent 'make-overlay)
|
0
|
364
|
|
365 (sysdep-defun extent-property (extent property &optional default)
|
|
366 (or (overlay-get extent property) default))
|
|
367
|
|
368 (sysdep-defun extent-at (pos &optional object property before at-flag)
|
|
369 (let ((tmp (overlays-at (point)))
|
|
370 ovls)
|
|
371 (if property
|
|
372 (while tmp
|
|
373 (if (extent-property (car tmp) property)
|
|
374 (setq ovls (cons (car tmp) ovls)))
|
|
375 (setq tmp (cdr tmp)))
|
|
376 (setq ovls tmp
|
|
377 tmp nil))
|
|
378 (car-safe
|
|
379 (sort ovls
|
|
380 (function
|
|
381 (lambda (a b)
|
|
382 (< (- (extent-end-position a) (extent-start-position a))
|
|
383 (- (extent-end-position b) (extent-start-position b)))))))))
|
|
384
|
|
385 (sysdep-defun overlays-in (beg end)
|
|
386 "Return a list of the overlays that overlap the region BEG ... END.
|
|
387 Overlap means that at least one character is contained within the overlay
|
|
388 and also contained within the specified region.
|
|
389 Empty overlays are included in the result if they are located at BEG
|
|
390 or between BEG and END."
|
|
391 (let ((ovls (overlay-lists))
|
|
392 tmp retval)
|
|
393 (if (< end beg)
|
|
394 (setq tmp end
|
|
395 end beg
|
|
396 beg tmp))
|
|
397 (setq ovls (nconc (car ovls) (cdr ovls)))
|
|
398 (while ovls
|
|
399 (setq tmp (car ovls)
|
|
400 ovls (cdr ovls))
|
|
401 (if (or (and (<= (overlay-start tmp) end)
|
|
402 (>= (overlay-start tmp) beg))
|
|
403 (and (<= (overlay-end tmp) end)
|
|
404 (>= (overlay-end tmp) beg)))
|
|
405 (setq retval (cons tmp retval))))
|
|
406 retval))
|
|
407
|
|
408 (sysdep-defun map-extents (function &optional object from to
|
|
409 maparg flags property value)
|
|
410 (let ((tmp (overlays-in (or from (point-min))
|
|
411 (or to (point-max))))
|
|
412 ovls)
|
|
413 (if property
|
|
414 (while tmp
|
|
415 (if (extent-property (car tmp) property)
|
|
416 (setq ovls (cons (car tmp) ovls)))
|
|
417 (setq tmp (cdr tmp)))
|
|
418 (setq ovls tmp
|
|
419 tmp nil))
|
|
420 (catch 'done
|
|
421 (while ovls
|
|
422 (setq tmp (funcall function (car ovls) maparg)
|
|
423 ovls (cdr ovls))
|
|
424 (if tmp
|
|
425 (throw 'done tmp))))))
|
|
426
|
|
427 ;; misc
|
2
|
428 (sysdep-fset 'make-local-hook 'make-local-variable)
|
|
429
|
|
430 (sysdep-defun buffer-substring-no-properties (beg end)
|
|
431 "Return the text from BEG to END, without text properties, as a string."
|
|
432 (format "%s" (buffer-substring beg end)))
|
|
433
|
0
|
434 (sysdep-defun symbol-value-in-buffer (symbol buffer &optional unbound-value)
|
|
435 "Return the value of SYMBOL in BUFFER, or UNBOUND-VALUE if it is unbound."
|
|
436 (save-excursion
|
|
437 (set-buffer buffer)
|
|
438 (if (not (boundp symbol))
|
|
439 unbound-value
|
|
440 (symbol-value symbol))))
|
|
441
|
|
442 (sysdep-defun insert-file-contents-literally
|
|
443 (file &optional visit beg end replace)
|
|
444 "Like `insert-file-contents', q.v., but only reads in the file.
|
|
445 A buffer may be modified in several ways after reading into the buffer due
|
|
446 to advanced Emacs features, such as file-name-handlers, format decoding,
|
|
447 find-file-hooks, etc.
|
|
448 This function ensures that none of these modifications will take place."
|
|
449 (let ((file-name-handler-alist nil)
|
|
450 (find-file-hooks nil))
|
|
451 (insert-file-contents file visit beg end replace)))
|
|
452
|
|
453 (sysdep-defun alist-to-plist (alist)
|
|
454 "Convert association list ALIST into the equivalent property-list form.
|
|
455 The plist is returned. This converts from
|
|
456
|
|
457 \((a . 1) (b . 2) (c . 3))
|
|
458
|
|
459 into
|
|
460
|
|
461 \(a 1 b 2 c 3)
|
|
462
|
|
463 The original alist is not modified. See also `destructive-alist-to-plist'."
|
|
464 (let (plist)
|
|
465 (while alist
|
|
466 (let ((el (car alist)))
|
|
467 (setq plist (cons (cdr el) (cons (car el) plist))))
|
|
468 (setq alist (cdr alist)))
|
|
469 (nreverse plist)))
|
|
470
|
|
471 (sysdep-defun add-minor-mode (toggle name &optional keymap after toggle-fun)
|
|
472 "Add a minor mode to `minor-mode-alist' and `minor-mode-map-alist'.
|
|
473 TOGGLE is a symbol which is used as the variable which toggle the minor mode,
|
|
474 NAME is the name that should appear in the modeline (it should be a string
|
|
475 beginning with a space), KEYMAP is a keymap to make active when the minor
|
|
476 mode is active, and AFTER is the toggling symbol used for another minor
|
|
477 mode. If AFTER is non-nil, then it is used to position the new mode in the
|
|
478 minor-mode alists. TOGGLE-FUN specifies an interactive function that
|
|
479 is called to toggle the mode on and off; this affects what appens when
|
|
480 button2 is pressed on the mode, and when button3 is pressed somewhere
|
|
481 in the list of modes. If TOGGLE-FUN is nil and TOGGLE names an
|
|
482 interactive function, TOGGLE is used as the toggle function.
|
|
483
|
|
484 Example: (add-minor-mode 'view-minor-mode \" View\" view-mode-map)"
|
|
485 (if (not (assq toggle minor-mode-alist))
|
|
486 (setq minor-mode-alist (cons (list toggle name) minor-mode-alist)))
|
|
487 (if (and keymap (not (assq toggle minor-mode-map-alist)))
|
|
488 (setq minor-mode-map-alist (cons (cons toggle keymap)
|
|
489 minor-mode-map-alist))))
|
|
490
|
|
491 (sysdep-defvar x-font-regexp-foundry-and-family
|
|
492 (let ((- "[-?]")
|
|
493 (foundry "[^-]+")
|
|
494 (family "[^-]+")
|
|
495 )
|
|
496 (concat "\\`[-?*]" foundry - "\\(" family "\\)" -)))
|
|
497
|
|
498 (sysdep-defun match-string (num &optional string)
|
|
499 "Return string of text matched by last search.
|
|
500 NUM specifies which parenthesized expression in the last regexp.
|
|
501 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
|
|
502 Zero means the entire text matched by the whole regexp or whole string.
|
|
503 STRING should be given if the last search was by `string-match' on STRING."
|
|
504 (if (match-beginning num)
|
|
505 (if string
|
|
506 (substring string (match-beginning num) (match-end num))
|
|
507 (buffer-substring (match-beginning num) (match-end num)))))
|
|
508
|
|
509 (sysdep-defun add-hook (hook-var function &optional at-end)
|
|
510 "Add a function to a hook.
|
|
511 First argument HOOK-VAR (a symbol) is the name of a hook, second
|
|
512 argument FUNCTION is the function to add.
|
|
513 Third (optional) argument AT-END means to add the function at the end
|
|
514 of the hook list instead of the beginning. If the function is already
|
|
515 present, this has no effect.
|
|
516 Returns nil if FUNCTION was already present in HOOK-VAR, else new
|
|
517 value of HOOK-VAR."
|
|
518 (if (not (boundp hook-var)) (set hook-var nil))
|
|
519 (let ((old (symbol-value hook-var)))
|
|
520 (if (or (not (listp old)) (eq (car old) 'lambda))
|
|
521 (setq old (list old)))
|
|
522 (if (member function old)
|
|
523 nil
|
|
524 (set hook-var
|
|
525 (if at-end
|
|
526 (append old (list function)) ; don't nconc
|
|
527 (cons function old))))))
|
|
528
|
|
529 (sysdep-defalias 'valid-color-name-p
|
|
530 (cond
|
|
531 ((fboundp 'x-valid-color-name-p) ; XEmacs/Lucid
|
|
532 'x-valid-color-name-p)
|
|
533 ((and window-system
|
|
534 (fboundp 'color-defined-p)) ; NS/Emacs 19
|
|
535 'color-defined-p)
|
|
536 ((and window-system
|
2
|
537 (fboundp 'pm-color-defined-p))
|
|
538 'pm-color-defined-p)
|
|
539 ((and window-system
|
0
|
540 (fboundp 'x-color-defined-p)) ; Emacs 19
|
|
541 'x-color-defined-p)
|
|
542 ((fboundp 'get-color) ; Epoch
|
|
543 (function (lambda (color)
|
|
544 (let ((x (get-color color)))
|
|
545 (if x
|
|
546 (setq x (progn
|
|
547 (free-color x)
|
|
548 t)))
|
|
549 x))))
|
|
550 (t 'identity))) ; All others
|
|
551
|
|
552 ;; Misc.
|
108
|
553 ;; NT doesn't have make-symbolic-link
|
|
554 (sysdep-defalias 'make-symbolic-link 'copy-file)
|
|
555
|
122
|
556 (sysdep-defun run-hook-with-args-until-success (hook &rest args)
|
|
557 "Run HOOK with the specified arguments ARGS.
|
|
558 HOOK should be a symbol, a hook variable. Its value should
|
|
559 be a list of functions. We call those functions, one by one,
|
|
560 passing arguments ARGS to each of them, until one of them
|
|
561 returns a non-nil value. Then we return that value.
|
|
562 If all the functions return nil, we return nil."
|
|
563 (let ((rval nil)
|
|
564 (todo (and (boundp hook) (symbol-value hook)))
|
|
565 (global (and (boundp hook) (default-value hook)))
|
|
566 (cur nil))
|
|
567 (while (and (setq cur (car todo)) (not rval))
|
|
568 (setq todo (cdr todo))
|
|
569 (if (eq cur t)
|
|
570 (if global
|
|
571 (setq todo (append global todo)))
|
|
572 (setq rval (apply cur args))))))
|
|
573
|
0
|
574 (sysdep-defun split-string (string pattern)
|
|
575 "Return a list of substrings of STRING which are separated by PATTERN."
|
|
576 (let (parts (start 0))
|
|
577 (while (string-match pattern string start)
|
|
578 (setq parts (cons (substring string start (match-beginning 0)) parts)
|
|
579 start (match-end 0)))
|
|
580 (nreverse (cons (substring string start) parts))
|
|
581 ))
|
|
582
|
|
583 (sysdep-defun member (elt list)
|
|
584 (while (and list (not (equal elt (car list))))
|
|
585 (setq list (cdr list)))
|
|
586 list)
|
|
587
|
|
588 (sysdep-defun rassoc (key list)
|
|
589 (let ((found nil))
|
|
590 (while (and list (not found))
|
|
591 (if (equal (cdr (car list)) key) (setq found (car list)))
|
|
592 (setq list (cdr list)))
|
|
593 found))
|
|
594
|
|
595 (sysdep-defun display-error (error-object stream)
|
|
596 "Display `error-object' on `stream' in a user-friendly way."
|
|
597 (funcall (or (let ((type (car-safe error-object)))
|
|
598 (catch 'error
|
|
599 (and (consp error-object)
|
|
600 (symbolp type)
|
|
601 ;;(stringp (get type 'error-message))
|
|
602 (consp (get type 'error-conditions))
|
|
603 (let ((tail (cdr error-object)))
|
|
604 (while (not (null tail))
|
|
605 (if (consp tail)
|
|
606 (setq tail (cdr tail))
|
|
607 (throw 'error nil)))
|
|
608 t)
|
|
609 ;; (check-type condition condition)
|
|
610 (get type 'error-conditions)
|
|
611 ;; Search class hierarchy
|
|
612 (let ((tail (get type 'error-conditions)))
|
|
613 (while (not (null tail))
|
|
614 (cond ((not (and (consp tail)
|
|
615 (symbolp (car tail))))
|
|
616 (throw 'error nil))
|
|
617 ((get (car tail) 'display-error)
|
|
618 (throw 'error (get (car tail)
|
|
619 'display-error)))
|
|
620 (t
|
|
621 (setq tail (cdr tail)))))
|
|
622 ;; Default method
|
|
623 (function
|
|
624 (lambda (error-object stream)
|
|
625 (let ((type (car error-object))
|
|
626 (tail (cdr error-object))
|
|
627 (first t))
|
|
628 (if (eq type 'error)
|
|
629 (progn (princ (car tail) stream)
|
|
630 (setq tail (cdr tail)))
|
|
631 (princ (or (get type 'error-message) type)
|
|
632 stream))
|
|
633 (while tail
|
|
634 (princ (if first ": " ", ") stream)
|
|
635 (prin1 (car tail) stream)
|
|
636 (setq tail (cdr tail)
|
|
637 first nil)))))))))
|
|
638 (function
|
|
639 (lambda (error-object stream)
|
|
640 (princ "Peculiar error " stream)
|
|
641 (prin1 error-object stream))))
|
|
642 error-object stream))
|
|
643
|
80
|
644 (sysdep-defun decode-time (&optional specified-time)
|
|
645 (let* ((date (current-time-string specified-time))
|
|
646 (dateinfo (and date (timezone-parse-date date)))
|
|
647 (timeinfo (and dateinfo (timezone-parse-time (aref dateinfo 3)))))
|
|
648 (list (aref timeinfo 2) (aref timeinfo 1)
|
|
649 (aref timeinfo 0) (aref dateinfo 2)
|
|
650 (aref dateinfo 1) (aref dateinfo 0)
|
|
651 "unknown" nil 0)))
|
|
652
|
0
|
653 (sysdep-defun find-face (face)
|
|
654 (car-safe (memq face (face-list))))
|
|
655
|
2
|
656 (sysdep-defun set-marker-insertion-type (marker type)
|
|
657 "Set the insertion-type of MARKER to TYPE.
|
|
658 If TYPE is t, it means the marker advances when you insert text at it.
|
|
659 If TYPE is nil, it means the marker stays behind when you insert text at it."
|
|
660 nil)
|
|
661
|
0
|
662 ;; window functions
|
|
663
|
|
664 ;; not defined in v18
|
|
665 (sysdep-defun eval-buffer (bufname &optional printflag)
|
80
|
666 (interactive)
|
0
|
667 (save-excursion
|
|
668 (set-buffer bufname)
|
|
669 (eval-current-buffer)))
|
|
670
|
|
671 (sysdep-defun window-minibuffer-p (window)
|
|
672 "Returns non-nil if WINDOW is a minibuffer window."
|
|
673 (eq window (minibuffer-window)))
|
|
674
|
|
675 (sysdep-defun window-live-p (window)
|
|
676 "Returns t if OBJ is a window which is currently visible."
|
|
677 (and (windowp window)
|
|
678 (window-point window)))
|
|
679
|
80
|
680 (provide 'w3-sysdp)
|
0
|
681 ;;; sysdep.el ends here
|
|
682
|
|
683 ;;;(sysdep.el) Local Variables:
|
|
684 ;;;(sysdep.el) eval: (put 'sysdep-defun 'lisp-indent-function 'defun)
|
|
685 ;;;(sysdep.el) eval: (put 'sysdep-defalias 'lisp-indent-function 'defun)
|
|
686 ;;;(sysdep.el) eval: (put 'sysdep-defconst 'lisp-indent-function 'defun)
|
|
687 ;;;(sysdep.el) eval: (put 'sysdep-defvar 'lisp-indent-function 'defun)
|
|
688 ;;;(sysdep.el) End:
|