1 ;;; poe-18.el --- poe API implementation for Emacs 18.*
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
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 GNU Emacs; 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 (defvar-maybe data-directory exec-directory)
33 (defvar-maybe buffer-undo-list nil)
42 (defun delete (elt list)
43 "Delete by side effect any occurrences of ELT as a member of LIST.
44 The modified LIST is returned. Comparison is done with `equal'.
45 If the first member of LIST is ELT, deleting it is not a side effect;
46 it is simply using a different list.
47 Therefore, write `(setq foo (delete element foo))'
48 to be sure of changing the value of `foo'.
49 \[poe-18.el; EMACS 19 emulating function]"
50 (if (equal elt (car list))
55 (while (and rrest (not (equal elt (car rrest))))
59 (rplacd rest (cdr rrest))
62 (defun member (elt list)
63 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
64 The value is actually the tail of LIST whose car is ELT.
65 \[poe-18.el; EMACS 19 emulating function]"
66 (while (and list (not (equal elt (car list))))
67 (setq list (cdr list)))
71 ;;; @@ environment variable
74 (autoload 'setenv "env"
75 "Set the value of the environment variable named VARIABLE to VALUE.
76 VARIABLE should be a string. VALUE is optional; if not provided or is
77 `nil', the environment variable VARIABLE will be removed.
78 This function works by modifying `process-environment'."
85 (defun defalias (sym newdef)
86 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
87 Associates the function with the current load file, if any.
88 \[poe-18.el; EMACS 19 emulating function]"
93 ;;; @ Compilation Features
96 (defmacro-maybe eval-and-compile (&rest body)
97 "Like `progn', but evaluates the body at compile time and at load time."
98 ;; Remember, it's magic.
101 (defun byte-code-function-p (exp)
102 "T if OBJECT is a byte-compiled function object.
103 \[poe-18.el; EMACS 19 emulating function]"
105 (let* ((rest (cdr (cdr exp))) elt)
106 (if (stringp (car rest))
107 (setq rest (cdr rest))
111 (setq elt (car rest))
112 (if (and (consp elt)(eq (car elt) 'byte-code))
115 (setq rest (cdr rest))
119 (defun-maybe make-obsolete (fn new)
120 "Make the byte-compiler warn that FUNCTION is obsolete.
121 The warning will say that NEW should be used instead.
122 If NEW is a string, that is the `use instead' message."
123 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
124 (let ((handler (get fn 'byte-compile)))
125 (if (eq 'byte-compile-obsolete handler)
126 (setcar (get fn 'byte-obsolete-info) new)
127 (put fn 'byte-obsolete-info (cons new handler))
128 (put fn 'byte-compile 'byte-compile-obsolete)))
135 (defun set-text-properties (start end properties &optional object))
137 (defun remove-text-properties (start end properties &optional object))
143 (defun make-directory-internal (dirname)
144 "Create a directory. One argument, a file name string.
145 \[poe-18.el; EMACS 19 emulating function]"
146 (if (file-exists-p dirname)
147 (error "Creating directory: %s is already exist" dirname)
148 (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
149 (error "Creating directory: no such file or directory, %s" dirname)
152 (defun make-directory (dir &optional parents)
153 "Create the directory DIR and any nonexistent parent dirs.
154 The second (optional) argument PARENTS says whether
155 to create parent directories if they don't exist.
156 \[poe-18.el; EMACS 19 emulating function]"
157 (let ((len (length dir))
160 (while (and (< p len) (string-match "[^/]*/?" dir p))
161 (setq p1 (match-end 0))
165 (setq path (substring dir 0 p1))
166 (if (not (file-directory-p path))
167 (cond ((file-exists-p path)
168 (error "Creating directory: %s is not directory" path)
171 (error "Creating directory: %s is not exist" path)
174 (make-directory-internal path)
179 (make-directory-internal dir)
182 ;; Imported from files.el of EMACS 19.33.
183 (defun parse-colon-path (cd-path)
184 "Explode a colon-separated list of paths into a string list."
186 (let (cd-prefix cd-list (cd-start 0) cd-colon)
187 (setq cd-path (concat cd-path path-separator))
188 (while (setq cd-colon (string-match path-separator cd-path cd-start))
191 (list (if (= cd-start cd-colon)
193 (substitute-in-file-name
194 (file-name-as-directory
195 (substring cd-path cd-start cd-colon)))))))
196 (setq cd-start (+ cd-colon 1)))
199 ;; Imported from files.el of EMACS 19.33.
200 (defun file-relative-name (filename &optional directory)
201 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
202 (setq filename (expand-file-name filename)
203 directory (file-name-as-directory (expand-file-name
204 (or directory default-directory))))
206 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
207 (setq directory (file-name-directory (substring directory 0 -1))
208 ancestor (concat "../" ancestor)))
209 (concat ancestor (substring filename (match-end 0)))))
211 (or (fboundp 'si:directory-files)
212 (fset 'si:directory-files (symbol-function 'directory-files)))
213 (defun directory-files (directory &optional full match nosort)
214 "Return a list of names of files in DIRECTORY.
215 There are three optional arguments:
216 If FULL is non-nil, return absolute file names. Otherwise return names
217 that are relative to the specified directory.
218 If MATCH is non-nil, mention only file names that match the regexp MATCH.
219 If NOSORT is dummy for compatibility.
220 \[poe-18.el; EMACS 19 emulating function]"
221 (si:directory-files directory full match)
225 ;;; @ Display Features
228 ;;; Imported from Emacs 19.30.
229 (defun force-mode-line-update (&optional all)
230 "Force the mode-line of the current buffer to be redisplayed.
231 With optional non-nil ALL, force redisplay of all mode-lines.
232 \[poe-18.el; Emacs 19 emulating function]"
233 (if all (save-excursion (set-buffer (other-buffer))))
234 (set-buffer-modified-p (buffer-modified-p)))
240 (cond ((boundp 'NEMACS)
241 (defvar emu:available-face-attribute-alist
243 ;;(bold . inversed-region)
244 (italic . underlined-region)
245 (underline . underlined-region)
248 ;; by YAMATE Keiichirou 1994/10/28
249 (defun attribute-add-narrow-attribute (attr from to)
250 (or (consp (symbol-value attr))
252 (let* ((attr-value (symbol-value attr))
253 (len (car attr-value))
256 (while (and (< posfrom len)
257 (> from (nth posfrom attr-value)))
258 (setq posfrom (1+ posfrom)))
260 (while (and (< posto len)
261 (> to (nth posto attr-value)))
262 (setq posto (1+ posto)))
263 (if (= posto posfrom)
264 (if (= (% posto 2) 1)
266 (= to (nth posto attr-value)))
267 (set-marker (nth posto attr-value) from)
268 (setcdr (nthcdr (1- posfrom) attr-value)
269 (cons (set-marker-type (set-marker (make-marker)
272 (cons (set-marker-type
273 (set-marker (make-marker)
276 (nthcdr posto attr-value))))
277 (setcar attr-value (+ len 2))))
278 (if (= (% posfrom 2) 0)
279 (setq posfrom (1- posfrom))
280 (set-marker (nth posfrom attr-value) from))
281 (if (= (% posto 2) 0)
283 (setq posto (1- posto))
284 (set-marker (nth posto attr-value) to))
285 (setcdr (nthcdr posfrom attr-value)
286 (nthcdr posto attr-value)))))
288 (defalias 'make-overlay 'cons)
290 (defun overlay-put (overlay prop value)
291 (let ((ret (and (eq prop 'face)
292 (assq value emu:available-face-attribute-alist)
295 (attribute-add-narrow-attribute (cdr ret)
296 (car overlay)(cdr overlay))
300 (defun make-overlay (beg end &optional buffer type))
301 (defun overlay-put (overlay prop value))
304 (defun overlay-buffer (overlay))
310 (defun-maybe generate-new-buffer-name (name &optional ignore)
311 "Return a string that is the name of no existing buffer based on NAME.
312 If there is no live buffer named NAME, then return NAME.
313 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
314 until an unused name is found, and then return that name.
315 Optional second argument IGNORE specifies a name that is okay to use
316 \(if it is in the sequence to be tried)
317 even if a buffer with that name exists."
318 (if (get-buffer name)
320 (while (get-buffer (setq new (format "%s<%d>" name n)))
325 (or (fboundp 'si:mark)
326 (fset 'si:mark (symbol-function 'mark)))
327 (defun mark (&optional force)
335 ;; These function are imported from EMACS 19.28.
336 (defun add-hook (hook function &optional append)
337 "Add to the value of HOOK the function FUNCTION.
338 FUNCTION is not added if already present.
339 FUNCTION is added (if necessary) at the beginning of the hook list
340 unless the optional argument APPEND is non-nil, in which case
341 FUNCTION is added at the end.
343 HOOK should be a symbol, and FUNCTION may be any valid function. If
344 HOOK is void, it is first set to nil. If HOOK's value is a single
345 function, it is changed to a list of functions.
346 \[poe-18.el; EMACS 19 emulating function]"
350 ;; If the hook value is a single function, turn it into a list.
351 (let ((old (symbol-value hook)))
352 (if (or (not (listp old))
353 (eq (car old) 'lambda))
354 (set hook (list old))
356 (or (if (consp function)
357 ;; Clever way to tell whether a given lambda-expression
358 ;; is equal to anything in the hook.
359 (let ((tail (assoc (cdr function) (symbol-value hook))))
360 (equal function tail)
362 (memq function (symbol-value hook))
366 (nconc (symbol-value hook) (list function))
367 (cons function (symbol-value hook))
371 (defun remove-hook (hook function)
372 "Remove from the value of HOOK the function FUNCTION.
373 HOOK should be a symbol, and FUNCTION may be any valid function. If
374 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
375 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
376 \[poe-18.el; EMACS 19 emulating function]"
377 (if (or (not (boundp hook)) ;unbound symbol, or
378 (null (symbol-value hook)) ;value is nil, or
379 (null function)) ;function is nil, then
381 (let ((hook-value (symbol-value hook)))
382 (if (consp hook-value)
383 (setq hook-value (delete function hook-value))
384 (if (equal hook-value function)
385 (setq hook-value nil)
387 (set hook hook-value)
396 ;;; poe-18.el ends here