1 ;;; emu-18.el --- emu API implementation for Emacs 18.*
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-18.el,v 7.33 1997/04/05 06:44:01 morioka Exp $
7 ;; Keywords: emulation, compatibility
9 ;; This file is part of emu.
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 (autoload 'setenv "env"
29 "Set the value of the environment variable named VARIABLE to VALUE.
30 VARIABLE should be a string. VALUE is optional; if not provided or is
31 `nil', the environment variable VARIABLE will be removed.
32 This function works by modifying `process-environment'."
35 (defvar data-directory exec-directory)
41 (defvar buffer-undo-list nil)
47 ;; These function are imported from EMACS 19.28.
48 (defun add-hook (hook function &optional append)
49 "Add to the value of HOOK the function FUNCTION.
50 FUNCTION is not added if already present.
51 FUNCTION is added (if necessary) at the beginning of the hook list
52 unless the optional argument APPEND is non-nil, in which case
53 FUNCTION is added at the end.
55 HOOK should be a symbol, and FUNCTION may be any valid function. If
56 HOOK is void, it is first set to nil. If HOOK's value is a single
57 function, it is changed to a list of functions.
58 \[emu-18.el; EMACS 19 emulating function]"
62 ;; If the hook value is a single function, turn it into a list.
63 (let ((old (symbol-value hook)))
64 (if (or (not (listp old))
65 (eq (car old) 'lambda))
68 (or (if (consp function)
69 ;; Clever way to tell whether a given lambda-expression
70 ;; is equal to anything in the hook.
71 (let ((tail (assoc (cdr function) (symbol-value hook))))
74 (memq function (symbol-value hook))
78 (nconc (symbol-value hook) (list function))
79 (cons function (symbol-value hook))
83 (defun remove-hook (hook function)
84 "Remove from the value of HOOK the function FUNCTION.
85 HOOK should be a symbol, and FUNCTION may be any valid function. If
86 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
87 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
88 \[emu-18.el; EMACS 19 emulating function]"
89 (if (or (not (boundp hook)) ;unbound symbol, or
90 (null (symbol-value hook)) ;value is nil, or
91 (null function)) ;function is nil, then
93 (let ((hook-value (symbol-value hook)))
94 (if (consp hook-value)
95 (setq hook-value (delete function hook-value))
96 (if (equal hook-value function)
106 (defun member (elt list)
107 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
108 The value is actually the tail of LIST whose car is ELT.
109 \[emu-18.el; EMACS 19 emulating function]"
110 (while (and list (not (equal elt (car list))))
111 (setq list (cdr list)))
114 (defun delete (elt list)
115 "Delete by side effect any occurrences of ELT as a member of LIST.
116 The modified LIST is returned. Comparison is done with `equal'.
117 If the first member of LIST is ELT, deleting it is not a side effect;
118 it is simply using a different list.
119 Therefore, write `(setq foo (delete element foo))'
120 to be sure of changing the value of `foo'.
121 \[emu-18.el; EMACS 19 emulating function]"
122 (if (equal elt (car list))
127 (while (and rrest (not (equal elt (car rrest))))
131 (rplacd rest (cdr rrest))
138 (defun defalias (sym newdef)
139 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
140 Associates the function with the current load file, if any.
141 \[emu-18.el; EMACS 19 emulating function]"
145 (defun byte-code-function-p (exp)
146 "T if OBJECT is a byte-compiled function object.
147 \[emu-18.el; EMACS 19 emulating function]"
149 (let* ((rest (cdr (cdr exp))) elt)
150 (if (stringp (car rest))
151 (setq rest (cdr rest))
155 (setq elt (car rest))
156 (if (and (consp elt)(eq (car elt) 'byte-code))
159 (setq rest (cdr rest))
163 (defmacro-maybe defsubst (name arglist &rest body)
164 "Define an inline function. The syntax is just like that of `defun'."
165 (cons 'defun (cons name (cons arglist body)))
172 (defun make-directory-internal (dirname)
173 "Create a directory. One argument, a file name string.
174 \[emu-18.el; EMACS 19 emulating function]"
175 (if (file-exists-p dirname)
176 (error "Creating directory: %s is already exist" dirname)
177 (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
178 (error "Creating directory: no such file or directory, %s" dirname)
181 (defun make-directory (dir &optional parents)
182 "Create the directory DIR and any nonexistent parent dirs.
183 The second (optional) argument PARENTS says whether
184 to create parent directories if they don't exist.
185 \[emu-18.el; EMACS 19 emulating function]"
186 (let ((len (length dir))
189 (while (and (< p len) (string-match "[^/]*/?" dir p))
190 (setq p1 (match-end 0))
194 (setq path (substring dir 0 p1))
195 (if (not (file-directory-p path))
196 (cond ((file-exists-p path)
197 (error "Creating directory: %s is not directory" path)
200 (error "Creating directory: %s is not exist" path)
203 (make-directory-internal path)
208 (make-directory-internal dir)
211 ;; Imported from files.el of EMACS 19.33.
212 (defun parse-colon-path (cd-path)
213 "Explode a colon-separated list of paths into a string list."
215 (let (cd-prefix cd-list (cd-start 0) cd-colon)
216 (setq cd-path (concat cd-path path-separator))
217 (while (setq cd-colon (string-match path-separator cd-path cd-start))
220 (list (if (= cd-start cd-colon)
222 (substitute-in-file-name
223 (file-name-as-directory
224 (substring cd-path cd-start cd-colon)))))))
225 (setq cd-start (+ cd-colon 1)))
228 ;; Imported from files.el of EMACS 19.33.
229 (defun file-relative-name (filename &optional directory)
230 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
231 (setq filename (expand-file-name filename)
232 directory (file-name-as-directory (expand-file-name
233 (or directory default-directory))))
235 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
236 (setq directory (file-name-directory (substring directory 0 -1))
237 ancestor (concat "../" ancestor)))
238 (concat ancestor (substring filename (match-end 0)))))
240 (or (fboundp 'si:directory-files)
241 (fset 'si:directory-files (symbol-function 'directory-files)))
242 (defun directory-files (directory &optional full match nosort)
243 "Return a list of names of files in DIRECTORY.
244 There are three optional arguments:
245 If FULL is non-nil, return absolute file names. Otherwise return names
246 that are relative to the specified directory.
247 If MATCH is non-nil, mention only file names that match the regexp MATCH.
248 If NOSORT is dummy for compatibility.
249 \[emu-18.el; EMACS 19 emulating function]"
250 (si:directory-files directory full match)
257 (or (fboundp 'si:mark)
258 (fset 'si:mark (symbol-function 'mark)))
259 (defun mark (&optional force)
267 ;;; Imported from Emacs 19.30.
268 (defun force-mode-line-update (&optional all)
269 "Force the mode-line of the current buffer to be redisplayed.
270 With optional non-nil ALL, force redisplay of all mode-lines.
271 \[emu-18.el; Emacs 19 emulating function]"
272 (if all (save-excursion (set-buffer (other-buffer))))
273 (set-buffer-modified-p (buffer-modified-p)))
279 (defun overlay-buffer (overlay))
285 (defun remove-text-properties (start end properties &optional object))
288 ;;; @@ visible/invisible
291 (defmacro enable-invisible ()
294 (make-local-variable 'original-selective-display)
295 (setq original-selective-display selective-display)
296 (setq selective-display t)
299 (defmacro end-of-invisible ()
300 (` (setq selective-display
301 (if (boundp 'original-selective-display)
302 original-selective-display))
305 (defun invisible-region (start end)
306 (let ((buffer-read-only nil) ;Okay even if write protected.
307 (modp (buffer-modified-p)))
310 (eq (following-char) ?\n)
315 (subst-char-in-region start end ?\n ?\^M t)
316 (set-buffer-modified-p modp)
319 (defun visible-region (start end)
320 (let ((buffer-read-only nil) ;Okay even if write protected.
321 (modp (buffer-modified-p)))
323 (subst-char-in-region start end ?\^M ?\n t)
324 (set-buffer-modified-p modp)
327 (defun invisible-p (pos)
330 (eq (following-char) ?\^M)
333 (defun next-visible-point (pos)
337 (if (eq (following-char) ?\n)
347 (defvar mouse-button-1 nil)
348 (defvar mouse-button-2 nil)
349 (defvar mouse-button-3 nil)
355 (defun char-list-to-string (char-list)
356 "Convert list of character CHAR-LIST to string. [emu-18.el]"
357 (mapconcat (function char-to-string) char-list "")
366 ;;; emu-18.el ends here