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 (autoload 'setenv "env"
28 "Set the value of the environment variable named VARIABLE to VALUE.
29 VARIABLE should be a string. VALUE is optional; if not provided or is
30 `nil', the environment variable VARIABLE will be removed.
31 This function works by modifying `process-environment'."
34 (defvar data-directory exec-directory)
40 (defvar buffer-undo-list nil)
46 ;; These function are imported from EMACS 19.28.
47 (defun add-hook (hook function &optional append)
48 "Add to the value of HOOK the function FUNCTION.
49 FUNCTION is not added if already present.
50 FUNCTION is added (if necessary) at the beginning of the hook list
51 unless the optional argument APPEND is non-nil, in which case
52 FUNCTION is added at the end.
54 HOOK should be a symbol, and FUNCTION may be any valid function. If
55 HOOK is void, it is first set to nil. If HOOK's value is a single
56 function, it is changed to a list of functions.
57 \[poe-18.el; EMACS 19 emulating function]"
61 ;; If the hook value is a single function, turn it into a list.
62 (let ((old (symbol-value hook)))
63 (if (or (not (listp old))
64 (eq (car old) 'lambda))
67 (or (if (consp function)
68 ;; Clever way to tell whether a given lambda-expression
69 ;; is equal to anything in the hook.
70 (let ((tail (assoc (cdr function) (symbol-value hook))))
73 (memq function (symbol-value hook))
77 (nconc (symbol-value hook) (list function))
78 (cons function (symbol-value hook))
82 (defun remove-hook (hook function)
83 "Remove from the value of HOOK the function FUNCTION.
84 HOOK should be a symbol, and FUNCTION may be any valid function. If
85 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
86 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
87 \[poe-18.el; EMACS 19 emulating function]"
88 (if (or (not (boundp hook)) ;unbound symbol, or
89 (null (symbol-value hook)) ;value is nil, or
90 (null function)) ;function is nil, then
92 (let ((hook-value (symbol-value hook)))
93 (if (consp hook-value)
94 (setq hook-value (delete function hook-value))
95 (if (equal hook-value function)
105 (defun member (elt list)
106 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
107 The value is actually the tail of LIST whose car is ELT.
108 \[poe-18.el; EMACS 19 emulating function]"
109 (while (and list (not (equal elt (car list))))
110 (setq list (cdr list)))
113 (defun delete (elt list)
114 "Delete by side effect any occurrences of ELT as a member of LIST.
115 The modified LIST is returned. Comparison is done with `equal'.
116 If the first member of LIST is ELT, deleting it is not a side effect;
117 it is simply using a different list.
118 Therefore, write `(setq foo (delete element foo))'
119 to be sure of changing the value of `foo'.
120 \[poe-18.el; EMACS 19 emulating function]"
121 (if (equal elt (car list))
126 (while (and rrest (not (equal elt (car rrest))))
130 (rplacd rest (cdr rrest))
137 (defun defalias (sym newdef)
138 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
139 Associates the function with the current load file, if any.
140 \[poe-18.el; EMACS 19 emulating function]"
144 (defun byte-code-function-p (exp)
145 "T if OBJECT is a byte-compiled function object.
146 \[poe-18.el; EMACS 19 emulating function]"
148 (let* ((rest (cdr (cdr exp))) elt)
149 (if (stringp (car rest))
150 (setq rest (cdr rest))
154 (setq elt (car rest))
155 (if (and (consp elt)(eq (car elt) 'byte-code))
158 (setq rest (cdr rest))
162 (defmacro-maybe defsubst (name arglist &rest body)
163 "Define an inline function. The syntax is just like that of `defun'."
164 (cons 'defun (cons name (cons arglist body)))
171 (defun make-directory-internal (dirname)
172 "Create a directory. One argument, a file name string.
173 \[poe-18.el; EMACS 19 emulating function]"
174 (if (file-exists-p dirname)
175 (error "Creating directory: %s is already exist" dirname)
176 (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
177 (error "Creating directory: no such file or directory, %s" dirname)
180 (defun make-directory (dir &optional parents)
181 "Create the directory DIR and any nonexistent parent dirs.
182 The second (optional) argument PARENTS says whether
183 to create parent directories if they don't exist.
184 \[poe-18.el; EMACS 19 emulating function]"
185 (let ((len (length dir))
188 (while (and (< p len) (string-match "[^/]*/?" dir p))
189 (setq p1 (match-end 0))
193 (setq path (substring dir 0 p1))
194 (if (not (file-directory-p path))
195 (cond ((file-exists-p path)
196 (error "Creating directory: %s is not directory" path)
199 (error "Creating directory: %s is not exist" path)
202 (make-directory-internal path)
207 (make-directory-internal dir)
210 ;; Imported from files.el of EMACS 19.33.
211 (defun parse-colon-path (cd-path)
212 "Explode a colon-separated list of paths into a string list."
214 (let (cd-prefix cd-list (cd-start 0) cd-colon)
215 (setq cd-path (concat cd-path path-separator))
216 (while (setq cd-colon (string-match path-separator cd-path cd-start))
219 (list (if (= cd-start cd-colon)
221 (substitute-in-file-name
222 (file-name-as-directory
223 (substring cd-path cd-start cd-colon)))))))
224 (setq cd-start (+ cd-colon 1)))
227 ;; Imported from files.el of EMACS 19.33.
228 (defun file-relative-name (filename &optional directory)
229 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
230 (setq filename (expand-file-name filename)
231 directory (file-name-as-directory (expand-file-name
232 (or directory default-directory))))
234 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
235 (setq directory (file-name-directory (substring directory 0 -1))
236 ancestor (concat "../" ancestor)))
237 (concat ancestor (substring filename (match-end 0)))))
239 (or (fboundp 'si:directory-files)
240 (fset 'si:directory-files (symbol-function 'directory-files)))
241 (defun directory-files (directory &optional full match nosort)
242 "Return a list of names of files in DIRECTORY.
243 There are three optional arguments:
244 If FULL is non-nil, return absolute file names. Otherwise return names
245 that are relative to the specified directory.
246 If MATCH is non-nil, mention only file names that match the regexp MATCH.
247 If NOSORT is dummy for compatibility.
248 \[poe-18.el; EMACS 19 emulating function]"
249 (si:directory-files directory full match)
256 (or (fboundp 'si:mark)
257 (fset 'si:mark (symbol-function 'mark)))
258 (defun mark (&optional force)
266 ;;; Imported from Emacs 19.30.
267 (defun force-mode-line-update (&optional all)
268 "Force the mode-line of the current buffer to be redisplayed.
269 With optional non-nil ALL, force redisplay of all mode-lines.
270 \[poe-18.el; Emacs 19 emulating function]"
271 (if all (save-excursion (set-buffer (other-buffer))))
272 (set-buffer-modified-p (buffer-modified-p)))
278 (defun overlay-buffer (overlay))
284 (defun remove-text-properties (start end properties &optional object))
287 ;;; @@ visible/invisible
290 (defmacro enable-invisible ()
293 (make-local-variable 'original-selective-display)
294 (setq original-selective-display selective-display)
295 (setq selective-display t)
298 (defmacro end-of-invisible ()
299 (` (setq selective-display
300 (if (boundp 'original-selective-display)
301 original-selective-display))
304 (defun invisible-region (start end)
305 (let ((buffer-read-only nil) ;Okay even if write protected.
306 (modp (buffer-modified-p)))
309 (eq (following-char) ?\n)
314 (subst-char-in-region start end ?\n ?\^M t)
315 (set-buffer-modified-p modp)
318 (defun visible-region (start end)
319 (let ((buffer-read-only nil) ;Okay even if write protected.
320 (modp (buffer-modified-p)))
322 (subst-char-in-region start end ?\^M ?\n t)
323 (set-buffer-modified-p modp)
326 (defun invisible-p (pos)
329 (eq (following-char) ?\^M)
332 (defun next-visible-point (pos)
336 (if (eq (following-char) ?\n)
346 (defun char-list-to-string (char-list)
347 "Convert list of character CHAR-LIST to string. [poe-18.el]"
348 (mapconcat (function char-to-string) char-list "")
355 (defun-maybe generate-new-buffer-name (name &optional ignore)
356 "Return a string that is the name of no existing buffer based on NAME.
357 If there is no live buffer named NAME, then return NAME.
358 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
359 until an unused name is found, and then return that name.
360 Optional second argument IGNORE specifies a name that is okay to use
361 \(if it is in the sequence to be tried)
362 even if a buffer with that name exists."
363 (if (get-buffer name)
365 (while (get-buffer (setq new (format "%s<%d>" name n)))
376 ;;; poe-18.el ends here