compatibility.el 22.5 KB
Newer Older
David Byers's avatar
David Byers committed
1
;;;;; -*-coding: iso-8859-1;-*-
2
;;;;;
3
;;;;; $Id$
4
;;;;; Copyright (C) 1991-2002  Lysator Academic Computer Association.
5
;;;;; Copyright (C) 2001 Free Software Foundation, Inc.
6
;;;;;
7
;;;;; This file is part of the LysKOM Emacs LISP client.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;;;;; 
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by 
;;;;; the Free Software Foundation; either version 2, or (at your option) 
;;;;; any later version.
;;;;; 
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;;;;; for more details.
;;;;; 
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING.  If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se. 
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: compatibility.el
;;;;
;;;; This file contains functions that may not exist in all supported
;;;; versions of Gnu Emacs. XEmacs-specific and Emacs 18-specific code
;;;; should go in some other file.
;;;;

(setq lyskom-clientversion-long 
      (concat lyskom-clientversion-long
	      "$Id$\n"))


;;; ======================================================================
;;; Use lyskom-provide to supply a definition that is only to be used
;;; if no definition already exists. The definition will be evaluated at
;;; both compile and run time.
;;;
;;; lyskom-provide-macros behaves like defmacro
;;; lyskom-provide-function behaves like defun
;;; lyskom-provide-subst behaves like defsubst
;;;

(eval-and-compile
  (defvar lyskom-compatibility-definitions nil
    "Functions defined or redefined because they are incompatible with
LysKOM"))

;;; ============================================================
;;; lyskom-compatibility-forms
;;; lyskom-compatibility-definition
;;;


(defmacro lyskom-compatibility-forms (predicate &rest forms)
  "If PREDICATE is nil, evaluate FORMS at compile and run time"
  (` (eval-and-compile
       (if (not (, predicate))
           (progn (,@ forms))))))

(defmacro lyskom-compatibility-definition (predicate definition)
  "If PREDICATE is nil, evaluate DEFINITION at compile and run time.
Definition should be a function definition of some kind, with syntax 
similar to defun or defmacro.

To simply define a function if it is not already defined, used one
of the lyskom-provide-* functions instead."
76
77
78
79
80
  (` (progn ;(eval-when-compile
            ;  (if (not (, predicate))
            ;      (message "Compatibility %S for %S"
            ;               (quote (, (car definition)))
            ;               (quote (, (car (cdr definition)))))))
81
              (eval-and-compile
David Byers's avatar
David Byers committed
82
83
84
85
86
87
88
                (if (not (, predicate))
                    (progn
                      (, definition)
                      (setq lyskom-compatibility-definitions
                            (cons (quote (, (car (cdr definition))))
                                  lyskom-compatibility-definitions))))))))

89
90
91
92
93
94
95
96
97
98
99

;;; ============================================================
;;; lyskom-provide
;;; lyskom-provide-macro
;;; lyskom-provide-function
;;; lyskom-provide-subst
;;;
;;; Define functions if they are not already defined
;;;

(defmacro lyskom-provide (definer name rest)
100
101
102
103
104
105
  `(eval-and-compile
     (if (not (fboundp ',name))
         (progn (setq lyskom-compatibility-definitions
                      (cons ',name lyskom-compatibility-definitions))
                (,definer ,name ,@rest)))))

106
107
108
109
110
111
112
113
114
115
116
117
118
119

(defmacro lyskom-provide-macro (name &rest rest)
  "If NAME is not already defined, define it as a macro."
  (` (lyskom-provide defmacro (, name) (, rest))))

(defmacro lyskom-provide-function (name &rest rest)
  "If NAME is not already defined, define it as a function."
  (` (lyskom-provide defun (, name) (, rest))))

(defmacro lyskom-provide-subst (name &rest rest)
  "If NAME is not already defined, define it as a defsubst."
  (` (lyskom-provide defsubst (, name) (, rest))))


David Byers's avatar
X    
David Byers committed
120
121
;;; ============================================================
;;; lyskom-xemacs-or-gnu
122
123
;;;

David Byers's avatar
David Byers committed
124
125
126
127
128
129
(eval-and-compile
  (defmacro lyskom-xemacs-or-gnu (xemacs-form gnu-form)
    "Eval XEMACS-FORM in XEmacs and GNU-FORM in Gnu Emacs."
    (if (string-match "XEmacs" (emacs-version))
        xemacs-form
      gnu-form)))
130

131
(put 'lyskom-xemacs-or-gnu 'edebug-form-spec '(form form))
132

133
134
135
136
137


;;; ======================================================================
;;; Defining keys
;;;
138
139
140
141
142
143
;;; Lots of Emacsen have buggy definitions of kbd (or no definition at all)
;;; Although it's crufty to redefine a function from subr.el, I will do so
;;; if it appears to be misbehaving. Don't like it? Tough!
;;;

(lyskom-compatibility-definition
144
    (condition-case nil
145
146
147
148
        (or (equal (kbd (identity "<down-mouse-2>"))
                   [down-mouse-2])
            (error "Bad definition of kbd"))
      (error nil))
149

150
151
    (defmacro kbd (keys)
      "Convert KEYS to the internal Emacs key representation.
152
153
KEYS should be a string in the format used for saving keyboard macros
\(see `insert-kbd-macro')."
154
155
156
157
      (if (or (stringp keys)
              (vectorp keys))
          (read-kbd-macro keys)
        `(read-kbd-macro ,keys))))
158
159


David Byers's avatar
X    
David Byers committed
160
161
162
;;; ======================================================================
;;; ======================================================================
;;; ======================================================================
163
164
165
166

;;;


David Byers's avatar
David Byers committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
(lyskom-provide-macro char-before (&optional pos buffer)
  `(save-excursion
     (save-restriction 
       (widen)
       ,@(if buffer `((set-buffer ,buffer)))
       ,(if pos 
	    `(if (or (> ,pos (point-max))
		     (<= ,pos (point-min)))
		 nil
	       (goto-char ,pos)
	       (preceding-char))
	   `(if (<= (point) (point-min))
		nil
	      (preceding-char))))))
		       

