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'. Especially, you cannot use
32 ;; `eval-when-compile' and `eval-and-compile' in this file.
36 (provide 'poe-18) ; beware of circular dependency.
37 (require 'poe) ; load definitions of `*-maybe'.
42 (defvar-maybe buffer-undo-list nil)
45 ;;; @ Emacs 19 emulation
48 (defvar-maybe data-directory exec-directory)
57 (defun delete (elt list)
58 "Delete by side effect any occurrences of ELT as a member of LIST.
59 The modified LIST is returned. Comparison is done with `equal'.
60 If the first member of LIST is ELT, deleting it is not a side effect;
61 it is simply using a different list.
62 Therefore, write `(setq foo (delete element foo))'
63 to be sure of changing the value of `foo'.
64 \[poe-18.el; EMACS 19 emulating function]"
65 (if (equal elt (car list))
69 (while (and rrest (not (equal elt (car rrest))))
72 (setcdr rest (cdr rrest))
75 (defun member (elt list)
76 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
77 The value is actually the tail of LIST whose car is ELT.
78 \[poe-18.el; EMACS 19 emulating function]"
79 (while (and list (not (equal elt (car list))))
80 (setq list (cdr list)))
84 ;;; @@ buffer-local variable
87 (defun default-boundp (symbol)
88 "Return t if SYMBOL has a non-void default value.
89 This is the value that is seen in buffers that do not have their own values
91 \[poe-18.el; EMACS 19 emulating function]"
94 (default-value symbol)
99 ;;; @@ environment variable
102 (autoload 'setenv "env"
103 "Set the value of the environment variable named VARIABLE to VALUE.
104 VARIABLE should be a string. VALUE is optional; if not provided or is
105 `nil', the environment variable VARIABLE will be removed.
106 This function works by modifying `process-environment'."
113 (defun defalias (sym newdef)
114 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
115 Associates the function with the current load file, if any."
118 (defun byte-code-function-p (exp)
119 "T if OBJECT is a byte-compiled function object.
120 \[poe-18.el; EMACS 19 emulating function]"
122 (let ((rest (cdr (cdr exp)))
124 (if (stringp (car rest))
125 (setq rest (cdr rest)))
128 (setq elt (car rest))
130 (eq (car elt) 'byte-code))
132 (setq rest (cdr rest)))))))
135 ;;; @ Compilation Features
138 (put 'eval-when-compile 'lisp-indent-hook 0)
139 (defmacro-maybe eval-when-compile (&rest body)
140 "Like progn, but evaluates the body at compile-time.
142 This emulating macro does not work if used at top-level.
143 Top-level macros are expanded at load-time.
144 \[poe-18.el; EMACS 19 emulating macro]"
145 (list 'quote (eval (cons 'progn body))))
147 (put 'eval-and-compile 'lisp-indent-hook 0)
148 (defmacro-maybe eval-and-compile (&rest body)
149 "Like progn, but evaluates the body at compile-time as well as at load-time.
151 This emulating macro does not work if used at top-level.
152 Top-level macros are expanded at load-time.
153 \[poe-18.el; EMACS 19 emulating macro]"
154 ;; `form' is a parameter of `byte-compile-form'. kludge! kludge! kludge!
155 ;; this kludge prevents from evaluating `body' twice when this macro is
156 ;; expanded at load-time.
157 (if (and (boundp 'form)
158 (eq (car-safe form) 'eval-and-compile))
159 (eval (cons 'progn body)))
162 (put 'defsubst 'lisp-indent-hook 'defun)
163 (put 'defsubst 'edebug-form-spec 'defun)
164 (defmacro-maybe defsubst (name arglist &rest body)
165 "Define an inline function. The syntax is just like that of `defun'.
167 This emulating macro does not support function inlining because old (v18)
168 compiler does not support inlining feature.
169 \[poe-18.el; EMACS 19 emulating macro]"
170 (cons 'defun (cons name (cons arglist body))))
172 (defun-maybe make-obsolete (fn new)
173 "Make the byte-compiler warn that FUNCTION is obsolete.
174 The warning will say that NEW should be used instead.
175 If NEW is a string, that is the `use instead' message.
177 This emulating function does nothing because old (v18) compiler does not
178 support this feature.
179 \[poe-18.el; EMACS 19 emulating function]"
180 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
187 (defun set-text-properties (start end properties &optional object))
189 (defun remove-text-properties (start end properties &optional object))
195 (defun make-directory-internal (dirname)
196 "Create a directory. One argument, a file name string.
197 \[poe-18.el; EMACS 19 emulating function]"
198 (let ((dir (expand-file-name dirname)))
199 (if (file-exists-p dir)
200 (error "Creating directory: %s is already exist" dir)
201 (call-process "mkdir" nil nil nil dir))))
203 (defun make-directory (dir &optional parents)
204 "Create the directory DIR and any nonexistent parent dirs.
205 The second (optional) argument PARENTS says whether
206 to create parent directories if they don't exist.
207 \[poe-18.el; EMACS 19 emulating function]"
208 (let ((len (length dir))
211 (while (and (< p len) (string-match "[^/]*/?" dir p))
212 (setq p1 (match-end 0))
215 (setq path (substring dir 0 p1))
216 (if (not (file-directory-p path))
217 (cond ((file-exists-p path)
218 (error "Creating directory: %s is not directory" path))
220 (error "Creating directory: %s is not exist" path))
222 (make-directory-internal path))))
224 (make-directory-internal dir)))
226 ;; Imported from files.el of EMACS 19.33.
227 (defun parse-colon-path (cd-path)
228 "Explode a colon-separated list of paths into a string list."
230 (let (cd-prefix cd-list (cd-start 0) cd-colon)
231 (setq cd-path (concat cd-path path-separator))
232 (while (setq cd-colon (string-match path-separator cd-path cd-start))
235 (list (if (= cd-start cd-colon)
237 (substitute-in-file-name
238 (file-name-as-directory
239 (substring cd-path cd-start cd-colon)))))))
240 (setq cd-start (+ cd-colon 1)))
243 ;; Imported from files.el of EMACS 19.33.
244 (defun file-relative-name (filename &optional directory)
245 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
246 (setq filename (expand-file-name filename)
247 directory (file-name-as-directory (expand-file-name
248 (or directory default-directory))))
250 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
251 (setq directory (file-name-directory (substring directory 0 -1))
252 ancestor (concat "../" ancestor)))
253 (concat ancestor (substring filename (match-end 0)))))
255 (or (fboundp 'si:directory-files)
256 (fset 'si:directory-files (symbol-function 'directory-files)))
257 (defun directory-files (directory &optional full match nosort)
258 "Return a list of names of files in DIRECTORY.
259 There are three optional arguments:
260 If FULL is non-nil, return absolute file names. Otherwise return names
261 that are relative to the specified directory.
262 If MATCH is non-nil, mention only file names that match the regexp MATCH.
263 If NOSORT is dummy for compatibility.
264 \[poe-18.el; EMACS 19 emulating function]"
265 (si:directory-files directory full match))
268 ;;; @ Display Features
271 ;;; Imported from Emacs 19.30.
272 (defun force-mode-line-update (&optional all)
273 "Force the mode-line of the current buffer to be redisplayed.
274 With optional non-nil ALL, force redisplay of all mode-lines.
275 \[poe-18.el; Emacs 19 emulating function]"
276 (if all (save-excursion (set-buffer (other-buffer))))
277 (set-buffer-modified-p (buffer-modified-p)))
283 (cond ((boundp 'NEMACS)
284 (defvar emu:available-face-attribute-alist
286 ;;(bold . inversed-region)
287 (italic . underlined-region)
288 (underline . underlined-region)
291 ;; by YAMATE Keiichirou 1994/10/28
292 (defun attribute-add-narrow-attribute (attr from to)
293 (or (consp (symbol-value attr))
295 (let* ((attr-value (symbol-value attr))
296 (len (car attr-value))
299 (while (and (< posfrom len)
300 (> from (nth posfrom attr-value)))
301 (setq posfrom (1+ posfrom)))
303 (while (and (< posto len)
304 (> to (nth posto attr-value)))
305 (setq posto (1+ posto)))
306 (if (= posto posfrom)
307 (if (= (% posto 2) 1)
309 (= to (nth posto attr-value)))
310 (set-marker (nth posto attr-value) from)
311 (setcdr (nthcdr (1- posfrom) attr-value)
312 (cons (set-marker-type (set-marker (make-marker)
315 (cons (set-marker-type
316 (set-marker (make-marker)
319 (nthcdr posto attr-value))))
320 (setcar attr-value (+ len 2))))
321 (if (= (% posfrom 2) 0)
322 (setq posfrom (1- posfrom))
323 (set-marker (nth posfrom attr-value) from))
324 (if (= (% posto 2) 0)
326 (setq posto (1- posto))
327 (set-marker (nth posto attr-value) to))
328 (setcdr (nthcdr posfrom attr-value)
329 (nthcdr posto attr-value)))))
331 (defalias 'make-overlay 'cons)
333 (defun overlay-put (overlay prop value)
334 (let ((ret (and (eq prop 'face)
335 (assq value emu:available-face-attribute-alist))))
337 (attribute-add-narrow-attribute (cdr ret)
338 (car overlay)(cdr overlay))))))
340 (defun make-overlay (beg end &optional buffer type))
341 (defun overlay-put (overlay prop value))))
343 (defun overlay-buffer (overlay))
349 (defun-maybe generate-new-buffer-name (name &optional ignore)
350 "Return a string that is the name of no existing buffer based on NAME.
351 If there is no live buffer named NAME, then return NAME.
352 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
353 until an unused name is found, and then return that name.
354 Optional second argument IGNORE specifies a name that is okay to use
355 \(if it is in the sequence to be tried)
356 even if a buffer with that name exists."
357 (if (get-buffer name)
359 (while (get-buffer (setq new (format "%s<%d>" name n)))
364 (or (fboundp 'si:mark)
365 (fset 'si:mark (symbol-function 'mark)))
366 (defun mark (&optional force)
373 ;;; poe-18.el ends here