(config-apel, config-apel-package): Replace "\n" in fotmat-strings
[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
54 (defun defalias (sym newdef)
55   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL."
56   (fset sym newdef))
57
58 (defun byte-code-function-p (object)
59   "Return t if OBJECT is a byte-compiled function object."
60   (and (consp object) (consp (cdr object))
61        (let ((rest (cdr (cdr object)))
62              elt)
63          (if (stringp (car rest))
64              (setq rest (cdr rest)))
65          (catch 'tag
66            (while rest
67              (setq elt (car rest))
68              (if (and (consp elt)
69                       (eq (car elt) 'byte-code))
70                  (throw 'tag t))
71              (setq rest (cdr rest)))))))
72
73 ;; (symbol-plist 'cyclic-function-indirection)
74 (put 'cyclic-function-indirection
75      'error-conditions
76      '(cyclic-function-indirection error))
77 (put 'cyclic-function-indirection
78      'error-message
79      "Symbol's chain of function indirections contains a loop")
80
81 ;; The following function definition is a direct translation of its
82 ;; C definition in emacs-20.4/src/data.c.
83 (defun indirect-function (object)
84   "Return the function at the end of OBJECT's function chain.
85 If OBJECT is a symbol, follow all function indirections and return the final
86 function binding.
87 If OBJECT is not a symbol, just return it.
88 Signal a void-function error if the final symbol is unbound.
89 Signal a cyclic-function-indirection error if there is a loop in the
90 function chain of symbols."
91   (let* ((hare object)
92          (tortoise hare))
93     (catch 'found
94       (while t
95         (or (symbolp hare) (throw 'found hare))
96         (or (fboundp hare) (signal 'void-function (cons object nil)))
97         (setq hare (symbol-function hare))
98         (or (symbolp hare) (throw 'found hare))
99         (or (fboundp hare) (signal 'void-function (cons object nil)))
100         (setq hare (symbol-function hare))
101
102         (setq tortoise (symbol-function tortoise))
103
104         (if (eq hare tortoise)
105             (signal 'cyclic-function-indirection (cons object nil)))))
106     hare))
107
108 ;;; Emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
109 ;;; (note: jwz's original compiler and XEmacs compiler have some more
110 ;;;  macros; they are "nuked" by rms in FSF version.)
111
112 ;; Use `*-maybe' here because new byte-compiler may be installed.
113 (put 'inline 'lisp-indent-hook 0)
114 (defmacro-maybe inline (&rest body)
115   "Eval BODY forms sequentially and return value of last one.
116
117 This emulating macro does not support function inlining because old \(v18\)
118 compiler does not support inlining feature."
119   (cons 'progn body))
120
121 (put 'defsubst 'lisp-indent-hook 'defun)
122 (put 'defsubst 'edebug-form-spec 'defun)
123 (defmacro-maybe defsubst (name arglist &rest body)
124   "Define an inline function.  The syntax is just like that of `defun'.
125
126 This emulating macro does not support function inlining because old \(v18\)
127 compiler does not support inlining feature."
128   (cons 'defun (cons name (cons arglist body))))
129
130 (defun-maybe make-obsolete (fn new)
131   "Make the byte-compiler warn that FUNCTION is obsolete.
132 The warning will say that NEW should be used instead.
133 If NEW is a string, that is the `use instead' message.
134
135 This emulating function does nothing because old \(v18\) compiler does not
136 support this feature."
137   (interactive "aMake function obsolete: \nxObsoletion replacement: ")
138   fn)
139
140 (defun-maybe make-obsolete-variable (var new)
141   "Make the byte-compiler warn that VARIABLE is obsolete,
142 and NEW should be used instead.  If NEW is a string, then that is the
143 `use instead' message.
144
145 This emulating function does nothing because old \(v18\) compiler does not
146 support this feature."
147   (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
148   var)
149
150 (put 'dont-compile 'lisp-indent-hook 0)
151 (defmacro-maybe dont-compile (&rest body)
152   "Like `progn', but the body always runs interpreted \(not compiled\).
153 If you think you need this, you're probably making a mistake somewhere."
154   (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
155
156 (put 'eval-when-compile 'lisp-indent-hook 0)
157 (defmacro-maybe eval-when-compile (&rest body)
158   "Like progn, but evaluates the body at compile-time.
159
160 This emulating macro does not do compile-time evaluation at all because
161 of the limitation of old \(v18\) compiler."
162   (cons 'progn body))
163
164 (put 'eval-and-compile 'lisp-indent-hook 0)
165 (defmacro-maybe eval-and-compile (&rest body)
166   "Like progn, but evaluates the body at compile-time as well as at load-time.
167
168 This emulating macro does not do compile-time evaluation at all because
169 of the limitation of old \(v18\) compiler."
170   (cons 'progn body))
171
172
173 ;;; @ C primitives emulation.
174 ;;;
175
176 (defun member (elt list)
177   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
178 The value is actually the tail of LIST whose car is ELT."
179   (while (and list (not (equal elt (car list))))
180     (setq list (cdr list)))
181   list)
182
183 (defun delete (elt list)
184   "Delete by side effect any occurrences of ELT as a member of LIST.
185 The modified LIST is returned.  Comparison is done with `equal'.
186 If the first member of LIST is ELT, deleting it is not a side effect;
187 it is simply using a different list.
188 Therefore, write `(setq foo (delete element foo))'
189 to be sure of changing the value of `foo'."
190   (if list
191       (if (equal elt (car list))
192           (cdr list)
193         (let ((rest list)
194               (rrest (cdr list)))
195           (while (and rrest (not (equal elt (car rrest))))
196             (setq rest rrest
197                   rrest (cdr rrest)))
198           (setcdr rest (cdr rrest))
199           list))))
200
201 (defun default-boundp (symbol)
202   "Return t if SYMBOL has a non-void default value.
203 This is the value that is seen in buffers that do not have their own values
204 for this variable."
205   (condition-case error
206       (progn
207         (default-value symbol)
208         t)
209     (void-variable nil)))
210
211 ;;; @@ current-time.
212 ;;;
213
214 (defvar current-time-world-timezones
215   '(("PST" .  -800)("PDT" .  -700)("MST" .  -700)
216     ("MDT" .  -600)("CST" .  -600)("CDT" .  -500)
217     ("EST" .  -500)("EDT" .  -400)("AST" .  -400)
218     ("NST" .  -330)("UT"  .  +000)("GMT" .  +000)
219     ("BST" .  +100)("MET" .  +100)("EET" .  +200)
220     ("JST" .  +900)("GMT+1"  .  +100)("GMT+2"  .  +200)
221     ("GMT+3"  .  +300)("GMT+4"  .  +400)("GMT+5"  .  +500)
222     ("GMT+6"  .  +600)("GMT+7"  .  +700)("GMT+8"  .  +800)
223     ("GMT+9"  .  +900)("GMT+10" . +1000)("GMT+11" . +1100)
224     ("GMT+12" . +1200)("GMT+13" . +1300)("GMT-1"  .  -100)
225     ("GMT-2"  .  -200)("GMT-3"  .  -300)("GMT-4"  .  -400)
226     ("GMT-5"  .  -500)("GMT-6"  .  -600)("GMT-7"  .  -700)
227     ("GMT-8"  .  -800)("GMT-9"  .  -900)("GMT-10" . -1000)
228     ("GMT-11" . -1100) ("GMT-12" . -1200))
229   "Time differentials of timezone from GMT in +-HHMM form.
230 Used in `current-time-zone'.")
231
232 (defvar current-time-local-timezone nil 
233   "*Local timezone name.
234 Used in `current-time-zone'.")
235
236 (defun set-time-zone-rule (tz)
237   "Set the local time zone using TZ, a string specifying a time zone rule.
238 If TZ is nil, use implementation-defined default time zone information.
239 If TZ is t, use Universal Time."
240   (cond
241    ((stringp tz)
242     (setq current-time-local-timezone tz))
243    (tz
244     (setq current-time-local-timezone "GMT"))
245    (t
246     (setq current-time-local-timezone
247           (with-temp-buffer
248             ;; We use `date' command to get timezone information.
249             (call-process "date" nil (current-buffer) t)
250             (goto-char (point-min))
251             (if (looking-at 
252                  "^.*\\([A-Z][A-Z][A-Z]\\([^ \n\t]*\\)\\).*$")
253                 (buffer-substring (match-beginning 1)
254                                   (match-end 1))))))))
255
256 (defun current-time-zone (&optional specified-time)
257   "Return the offset and name for the local time zone.
258 This returns a list of the form (OFFSET NAME).
259 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
260     A negative value means west of Greenwich.
261 NAME is a string giving the name of the time zone.
262 Optional argument SPECIFIED-TIME is ignored in this implementation.
263 Some operating systems cannot provide all this information to Emacs;
264 in this case, `current-time-zone' returns a list containing nil for
265 the data it can't find."
266   (let ((local-timezone (or current-time-local-timezone
267                             (progn
268                               (set-time-zone-rule nil)
269                               current-time-local-timezone)))
270         timezone abszone seconds)
271     (setq timezone
272           (or (cdr (assoc (upcase local-timezone) 
273                           current-time-world-timezones))
274               ;; "+900" style or nil.
275               local-timezone))
276     (when timezone
277       (if (stringp timezone)
278           (setq timezone (string-to-int timezone)))
279       ;; Taking account of minute in timezone.
280       ;; HHMM -> MM
281       (setq abszone (abs timezone))
282       (setq seconds (* 60 (+ (* 60 (/ abszone 100)) (% abszone 100))))
283       (list (if (< timezone 0) (- seconds) seconds)
284             local-timezone))))
285
286 (or (fboundp 'si:current-time-string)
287     (fset 'si:current-time-string (symbol-function 'current-time-string)))
288 (defun current-time-string (&optional specified-time)
289   "Return the current time, as a human-readable string.
290 Programs can use this function to decode a time,
291 since the number of columns in each field is fixed.
292 The format is `Sun Sep 16 01:03:52 1973'.
293 If an argument SPECIFIED-TIME is given, it specifies a time to format
294 instead of the current time.  The argument should have the form:
295   (HIGH . LOW)
296 or the form:
297   (HIGH LOW . IGNORED).
298 Thus, you can use times obtained from `current-time'
299 and from `file-attributes'."
300   (if (null specified-time)
301       (si:current-time-string)
302     (or (consp specified-time)
303         (error "Wrong type argument %s" specified-time))
304     (let ((high (car specified-time))
305           (low  (cdr specified-time))
306           (offset (or (car (current-time-zone)) 0))
307           (mdays '(31 28 31 30 31 30 31 31 30 31 30 31))
308           (mnames '("Jan" "Feb" "Mar" "Apr" "May" "Jun" 
309                     "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
310           (wnames '("Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"))
311           days dd yyyy lyear mm HH MM SS)
312       (if (consp low)
313           (setq low (car low)))
314       (or (integerp high)
315           (error "Wrong type argument %s" high))
316       (or (integerp low)
317           (error "Wrong type argument %s" low))
318       (setq low (+ low offset))
319       (while (> low 65535)
320         (setq high (1+ high)
321               low (- low 65536)))
322       (setq yyyy 1970)
323       (while (or (> high 481)
324                  (and (= high 481)
325                       (>= low 13184)))
326         (if (and (> high 0)
327                  (< low 13184))
328             (setq high (1- high)
329                   low  (+ 65536 low)))
330         (setq high (- high 481)
331               low  (- low 13184))
332         (if (and (zerop (% yyyy 4))
333                  (or (not (zerop (% yyyy 100)))
334                      (zerop (% yyyy 400))))
335             (progn
336               (if (and (> high 0) 
337                        (< low 20864))
338                   (setq high (1- high)
339                         low  (+ 65536 low)))
340               (setq high (- high 1)
341                     low (- low 20864))))
342         (setq yyyy (1+ yyyy)))
343       (setq dd 1)
344       (while (or (> high 1)
345                  (and (= high 1)
346                       (>= low 20864)))
347         (if (and (> high 0)
348                  (< low 20864))
349             (setq high (1- high)
350                   low  (+ 65536 low)))
351         (setq high (- high 1)
352               low  (- low 20864)
353               dd (1+ dd)))
354       (setq days dd)
355       (if (= high 1)
356           (setq low (+ 65536 low)))
357       (setq mm 0)
358       (setq lyear (and (zerop (% yyyy 4))
359                        (or (not (zerop (% yyyy 100)))
360                            (zerop (% yyyy 400)))))
361       (while (> (- dd  (if (and lyear (= mm 1)) 29 (nth mm mdays))) 0)
362         (setq dd (- dd (if (and lyear (= mm 1)) 29 (nth mm mdays))))
363         (setq mm (1+ mm)))
364       (setq HH (/ low 3600)
365             low (% low 3600)
366             MM (/ low 60)
367             SS (% low 60))
368       (format "%s %s %2d %02d:%02d:%02d %4d"
369               (nth (% (+ days
370                          (- (+ (* (1- yyyy) 365) (/ (1- yyyy) 400) 
371                                (/ (1- yyyy) 4)) (/ (1- yyyy) 100))) 7)
372                    wnames)
373               (nth mm mnames)
374               dd HH MM SS yyyy))))
375
376 (defun current-time ()
377   "Return the current time, as the number of seconds since 1970-01-01 00:00:00.
378 The time is returned as a list of three integers.  The first has the
379 most significant 16 bits of the seconds, while the second has the
380 least significant 16 bits.  The third integer gives the microsecond
381 count.
382
383 The microsecond count is zero on systems that do not provide
384 resolution finer than a second."
385   (let* ((str (current-time-string))
386          (yyyy (string-to-int (substring str 20 24)))
387          (mm (length (member (substring str 4 7)
388                              '("Dec" "Nov" "Oct" "Sep" "Aug" "Jul"
389                                "Jun" "May" "Apr" "Mar" "Feb" "Jan"))))
390          (dd (string-to-int (substring str 8 10)))
391          (HH (string-to-int (substring str 11 13)))
392          (MM (string-to-int (substring str 14 16)))
393          (SS (string-to-int (substring str 17 19)))
394          (offset (or (car (current-time-zone)) 0))
395          dn ct1 ct2 i1 i2
396          year uru)
397     (setq ct1 0 ct2 0 i1 0 i2 0)
398     (setq year (- yyyy 1970))
399     (while (> year 0)
400       (setq year (1- year)
401             ct1 (+ ct1 481)
402             ct2 (+ ct2 13184))
403       (while (> ct2 65535)
404         (setq ct1 (1+ ct1)
405               ct2 (- ct2 65536))))
406     (setq year (- yyyy 1))
407     (setq uru (- (+ (- (/ year 4) (/ year 100)) 
408                     (/ year 400)) 477))
409     (while (> uru 0)
410       (setq uru (1- uru)
411             i1 (1+ i1)
412             i2 (+ i2 20864))
413       (if (> i2 65535)
414           (setq i1 (1+ i1)
415                 i2 (- i2 65536))))
416     (setq ct1 (+ ct1 i1)
417           ct2 (+ ct2 i2))
418     (while (> ct2 65535)
419       (setq ct1 (1+ ct1)
420             ct2 (- ct2 65536)))
421     (setq dn (+ dd (* 31 (1- mm))))
422     (if (> mm 2)
423         (setq dn (+ (- dn (/ (+ 23 (* 4 mm)) 10))
424                     (if (and (zerop (% yyyy 4))
425                              (or (not (zerop (% yyyy 100)))
426                                  (zerop (% yyyy 400))))
427                         1 0))))
428     (setq dn (1- dn)
429           i1 0 
430           i2 0)
431     (while (> dn 0)
432       (setq dn (1- dn)
433             i1 (1+ i1)
434             i2 (+ i2 20864))
435       (if (> i2 65535)
436           (setq i1 (1+ i1)
437                 i2 (- i2 65536))))
438     (setq ct1 (+ (+ (+ ct1 i1) (/ ct2 65536)) 
439                  (/ (+ (* HH 3600) (* MM 60) SS)
440                     65536))
441           ct2 (+ (+ i2 (% ct2 65536))
442                  (% (+ (* HH 3600) (* MM 60) SS)
443                     65536)))
444     (while (< (- ct2 offset) 0)
445       (setq ct1 (1- ct1)
446             ct2 (+ ct2 65536)))
447     (setq ct2 (- ct2 offset))
448     (while (> ct2 65535)
449       (setq ct1 (1+ ct1)
450             ct2 (- ct2 65536)))
451     (list ct1 ct2 0)))
452
453 ;;; @@ Floating point numbers.
454 ;;;
455
456 (defun abs (arg)
457   "Return the absolute value of ARG."
458   (if (< arg 0) (- arg) arg))
459
460 ;;; @ Basic lisp subroutines.
461 ;;;
462
463 (defmacro lambda (&rest cdr)
464   "Return a lambda expression.
465 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
466 self-quoting; the result of evaluating the lambda expression is the
467 expression itself.  The lambda expression may then be treated as a
468 function, i.e., stored as the function value of a symbol, passed to
469 funcall or mapcar, etc.
470
471 ARGS should take the same form as an argument list for a `defun'.
472 DOCSTRING is an optional documentation string.
473  If present, it should describe how to call the function.
474  But documentation strings are usually not useful in nameless functions.
475 INTERACTIVE should be a call to the function `interactive', which see.
476 It may also be omitted.
477 BODY should be a list of lisp expressions."
478   ;; Note that this definition should not use backquotes; subr.el should not
479   ;; depend on backquote.el.
480   (list 'function (cons 'lambda cdr)))
481
482 (defun force-mode-line-update (&optional all)
483   "Force the mode-line of the current buffer to be redisplayed.
484 With optional non-nil ALL, force redisplay of all mode-lines."
485   (if all (save-excursion (set-buffer (other-buffer))))
486   (set-buffer-modified-p (buffer-modified-p)))
487
488 (defalias 'set-match-data 'store-match-data)
489
490 (defvar save-match-data-internal)
491
492 ;; We use save-match-data-internal as the local variable because
493 ;; that works ok in practice (people should not use that variable elsewhere).
494 (defmacro save-match-data (&rest body)
495   "Execute the BODY forms, restoring the global value of the match data."
496   (` (let ((save-match-data-internal (match-data)))
497        (unwind-protect (progn (,@ body))
498          (set-match-data save-match-data-internal)))))
499
500
501 ;;; @ Basic editing commands.
502 ;;;
503
504 ;; 18.55 does not have these variables.
505 (defvar buffer-undo-list nil
506   "List of undo entries in current buffer.
507 APEL provides this as dummy for a compatibility.")
508
509 (defvar auto-fill-function nil
510   "Function called (if non-nil) to perform auto-fill.
511 APEL provides this as dummy for a compatibility.")
512
513 (defvar unread-command-event nil
514   "APEL provides this as dummy for a compatibility.")
515 (defvar unread-command-events nil
516   "List of events to be read as the command input.
517 APEL provides this as dummy for a compatibility.")
518
519 ;; (defvar minibuffer-setup-hook nil
520 ;;   "Normal hook run just after entry to minibuffer.")
521 ;; (defvar minibuffer-exit-hook nil
522 ;;   "Normal hook run just after exit from minibuffer.")
523
524 (defvar minor-mode-map-alist nil
525   "Alist of keymaps to use for minor modes.
526 APEL provides this as dummy for a compatibility.")
527
528 (defalias 'insert-and-inherit 'insert)
529 (defalias 'insert-before-markers-and-inherit 'insert-before-markers)
530 (defalias 'number-to-string 'int-to-string)
531
532 (defun generate-new-buffer-name (name &optional ignore)
533   "Return a string that is the name of no existing buffer based on NAME.
534 If there is no live buffer named NAME, then return NAME.
535 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
536 until an unused name is found, and then return that name.
537 Optional second argument IGNORE specifies a name that is okay to use
538 \(if it is in the sequence to be tried\)
539 even if a buffer with that name exists."
540   (if (get-buffer name)
541       (let ((n 2) new)
542         (while (get-buffer (setq new (format "%s<%d>" name n)))
543           (setq n (1+ n)))
544         new)
545     name))
546
547 (or (fboundp 'si:mark)
548     (fset 'si:mark (symbol-function 'mark)))
549 (defun mark (&optional force)
550   (si:mark))
551
552 (defun window-minibuffer-p (&optional window)
553 "Return non-nil if WINDOW is a minibuffer window."
554   (eq (or window (selected-window)) (minibuffer-window)))
555
556 (defun window-live-p (object)
557   "Returns t if OBJECT is a window which is currently visible."
558   (and (windowp object)
559        (or (eq object (minibuffer-window))
560            (eq object (get-buffer-window (window-buffer object))))))
561
562 ;; Add optinal argument `hist'
563 (or (fboundp 'si:read-from-minibuffer)
564     (progn
565       (fset 'si:read-from-minibuffer (symbol-function 'read-from-minibuffer))
566       (defun read-from-minibuffer (prompt &optional
567                                           initial-contents keymap read hist)
568         
569         "Read a string from the minibuffer, prompting with string PROMPT.
570 If optional second arg INITIAL-CONTENTS is non-nil, it is a string
571 to be inserted into the minibuffer before reading input.
572 If INITIAL-CONTENTS is (STRING . POSITION), the initial input
573 is STRING, but point is placed at position POSITION in the minibuffer.
574 Third arg KEYMAP is a keymap to use whilst reading;
575 if omitted or nil, the default is `minibuffer-local-map'.
576 If fourth arg READ is non-nil, then interpret the result as a lisp object
577 and return that object:
578 in other words, do `(car (read-from-string INPUT-STRING))'
579 Fifth arg HIST is ignored in this implementation."
580         (si:read-from-minibuffer prompt initial-contents keymap read))))
581
582 ;; Add optional argument `frame'.
583 (or (fboundp 'si:get-buffer-window)
584     (progn
585       (fset 'si:get-buffer-window (symbol-function 'get-buffer-window))
586       (defun get-buffer-window (buffer &optional frame)
587         "Return a window currently displaying BUFFER, or nil if none.
588 Optional argument FRAME is ignored in this implementation."
589         (si:get-buffer-window buffer))))
590
591 (defun walk-windows (proc &optional minibuf all-frames)
592   "Cycle through all visible windows, calling PROC for each one.
593 PROC is called with a window as argument.
594
595 Optional second arg MINIBUF t means count the minibuffer window even
596 if not active.  MINIBUF nil or omitted means count the minibuffer iff
597 it is active.  MINIBUF neither t nor nil means not to count the
598 minibuffer even if it is active.
599 Optional third argument ALL-FRAMES is ignored in this implementation."
600   (if (window-minibuffer-p (selected-window))
601       (setq minibuf t))
602   (let* ((walk-windows-start (selected-window))
603          (walk-windows-current walk-windows-start))
604     (unwind-protect
605         (while (progn
606                  (setq walk-windows-current
607                        (next-window walk-windows-current minibuf))
608                  (funcall proc walk-windows-current)
609                  (not (eq walk-windows-current walk-windows-start))))
610       (select-window walk-windows-start))))
611
612 (defun buffer-disable-undo (&optional buffer)
613   "Make BUFFER stop keeping undo information.
614 No argument or nil as argument means do this for the current buffer."
615    (buffer-flush-undo (or buffer (current-buffer))))
616
617
618 ;;; @@ Frame (Emacs 18 cannot make frame)
619 ;;;
620 ;; The following four are frequently used for manipulating the current frame.
621 ;; frame.el has `screen-width', `screen-height', `set-screen-width' and
622 ;; `set-screen-height' for backward compatibility and declare them as obsolete.
623 (defun frame-width (&optional frame)
624   "Return number of columns available for display on FRAME.
625 If FRAME is omitted, describe the currently selected frame."
626   (screen-width))
627
628 (defun frame-height (&optional frame)
629   "Return number of lines available for display on FRAME.
630 If FRAME is omitted, describe the currently selected frame."
631   (screen-height))
632
633 (defun set-frame-width (frame cols &optional pretend)
634   "Specify that the frame FRAME has COLS columns.
635 Optional third arg non-nil means that redisplay should use COLS columns
636 but that the idea of the actual width of the frame should not be changed."
637   (set-screen-width cols pretend))
638
639 (defun set-frame-height (frame lines &optional pretend)
640   "Specify that the frame FRAME has LINES lines.
641 Optional third arg non-nil means that redisplay should use LINES lines
642 but that the idea of the actual height of the frame should not be changed."
643   (set-screen-height lines pretend))
644
645 ;;; @@ Environment variables.
646 ;;;
647
648 (autoload 'setenv "env"
649   "Set the value of the environment variable named VARIABLE to VALUE.
650 VARIABLE should be a string.  VALUE is optional; if not provided or is
651 `nil', the environment variable VARIABLE will be removed.
652 This function works by modifying `process-environment'."
653   t)
654
655
656 ;;; @ File input and output commands.
657 ;;;
658
659 (defvar data-directory exec-directory)
660
661 ;; In 18.55, `call-process' does not return exit status.
662 (defun file-executable-p (filename)
663   "Return t if FILENAME can be executed by you.
664 For a directory, this means you can access files in that directory."
665   (if (file-exists-p filename)
666       (let ((process (start-process "test" nil "test" "-x" filename)))
667         (while (eq 'run (process-status process)))
668         (zerop (process-exit-status process)))))
669
670 (defun make-directory-internal (dirname)
671   "Create a directory. One argument, a file name string."
672  (let ((dir (expand-file-name dirname)))
673    (if (file-exists-p dir)
674        (error "Creating directory: %s is already exist" dir)
675      (call-process "mkdir" nil nil nil dir))))
676
677 (defun make-directory (dir &optional parents)
678   "Create the directory DIR and any nonexistent parent dirs.
679 The second (optional) argument PARENTS says whether
680 to create parent directories if they don't exist."
681   (let ((len (length dir))
682         (p 0) p1 path)
683     (catch 'tag
684       (while (and (< p len) (string-match "[^/]*/?" dir p))
685         (setq p1 (match-end 0))
686         (if (= p1 len)
687             (throw 'tag nil))
688         (setq path (substring dir 0 p1))
689         (if (not (file-directory-p path))
690             (cond ((file-exists-p path)
691                    (error "Creating directory: %s is not directory" path))
692                   ((null parents)
693                    (error "Creating directory: %s is not exist" path))
694                   (t
695                    (make-directory-internal path))))
696         (setq p p1)))
697     (make-directory-internal dir)))
698
699 (defun parse-colon-path (cd-path)
700   "Explode a colon-separated list of paths into a string list."
701   (and cd-path
702        (let (cd-prefix cd-list (cd-start 0) cd-colon)
703          (setq cd-path (concat cd-path path-separator))
704          (while (setq cd-colon (string-match path-separator cd-path cd-start))
705            (setq cd-list
706                  (nconc cd-list
707                         (list (if (= cd-start cd-colon)
708                                   nil
709                                 (substitute-in-file-name
710                                  (file-name-as-directory
711                                   (substring cd-path cd-start cd-colon)))))))
712            (setq cd-start (+ cd-colon 1)))
713          cd-list)))
714
715 (defun file-relative-name (filename &optional directory)
716   "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
717   (setq filename (expand-file-name filename)
718         directory (file-name-as-directory (expand-file-name
719                                            (or directory default-directory))))
720   (let ((ancestor ""))
721     (while (not (string-match (concat "^" (regexp-quote directory)) filename))
722       (setq directory (file-name-directory (substring directory 0 -1))
723             ancestor (concat "../" ancestor)))
724     (concat ancestor (substring filename (match-end 0)))))
725
726 (or (fboundp 'si:directory-files)
727     (fset 'si:directory-files (symbol-function 'directory-files)))
728 (defun directory-files (directory &optional full match nosort)
729   "Return a list of names of files in DIRECTORY.
730 There are three optional arguments:
731 If FULL is non-nil, return absolute file names.  Otherwise return names
732  that are relative to the specified directory.
733 If MATCH is non-nil, mention only file names that match the regexp MATCH.
734 If NOSORT is dummy for compatibility."
735   (si:directory-files directory full match))
736
737 ;;; @ Process.
738 ;;; 
739 (or (fboundp 'si:accept-process-output)
740     (progn
741       (fset 'si:accept-process-output (symbol-function 'accept-process-output))
742       (defun accept-process-output (&optional process timeout timeout-msecs)
743         "Allow any pending output from subprocesses to be read by Emacs.
744 It is read into the process' buffers or given to their filter functions.
745 Non-nil arg PROCESS means do not return until some output has been received
746  from PROCESS. Nil arg PROCESS means do not return until some output has
747  been received from any process.
748 TIMEOUT and TIMEOUT-MSECS are ignored in this implementation."
749         (si:accept-process-output process))))
750
751 ;;; @ Text property.
752 ;;;
753
754 ;; In Emacs 20.4, these functions are defined in src/textprop.c.
755 (defun text-properties-at (position &optional object))
756 (defun get-text-property (position prop &optional object))
757 (defun get-char-property (position prop &optional object))
758 (defun next-property-change (position &optional object limit))
759 (defun next-single-property-change (position prop &optional object limit))
760 (defun previous-property-change (position &optional object limit))
761 (defun previous-single-property-change (position prop &optional object limit))
762 (defun add-text-properties (start end properties &optional object))
763 (defun put-text-property (start end property value &optional object))
764 (defun set-text-properties (start end properties &optional object))
765 (defun remove-text-properties (start end properties &optional object))
766 (defun text-property-any (start end property value &optional object))
767 (defun text-property-not-all (start end property value &optional object))
768 ;; the following two functions are new in v20.
769 (defun next-char-property-change (position &optional object))
770 (defun previous-char-property-change (position &optional object))
771 ;; the following two functions are obsolete.
772 ;; (defun erase-text-properties (start end &optional object)
773 ;; (defun copy-text-properties (start end src pos dest &optional prop)
774
775
776 ;;; @ Overlay.
777 ;;;
778
779 (defun overlayp (object))
780 (defun make-overlay (beg end &optional buffer front-advance rear-advance))
781 (defun move-overlay (overlay beg end &optional buffer))
782 (defun delete-overlay (overlay))
783 (defun overlay-start (overlay))
784 (defun overlay-end (overlay))
785 (defun overlay-buffer (overlay))
786 (defun overlay-properties (overlay))
787 (defun overlays-at (pos))
788 (defun overlays-in (beg end))
789 (defun next-overlay-change (pos))
790 (defun previous-overlay-change (pos))
791 (defun overlay-lists ())
792 (defun overlay-recenter (pos))
793 (defun overlay-get (overlay prop))
794 (defun overlay-put (overlay prop value))
795
796 ;;; @ End.
797 ;;;
798
799 (require 'product)
800 (product-provide (provide 'poe-18) (require 'apel-ver))
801
802 ;;; poe-18.el ends here