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 (defmacro inline (&rest body)
146 "Eval BODY forms sequentially and return value of last one.
148 This emulating macro does not support function inlining because old \(v18\)
149 compiler does not support inlining feature.
150 \[poe-18.el; EMACS 19 emulating macro]"
151 (` (progn (,@ body))))
153 (put 'defsubst 'lisp-indent-hook 'defun)
154 (put 'defsubst 'edebug-form-spec 'defun)
155 (defmacro-maybe defsubst (name arglist &rest body)
156 "Define an inline function. The syntax is just like that of `defun'.
158 This emulating macro does not support function inlining because old \(v18\)
159 compiler does not support inlining feature.
160 \[poe-18.el; EMACS 19 emulating macro]"
161 (cons 'defun (cons name (cons arglist body))))
163 (defun-maybe make-obsolete (fn new)
164 "Make the byte-compiler warn that FUNCTION is obsolete.
165 The warning will say that NEW should be used instead.
166 If NEW is a string, that is the `use instead' message.
168 This emulating function does nothing because old \(v18\) compiler does not
169 support this feature.
170 \[poe-18.el; EMACS 19 emulating function]"
171 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
174 (defun-maybe make-obsolete-variable (var new)
175 "Make the byte-compiler warn that VARIABLE is obsolete,
176 and NEW should be used instead. If NEW is a string, then that is the
177 `use instead' message.
179 This emulating function does nothing because old \(v18\) compiler does not
180 support this feature.
181 \[poe-18.el; EMACS 19 emulating function]"
182 (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
185 (put 'dont-compile 'lisp-indent-hook 0)
186 (defmacro-maybe dont-compile (&rest body)
187 "Like `progn', but the body always runs interpreted \(not compiled\).
188 If you think you need this, you're probably making a mistake somewhere.
189 \[poe-18.el; EMACS 19 emulating macro]"
190 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
192 (put 'eval-when-compile 'lisp-indent-hook 0)
193 (defmacro-maybe eval-when-compile (&rest body)
194 "Like progn, but evaluates the body at compile-time.
196 This emulating macro does not do compile-time evaluation at all because
197 of the limitation of old \(v18\) compiler.
198 \[poe-18.el; EMACS 19 emulating macro]"
201 (put 'eval-and-compile 'lisp-indent-hook 0)
202 (defmacro-maybe eval-and-compile (&rest body)
203 "Like progn, but evaluates the body at compile-time as well as at load-time.
205 This emulating macro does not do compile-time evaluation at all because
206 of the limitation of old \(v18\) compiler.
207 \[poe-18.el; EMACS 19 emulating macro]"
214 (defun set-text-properties (start end properties &optional object))
216 (defun remove-text-properties (start end properties &optional object))
222 (defun make-directory-internal (dirname)
223 "Create a directory. One argument, a file name string.
224 \[poe-18.el; EMACS 19 emulating function]"
225 (let ((dir (expand-file-name dirname)))
226 (if (file-exists-p dir)
227 (error "Creating directory: %s is already exist" dir)
228 (call-process "mkdir" nil nil nil dir))))
230 (defun make-directory (dir &optional parents)
231 "Create the directory DIR and any nonexistent parent dirs.
232 The second (optional) argument PARENTS says whether
233 to create parent directories if they don't exist.
234 \[poe-18.el; EMACS 19 emulating function]"
235 (let ((len (length dir))
238 (while (and (< p len) (string-match "[^/]*/?" dir p))
239 (setq p1 (match-end 0))
242 (setq path (substring dir 0 p1))
243 (if (not (file-directory-p path))
244 (cond ((file-exists-p path)
245 (error "Creating directory: %s is not directory" path))
247 (error "Creating directory: %s is not exist" path))
249 (make-directory-internal path))))
251 (make-directory-internal dir)))
253 ;; Imported from files.el of EMACS 19.33.
254 (defun parse-colon-path (cd-path)
255 "Explode a colon-separated list of paths into a string list."
257 (let (cd-prefix cd-list (cd-start 0) cd-colon)
258 (setq cd-path (concat cd-path path-separator))
259 (while (setq cd-colon (string-match path-separator cd-path cd-start))
262 (list (if (= cd-start cd-colon)
264 (substitute-in-file-name
265 (file-name-as-directory
266 (substring cd-path cd-start cd-colon)))))))
267 (setq cd-start (+ cd-colon 1)))
270 ;; Imported from files.el of EMACS 19.33.
271 (defun file-relative-name (filename &optional directory)
272 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
273 (setq filename (expand-file-name filename)
274 directory (file-name-as-directory (expand-file-name
275 (or directory default-directory))))
277 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
278 (setq directory (file-name-directory (substring directory 0 -1))
279 ancestor (concat "../" ancestor)))
280 (concat ancestor (substring filename (match-end 0)))))
282 (or (fboundp 'si:directory-files)
283 (fset 'si:directory-files (symbol-function 'directory-files)))
284 (defun directory-files (directory &optional full match nosort)
285 "Return a list of names of files in DIRECTORY.
286 There are three optional arguments:
287 If FULL is non-nil, return absolute file names. Otherwise return names
288 that are relative to the specified directory.
289 If MATCH is non-nil, mention only file names that match the regexp MATCH.
290 If NOSORT is dummy for compatibility.
291 \[poe-18.el; EMACS 19 emulating function]"
292 (si:directory-files directory full match))
295 ;;; @ Display Features
298 ;;; Imported from Emacs 19.30.
299 (defun force-mode-line-update (&optional all)
300 "Force the mode-line of the current buffer to be redisplayed.
301 With optional non-nil ALL, force redisplay of all mode-lines.
302 \[poe-18.el; Emacs 19 emulating function]"
303 (if all (save-excursion (set-buffer (other-buffer))))
304 (set-buffer-modified-p (buffer-modified-p)))
310 (cond ((boundp 'NEMACS)
311 (defvar emu:available-face-attribute-alist
313 ;;(bold . inversed-region)
314 (italic . underlined-region)
315 (underline . underlined-region)
318 ;; by YAMATE Keiichirou 1994/10/28
319 (defun attribute-add-narrow-attribute (attr from to)
320 (or (consp (symbol-value attr))
322 (let* ((attr-value (symbol-value attr))
323 (len (car attr-value))
326 (while (and (< posfrom len)
327 (> from (nth posfrom attr-value)))
328 (setq posfrom (1+ posfrom)))
330 (while (and (< posto len)
331 (> to (nth posto attr-value)))
332 (setq posto (1+ posto)))
333 (if (= posto posfrom)
334 (if (= (% posto 2) 1)
336 (= to (nth posto attr-value)))
337 (set-marker (nth posto attr-value) from)
338 (setcdr (nthcdr (1- posfrom) attr-value)
339 (cons (set-marker-type (set-marker (make-marker)
342 (cons (set-marker-type
343 (set-marker (make-marker)
346 (nthcdr posto attr-value))))
347 (setcar attr-value (+ len 2))))
348 (if (= (% posfrom 2) 0)
349 (setq posfrom (1- posfrom))
350 (set-marker (nth posfrom attr-value) from))
351 (if (= (% posto 2) 0)
353 (setq posto (1- posto))
354 (set-marker (nth posto attr-value) to))
355 (setcdr (nthcdr posfrom attr-value)
356 (nthcdr posto attr-value)))))
358 (defalias 'make-overlay 'cons)
360 (defun overlay-put (overlay prop value)
361 (let ((ret (and (eq prop 'face)
362 (assq value emu:available-face-attribute-alist))))
364 (attribute-add-narrow-attribute (cdr ret)
365 (car overlay)(cdr overlay))))))
367 (defun make-overlay (beg end &optional buffer type))
368 (defun overlay-put (overlay prop value))))
370 (defun overlay-buffer (overlay))
376 (defun-maybe generate-new-buffer-name (name &optional ignore)
377 "Return a string that is the name of no existing buffer based on NAME.
378 If there is no live buffer named NAME, then return NAME.
379 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
380 until an unused name is found, and then return that name.
381 Optional second argument IGNORE specifies a name that is okay to use
382 \(if it is in the sequence to be tried)
383 even if a buffer with that name exists."
384 (if (get-buffer name)
386 (while (get-buffer (setq new (format "%s<%d>" name n)))
391 (or (fboundp 'si:mark)
392 (fset 'si:mark (symbol-function 'mark)))
393 (defun mark (&optional force)
400 ;;; poe-18.el ends here