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 (provide 'poe-18) ; beware of circular dependency.
38 (require 'poe) ; load definitions of `*-maybe'.
43 (defvar-maybe buffer-undo-list nil)
46 ;;; @ Emacs 19 emulation
49 (defvar-maybe data-directory exec-directory)
58 (defun delete (elt list)
59 "Delete by side effect any occurrences of ELT as a member of LIST.
60 The modified LIST is returned. Comparison is done with `equal'.
61 If the first member of LIST is ELT, deleting it is not a side effect;
62 it is simply using a different list.
63 Therefore, write `(setq foo (delete element foo))'
64 to be sure of changing the value of `foo'.
65 \[poe-18.el; EMACS 19 emulating function]"
67 (if (equal elt (car list))
71 (while (and rrest (not (equal elt (car rrest))))
74 (setcdr rest (cdr rrest))
77 (defun member (elt list)
78 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
79 The value is actually the tail of LIST whose car is ELT.
80 \[poe-18.el; EMACS 19 emulating function]"
81 (while (and list (not (equal elt (car list))))
82 (setq list (cdr list)))
86 ;;; @@ buffer-local variable
89 (defun default-boundp (symbol)
90 "Return t if SYMBOL has a non-void default value.
91 This is the value that is seen in buffers that do not have their own values
93 \[poe-18.el; EMACS 19 emulating function]"
96 (default-value symbol)
101 ;;; @@ environment variable
104 (autoload 'setenv "env"
105 "Set the value of the environment variable named VARIABLE to VALUE.
106 VARIABLE should be a string. VALUE is optional; if not provided or is
107 `nil', the environment variable VARIABLE will be removed.
108 This function works by modifying `process-environment'."
115 (defun defalias (sym newdef)
116 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
117 Associates the function with the current load file, if any."
120 (defun byte-code-function-p (exp)
121 "T if OBJECT is a byte-compiled function object.
122 \[poe-18.el; EMACS 19 emulating function]"
124 (let ((rest (cdr (cdr exp)))
126 (if (stringp (car rest))
127 (setq rest (cdr rest)))
130 (setq elt (car rest))
132 (eq (car elt) 'byte-code))
134 (setq rest (cdr rest)))))))
137 ;;; @ Compilation Features
140 ;;; emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
141 ;;; (note: jwz's original compiler and XEmacs compiler have some more
142 ;;; macros; they are "nuked" by rms in FSF version.)
144 (put 'inline 'lisp-indent-hook 0)
145 (defalias 'inline 'progn)
147 (put 'defsubst 'lisp-indent-hook 'defun)
148 (put 'defsubst 'edebug-form-spec 'defun)
149 (defmacro-maybe defsubst (name arglist &rest body)
150 "Define an inline function. The syntax is just like that of `defun'.
152 This emulating macro does not support function inlining because old \(v18\)
153 compiler does not support inlining feature.
154 \[poe-18.el; EMACS 19 emulating macro]"
155 (cons 'defun (cons name (cons arglist body))))
157 (defun-maybe make-obsolete (fn new)
158 "Make the byte-compiler warn that FUNCTION is obsolete.
159 The warning will say that NEW should be used instead.
160 If NEW is a string, that is the `use instead' message.
162 This emulating function does nothing because old \(v18\) compiler does not
163 support this feature.
164 \[poe-18.el; EMACS 19 emulating function]"
165 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
168 (defun-maybe make-obsolete-variable (var new)
169 "Make the byte-compiler warn that VARIABLE is obsolete,
170 and NEW should be used instead. If NEW is a string, then that is the
171 `use instead' message.
173 This emulating function does nothing because old \(v18\) compiler does not
174 support this feature.
175 \[poe-18.el; EMACS 19 emulating function]"
176 (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
179 (put 'dont-compile 'lisp-indent-hook 0)
180 (defmacro-maybe dont-compile (&rest body)
181 "Like `progn', but the body always runs interpreted \(not compiled\).
182 If you think you need this, you're probably making a mistake somewhere.
183 \[poe-18.el; EMACS 19 emulating macro]"
184 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
186 (put 'eval-when-compile 'lisp-indent-hook 0)
187 (defmacro-maybe eval-when-compile (&rest body)
188 "Like progn, but evaluates the body at compile-time.
190 This emulating macro does not do compile-time evaluation at all because
191 of the limitation of old \(v18\) compiler.
192 \[poe-18.el; EMACS 19 emulating macro]"
195 (put 'eval-and-compile 'lisp-indent-hook 0)
196 (defmacro-maybe eval-and-compile (&rest body)
197 "Like progn, but evaluates the body at compile-time as well as at load-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]"
208 (defun set-text-properties (start end properties &optional object))
210 (defun remove-text-properties (start end properties &optional object))
216 (defun make-directory-internal (dirname)
217 "Create a directory. One argument, a file name string.
218 \[poe-18.el; EMACS 19 emulating function]"
219 (let ((dir (expand-file-name dirname)))
220 (if (file-exists-p dir)
221 (error "Creating directory: %s is already exist" dir)
222 (call-process "mkdir" nil nil nil dir))))
224 (defun make-directory (dir &optional parents)
225 "Create the directory DIR and any nonexistent parent dirs.
226 The second (optional) argument PARENTS says whether
227 to create parent directories if they don't exist.
228 \[poe-18.el; EMACS 19 emulating function]"
229 (let ((len (length dir))
232 (while (and (< p len) (string-match "[^/]*/?" dir p))
233 (setq p1 (match-end 0))
236 (setq path (substring dir 0 p1))
237 (if (not (file-directory-p path))
238 (cond ((file-exists-p path)
239 (error "Creating directory: %s is not directory" path))
241 (error "Creating directory: %s is not exist" path))
243 (make-directory-internal path))))
245 (make-directory-internal dir)))
247 ;; Imported from files.el of EMACS 19.33.
248 (defun parse-colon-path (cd-path)
249 "Explode a colon-separated list of paths into a string list."
251 (let (cd-prefix cd-list (cd-start 0) cd-colon)
252 (setq cd-path (concat cd-path path-separator))
253 (while (setq cd-colon (string-match path-separator cd-path cd-start))
256 (list (if (= cd-start cd-colon)
258 (substitute-in-file-name
259 (file-name-as-directory
260 (substring cd-path cd-start cd-colon)))))))
261 (setq cd-start (+ cd-colon 1)))
264 ;; Imported from files.el of EMACS 19.33.
265 (defun file-relative-name (filename &optional directory)
266 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
267 (setq filename (expand-file-name filename)
268 directory (file-name-as-directory (expand-file-name
269 (or directory default-directory))))
271 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
272 (setq directory (file-name-directory (substring directory 0 -1))
273 ancestor (concat "../" ancestor)))
274 (concat ancestor (substring filename (match-end 0)))))
276 (or (fboundp 'si:directory-files)
277 (fset 'si:directory-files (symbol-function 'directory-files)))
278 (defun directory-files (directory &optional full match nosort)
279 "Return a list of names of files in DIRECTORY.
280 There are three optional arguments:
281 If FULL is non-nil, return absolute file names. Otherwise return names
282 that are relative to the specified directory.
283 If MATCH is non-nil, mention only file names that match the regexp MATCH.
284 If NOSORT is dummy for compatibility.
285 \[poe-18.el; EMACS 19 emulating function]"
286 (si:directory-files directory full match))
289 ;;; @ Display Features
292 ;;; Imported from Emacs 19.30.
293 (defun force-mode-line-update (&optional all)
294 "Force the mode-line of the current buffer to be redisplayed.
295 With optional non-nil ALL, force redisplay of all mode-lines.
296 \[poe-18.el; Emacs 19 emulating function]"
297 (if all (save-excursion (set-buffer (other-buffer))))
298 (set-buffer-modified-p (buffer-modified-p)))
304 (cond ((boundp 'NEMACS)
305 (defvar emu:available-face-attribute-alist
307 ;;(bold . inversed-region)
308 (italic . underlined-region)
309 (underline . underlined-region)
312 ;; by YAMATE Keiichirou 1994/10/28
313 (defun attribute-add-narrow-attribute (attr from to)
314 (or (consp (symbol-value attr))
316 (let* ((attr-value (symbol-value attr))
317 (len (car attr-value))
320 (while (and (< posfrom len)
321 (> from (nth posfrom attr-value)))
322 (setq posfrom (1+ posfrom)))
324 (while (and (< posto len)
325 (> to (nth posto attr-value)))
326 (setq posto (1+ posto)))
327 (if (= posto posfrom)
328 (if (= (% posto 2) 1)
330 (= to (nth posto attr-value)))
331 (set-marker (nth posto attr-value) from)
332 (setcdr (nthcdr (1- posfrom) attr-value)
333 (cons (set-marker-type (set-marker (make-marker)
336 (cons (set-marker-type
337 (set-marker (make-marker)
340 (nthcdr posto attr-value))))
341 (setcar attr-value (+ len 2))))
342 (if (= (% posfrom 2) 0)
343 (setq posfrom (1- posfrom))
344 (set-marker (nth posfrom attr-value) from))
345 (if (= (% posto 2) 0)
347 (setq posto (1- posto))
348 (set-marker (nth posto attr-value) to))
349 (setcdr (nthcdr posfrom attr-value)
350 (nthcdr posto attr-value)))))
352 (defalias 'make-overlay 'cons)
354 (defun overlay-put (overlay prop value)
355 (let ((ret (and (eq prop 'face)
356 (assq value emu:available-face-attribute-alist))))
358 (attribute-add-narrow-attribute (cdr ret)
359 (car overlay)(cdr overlay))))))
361 (defun make-overlay (beg end &optional buffer type))
362 (defun overlay-put (overlay prop value))))
364 (defun overlay-buffer (overlay))
370 (defun-maybe generate-new-buffer-name (name &optional ignore)
371 "Return a string that is the name of no existing buffer based on NAME.
372 If there is no live buffer named NAME, then return NAME.
373 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
374 until an unused name is found, and then return that name.
375 Optional second argument IGNORE specifies a name that is okay to use
376 \(if it is in the sequence to be tried)
377 even if a buffer with that name exists."
378 (if (get-buffer name)
380 (while (get-buffer (setq new (format "%s<%d>" name n)))
385 (or (fboundp 'si:mark)
386 (fset 'si:mark (symbol-function 'mark)))
387 (defun mark (&optional force)
394 ;;; poe-18.el ends here