1 ;;; poe-18.el --- poe API implementation for Emacs 18.*
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: emulation, compatibility
8 ;; This file is part of APEL (A Portable Emacs Library).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Note to developers:
29 ;; If old (v18) compiler is used, top-level macros are expanded at
30 ;; *load-time*, not compile-time. So, you cannot use macros defined
31 ;; in this file using `defmacro-maybe'. In addition, due to this
32 ;; limitation, `eval-when-compile' and `eval-and-compile' provided by
33 ;; this file do not do compile-time evaluation at all.
37 ;; beware of circular dependency.
39 (product-provide (provide 'poe-18) (require 'apel-ver))
41 (require 'poe) ; load definitions of `*-maybe'.
46 (defvar-maybe buffer-undo-list nil)
49 ;;; @ Emacs 19 emulation
52 (defvar-maybe data-directory exec-directory)
61 (defun delete (elt list)
62 "Delete by side effect any occurrences of ELT as a member of LIST.
63 The modified LIST is returned. Comparison is done with `equal'.
64 If the first member of LIST is ELT, deleting it is not a side effect;
65 it is simply using a different list.
66 Therefore, write `(setq foo (delete element foo))'
67 to be sure of changing the value of `foo'.
68 \[poe-18.el; EMACS 19 emulating function]"
70 (if (equal elt (car list))
74 (while (and rrest (not (equal elt (car rrest))))
77 (setcdr rest (cdr rrest))
80 (defun member (elt list)
81 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
82 The value is actually the tail of LIST whose car is ELT.
83 \[poe-18.el; EMACS 19 emulating function]"
84 (while (and list (not (equal elt (car list))))
85 (setq list (cdr list)))
89 ;;; @@ buffer-local variable
92 (defun default-boundp (symbol)
93 "Return t if SYMBOL has a non-void default value.
94 This is the value that is seen in buffers that do not have their own values
96 \[poe-18.el; EMACS 19 emulating function]"
99 (default-value symbol)
101 (void-variable nil)))
104 ;;; @@ environment variable
107 (autoload 'setenv "env"
108 "Set the value of the environment variable named VARIABLE to VALUE.
109 VARIABLE should be a string. VALUE is optional; if not provided or is
110 `nil', the environment variable VARIABLE will be removed.
111 This function works by modifying `process-environment'."
118 (defun defalias (sym newdef)
119 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
120 Associates the function with the current load file, if any."
123 (defun byte-code-function-p (exp)
124 "T if OBJECT is a byte-compiled function object.
125 \[poe-18.el; EMACS 19 emulating function]"
127 (let ((rest (cdr (cdr exp)))
129 (if (stringp (car rest))
130 (setq rest (cdr rest)))
133 (setq elt (car rest))
135 (eq (car elt) 'byte-code))
137 (setq rest (cdr rest)))))))
140 ;;; @ Compilation Features
143 ;;; emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
144 ;;; (note: jwz's original compiler and XEmacs compiler have some more
145 ;;; macros; they are "nuked" by rms in FSF version.)
147 (put 'inline 'lisp-indent-hook 0)
148 (defmacro inline (&rest body)
149 "Eval BODY forms sequentially and return value of last one.
151 This emulating macro does not support function inlining because old \(v18\)
152 compiler does not support inlining feature.
153 \[poe-18.el; EMACS 19 emulating macro]"
154 (` (progn (,@ body))))
156 (put 'defsubst 'lisp-indent-hook 'defun)
157 (put 'defsubst 'edebug-form-spec 'defun)
158 (defmacro-maybe defsubst (name arglist &rest body)
159 "Define an inline function. The syntax is just like that of `defun'.
161 This emulating macro does not support function inlining because old \(v18\)
162 compiler does not support inlining feature.
163 \[poe-18.el; EMACS 19 emulating macro]"
164 (cons 'defun (cons name (cons arglist body))))
166 (defun-maybe make-obsolete (fn new)
167 "Make the byte-compiler warn that FUNCTION is obsolete.
168 The warning will say that NEW should be used instead.
169 If NEW is a string, that is the `use instead' message.
171 This emulating function does nothing because old \(v18\) compiler does not
172 support this feature.
173 \[poe-18.el; EMACS 19 emulating function]"
174 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
177 (defun-maybe make-obsolete-variable (var new)
178 "Make the byte-compiler warn that VARIABLE is obsolete,
179 and NEW should be used instead. If NEW is a string, then that is the
180 `use instead' message.
182 This emulating function does nothing because old \(v18\) compiler does not
183 support this feature.
184 \[poe-18.el; EMACS 19 emulating function]"
185 (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
188 (put 'dont-compile 'lisp-indent-hook 0)
189 (defmacro-maybe dont-compile (&rest body)
190 "Like `progn', but the body always runs interpreted \(not compiled\).
191 If you think you need this, you're probably making a mistake somewhere.
192 \[poe-18.el; EMACS 19 emulating macro]"
193 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
195 (put 'eval-when-compile 'lisp-indent-hook 0)
196 (defmacro-maybe eval-when-compile (&rest body)
197 "Like progn, but evaluates the body at compile-time.
199 This emulating macro does not do compile-time evaluation at all because
200 of the limitation of old \(v18\) compiler.
201 \[poe-18.el; EMACS 19 emulating macro]"
204 (put 'eval-and-compile 'lisp-indent-hook 0)
205 (defmacro-maybe eval-and-compile (&rest body)
206 "Like progn, but evaluates the body at compile-time as well as at load-time.
208 This emulating macro does not do compile-time evaluation at all because
209 of the limitation of old \(v18\) compiler.
210 \[poe-18.el; EMACS 19 emulating macro]"
217 (defun set-text-properties (start end properties &optional object))
219 (defun remove-text-properties (start end properties &optional object))
221 (defun get-text-property (position prop &optional object))
223 (defun add-text-properties (start end properties &optional object))
225 (defun put-text-property (start end property value &optional object))
227 (defun next-property-change (position &optional object limit))
229 (defun text-properties-at (position &optional object))
234 (defun make-directory-internal (dirname)
235 "Create a directory. One argument, a file name string.
236 \[poe-18.el; EMACS 19 emulating function]"
237 (let ((dir (expand-file-name dirname)))
238 (if (file-exists-p dir)
239 (error "Creating directory: %s is already exist" dir)
240 (call-process "mkdir" nil nil nil dir))))
242 (defun make-directory (dir &optional parents)
243 "Create the directory DIR and any nonexistent parent dirs.
244 The second (optional) argument PARENTS says whether
245 to create parent directories if they don't exist.
246 \[poe-18.el; EMACS 19 emulating function]"
247 (let ((len (length dir))
250 (while (and (< p len) (string-match "[^/]*/?" dir p))
251 (setq p1 (match-end 0))
254 (setq path (substring dir 0 p1))
255 (if (not (file-directory-p path))
256 (cond ((file-exists-p path)
257 (error "Creating directory: %s is not directory" path))
259 (error "Creating directory: %s is not exist" path))
261 (make-directory-internal path))))
263 (make-directory-internal dir)))
265 ;; Imported from files.el of EMACS 19.33.
266 (defun parse-colon-path (cd-path)
267 "Explode a colon-separated list of paths into a string list."
269 (let (cd-prefix cd-list (cd-start 0) cd-colon)
270 (setq cd-path (concat cd-path path-separator))
271 (while (setq cd-colon (string-match path-separator cd-path cd-start))
274 (list (if (= cd-start cd-colon)
276 (substitute-in-file-name
277 (file-name-as-directory
278 (substring cd-path cd-start cd-colon)))))))
279 (setq cd-start (+ cd-colon 1)))
282 ;; Imported from files.el of EMACS 19.33.
283 (defun file-relative-name (filename &optional directory)
284 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
285 (setq filename (expand-file-name filename)
286 directory (file-name-as-directory (expand-file-name
287 (or directory default-directory))))
289 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
290 (setq directory (file-name-directory (substring directory 0 -1))
291 ancestor (concat "../" ancestor)))
292 (concat ancestor (substring filename (match-end 0)))))
294 (or (fboundp 'si:directory-files)
295 (fset 'si:directory-files (symbol-function 'directory-files)))
296 (defun directory-files (directory &optional full match nosort)
297 "Return a list of names of files in DIRECTORY.
298 There are three optional arguments:
299 If FULL is non-nil, return absolute file names. Otherwise return names
300 that are relative to the specified directory.
301 If MATCH is non-nil, mention only file names that match the regexp MATCH.
302 If NOSORT is dummy for compatibility.
303 \[poe-18.el; EMACS 19 emulating function]"
304 (si:directory-files directory full match))
306 (defun file-executable-p (filename)
307 "Return t if FILENAME can be executed by you.
308 For a directory, this means you can access files in that directory.
309 \[poe-18.el; EMACS 19 emulating function]"
310 (if (file-exists-p filename)
311 (let ((process (start-process "test" nil "test" "-x" filename)))
312 (while (eq 'run (process-status process)))
313 (zerop (process-exit-status process)))))
316 ;;; @ Display Features
319 ;;; Imported from Emacs 19.30.
320 (defun force-mode-line-update (&optional all)
321 "Force the mode-line of the current buffer to be redisplayed.
322 With optional non-nil ALL, force redisplay of all mode-lines.
323 \[poe-18.el; Emacs 19 emulating function]"
324 (if all (save-excursion (set-buffer (other-buffer))))
325 (set-buffer-modified-p (buffer-modified-p)))
331 (cond ((boundp 'NEMACS)
332 (defvar emu:available-face-attribute-alist
334 ;;(bold . inversed-region)
335 (italic . underlined-region)
336 (underline . underlined-region)
339 ;; by YAMATE Keiichirou 1994/10/28
340 (defun attribute-add-narrow-attribute (attr from to)
341 (or (consp (symbol-value attr))
343 (let* ((attr-value (symbol-value attr))
344 (len (car attr-value))
347 (while (and (< posfrom len)
348 (> from (nth posfrom attr-value)))
349 (setq posfrom (1+ posfrom)))
351 (while (and (< posto len)
352 (> to (nth posto attr-value)))
353 (setq posto (1+ posto)))
354 (if (= posto posfrom)
355 (if (= (% posto 2) 1)
357 (= to (nth posto attr-value)))
358 (set-marker (nth posto attr-value) from)
359 (setcdr (nthcdr (1- posfrom) attr-value)
360 (cons (set-marker-type (set-marker (make-marker)
363 (cons (set-marker-type
364 (set-marker (make-marker)
367 (nthcdr posto attr-value))))
368 (setcar attr-value (+ len 2))))
369 (if (= (% posfrom 2) 0)
370 (setq posfrom (1- posfrom))
371 (set-marker (nth posfrom attr-value) from))
372 (if (= (% posto 2) 0)
374 (setq posto (1- posto))
375 (set-marker (nth posto attr-value) to))
376 (setcdr (nthcdr posfrom attr-value)
377 (nthcdr posto attr-value)))))
379 (defalias 'make-overlay 'cons)
381 (defun overlay-put (overlay prop value)
382 (let ((ret (and (eq prop 'face)
383 (assq value emu:available-face-attribute-alist))))
385 (attribute-add-narrow-attribute (cdr ret)
386 (car overlay)(cdr overlay))))))
388 (defun make-overlay (beg end &optional buffer type))
389 (defun overlay-put (overlay prop value))))
391 (defun overlay-buffer (overlay))
397 (defun-maybe generate-new-buffer-name (name &optional ignore)
398 "Return a string that is the name of no existing buffer based on NAME.
399 If there is no live buffer named NAME, then return NAME.
400 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
401 until an unused name is found, and then return that name.
402 Optional second argument IGNORE specifies a name that is okay to use
403 \(if it is in the sequence to be tried)
404 even if a buffer with that name exists."
405 (if (get-buffer name)
407 (while (get-buffer (setq new (format "%s<%d>" name n)))
412 (or (fboundp 'si:mark)
413 (fset 'si:mark (symbol-function 'mark)))
414 (defun mark (&optional force)
420 (defvar current-time-world-timezones
421 '(("PST" . -800)("PDT" . -700)("MST" . -700)
422 ("MDT" . -600)("CST" . -600)("CDT" . -500)
423 ("EST" . -500)("EDT" . -400)("AST" . -400)
424 ("NST" . -330)("UT" . +000)("GMT" . +000)
425 ("BST" . +100)("MET" . +100)("EET" . +200)
426 ("JST" . +900)("GMT+1" . +100)("GMT+2" . +200)
427 ("GMT+3" . +300)("GMT+4" . +400)("GMT+5" . +500)
428 ("GMT+6" . +600)("GMT+7" . +700)("GMT+8" . +800)
429 ("GMT+9" . +900)("GMT+10" . +1000)("GMT+11" . +1100)
430 ("GMT+12" . +1200)("GMT+13" . +1300)("GMT-1" . -100)
431 ("GMT-2" . -200)("GMT-3" . -300)("GMT-4" . -400)
432 ("GMT-5" . -500)("GMT-6" . -600)("GMT-7" . -700)
433 ("GMT-8" . -800)("GMT-9" . -900)("GMT-10" . -1000)
434 ("GMT-11" . -1100) ("GMT-12" . -1200))
435 "Time differentials of timezone from GMT in +-HHMM form.
436 Used in `current-time-zone' (Emacs 19 emulating function in poe-18.el).")
438 (defvar current-time-local-timezone nil
439 "*Local timezone name.
440 Used in `current-time-zone' (Emacs 19 emulating function in poe-18.el).")
442 (defun current-time-zone (&optional specified-time)
443 "Return the offset and name for the local time zone.
444 This returns a list of the form (OFFSET NAME).
445 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
446 A negative value means west of Greenwich.
447 NAME is a string giving the name of the time zone.
448 Optional argument SPECIFIED-TIME is ignored in this implementation.
449 Some operating systems cannot provide all this information to Emacs;
450 in this case, `current-time-zone' returns a list containing nil for
451 the data it can't find."
452 (let ((local-timezone
453 (or current-time-local-timezone
454 (setq current-time-local-timezone
456 (call-process "date" nil (current-buffer) t)
457 (goto-char (point-min))
459 "^.*\\([A-Z][A-Z][A-Z]\\([^ \n\t]*\\)\\).*$")
460 (buffer-substring (match-beginning 1)
462 timezone abszone seconds)
464 (or (cdr (assoc (upcase local-timezone)
465 current-time-world-timezones))
466 ;; "+900" style or nil.
469 (if (stringp timezone)
470 (setq timezone (string-to-int timezone)))
471 ;; Taking account of minute in timezone.
473 (setq abszone (if (< timezone 0) (- timezone) timezone))
474 (setq seconds (* 60 (+ (* 60 (/ abszone 100)) (% abszone 100))))
475 (list (if (< timezone 0) (- seconds) seconds)
478 (or (fboundp 'si:current-time-string)
479 (fset 'si:current-time-string (symbol-function 'current-time-string)))
480 (defun current-time-string (&optional specified-time)
481 "Return the current time, as a human-readable string.
482 Programs can use this function to decode a time,
483 since the number of columns in each field is fixed.
484 The format is `Sun Sep 16 01:03:52 1973'.
485 If an argument SPECIFIED-TIME is given, it specifies a time to format
486 instead of the current time. The argument should have the form:
489 (HIGH LOW . IGNORED).
490 Thus, you can use times obtained from `current-time'
491 and from `file-attributes'."
492 (if (null specified-time)
493 (si:current-time-string)
494 (or (consp specified-time)
495 (error "Wrong type argument %s" specified-time))
496 (let ((high (car specified-time))
497 (low (cdr specified-time))
498 (offset (or (car (current-time-zone)) 0))
499 (mdays '(31 28 31 30 31 30 31 31 30 31 30 31))
500 (mnames '("Jan" "Feb" "Mar" "Apr" "May" "Jun"
501 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
502 (wnames '("Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"))
503 days dd yyyy lyear mm HH MM SS)
505 (setq low (car low)))
507 (error "Wrong type argument %s" high))
509 (error "Wrong type argument %s" low))
510 (setq low (+ low offset))
515 (while (or (> high 481)
522 (setq high (- high 481)
524 (if (and (zerop (% yyyy 4))
525 (or (not (zerop (% yyyy 100)))
526 (zerop (% yyyy 400))))
532 (setq high (- high 1)
534 (setq yyyy (1+ yyyy)))
536 (while (or (> high 1)
543 (setq high (- high 1)
548 (setq low (+ 65536 low)))
550 (setq lyear (and (zerop (% yyyy 4))
551 (or (not (zerop (% yyyy 100)))
552 (zerop (% yyyy 400)))))
553 (while (> (- dd (nth mm mdays)) 0)
554 (if (and (= mm 1) lyear)
556 (setq dd (- dd (nth mm mdays))))
558 (setq HH (/ low 3600)
562 (format "%s %s %2d %02d:%02d:%02d %4d"
564 (- (+ (* (1- yyyy) 365) (/ (1- yyyy) 400)
565 (/ (1- yyyy) 4)) (/ (1- yyyy) 100))) 7)
570 (defun current-time ()
571 "Return the current time, as the number of seconds since 1970-01-01 00:00:00.
572 The time is returned as a list of three integers. The first has the
573 most significant 16 bits of the seconds, while the second has the
574 least significant 16 bits. The third integer gives the microsecond
577 The microsecond count is zero on systems that do not provide
578 resolution finer than a second."
579 (let* ((str (current-time-string))
580 (yyyy (string-to-int (substring str 20 24)))
581 (mm (length (member (substring str 4 7)
582 '("Dec" "Nov" "Oct" "Sep" "Aug" "Jul"
583 "Jun" "May" "Apr" "Mar" "Feb" "Jan"))))
584 (dd (string-to-int (substring str 8 10)))
585 (HH (string-to-int (substring str 11 13)))
586 (MM (string-to-int (substring str 14 16)))
587 (SS (string-to-int (substring str 17 19)))
588 (offset (or (car (current-time-zone)) 0))
591 (setq ct1 0 ct2 0 i1 0 i2 0)
592 (setq year (- yyyy 1970))
600 (setq uru (- (+ (- (/ yyyy 4) (/ yyyy 100))
614 (setq dn (+ dd (* 31 (1- mm))))
616 (setq dn (+ (- dn (/ (+ 23 (* 4 mm)) 10))
617 (if (and (zerop (% yyyy 4))
618 (or (not (zerop (% yyyy 100)))
619 (zerop (% yyyy 400))))
631 (setq ct1 (+ (+ (+ ct1 i1) (/ ct2 65536))
632 (/ (+ (* HH 3600) (* MM 60) SS)
634 ct2 (+ (+ i2 (% ct2 65536))
635 (% (+ (* HH 3600) (* MM 60) SS)
637 (while (< (- ct2 offset) 0)
640 (setq ct2 (- ct2 offset))
649 ;;; poe-18.el ends here