David Byers's avatar
David Byers committed
183
184
185
(lyskom-provide-function characterp (obj)
  (integerp obj))

David Byers's avatar
David Byers committed
186
187
188
(lyskom-provide-function int-to-char (obj)
  obj)

189
190
191
(lyskom-compatibility-forms (fboundp 'frame-width)
    (fset 'frame-width 'screen-width))

192
193
194
195
196
(lyskom-provide-function signum (num)
  (cond ((< num 0) -1)
        ((> num 0) 1)
        (t 0)))

197
198
199
200
201
202
203

;;; ======================================================================
;;; Definition of map-keymap that hopefully works like the one in XEmacs
;;; except that the sort-first argument is ignored.
;;;

(lyskom-provide-function map-keymap (fn keymap &optional sort-first)
David Byers's avatar
David Byers committed
204
  (let ((r 0))
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    (cond ((vectorp keymap)
           (while (< r (length keymap))
             (if (aref keymap r)
                 (funcall fn r (aref keymap r)))
             (setq r (1+ r))))
          (t (mapcar (function 
                      (lambda (x)
                        (funcall fn (car x) (cdr x))))
                     (cdr keymap))))))


(lyskom-provide-function set-keymap-parent (keymap new-parent)
   (let ((tail keymap))
     (while (and tail (cdr tail) (not (eq (car (cdr tail)) 'keymap)))
       (setq tail (cdr tail)))
     (if tail
         (setcdr tail new-parent))))

223
(defconst lyskom-gnu-keysym
David Byers's avatar
David Byers committed
224
225
226
227
228
  '((button1   . "<down-mouse-1>")
    (button2   . "<down-mouse-2>")
    (button3   . "<down-mouse-3>")
    (button1up . "<mouse-1>")
    (button2up . "<mouse-2>")
David Byers's avatar
David Byers committed
229
230
231
232
233
234
235
236
237
238
    (button3up . "<mouse-3>")
    (	       . [229])
    (	       . [197])
    (C-       . [(control 229)])
    (C-       . [(control 197)])
    (	       . [228])
    (	       . [196])
    (	       . [246])
    (	       . [214])
))
David Byers's avatar
David Byers committed
239
240
241
242
243
244
245

(defconst lyskom-xemacs-keysym
  '((button1   . "<button1>")
    (button2   . "<button2>")
    (button3   . "<button3>")
    (button1up . "<button1up>")
    (button2up . "<button2up>")
David Byers's avatar
David Byers committed
246
    (button3up . "<button3up>")
David Byers's avatar
David Byers committed
247
248
    (C-       . [(control aring)])
    (C-       . [(control Aring)])
David Byers's avatar
David Byers committed
249
250
251
252
253
254
255
    (	       . [aring])
    (	       . [Aring])
    (	       . [adiaeresis])
    (	       . [Adiaeresis])
    (	       . [odiaeresis])
    (	       . [Odiaeresis])
))
David Byers's avatar
David Byers committed
256
257
258
259
260
261
262


(defun lyskom-keys (sym)
  "Look up the key description for key SYM."
  (cdr (assq sym (lyskom-xemacs-or-gnu lyskom-xemacs-keysym
                                       lyskom-gnu-keysym))))

David Byers's avatar
X    
David Byers committed
263

David Byers's avatar
David Byers committed
264
265
266
267
268
269
;;; ============================================================
;;; Text property and extents stuff
;;;

(lyskom-provide-function map-extents (&rest args))

David Byers's avatar
David Byers committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
(lyskom-provide-function next-text-property-bounds 
    (count pos prop &optional object)
  "Return the COUNTth bounded property region of property PROP after POS.
If COUNT is less than zero, search backwards.  This returns a cons
\(START . END) of the COUNTth maximal region of text that begins after POS
\(starts before POS) and has a non-nil value for PROP.  If there aren't
that many regions, nil is returned.  OBJECT specifies the buffer or
string to search in."
  (or object (setq object (current-buffer)))
  (let ((begin (if (stringp object) 0 (point-min)))
	(end (if (stringp object) (length object) (point-max))))
    (catch 'hit-end
      (if (> count 0)
	  (progn
	    (while (> count 0)
	      (if (>= pos end)
		  (throw 'hit-end nil)
		(and (get-char-property pos prop object)
		     (setq pos (next-single-property-change pos prop
							    object end)))
		(setq pos (next-single-property-change pos prop object end)))
	      (setq count (1- count)))
	    (and (< pos end)
		 (cons pos (next-single-property-change pos prop object end))))
	(while (< count 0)
	  (if (<= pos begin)
	      (throw 'hit-end nil)
	    (and (get-char-property (1- pos) prop object)
		 (setq pos (previous-single-property-change pos prop
							    object begin)))
	    (setq pos (previous-single-property-change pos prop object
						       begin)))
	  (setq count (1+ count)))
	(and (> pos begin)
	     (cons (previous-single-property-change pos prop object begin)
		   pos))))))

David Byers's avatar
David Byers committed
307

David Byers's avatar
David Byers committed
308
;;; ============================================================
309
;;; Basic stuff
David Byers's avatar
David Byers committed
310

David Byers's avatar
Bugfix    
David Byers committed
311
(lyskom-provide-function char-to-int (c) c)
David Byers's avatar
David Byers committed
312

313
314
315
316
317
318
(defvar enable-multibyte-characters nil)
(lyskom-provide-function set-buffer-multibyte (arg)
  (put 'enable-multibyte-characters 'permanent-local t)
  (make-local-variable 'enable-multibyte-characters)
  (setq enable-multibyte-characters arg))

319
(lyskom-provide-function set-process-coding-system (proc &optional encoding decoding)
320
  ) 
321

322
323
(lyskom-provide-function encode-coding-string (str coding-system) (copy-sequence str))
(lyskom-provide-function decode-coding-string (str coding-system) (copy-sequence str))
324
(lyskom-provide-function string-bytes (str) (length str))
David Byers's avatar
David Byers committed
325
(lyskom-provide-function check-coding-system (name) (error "No such coding system"))
David Byers's avatar
David Byers committed
326
327
(lyskom-provide-function find-coding-systems-for-charsets (cs) nil)
(lyskom-provide-function coding-system-get (cs prop) nil)
David Byers's avatar
David Byers committed
328
329
330
(lyskom-provide-function string-width (str) (length str))
(lyskom-provide-function char-width (c) 1)
(lyskom-provide-function find-charset-string (str) '(ascii))
331
(lyskom-provide-function string-as-unibyte (str) str)
David Byers's avatar
David Byers committed
332
333
334
335
(lyskom-provide-function string-make-unibyte (str) str)
(lyskom-provide-function string-make-multibyte (str) str)
(lyskom-provide-function multibyte-string-p (str) nil)

336

337
;;; Detect buggy versions of encode-coding-string and decode-coding-string
338
339
;;; such as those provided by APEL (part of TM and often included in XEmacs)

340
(defun lyskom-buggy-encode-coding-string (str coding-system) str)
341
342
(eval-and-compile
  (if (let ((test "TEM")) (eq (encode-coding-string test 'raw-text) test))
343
      (progn (fset 'lyskom-buggy-encode-coding-string
344
345
                   (symbol-function 'encode-coding-string))
             (defun encode-coding-string (str coding-system)
346
               (copy-sequence (lyskom-buggy-encode-coding-string str coding-system))))))
347

348
(defun lyskom-buggy-decode-coding-string (str coding-system) str)
349
350
(eval-and-compile
  (if (let ((test "TEM")) (eq (decode-coding-string test 'raw-text) test))
351
      (progn (fset 'lyskom-buggy-decode-coding-string
352
353
                   (symbol-function 'decode-coding-string))
             (defun decode-coding-string (str coding-system)
354
               (copy-sequence (lyskom-buggy-decode-coding-string str coding-system))))))
355
356


357
358
;; defmacro lyskom-encode-coding-char in XEmacs so the compiled code
;; is quicker. In Gnu Emacs define it as a function.
David Byers's avatar
David Byers committed
359
360
361
;;
;; The definition is made at compile-time to avoid getting warnings 
;; about encode-coding-char.
362

363
(eval-and-compile
David Byers's avatar
David Byers committed
364
365
366
367
368
369
370
371
372
  (cond ((eval-when-compile (string-match "XEmacs" (emacs-version)))
         (defmacro lyskom-encode-coding-char (c system) c))
        ((eval-when-compile (fboundp 'encode-coding-char))
         (defun lyskom-encode-coding-char (c system)
           (let ((s (encode-coding-char c system)))
             (if (and s (= (length s) 1))
                 (elt s 0)))))
        (t (defmacro lyskom-encode-coding-char (c system) c))))

373

David Byers's avatar
David Byers committed
374
375
376
377
378
379
380
381
382
383
384
385
(eval-and-compile
  (lyskom-xemacs-or-gnu
   (fset 'lyskom-string-width (symbol-function 'string-width))
   (defun lyskom-string-width (str)
     (cond ((and (multibyte-string-p str)
                 (null enable-multibyte-characters))
            (string-width (string-make-unibyte str)))
           ((and (null (multibyte-string-p str))
                 enable-multibyte-characters)
            (string-width (string-make-multibyte str)))
           (t (string-width str))))))

386

David Byers's avatar
David Byers committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
(eval-and-compile
  (cond ((eval-when-compile (string-match "XEmacs" (emacs-version)))
         (defun lyskom-completing-read (prompt
                                        table 
                                        &optional predicate require-match
                                        init hist def inherit-input-method)
           (completing-read prompt table predicate require-match init hist)))
        ((eval-when-compile (> emacs-major-version 19))
         (fset 'lyskom-completing-read (symbol-function 'completing-read)))
        (t 
         (defun lyskom-completing-read (prompt
                                        table 
                                        &optional predicate require-match
                                        init hist def inherit-input-method)
           (completing-read prompt table predicate require-match init hist)))))
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

(eval-and-compile
  (cond ((eval-when-compile (string-match "XEmacs" (emacs-version)))
	 (defun lyskom-read-from-minibuffer (prompt 
					     &optional initial-contents
					     keymap read hist default-value
					     inherit-input-method)
	   (read-from-minibuffer prompt
				 initial-contents
				 keymap
				 read
				 hist)))
	((eval-when-compile (> emacs-major-version 19))
	 (fset 'lyskom-read-from-minibuffer 
	       (symbol-function 'read-from-minibuffer)))
	(t (defun lyskom-read-from-minibuffer (prompt 
					       &optional initial-contents
					       keymap read hist default-value
					       inherit-input-method)
	     (read-from-minibuffer prompt
				   initial-contents
				   keymap
				   read
				   hist)))))

427
428
429
430
(if (fboundp 'minibuffer-contents)
    (defalias 'lyskom-minibuffer-contents 'minibuffer-contents)
  (defalias 'lyskom-minibuffer-contents 'buffer-string))

431
432
433
(lyskom-external-function temp-minibuffer-message)
(lyskom-provide-function minibuffer-message (message)
  (temp-minibuffer-message message))
David Byers's avatar
David Byers committed
434
435


436
437
438



439
440
441
442
443
444
445
446
447
448
449
450
451
(lyskom-provide-function last (x &optional n)
  "Returns the last link in the list LIST.
With optional argument N, returns the Nth-to-last link (default 1)."
  "Returns the last link in the list LIST.
With optional argument N, returns Nth-to-last link (default 1)."
  (if n
      (let ((m 0) (p x))
	(while (consp p) (setq m (1+ m)) (setq p (cdr p)))
	(if (<= n 0) p
	  (if (< n m) (nthcdr (- m n) x) x)))
    (while (consp (cdr x)) (setq x (cdr x)))
    x))

452
(lyskom-provide-function plist-member (plist prop)
453
454
455
456
457
458
459
460
461
  "Return non-nil if PLIST has the property PROP.
PLIST is a property list, which is a list of the form
\(PROP1 VALUE1 PROP2 VALUE2 ...\). PROP is a symbol.
Unlike `plist-get', this allows you to distinguish between a missing
property and a property with the value nil."
      (while (and plist (not (eq (car plist) prop)))
        (setq plist (cdr (cdr plist))))
      (and plist t))

462
463
464
465
466
467
468
469
470
471
472
473
474
475
;; The make-temp-file function below is taken verbatim from Emacs 21.2.
(lyskom-provide-function make-temp-file (prefix &optional dir-flag)
  "Create a temporary file.  The returned file name (created by
appending some random characters at the end of PREFIX, and expanding
against `temporary-file-directory' if necessary, is guaranteed to
point to a newly created empty file.  You can then use `write-region'
to write new data into the file.

If DIR-FLAG is non-nil, create a new empty directory instead of a file."
  (let (file)
    (while (condition-case ()
	       (progn
		 (setq file
		       (make-temp-name
David Byers's avatar
David Byers committed
476
477
478
479
			(expand-file-name prefix 
                                          (lyskom-xemacs-or-gnu
                                           (temp-directory)
                                           temporary-file-directory))))
480
481
		 (if dir-flag
		     (make-directory file)
David Byers's avatar
David Byers committed
482
		   (write-region "" nil file nil 'silent nil))
483
		 nil)
David Byers's avatar
David Byers committed
484
             (file-already-exists t))
485
486
487
488
489
      ;; the file was somehow created by someone else between
      ;; `make-temp-name' and `write-region', let's try again.
      nil)
    file))

490

491
492
493
494
495
496
;;; ================================================================
;;; Faces

(lyskom-provide-function reset-face (face &optional locale tag-set exact-p)
  )

David Byers's avatar
David Byers committed
497
(lyskom-provide-function lyskom-face-background-name (face)
498
499
  (face-background face))

David Byers's avatar
David Byers committed
500
501
502
503
(lyskom-provide-function lyskom-face-foreground-name (face)
  (face-foreground face))


504
505
506
507
508
509
510
511
(lyskom-provide-function find-face (face)
  (and (facep face) face))

(defun lyskom-make-face (name temporary)
  "Like make-face in XEmacs"
  (lyskom-xemacs-or-gnu (make-face name nil temporary)
                        (make-face name)))

David Byers's avatar
David Byers committed
512
513
514
515
516
517
(if (not (find-face 'strikethrough))
    (progn (make-face 'strikethrough)
           (if (eval-when-compile (fboundp 'set-face-strikethrough-p))
               (set-face-strikethru-p 'strikethrough t)
             (set-face-underline-p 'strikethrough t))))

518

David Byers's avatar
X    
David Byers committed
519
520
521
;;; ======================================================================
;;; Event stuff

522
(lyskom-external-function event-start)
David Byers's avatar
X    
David Byers committed
523
524
525
526
527
528
529
(lyskom-provide-function event-point (e)
  "Return the character position of the given mouse event.
If the event did not occur over a window, or did not occur over text,
then this returns nil.  Otherwise, it returns an index into the buffer
visible in the event's window."
  (car (cdr (event-start e))))

530
531
532
533
(lyskom-provide-function event-closest-point (e)
  "Return the character position closest to the mouse event EVENT."
  (car (cdr (event-start e))))

David Byers's avatar
David Byers committed
534
535
(lyskom-provide-function event-glyph (e))

David Byers's avatar
X    
David Byers committed
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597

(defun lyskom-get-buffer-window-list (buffer &optional minibuf frame)
  "Return windows currently displaying BUFFER, or nil if none.
See `walk-windows' for the meaning of MINIBUF and FRAME."
  (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
    (walk-windows (function (lambda (window)
			      (if (eq (window-buffer window) buffer)
				  (setq windows (cons window windows)))))
		  minibuf frame)
    windows))

(lyskom-provide-function 
 replace-in-string (str regexp newtext &optional literal)
  "Replaces all matches in STR for REGEXP with NEWTEXT string.
Optional LITERAL non-nil means do a literal replacement.
Otherwise treat \\ in NEWTEXT string as special:
  \\& means substitute original matched text,
  \\N means substitute match for \(...\) number N,
  \\\\ means insert one \\."
  (if (not (stringp str))
      (error "(replace-in-string): First argument must be a string: %s" str))
  (if (stringp newtext)
      nil
    (error "(replace-in-string): 3rd arg must be a string: %s"
	   newtext))
  (let ((rtn-str "")
	(start 0)
	(special)
	match prev-start)
    (while (setq match (string-match regexp str start))
      (setq prev-start start
	    start (match-end 0)
	    rtn-str
	    (concat
	      rtn-str
	      (substring str prev-start match)
	      (cond (literal newtext)
		    (t (mapconcat
			 (function
			   (lambda (c)
			     (if special
				 (progn
				   (setq special nil)
				   (cond ((eq c ?\\) "\\")
					 ((eq c ?&)
					  (substring str
						     (match-beginning 0)
						     (match-end 0)))
					 ((and (>= c ?0) (<= c ?9))
					  (if (> c (+ ?0 (length
							   (match-data))))
					      ;; Invalid match num
					      (error "(replace-in-string) Invalid match num: %c" c)
					    (setq c (- c ?0))
					    (substring str
						       (match-beginning c)
						       (match-end c))))
					 (t (char-to-string c))))
			       (if (eq c ?\\) (progn (setq special t) nil)
				 (char-to-string c)))))
			 newtext ""))))))
    (concat rtn-str (substring str start))))
598

599
600
601
602
603
604

(lyskom-provide-function buffer-live-p (object)
  "T of OBJECT is an editor buffer that has not been deleted."
  (and (bufferp object)
       (buffer-name object)))

David Byers's avatar
David Byers committed
605
606
607
;;; ================================================================
;;; Color stuff

David Byers's avatar
David Byers committed
608
609
610
611
(lyskom-external-function set-specifier)
(lyskom-external-function make-specifier)
(lyskom-external-function color-rgb-components)

612
613
(lyskom-compatibility-definition (not (and (fboundp 'color-rgb-components) 
                                           (fboundp 'make-specifier)))
David Byers's avatar
David Byers committed
614
615
616
617
618
619
620
    (defun lyskom-color-values (color)
      (when (stringp color)
        (let ((spec nil))
          (set-specifier (setq spec (make-specifier 'color)) color)
          (setq color spec)))
      (color-rgb-components color)))

David Byers's avatar
David Byers committed
621
(eval-and-compile
David Byers's avatar
David Byers committed
622
623
  (cond ((fboundp 'lyskom-color-values) nil)
        ((fboundp 'color-values) (fset 'lyskom-color-values 'color-values))
624
        ((fboundp 'x-color-values) (fset 'lyskom-color-values 'x-color-values))))
David Byers's avatar
David Byers committed
625
626


627
628
629
630
631
632
633
;;; ======================================================================
;;; Platform-specific stuff

(lyskom-provide-function w32-shell-execute (&rest args)
  "Dummy function that raises an error."
  (error "w32-shell-execute undefined"))

David Byers's avatar
David Byers committed
634
635
636
637
638
;; This code looks the way it does in order to avoid warnings in
;; Emacs 21.

(eval-and-compile
  (condition-case nil
639
640
      (setq lyskom-dummy-variable-to-fool-the-byte-compiler
            (symbol-value ':default-help-echo))
641
642
    (error (set ':default-help-echo ':default-help-echo)))
  (condition-case nil
643
644
      (setq lyskom-dummy-variable-to-fool-the-byte-compiler
            (symbol-value ':group))
645
646
647
    (error (set ':group ':group))))


David Byers's avatar
David Byers committed
648

649

650
651
652
653
654
655
656
;;; Local Variables:
;;; eval: (put 'lyskom-provide-macro 'lisp-indent-hook 2)
;;; eval: (put 'lyskom-provide-function 'lisp-indent-hook 2)
;;; eval: (put 'lyskom-provide-subst 'lisp-indent-hook 2)
;;; eval: (put 'lyskom-compatibility-forms 'lisp-indent-hook 2)
;;; eval: (put 'lyskom-compatibility-definition 'lisp-indent-hook 2)
;;; end: