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 (let ((dir (expand-file-name dirname)))
147 (if (file-exists-p dir)
148 (error "Creating directory: %s is already exist" dir)
149 (call-process "mkdir" nil nil nil dir))))
151 (defun make-directory (dir &optional parents)
152 "Create the directory DIR and any nonexistent parent dirs.
153 The second (optional) argument PARENTS says whether
154 to create parent directories if they don't exist.
155 \[poe-18.el; EMACS 19 emulating function]"
156 (let ((len (length dir))
159 (while (and (< p len) (string-match "[^/]*/?" dir p))
160 (setq p1 (match-end 0))
164 (setq path (substring dir 0 p1))
165 (if (not (file-directory-p path))
166 (cond ((file-exists-p path)
167 (error "Creating directory: %s is not directory" path)
170 (error "Creating directory: %s is not exist" path)
173 (make-directory-internal path)
178 (make-directory-internal dir)
181 ;; Imported from files.el of EMACS 19.33.
182 (defun parse-colon-path (cd-path)
183 "Explode a colon-separated list of paths into a string list."
185 (let (cd-prefix cd-list (cd-start 0) cd-colon)
186 (setq cd-path (concat cd-path path-separator))
187 (while (setq cd-colon (string-match path-separator cd-path cd-start))
190 (list (if (= cd-start cd-colon)
192 (substitute-in-file-name
193 (file-name-as-directory
194 (substring cd-path cd-start cd-colon)))))))
195 (setq cd-start (+ cd-colon 1)))
198 ;; Imported from files.el of EMACS 19.33.
199 (defun file-relative-name (filename &optional directory)
200 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
201 (setq filename (expand-file-name filename)
202 directory (file-name-as-directory (expand-file-name
203 (or directory default-directory))))
205 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
206 (setq directory (file-name-directory (substring directory 0 -1))
207 ancestor (concat "../" ancestor)))
208 (concat ancestor (substring filename (match-end 0)))))
210 (or (fboundp 'si:directory-files)
211 (fset 'si:directory-files (symbol-function 'directory-files)))
212 (defun directory-files (directory &optional full match nosort)
213 "Return a list of names of files in DIRECTORY.
214 There are three optional arguments:
215 If FULL is non-nil, return absolute file names. Otherwise return names
216 that are relative to the specified directory.
217 If MATCH is non-nil, mention only file names that match the regexp MATCH.
218 If NOSORT is dummy for compatibility.
219 \[poe-18.el; EMACS 19 emulating function]"
220 (si:directory-files directory full match)
224 ;;; @ Display Features
227 ;;; Imported from Emacs 19.30.
228 (defun force-mode-line-update (&optional all)
229 "Force the mode-line of the current buffer to be redisplayed.
230 With optional non-nil ALL, force redisplay of all mode-lines.
231 \[poe-18.el; Emacs 19 emulating function]"
232 (if all (save-excursion (set-buffer (other-buffer))))
233 (set-buffer-modified-p (buffer-modified-p)))
239 (cond ((boundp 'NEMACS)
240 (defvar emu:available-face-attribute-alist
242 ;;(bold . inversed-region)
243 (italic . underlined-region)
244 (underline . underlined-region)
247 ;; by YAMATE Keiichirou 1994/10/28
248 (defun attribute-add-narrow-attribute (attr from to)
249 (or (consp (symbol-value attr))
251 (let* ((attr-value (symbol-value attr))
252 (len (car attr-value))
255 (while (and (< posfrom len)
256 (> from (nth posfrom attr-value)))
257 (setq posfrom (1+ posfrom)))
259 (while (and (< posto len)
260 (> to (nth posto attr-value)))
261 (setq posto (1+ posto)))
262 (if (= posto posfrom)
263 (if (= (% posto 2) 1)
265 (= to (nth posto attr-value)))
266 (set-marker (nth posto attr-value) from)
267 (setcdr (nthcdr (1- posfrom) attr-value)
268 (cons (set-marker-type (set-marker (make-marker)
271 (cons (set-marker-type
272 (set-marker (make-marker)
275 (nthcdr posto attr-value))))
276 (setcar attr-value (+ len 2))))
277 (if (= (% posfrom 2) 0)
278 (setq posfrom (1- posfrom))
279 (set-marker (nth posfrom attr-value) from))
280 (if (= (% posto 2) 0)
282 (setq posto (1- posto))
283 (set-marker (nth posto attr-value) to))
284 (setcdr (nthcdr posfrom attr-value)
285 (nthcdr posto attr-value)))))
287 (defalias 'make-overlay 'cons)
289 (defun overlay-put (overlay prop value)
290 (let ((ret (and (eq prop 'face)
291 (assq value emu:available-face-attribute-alist)
294 (attribute-add-narrow-attribute (cdr ret)
295 (car overlay)(cdr overlay))
299 (defun make-overlay (beg end &optional buffer type))
300 (defun overlay-put (overlay prop value))
303 (defun overlay-buffer (overlay))
309 (defun-maybe generate-new-buffer-name (name &optional ignore)
310 "Return a string that is the name of no existing buffer based on NAME.
311 If there is no live buffer named NAME, then return NAME.
312 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
313 until an unused name is found, and then return that name.
314 Optional second argument IGNORE specifies a name that is okay to use
315 \(if it is in the sequence to be tried)
316 even if a buffer with that name exists."
317 (if (get-buffer name)
319 (while (get-buffer (setq new (format "%s<%d>" name n)))
324 (or (fboundp 'si:mark)
325 (fset 'si:mark (symbol-function 'mark)))
326 (defun mark (&optional force)
334 ;; These function are imported from EMACS 19.28.
335 (defun add-hook (hook function &optional append)
336 "Add to the value of HOOK the function FUNCTION.
337 FUNCTION is not added if already present.
338 FUNCTION is added (if necessary) at the beginning of the hook list
339 unless the optional argument APPEND is non-nil, in which case
340 FUNCTION is added at the end.
342 HOOK should be a symbol, and FUNCTION may be any valid function. If
343 HOOK is void, it is first set to nil. If HOOK's value is a single
344 function, it is changed to a list of functions.
345 \[poe-18.el; EMACS 19 emulating function]"
349 ;; If the hook value is a single function, turn it into a list.
350 (let ((old (symbol-value hook)))
351 (if (or (not (listp old))
352 (eq (car old) 'lambda))
353 (set hook (list old))
355 (or (if (consp function)
356 ;; Clever way to tell whether a given lambda-expression
357 ;; is equal to anything in the hook.
358 (let ((tail (assoc (cdr function) (symbol-value hook))))
359 (equal function tail)
361 (memq function (symbol-value hook))
365 (nconc (symbol-value hook) (list function))
366 (cons function (symbol-value hook))
370 (defun remove-hook (hook function)
371 "Remove from the value of HOOK the function FUNCTION.
372 HOOK should be a symbol, and FUNCTION may be any valid function. If
373 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
374 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
375 \[poe-18.el; EMACS 19 emulating function]"
376 (if (or (not (boundp hook)) ;unbound symbol, or
377 (null (symbol-value hook)) ;value is nil, or
378 (null function)) ;function is nil, then
380 (let ((hook-value (symbol-value hook)))
381 (if (consp hook-value)
382 (setq hook-value (delete function hook-value))
383 (if (equal hook-value function)
384 (setq hook-value nil)
386 (set hook hook-value)
395 ;;; poe-18.el ends here