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 ;; Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
7 ;; Keywords: emulation, compatibility
9 ;; This file is part of APEL (A Portable Emacs Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; Note to APEL developers and APEL programmers:
30 ;; If old (v18) compiler is used, top-level macros are expanded at
31 ;; *load-time*, not compile-time. Therefore,
33 ;; (1) you cannot use macros defined with `defmacro-maybe' within function
34 ;; definitions in the same file.
35 ;; (`defmacro-maybe' is evaluated at load-time, therefore byte-compiler
36 ;; treats such use of macros as (unknown) functions and compiles them
37 ;; into function calls, which will cause errors at run-time.)
39 ;; (2) `eval-when-compile' and `eval-and-compile' are evaluated at
40 ;; load-time if used at top-level.
44 (require 'pym) ; `static-*' and `def*-maybe'.
50 (defun defalias (sym newdef)
51 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
52 Associates the function with the current load file, if any."
55 (defun byte-code-function-p (exp)
56 "T if OBJECT is a byte-compiled function object."
58 (let ((rest (cdr (cdr exp)))
60 (if (stringp (car rest))
61 (setq rest (cdr rest)))
66 (eq (car elt) 'byte-code))
68 (setq rest (cdr rest)))))))
70 ;;; emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
71 ;;; (note: jwz's original compiler and XEmacs compiler have some more
72 ;;; macros; they are "nuked" by rms in FSF version.)
74 (put 'inline 'lisp-indent-hook 0)
75 (defmacro-maybe inline (&rest body)
76 "Eval BODY forms sequentially and return value of last one.
78 This emulating macro does not support function inlining because old \(v18\)
79 compiler does not support inlining feature."
82 (put 'defsubst 'lisp-indent-hook 'defun)
83 (put 'defsubst 'edebug-form-spec 'defun)
84 (defmacro-maybe defsubst (name arglist &rest body)
85 "Define an inline function. The syntax is just like that of `defun'.
87 This emulating macro does not support function inlining because old \(v18\)
88 compiler does not support inlining feature."
89 (cons 'defun (cons name (cons arglist body))))
91 (defun-maybe make-obsolete (fn new)
92 "Make the byte-compiler warn that FUNCTION is obsolete.
93 The warning will say that NEW should be used instead.
94 If NEW is a string, that is the `use instead' message.
96 This emulating function does nothing because old \(v18\) compiler does not
97 support this feature."
98 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
101 (defun-maybe make-obsolete-variable (var new)
102 "Make the byte-compiler warn that VARIABLE is obsolete,
103 and NEW should be used instead. If NEW is a string, then that is the
104 `use instead' message.
106 This emulating function does nothing because old \(v18\) compiler does not
107 support this feature."
108 (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
111 (put 'dont-compile 'lisp-indent-hook 0)
112 (defmacro-maybe dont-compile (&rest body)
113 "Like `progn', but the body always runs interpreted \(not compiled\).
114 If you think you need this, you're probably making a mistake somewhere."
115 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
117 (put 'eval-when-compile 'lisp-indent-hook 0)
118 (defmacro-maybe eval-when-compile (&rest body)
119 "Like progn, but evaluates the body at compile-time.
121 This emulating macro does not do compile-time evaluation at all because
122 of the limitation of old \(v18\) compiler."
125 (put 'eval-and-compile 'lisp-indent-hook 0)
126 (defmacro-maybe eval-and-compile (&rest body)
127 "Like progn, but evaluates the body at compile-time as well as at load-time.
129 This emulating macro does not do compile-time evaluation at all because
130 of the limitation of old \(v18\) compiler."
134 ;;; @ Basic lisp subroutines.
137 (defmacro lambda (&rest cdr)
138 "Return a lambda expression.
139 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
140 self-quoting; the result of evaluating the lambda expression is the
141 expression itself. The lambda expression may then be treated as a
142 function, i.e., stored as the function value of a symbol, passed to
143 funcall or mapcar, etc.
145 ARGS should take the same form as an argument list for a `defun'.
146 DOCSTRING is an optional documentation string.
147 If present, it should describe how to call the function.
148 But documentation strings are usually not useful in nameless functions.
149 INTERACTIVE should be a call to the function `interactive', which see.
150 It may also be omitted.
151 BODY should be a list of lisp expressions."
152 ;; Note that this definition should not use backquotes; subr.el should not
153 ;; depend on backquote.el.
154 (list 'function (cons 'lambda cdr)))
156 (defun delete (elt list)
157 "Delete by side effect any occurrences of ELT as a member of LIST.
158 The modified LIST is returned. Comparison is done with `equal'.
159 If the first member of LIST is ELT, deleting it is not a side effect;
160 it is simply using a different list.
161 Therefore, write `(setq foo (delete element foo))'
162 to be sure of changing the value of `foo'."
164 (if (equal elt (car list))
168 (while (and rrest (not (equal elt (car rrest))))
171 (setcdr rest (cdr rrest))
174 (defun member (elt list)
175 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
176 The value is actually the tail of LIST whose car is ELT."
177 (while (and list (not (equal elt (car list))))
178 (setq list (cdr list)))
181 (defun default-boundp (symbol)
182 "Return t if SYMBOL has a non-void default value.
183 This is the value that is seen in buffers that do not have their own values
185 (condition-case error
187 (default-value symbol)
189 (void-variable nil)))
191 (defun force-mode-line-update (&optional all)
192 "Force the mode-line of the current buffer to be redisplayed.
193 With optional non-nil ALL, force redisplay of all mode-lines."
194 (if all (save-excursion (set-buffer (other-buffer))))
195 (set-buffer-modified-p (buffer-modified-p)))
197 ;; (defalias 'save-match-data 'store-match-data)
200 ;;; @ Basic editing commands.
203 (defvar-maybe buffer-undo-list nil)
205 (defalias 'buffer-disable-undo 'buffer-flush-undo)
207 (defun-maybe generate-new-buffer-name (name &optional ignore)
208 "Return a string that is the name of no existing buffer based on NAME.
209 If there is no live buffer named NAME, then return NAME.
210 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
211 until an unused name is found, and then return that name.
212 Optional second argument IGNORE specifies a name that is okay to use
213 \(if it is in the sequence to be tried)
214 even if a buffer with that name exists."
215 (if (get-buffer name)
217 (while (get-buffer (setq new (format "%s<%d>" name n)))
222 (or (fboundp 'si:mark)
223 (fset 'si:mark (symbol-function 'mark)))
224 (defun mark (&optional force)
228 ;;; @@ Environment variables.
231 (autoload 'setenv "env"
232 "Set the value of the environment variable named VARIABLE to VALUE.
233 VARIABLE should be a string. VALUE is optional; if not provided or is
234 `nil', the environment variable VARIABLE will be removed.
235 This function works by modifying `process-environment'."
239 ;;; @ File input and output commands.
242 (defvar-maybe data-directory exec-directory)
244 ;; `call-process' does not return exit status.
245 (defun file-executable-p (filename)
246 "Return t if FILENAME can be executed by you.
247 For a directory, this means you can access files in that directory."
248 (if (file-exists-p filename)
249 (let ((process (start-process "test" nil "test" "-x" filename)))
250 (while (eq 'run (process-status process)))
251 (zerop (process-exit-status process)))))
253 (defun make-directory-internal (dirname)
254 "Create a directory. One argument, a file name string."
255 (let ((dir (expand-file-name dirname)))
256 (if (file-exists-p dir)
257 (error "Creating directory: %s is already exist" dir)
258 (call-process "mkdir" nil nil nil dir))))
260 (defun make-directory (dir &optional parents)
261 "Create the directory DIR and any nonexistent parent dirs.
262 The second (optional) argument PARENTS says whether
263 to create parent directories if they don't exist."
264 (let ((len (length dir))
267 (while (and (< p len) (string-match "[^/]*/?" dir p))
268 (setq p1 (match-end 0))
271 (setq path (substring dir 0 p1))
272 (if (not (file-directory-p path))
273 (cond ((file-exists-p path)
274 (error "Creating directory: %s is not directory" path))
276 (error "Creating directory: %s is not exist" path))
278 (make-directory-internal path))))
280 (make-directory-internal dir)))
282 (defun parse-colon-path (cd-path)
283 "Explode a colon-separated list of paths into a string list."
285 (let (cd-prefix cd-list (cd-start 0) cd-colon)
286 (setq cd-path (concat cd-path path-separator))
287 (while (setq cd-colon (string-match path-separator cd-path cd-start))
290 (list (if (= cd-start cd-colon)
292 (substitute-in-file-name
293 (file-name-as-directory
294 (substring cd-path cd-start cd-colon)))))))
295 (setq cd-start (+ cd-colon 1)))
298 (defun file-relative-name (filename &optional directory)
299 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
300 (setq filename (expand-file-name filename)
301 directory (file-name-as-directory (expand-file-name
302 (or directory default-directory))))
304 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
305 (setq directory (file-name-directory (substring directory 0 -1))
306 ancestor (concat "../" ancestor)))
307 (concat ancestor (substring filename (match-end 0)))))
309 (or (fboundp 'si:directory-files)
310 (fset 'si:directory-files (symbol-function 'directory-files)))
311 (defun directory-files (directory &optional full match nosort)
312 "Return a list of names of files in DIRECTORY.
313 There are three optional arguments:
314 If FULL is non-nil, return absolute file names. Otherwise return names
315 that are relative to the specified directory.
316 If MATCH is non-nil, mention only file names that match the regexp MATCH.
317 If NOSORT is dummy for compatibility."
318 (si:directory-files directory full match))
324 ;; In Emacs 20.4, these functions are defined in src/textprop.c.
325 (defun text-properties-at (position &optional object))
326 (defun get-text-property (position prop &optional object))
327 (defun get-char-property (position prop &optional object))
328 (defun next-property-change (position &optional object limit))
329 (defun next-single-property-change (position prop &optional object limit))
330 (defun previous-property-change (position &optional object limit))
331 (defun previous-single-property-change (position prop &optional object limit))
332 (defun add-text-properties (start end properties &optional object))
333 (defun put-text-properties (start end property &optional object))
334 (defun set-text-properties (start end properties &optional object))
335 (defun remove-text-properties (start end properties &optional object))
336 (defun text-property-any (start end property value &optional object))
337 (defun text-property-not-all (start end property value &optional object))
338 ;; the following two functions are new in v20.
339 (defun next-char-property-change (position &optional object))
340 (defun previous-char-property-change (position &optional object))
341 ;; the following two functions are obsolete.
342 ;; (defun erase-text-properties (start end &optional object)
343 ;; (defun copy-text-properties (start end src pos dest &optional prop)
351 (defvar emu:available-face-attribute-alist
353 ;;(bold . inversed-region)
354 (italic . underlined-region)
355 (underline . underlined-region)))
357 ;; by YAMATE Keiichirou 1994/10/28
358 (defun attribute-add-narrow-attribute (attr from to)
359 (or (consp (symbol-value attr))
361 (let* ((attr-value (symbol-value attr))
362 (len (car attr-value))
365 (while (and (< posfrom len)
366 (> from (nth posfrom attr-value)))
367 (setq posfrom (1+ posfrom)))
369 (while (and (< posto len)
370 (> to (nth posto attr-value)))
371 (setq posto (1+ posto)))
372 (if (= posto posfrom)
373 (if (= (% posto 2) 1)
375 (= to (nth posto attr-value)))
376 (set-marker (nth posto attr-value) from)
377 (setcdr (nthcdr (1- posfrom) attr-value)
378 (cons (set-marker-type (set-marker (make-marker)
381 (cons (set-marker-type
382 (set-marker (make-marker)
385 (nthcdr posto attr-value))))
386 (setcar attr-value (+ len 2))))
387 (if (= (% posfrom 2) 0)
388 (setq posfrom (1- posfrom))
389 (set-marker (nth posfrom attr-value) from))
390 (if (= (% posto 2) 0)
392 (setq posto (1- posto))
393 (set-marker (nth posto attr-value) to))
394 (setcdr (nthcdr posfrom attr-value)
395 (nthcdr posto attr-value)))))
397 (defalias 'make-overlay 'cons)
399 (defun overlay-put (overlay prop value)
400 (let ((ret (and (eq prop 'face)
401 (assq value emu:available-face-attribute-alist))))
403 (attribute-add-narrow-attribute (cdr ret)
404 (car overlay)(cdr overlay))))))
406 (defun make-overlay (beg end &optional buffer type))
407 (defun overlay-put (overlay prop value))))
409 (defun overlay-buffer (overlay))
417 ;;; poe-18.el ends here