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]"
66 (if (equal elt (car list))
70 (while (and rrest (not (equal elt (car rrest))))
73 (setcdr rest (cdr rrest))
76 (defun member (elt list)
77 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
78 The value is actually the tail of LIST whose car is ELT.
79 \[poe-18.el; EMACS 19 emulating function]"
80 (while (and list (not (equal elt (car list))))
81 (setq list (cdr list)))
85 ;;; @@ buffer-local variable
88 (defun default-boundp (symbol)
89 "Return t if SYMBOL has a non-void default value.
90 This is the value that is seen in buffers that do not have their own values
92 \[poe-18.el; EMACS 19 emulating function]"
95 (default-value symbol)
100 ;;; @@ environment variable
103 (autoload 'setenv "env"
104 "Set the value of the environment variable named VARIABLE to VALUE.
105 VARIABLE should be a string. VALUE is optional; if not provided or is
106 `nil', the environment variable VARIABLE will be removed.
107 This function works by modifying `process-environment'."
114 (defun defalias (sym newdef)
115 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
116 Associates the function with the current load file, if any."
119 (defun byte-code-function-p (exp)
120 "T if OBJECT is a byte-compiled function object.
121 \[poe-18.el; EMACS 19 emulating function]"
123 (let ((rest (cdr (cdr exp)))
125 (if (stringp (car rest))
126 (setq rest (cdr rest)))
129 (setq elt (car rest))
131 (eq (car elt) 'byte-code))
133 (setq rest (cdr rest)))))))
136 ;;; @ Compilation Features
139 ;;; emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
140 ;;; (note: jwz's original compiler and XEmacs compiler have some more
141 ;;; macros; they are "nuked" by rms in FSF version.)
143 (put 'inline 'lisp-indent-hook 0)
144 (defalias-maybe 'inline 'progn)
146 (put 'defsubst 'lisp-indent-hook 'defun)
147 (put 'defsubst 'edebug-form-spec 'defun)
148 (defmacro-maybe defsubst (name arglist &rest body)
149 "Define an inline function. The syntax is just like that of `defun'.
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 (cons 'defun (cons name (cons arglist body))))
156 (defun-maybe make-obsolete (fn new)
157 "Make the byte-compiler warn that FUNCTION is obsolete.
158 The warning will say that NEW should be used instead.
159 If NEW is a string, that is the `use instead' message.
161 This emulating function does nothing because old \(v18\) compiler does not
162 support this feature.
163 \[poe-18.el; EMACS 19 emulating function]"
164 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
167 (defun-maybe make-obsolete-variable (var new)
168 "Make the byte-compiler warn that VARIABLE is obsolete,
169 and NEW should be used instead. If NEW is a string, then that is the
170 `use instead' message.
172 This emulating function does nothing because old \(v18\) compiler does not
173 support this feature.
174 \[poe-18.el; EMACS 19 emulating function]"
175 (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
178 (put 'dont-compile 'lisp-indent-hook 0)
179 (defmacro-maybe dont-compile (&rest body)
180 "Like `progn', but the body always runs interpreted \(not compiled\).
181 If you think you need this, you're probably making a mistake somewhere.
182 \[poe-18.el; EMACS 19 emulating macro]"
183 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
185 (put 'eval-when-compile 'lisp-indent-hook 0)
186 (defmacro-maybe eval-when-compile (&rest body)
187 "Like progn, but evaluates the body at compile-time.
189 This emulating macro does not do compile-time evaluation at all because
190 of the limitation of old \(v18\) compiler.
191 \[poe-18.el; EMACS 19 emulating macro]"
194 (put 'eval-and-compile 'lisp-indent-hook 0)
195 (defmacro-maybe eval-and-compile (&rest body)
196 "Like progn, but evaluates the body at compile-time as well as at load-time.
198 This emulating macro does not do compile-time evaluation at all because
199 of the limitation of old \(v18\) compiler.
200 \[poe-18.el; EMACS 19 emulating macro]"
207 (defun set-text-properties (start end properties &optional object))
209 (defun remove-text-properties (start end properties &optional object))
215 (defun make-directory-internal (dirname)
216 "Create a directory. One argument, a file name string.
217 \[poe-18.el; EMACS 19 emulating function]"
218 (let ((dir (expand-file-name dirname)))
219 (if (file-exists-p dir)
220 (error "Creating directory: %s is already exist" dir)
221 (call-process "mkdir" nil nil nil dir))))
223 (defun make-directory (dir &optional parents)
224 "Create the directory DIR and any nonexistent parent dirs.
225 The second (optional) argument PARENTS says whether
226 to create parent directories if they don't exist.
227 \[poe-18.el; EMACS 19 emulating function]"
228 (let ((len (length dir))
231 (while (and (< p len) (string-match "[^/]*/?" dir p))
232 (setq p1 (match-end 0))
235 (setq path (substring dir 0 p1))
236 (if (not (file-directory-p path))
237 (cond ((file-exists-p path)
238 (error "Creating directory: %s is not directory" path))
240 (error "Creating directory: %s is not exist" path))
242 (make-directory-internal path))))
244 (make-directory-internal dir)))
246 ;; Imported from files.el of EMACS 19.33.
247 (defun parse-colon-path (cd-path)
248 "Explode a colon-separated list of paths into a string list."
250 (let (cd-prefix cd-list (cd-start 0) cd-colon)
251 (setq cd-path (concat cd-path path-separator))
252 (while (setq cd-colon (string-match path-separator cd-path cd-start))
255 (list (if (= cd-start cd-colon)
257 (substitute-in-file-name
258 (file-name-as-directory
259 (substring cd-path cd-start cd-colon)))))))
260 (setq cd-start (+ cd-colon 1)))
263 ;; Imported from files.el of EMACS 19.33.
264 (defun file-relative-name (filename &optional directory)
265 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
266 (setq filename (expand-file-name filename)
267 directory (file-name-as-directory (expand-file-name
268 (or directory default-directory))))
270 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
271 (setq directory (file-name-directory (substring directory 0 -1))
272 ancestor (concat "../" ancestor)))
273 (concat ancestor (substring filename (match-end 0)))))
275 (or (fboundp 'si:directory-files)
276 (fset 'si:directory-files (symbol-function 'directory-files)))
277 (defun directory-files (directory &optional full match nosort)
278 "Return a list of names of files in DIRECTORY.
279 There are three optional arguments:
280 If FULL is non-nil, return absolute file names. Otherwise return names
281 that are relative to the specified directory.
282 If MATCH is non-nil, mention only file names that match the regexp MATCH.
283 If NOSORT is dummy for compatibility.
284 \[poe-18.el; EMACS 19 emulating function]"
285 (si:directory-files directory full match))
288 ;;; @ Display Features
291 ;;; Imported from Emacs 19.30.
292 (defun force-mode-line-update (&optional all)
293 "Force the mode-line of the current buffer to be redisplayed.
294 With optional non-nil ALL, force redisplay of all mode-lines.
295 \[poe-18.el; Emacs 19 emulating function]"
296 (if all (save-excursion (set-buffer (other-buffer))))
297 (set-buffer-modified-p (buffer-modified-p)))
303 (cond ((boundp 'NEMACS)
304 (defvar emu:available-face-attribute-alist
306 ;;(bold . inversed-region)
307 (italic . underlined-region)
308 (underline . underlined-region)
311 ;; by YAMATE Keiichirou 1994/10/28
312 (defun attribute-add-narrow-attribute (attr from to)
313 (or (consp (symbol-value attr))
315 (let* ((attr-value (symbol-value attr))
316 (len (car attr-value))
319 (while (and (< posfrom len)
320 (> from (nth posfrom attr-value)))
321 (setq posfrom (1+ posfrom)))
323 (while (and (< posto len)
324 (> to (nth posto attr-value)))
325 (setq posto (1+ posto)))
326 (if (= posto posfrom)
327 (if (= (% posto 2) 1)
329 (= to (nth posto attr-value)))
330 (set-marker (nth posto attr-value) from)
331 (setcdr (nthcdr (1- posfrom) attr-value)
332 (cons (set-marker-type (set-marker (make-marker)
335 (cons (set-marker-type
336 (set-marker (make-marker)
339 (nthcdr posto attr-value))))
340 (setcar attr-value (+ len 2))))
341 (if (= (% posfrom 2) 0)
342 (setq posfrom (1- posfrom))
343 (set-marker (nth posfrom attr-value) from))
344 (if (= (% posto 2) 0)
346 (setq posto (1- posto))
347 (set-marker (nth posto attr-value) to))
348 (setcdr (nthcdr posfrom attr-value)
349 (nthcdr posto attr-value)))))
351 (defalias 'make-overlay 'cons)
353 (defun overlay-put (overlay prop value)
354 (let ((ret (and (eq prop 'face)
355 (assq value emu:available-face-attribute-alist))))
357 (attribute-add-narrow-attribute (cdr ret)
358 (car overlay)(cdr overlay))))))
360 (defun make-overlay (beg end &optional buffer type))
361 (defun overlay-put (overlay prop value))))
363 (defun overlay-buffer (overlay))
369 (defun-maybe generate-new-buffer-name (name &optional ignore)
370 "Return a string that is the name of no existing buffer based on NAME.
371 If there is no live buffer named NAME, then return NAME.
372 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
373 until an unused name is found, and then return that name.
374 Optional second argument IGNORE specifies a name that is okay to use
375 \(if it is in the sequence to be tried)
376 even if a buffer with that name exists."
377 (if (get-buffer name)
379 (while (get-buffer (setq new (format "%s<%d>" name n)))
384 (or (fboundp 'si:mark)
385 (fset 'si:mark (symbol-function 'mark)))
386 (defun mark (&optional force)
393 ;;; poe-18.el ends here