* poe-18.el (defalias): Remove its definition as a function and
[elisp/apel.git] / poe-18.el
1 ;;; poe-18.el --- poe API implementation for Emacs 18.*
2
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
4 ;; Copyright (C) 1999 Yuuichi Teranishi
5
6 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
7 ;;      Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
8 ;;      Yuuichi Teranishi <teranisi@gohome.org>
9 ;; Keywords: emulation, compatibility
10
11 ;; This file is part of APEL (A Portable Emacs Library).
12
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
17
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30 ;; Note to APEL developers and APEL programmers:
31 ;;
32 ;; If old (v18) compiler is used, top-level macros are expanded at
33 ;; *load-time*, not compile-time. Therefore,
34 ;;
35 ;; (1) Definitions with `*-maybe' won't be compiled.
36 ;;
37 ;; (2) you cannot use macros defined with `defmacro-maybe' within function
38 ;;     definitions in the same file.
39 ;;     (`defmacro-maybe' is evaluated at load-time, therefore byte-compiler
40 ;;      treats such use of macros as (unknown) functions and compiles them
41 ;;      into function calls, which will cause errors at run-time.)
42 ;;
43 ;; (3) `eval-when-compile' and `eval-and-compile' are evaluated at
44 ;;     load-time if used at top-level.
45
46 ;;; Code:
47
48 (require 'pym)
49
50
51 ;;; @ Compilation.
52 ;;;
53 (fset 'defalias 'fset)
54
55 (defun byte-code-function-p (object)
56   "Return t if OBJECT is a byte-compiled function object."
57   (and (consp object) (consp (cdr object))
58        (let ((rest (cdr (cdr object)))
59              elt)
60          (if (stringp (car rest))
61              (setq rest (cdr rest)))
62          (catch 'tag
63            (while rest
64              (setq elt (car rest))
65              (if (and (consp elt)
66                       (eq (car elt) 'byte-code))
67                  (throw 'tag t))
68              (setq rest (cdr rest)))))))
69
70 ;; (symbol-plist 'cyclic-function-indirection)
71 (put 'cyclic-function-indirection
72      'error-conditions
73      '(cyclic-function-indirection error))
74 (put 'cyclic-function-indirection
75      'error-message
76      "Symbol's chain of function indirections contains a loop")
77
78 ;; The following function definition is a direct translation of its
79 ;; C definition in emacs-20.4/src/data.c.
80 (defun indirect-function (object)
81   "Return the function at the end of OBJECT's function chain.
82 If OBJECT is a symbol, follow all function indirections and return the final
83 function binding.
84 If OBJECT is not a symbol, just return it.
85 Signal a void-function error if the final symbol is unbound.
86 Signal a cyclic-function-indirection error if there is a loop in the
87 function chain of symbols."
88   (let* ((hare object)
89          (tortoise hare))
90     (catch 'found
91       (while t
92         (or (symbolp hare) (throw 'found hare))
93         (or (fboundp hare) (signal 'void-function (cons object nil)))
94         (setq hare (symbol-function hare))
95         (or (symbolp hare) (throw 'found hare))
96         (or (fboundp hare) (signal 'void-function (cons object nil)))
97         (setq hare (symbol-function hare))
98
99         (setq tortoise (symbol-function tortoise))
100
101         (if (eq hare tortoise)
102             (signal 'cyclic-function-indirection (cons object nil)))))
103     hare))
104
105 ;;; Emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
106 ;;; (note: jwz's original compiler and XEmacs compiler have some more
107 ;;;  macros; they are "nuked" by rms in FSF version.)
108
109 ;; Use `*-maybe' here because new byte-compiler may be installed.
110 (put 'inline 'lisp-indent-hook 0)
111 (defmacro-maybe inline (&rest body)
112   "Eval BODY forms sequentially and return value of last one.
113
114 This emulating macro does not support function inlining because old \(v18\)
115 compiler does not support inlining feature."
116   (cons 'progn body))
117
118 (put 'defsubst 'lisp-indent-hook 'defun)
119 (put 'defsubst 'edebug-form-spec 'defun)
120 (defmacro-maybe defsubst (name arglist &rest body)
121   "Define an inline function.  The syntax is just like that of `defun'.
122
123 This emulating macro does not support function inlining because old \(v18\)
124 compiler does not support inlining feature."
125   (cons 'defun (cons name (cons arglist body))))
126
127 (defun-maybe make-obsolete (fn new)
128   "Make the byte-compiler warn that FUNCTION is obsolete.
129 The warning will say that NEW should be used instead.
130 If NEW is a string, that is the `use instead' message.
131
132 This emulating function does nothing because old \(v18\) compiler does not
133 support this feature."
134   (interactive "aMake function obsolete: \nxObsoletion replacement: ")
135   fn)
136
137 (defun-maybe make-obsolete-variable (var new)
138   "Make the byte-compiler warn that VARIABLE is obsolete,
139 and NEW should be used instead.  If NEW is a string, then that is the
140 `use instead' message.
141
142 This emulating function does nothing because old \(v18\) compiler does not
143 support this feature."
144   (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
145   var)
146
147 (put 'dont-compile 'lisp-indent-hook 0)
148 (defmacro-maybe dont-compile (&rest body)
149   "Like `progn', but the body always runs interpreted \(not compiled\).
150 If you think you need this, you're probably making a mistake somewhere."
151   (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
152
153 (put 'eval-when-compile 'lisp-indent-hook 0)
154 (defmacro-maybe eval-when-compile (&rest body)
155   "Like progn, but evaluates the body at compile-time.
156
157 This emulating macro does not do compile-time evaluation at all because
158 of the limitation of old \(v18\) compiler."
159   (cons 'progn body))
160
161 (put 'eval-and-compile 'lisp-indent-hook 0)
162 (defmacro-maybe eval-and-compile (&rest body)
163   "Like progn, but evaluates the body at compile-time as well as at load-time.
164
165 This emulating macro does not do compile-time evaluation at all because
166 of the limitation of old \(v18\) compiler."
167   (cons 'progn body))
168
169
170 ;;; @ C primitives emulation.
171 ;;;
172
173 (defun member (elt list)
174   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
175 The value is actually the tail of LIST whose car is ELT."
176   (while (and list (not (equal elt (car list))))
177     (setq list (cdr list)))
178   list)
179
180 (defun delete (elt list)
181   "Delete by side effect any occurrences of ELT as a member of LIST.
182 The modified LIST is returned.  Comparison is done with `equal'.
183 If the first member of LIST is ELT, deleting it is not a side effect;
184 it is simply using a different list.
185 Therefore, write `(setq foo (delete element foo))'
186 to be sure of changing the value of `foo'."
187   (if list
188       (if (equal elt (car list))
189           (cdr list)
190         (let ((rest list)
191               (rrest (cdr list)))
192           (while (and rrest (not (equal elt (car rrest))))
193             (setq rest rrest
194                   rrest (cdr rrest)))
195           (setcdr rest (cdr rrest))
196           list))))
197
198 (defun default-boundp (symbol)
199   "Return t if SYMBOL has a non-void default value.
200 This is the value that is seen in buffers that do not have their own values
201 for this variable."
202   (condition-case error
203       (progn
204         (default-value symbol)
205         t)
206     (void-variable nil)))
207
208 ;;; @@ current-time.
209 ;;;
210
211 (defvar current-time-world-timezones
212   '(("PST" .  -800)("PDT" .  -700)("MST" .  -700)
213     ("MDT" .  -600)("CST" .  -600)("CDT" .  -500)
214     ("EST" .  -500)("EDT" .  -400)("AST" .  -400)
215     ("NST" .  -330)("UT"  .  +000)("GMT" .  +000)
216     ("BST" .  +100)("MET" .  +100)("EET" .  +200)
217     ("JST" .  +900)("GMT+1"  .  +100)("GMT+2"  .  +200)
218     ("GMT+3"  .  +300)("GMT+4"  .  +400)("GMT+5"  .  +500)
219     ("GMT+6"  .  +600)("GMT+7"  .  +700)("GMT+8"  .  +800)
220     ("GMT+9"  .  +900)("GMT+10" . +1000)("GMT+11" . +1100)
221     ("GMT+12" . +1200)("GMT+13" . +1300)("GMT-1"  .  -100)
222     ("GMT-2"  .  -200)("GMT-3"  .  -300)("GMT-4"  .  -400)
223     ("GMT-5"  .  -500)("GMT-6"  .  -600)("GMT-7"  .  -700)
224     ("GMT-8"  .  -800)("GMT-9"  .  -900)("GMT-10" . -1000)
225     ("GMT-11" . -1100) ("GMT-12" . -1200))
226   "Time differentials of timezone from GMT in +-HHMM form.
227 Used in `current-time-zone' (Emacs 19 emulating function in poe-18.el).")
228
229 (defvar current-time-local-timezone nil 
230   "*Local timezone name.
231 Used in `current-time-zone' (Emacs 19 emulating function in poe-18.el).")
232
233 (defun current-time-zone (&optional specified-time)
234   "Return the offset and name for the local time zone.
235 This returns a list of the form (OFFSET NAME).
236 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
237     A negative value means west of Greenwich.
238 NAME is a string giving the name of the time zone.
239 Optional argument SPECIFIED-TIME is ignored in this implementation.
240 Some operating systems cannot provide all this information to Emacs;
241 in this case, `current-time-zone' returns a list containing nil for
242 the data it can't find."
243   (let ((local-timezone 
244          (or current-time-local-timezone
245              (setq current-time-local-timezone
246                    (with-temp-buffer
247                      (call-process "date" nil (current-buffer) t)
248                      (goto-char (point-min))
249                      (if (looking-at 
250                           "^.*\\([A-Z][A-Z][A-Z]\\([^ \n\t]*\\)\\).*$")
251                          (buffer-substring (match-beginning 1)
252                                            (match-end 1)))))))
253         timezone abszone seconds)
254     (setq timezone
255           (or (cdr (assoc (upcase local-timezone) 
256                           current-time-world-timezones))
257               ;; "+900" style or nil.
258               local-timezone))
259     (when timezone
260       (if (stringp timezone)
261           (setq timezone (string-to-int timezone)))
262       ;; Taking account of minute in timezone.
263       ;; HHMM -> MM
264       (setq abszone (abs timezone))
265       (setq seconds (* 60 (+ (* 60 (/ abszone 100)) (% abszone 100))))
266       (list (if (< timezone 0) (- seconds) seconds)
267             local-timezone))))
268
269 (or (fboundp 'si:current-time-string)
270     (fset 'si:current-time-string (symbol-function 'current-time-string)))
271 (defun current-time-string (&optional specified-time)
272   "Return the current time, as a human-readable string.
273 Programs can use this function to decode a time,
274 since the number of columns in each field is fixed.
275 The format is `Sun Sep 16 01:03:52 1973'.
276 If an argument SPECIFIED-TIME is given, it specifies a time to format
277 instead of the current time.  The argument should have the form:
278   (HIGH . LOW)
279 or the form:
280   (HIGH LOW . IGNORED).
281 Thus, you can use times obtained from `current-time'
282 and from `file-attributes'."
283   (if (null specified-time)
284       (si:current-time-string)
285     (or (consp specified-time)
286         (error "Wrong type argument %s" specified-time))
287     (let ((high (car specified-time))
288           (low  (cdr specified-time))
289           (offset (or (car (current-time-zone)) 0))
290           (mdays '(31 28 31 30 31 30 31 31 30 31 30 31))
291           (mnames '("Jan" "Feb" "Mar" "Apr" "May" "Jun" 
292                     "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
293           (wnames '("Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"))
294           days dd yyyy lyear mm HH MM SS)
295       (if (consp low)
296           (setq low (car low)))
297       (or (integerp high)
298           (error "Wrong type argument %s" high))
299       (or (integerp low)
300           (error "Wrong type argument %s" low))
301       (setq low (+ low offset))
302       (while (> low 65535)
303         (setq high (1+ high)
304               low (- low 65536)))
305       (setq yyyy 1970)
306       (while (or (> high 481)
307                  (and (= high 481)
308                       (>= low 13184)))
309         (if (and (> high 0)
310                  (< low 13184))
311             (setq high (1- high)
312                   low  (+ 65536 low)))
313         (setq high (- high 481)
314               low  (- low 13184))
315         (if (and (zerop (% yyyy 4))
316                  (or (not (zerop (% yyyy 100)))
317                      (zerop (% yyyy 400))))
318             (progn
319               (if (and (> high 0) 
320                        (< low 20864))
321                   (setq high (1- high)
322                         low  (+ 65536 low)))
323               (setq high (- high 1)
324                     low (- low 20864))))
325         (setq yyyy (1+ yyyy)))
326       (setq dd 1)
327       (while (or (> high 1)
328                  (and (= high 1)
329                       (>= low 20864)))
330         (if (and (> high 0)
331                  (< low 20864))
332             (setq high (1- high)
333                   low  (+ 65536 low)))
334         (setq high (- high 1)
335               low  (- low 20864)
336               dd (1+ dd)))
337       (setq days dd)
338       (if (= high 1)
339           (setq low (+ 65536 low)))
340       (setq mm 0)
341       (setq lyear (and (zerop (% yyyy 4))
342                        (or (not (zerop (% yyyy 100)))
343                            (zerop (% yyyy 400)))))
344       (while (> (- dd (nth mm mdays)) 0)
345         (if (and (= mm 1) lyear)
346             (setq dd (- dd 29))
347           (setq dd (- dd (nth mm mdays))))
348         (setq mm (1+ mm)))
349       (setq HH (/ low 3600)
350             low (% low 3600)
351             MM (/ low 60)
352             SS (% low 60))
353       (format "%s %s %2d %02d:%02d:%02d %4d"
354               (nth (% (+ days
355                          (- (+ (* (1- yyyy) 365) (/ (1- yyyy) 400) 
356                                (/ (1- yyyy) 4)) (/ (1- yyyy) 100))) 7)
357                    wnames)
358               (nth mm mnames)
359               dd HH MM SS yyyy))))
360
361 (defun current-time ()
362   "Return the current time, as the number of seconds since 1970-01-01 00:00:00.
363 The time is returned as a list of three integers.  The first has the
364 most significant 16 bits of the seconds, while the second has the
365 least significant 16 bits.  The third integer gives the microsecond
366 count.
367
368 The microsecond count is zero on systems that do not provide
369 resolution finer than a second."
370   (let* ((str (current-time-string))
371          (yyyy (string-to-int (substring str 20 24)))
372          (mm (length (member (substring str 4 7)
373                              '("Dec" "Nov" "Oct" "Sep" "Aug" "Jul"
374                                "Jun" "May" "Apr" "Mar" "Feb" "Jan"))))
375          (dd (string-to-int (substring str 8 10)))
376          (HH (string-to-int (substring str 11 13)))
377          (MM (string-to-int (substring str 14 16)))
378          (SS (string-to-int (substring str 17 19)))
379          (offset (or (car (current-time-zone)) 0))
380          dn ct1 ct2 i1 i2
381          year uru)
382     (setq ct1 0 ct2 0 i1 0 i2 0)
383     (setq year (- yyyy 1970))
384     (while (> year 0)
385       (setq year (1- year)
386             ct1 (+ ct1 481)
387             ct2 (+ ct2 13184))
388       (while (> ct2 65535)
389         (setq ct1 (1+ ct1)
390               ct2 (- ct2 65536))))
391     (setq uru (- (+ (- (/ yyyy 4) (/ yyyy 100)) 
392                     (/ yyyy 400)) 477))
393     (while (> uru 0)
394       (setq uru (1- uru)
395             i1 (1+ i1)
396             i2 (+ i2 20864))
397       (if (> i2 65535)
398           (setq i1 (1+ i1)
399                 i2 (- i2 65536))))
400     (setq ct1 (+ ct1 i1)
401           ct2 (+ ct2 i2))
402     (while (> ct2 65535)
403       (setq ct1 (1+ ct1)
404             ct2 (- ct2 65536)))
405     (setq dn (+ dd (* 31 (1- mm))))
406     (if (> mm 2)
407         (setq dn (+ (- dn (/ (+ 23 (* 4 mm)) 10))
408                     (if (and (zerop (% yyyy 4))
409                              (or (not (zerop (% yyyy 100)))
410                                  (zerop (% yyyy 400))))
411                         1 0))))
412     (setq dn (1- dn)
413           i1 0 
414           i2 0)
415     (while (> dn 0)
416       (setq dn (1- dn)
417             i1 (1+ i1)
418             i2 (+ i2 20864))
419       (if (> i2 65535)
420           (setq i1 (1+ i1)
421                 i2 (- i2 65536))))
422     (setq ct1 (+ (+ (+ ct1 i1) (/ ct2 65536)) 
423                  (/ (+ (* HH 3600) (* MM 60) SS)
424                     65536))
425           ct2 (+ (+ i2 (% ct2 65536))
426                  (% (+ (* HH 3600) (* MM 60) SS)
427                     65536)))
428     (while (< (- ct2 offset) 0)
429       (setq ct1 (1- ct1)
430             ct2 (+ ct2 65536)))
431     (setq ct2 (- ct2 offset))
432     (while (> ct2 65535)
433       (setq ct1 (1+ ct1)
434             ct2 (- ct2 65536)))
435     (list ct1 ct2 0)))
436
437 ;;; @@ Floating point numbers.
438 ;;;
439
440 (defalias 'numberp 'integerp)
441
442 (defun abs (arg)
443   "Return the absolute value of ARG."
444   (if (< arg 0) (- arg) arg))
445
446
447 ;;; @ Basic lisp subroutines.
448 ;;;
449
450 (defmacro lambda (&rest cdr)
451   "Return a lambda expression.
452 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
453 self-quoting; the result of evaluating the lambda expression is the
454 expression itself.  The lambda expression may then be treated as a
455 function, i.e., stored as the function value of a symbol, passed to
456 funcall or mapcar, etc.
457
458 ARGS should take the same form as an argument list for a `defun'.
459 DOCSTRING is an optional documentation string.
460  If present, it should describe how to call the function.
461  But documentation strings are usually not useful in nameless functions.
462 INTERACTIVE should be a call to the function `interactive', which see.
463 It may also be omitted.
464 BODY should be a list of lisp expressions."
465   ;; Note that this definition should not use backquotes; subr.el should not
466   ;; depend on backquote.el.
467   (list 'function (cons 'lambda cdr)))
468
469 (defun force-mode-line-update (&optional all)
470   "Force the mode-line of the current buffer to be redisplayed.
471 With optional non-nil ALL, force redisplay of all mode-lines."
472   (if all (save-excursion (set-buffer (other-buffer))))
473   (set-buffer-modified-p (buffer-modified-p)))
474
475 (defalias 'set-match-data 'store-match-data)
476
477 (defvar save-match-data-internal)
478
479 ;; We use save-match-data-internal as the local variable because
480 ;; that works ok in practice (people should not use that variable elsewhere).
481 (defmacro save-match-data (&rest body)
482   "Execute the BODY forms, restoring the global value of the match data."
483   (` (let ((save-match-data-internal (match-data)))
484        (unwind-protect (progn (,@ body))
485          (set-match-data save-match-data-internal)))))
486
487
488 ;;; @ Basic editing commands.
489 ;;;
490
491 ;; 18.55 does not have these variables.
492 (defvar buffer-undo-list nil)
493 (defvar-maybe auto-fill-function nil)
494 (defvar-maybe unread-command-event nil)
495 (defvar-maybe unread-command-events nil)
496
497 (defalias 'buffer-disable-undo 'buffer-flush-undo)
498 (defalias 'insert-and-inherit 'insert)
499 (defalias 'insert-before-markers-and-inherit 'insert-before-markers)
500 (defalias 'number-to-string 'int-to-string)
501
502 (defun generate-new-buffer-name (name &optional ignore)
503   "Return a string that is the name of no existing buffer based on NAME.
504 If there is no live buffer named NAME, then return NAME.
505 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
506 until an unused name is found, and then return that name.
507 Optional second argument IGNORE specifies a name that is okay to use
508 \(if it is in the sequence to be tried\)
509 even if a buffer with that name exists."
510   (if (get-buffer name)
511       (let ((n 2) new)
512         (while (get-buffer (setq new (format "%s<%d>" name n)))
513           (setq n (1+ n)))
514         new)
515     name))
516
517 (or (fboundp 'si:mark)
518     (fset 'si:mark (symbol-function 'mark)))
519 (defun mark (&optional force)
520   (si:mark))
521
522 (defun-maybe window-minibuffer-p (&optional window)
523 "Return non-nil if WINDOW is a minibuffer window."
524   (eq (or window (selected-window)) (minibuffer-window)))
525
526 ;;; @@ Environment variables.
527 ;;;
528
529 (autoload 'setenv "env"
530   "Set the value of the environment variable named VARIABLE to VALUE.
531 VARIABLE should be a string.  VALUE is optional; if not provided or is
532 `nil', the environment variable VARIABLE will be removed.
533 This function works by modifying `process-environment'."
534   t)
535
536
537 ;;; @ File input and output commands.
538 ;;;
539
540 (defvar data-directory exec-directory)
541
542 ;; In 18.55, `call-process' does not return exit status.
543 (defun file-executable-p (filename)
544   "Return t if FILENAME can be executed by you.
545 For a directory, this means you can access files in that directory."
546   (if (file-exists-p filename)
547       (let ((process (start-process "test" nil "test" "-x" filename)))
548         (while (eq 'run (process-status process)))
549         (zerop (process-exit-status process)))))
550
551 (defun make-directory-internal (dirname)
552   "Create a directory. One argument, a file name string."
553  (let ((dir (expand-file-name dirname)))
554    (if (file-exists-p dir)
555        (error "Creating directory: %s is already exist" dir)
556      (call-process "mkdir" nil nil nil dir))))
557
558 (defun make-directory (dir &optional parents)
559   "Create the directory DIR and any nonexistent parent dirs.
560 The second (optional) argument PARENTS says whether
561 to create parent directories if they don't exist."
562   (let ((len (length dir))
563         (p 0) p1 path)
564     (catch 'tag
565       (while (and (< p len) (string-match "[^/]*/?" dir p))
566         (setq p1 (match-end 0))
567         (if (= p1 len)
568             (throw 'tag nil))
569         (setq path (substring dir 0 p1))
570         (if (not (file-directory-p path))
571             (cond ((file-exists-p path)
572                    (error "Creating directory: %s is not directory" path))
573                   ((null parents)
574                    (error "Creating directory: %s is not exist" path))
575                   (t
576                    (make-directory-internal path))))
577         (setq p p1)))
578     (make-directory-internal dir)))
579
580 (defun parse-colon-path (cd-path)
581   "Explode a colon-separated list of paths into a string list."
582   (and cd-path
583        (let (cd-prefix cd-list (cd-start 0) cd-colon)
584          (setq cd-path (concat cd-path path-separator))
585          (while (setq cd-colon (string-match path-separator cd-path cd-start))
586            (setq cd-list
587                  (nconc cd-list
588                         (list (if (= cd-start cd-colon)
589                                   nil
590                                 (substitute-in-file-name
591                                  (file-name-as-directory
592                                   (substring cd-path cd-start cd-colon)))))))
593            (setq cd-start (+ cd-colon 1)))
594          cd-list)))
595
596 (defun file-relative-name (filename &optional directory)
597   "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
598   (setq filename (expand-file-name filename)
599         directory (file-name-as-directory (expand-file-name
600                                            (or directory default-directory))))
601   (let ((ancestor ""))
602     (while (not (string-match (concat "^" (regexp-quote directory)) filename))
603       (setq directory (file-name-directory (substring directory 0 -1))
604             ancestor (concat "../" ancestor)))
605     (concat ancestor (substring filename (match-end 0)))))
606
607 (or (fboundp 'si:directory-files)
608     (fset 'si:directory-files (symbol-function 'directory-files)))
609 (defun directory-files (directory &optional full match nosort)
610   "Return a list of names of files in DIRECTORY.
611 There are three optional arguments:
612 If FULL is non-nil, return absolute file names.  Otherwise return names
613  that are relative to the specified directory.
614 If MATCH is non-nil, mention only file names that match the regexp MATCH.
615 If NOSORT is dummy for compatibility."
616   (si:directory-files directory full match))
617
618
619 ;;; @ Text property.
620 ;;;
621
622 ;; In Emacs 20.4, these functions are defined in src/textprop.c.
623 (defun text-properties-at (position &optional object))
624 (defun get-text-property (position prop &optional object))
625 (defun get-char-property (position prop &optional object))
626 (defun next-property-change (position &optional object limit))
627 (defun next-single-property-change (position prop &optional object limit))
628 (defun previous-property-change (position &optional object limit))
629 (defun previous-single-property-change (position prop &optional object limit))
630 (defun add-text-properties (start end properties &optional object))
631 (defun put-text-property (start end property value &optional object))
632 (defun set-text-properties (start end properties &optional object))
633 (defun remove-text-properties (start end properties &optional object))
634 (defun text-property-any (start end property value &optional object))
635 (defun text-property-not-all (start end property value &optional object))
636 ;; the following two functions are new in v20.
637 (defun next-char-property-change (position &optional object))
638 (defun previous-char-property-change (position &optional object))
639 ;; the following two functions are obsolete.
640 ;; (defun erase-text-properties (start end &optional object)
641 ;; (defun copy-text-properties (start end src pos dest &optional prop)
642
643
644 ;;; @ Overlay.
645 ;;;
646
647 (cond
648  ((boundp 'NEMACS)
649   (defvar emu:available-face-attribute-alist
650     '(
651       ;;(bold      . inversed-region)
652       (italic    . underlined-region)
653       (underline . underlined-region)))
654
655   ;; by YAMATE Keiichirou 1994/10/28
656   (defun attribute-add-narrow-attribute (attr from to)
657     (or (consp (symbol-value attr))
658         (set attr (list 1)))
659     (let* ((attr-value (symbol-value attr))
660            (len (car attr-value))
661            (posfrom 1)
662            posto)
663       (while (and (< posfrom len)
664                   (> from (nth posfrom attr-value)))
665         (setq posfrom (1+ posfrom)))
666       (setq posto posfrom)
667       (while (and (< posto len)
668                   (> to (nth posto attr-value)))
669         (setq posto (1+ posto)))
670       (if  (= posto posfrom)
671           (if (= (% posto 2) 1)
672               (if (and (< to len)
673                        (= to (nth posto attr-value)))
674                   (set-marker (nth posto attr-value) from)
675                 (setcdr (nthcdr (1- posfrom) attr-value)
676                         (cons (set-marker-type (set-marker (make-marker)
677                                                            from)
678                                                'point-type)
679                               (cons (set-marker-type
680                                      (set-marker (make-marker)
681                                                  to)
682                                      nil)
683                                     (nthcdr posto attr-value))))
684                 (setcar attr-value (+ len 2))))
685         (if (= (% posfrom 2) 0)
686             (setq posfrom (1- posfrom))
687           (set-marker (nth posfrom attr-value) from))
688         (if (= (% posto 2) 0)
689             nil
690           (setq posto (1- posto))
691           (set-marker (nth posto attr-value) to))
692         (setcdr (nthcdr posfrom attr-value)
693                 (nthcdr posto attr-value)))))
694
695   (defalias 'make-overlay 'cons)
696
697   (defun overlay-put (overlay prop value)
698     (let ((ret (and (eq prop 'face)
699                     (assq value emu:available-face-attribute-alist))))
700       (if ret
701           (attribute-add-narrow-attribute (cdr ret)
702                                           (car overlay)(cdr overlay))))))
703  (t
704   (defun make-overlay (beg end &optional buffer type))
705   (defun overlay-put (overlay prop value))))
706
707 (defun overlay-buffer (overlay))
708
709
710 ;;; @ End.
711 ;;;
712
713 (require 'product)
714 (product-provide (provide 'poe-18) (require 'apel-ver))
715
716 ;;; poe-18.el ends here