1 ;;; emu-18.el --- EMACS 19.* emulation module for EMACS 18.*
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: emu-18.el,v 7.26 1996/09/21 16:29:25 morioka Exp $
7 ;; Keywords: emulation, compatibility
9 ;; This file is part of tl (Tiny Library).
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'."
39 (defvar buffer-undo-list nil)
45 ;; These function are imported from EMACS 19.28.
46 (defun add-hook (hook function &optional append)
47 "Add to the value of HOOK the function FUNCTION.
48 FUNCTION is not added if already present.
49 FUNCTION is added (if necessary) at the beginning of the hook list
50 unless the optional argument APPEND is non-nil, in which case
51 FUNCTION is added at the end.
53 HOOK should be a symbol, and FUNCTION may be any valid function. If
54 HOOK is void, it is first set to nil. If HOOK's value is a single
55 function, it is changed to a list of functions.
56 \[emu-18.el; EMACS 19 emulating function]"
60 ;; If the hook value is a single function, turn it into a list.
61 (let ((old (symbol-value hook)))
62 (if (or (not (listp old))
63 (eq (car old) 'lambda))
66 (or (if (consp function)
67 ;; Clever way to tell whether a given lambda-expression
68 ;; is equal to anything in the hook.
69 (let ((tail (assoc (cdr function) (symbol-value hook))))
72 (memq function (symbol-value hook))
76 (nconc (symbol-value hook) (list function))
77 (cons function (symbol-value hook))
81 (defun remove-hook (hook function)
82 "Remove from the value of HOOK the function FUNCTION.
83 HOOK should be a symbol, and FUNCTION may be any valid function. If
84 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
85 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
86 \[emu-18.el; EMACS 19 emulating function]"
87 (if (or (not (boundp hook)) ;unbound symbol, or
88 (null (symbol-value hook)) ;value is nil, or
89 (null function)) ;function is nil, then
91 (let ((hook-value (symbol-value hook)))
92 (if (consp hook-value)
93 (setq hook-value (delete function hook-value))
94 (if (equal hook-value function)
104 (defun member (elt list)
105 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
106 The value is actually the tail of LIST whose car is ELT.
107 \[emu-18.el; EMACS 19 emulating function]"
108 (while (and list (not (equal elt (car list))))
109 (setq list (cdr list)))
112 (defun delete (elt list)
113 "Delete by side effect any occurrences of ELT as a member of LIST.
114 The modified LIST is returned. Comparison is done with `equal'.
115 If the first member of LIST is ELT, deleting it is not a side effect;
116 it is simply using a different list.
117 Therefore, write `(setq foo (delete element foo))'
118 to be sure of changing the value of `foo'.
119 \[emu-18.el; EMACS 19 emulating function]"
120 (if (equal elt (car list))
125 (while (and rrest (not (equal elt (car rrest))))
129 (rplacd rest (cdr rrest))
136 (defun defalias (sym newdef)
137 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
138 Associates the function with the current load file, if any.
139 \[emu-18.el; EMACS 19 emulating function]"
143 (defun byte-code-function-p (exp)
144 "T if OBJECT is a byte-compiled function object.
145 \[emu-18.el; EMACS 19 emulating function]"
147 (let* ((rest (cdr (cdr exp))) elt)
148 (if (stringp (car rest))
149 (setq rest (cdr rest))
153 (setq elt (car rest))
154 (if (and (consp elt)(eq (car elt) 'byte-code))
157 (setq rest (cdr rest))
165 (defun make-directory-internal (dirname)
166 "Create a directory. One argument, a file name string.
167 \[emu-18.el; EMACS 19 emulating function]"
168 (if (file-exists-p dirname)
169 (error "Creating directory: %s is already exist" dirname)
170 (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
171 (error "Creating directory: no such file or directory, %s" dirname)
174 (defun make-directory (dir &optional parents)
175 "Create the directory DIR and any nonexistent parent dirs.
176 The second (optional) argument PARENTS says whether
177 to create parent directories if they don't exist.
178 \[emu-18.el; EMACS 19 emulating function]"
179 (let ((len (length dir))
182 (while (and (< p len) (string-match "[^/]*/?" dir p))
183 (setq p1 (match-end 0))
187 (setq path (substring dir 0 p1))
188 (if (not (file-directory-p path))
189 (cond ((file-exists-p path)
190 (error "Creating directory: %s is not directory" path)
193 (error "Creating directory: %s is not exist" path)
196 (make-directory-internal path)
201 (make-directory-internal dir)
204 ;; Imported from files.el of EMACS 19.33.
205 (defun parse-colon-path (cd-path)
206 "Explode a colon-separated list of paths into a string list."
208 (let (cd-prefix cd-list (cd-start 0) cd-colon)
209 (setq cd-path (concat cd-path path-separator))
210 (while (setq cd-colon (string-match path-separator cd-path cd-start))
213 (list (if (= cd-start cd-colon)
215 (substitute-in-file-name
216 (file-name-as-directory
217 (substring cd-path cd-start cd-colon)))))))
218 (setq cd-start (+ cd-colon 1)))
221 ;; Imported from files.el of EMACS 19.33.
222 (defun file-relative-name (filename &optional directory)
223 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
224 (setq filename (expand-file-name filename)
225 directory (file-name-as-directory (expand-file-name
226 (or directory default-directory))))
228 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
229 (setq directory (file-name-directory (substring directory 0 -1))
230 ancestor (concat "../" ancestor)))
231 (concat ancestor (substring filename (match-end 0)))))
233 (or (fboundp 'si:directory-files)
234 (fset 'si:directory-files (symbol-function 'directory-files)))
235 (defun directory-files (directory &optional full match nosort)
236 "Return a list of names of files in DIRECTORY.
237 There are three optional arguments:
238 If FULL is non-nil, return absolute file names. Otherwise return names
239 that are relative to the specified directory.
240 If MATCH is non-nil, mention only file names that match the regexp MATCH.
241 If NOSORT is dummy for compatibility.
242 \[emu-18.el; EMACS 19 emulating function]"
243 (si:directory-files directory full match)
250 (or (fboundp 'si:mark)
251 (fset 'si:mark (symbol-function 'mark)))
252 (defun mark (&optional force)
260 ;;; Imported from Emacs 19.30.
261 (defun force-mode-line-update (&optional all)
262 "Force the mode-line of the current buffer to be redisplayed.
263 With optional non-nil ALL, force redisplay of all mode-lines.
264 \[emu-18.el; Emacs 19 emulating function]"
265 (if all (save-excursion (set-buffer (other-buffer))))
266 (set-buffer-modified-p (buffer-modified-p)))
272 (defun tl:set-text-properties (start end properties &optional object))
273 (defun tl:add-text-properties (start end properties &optional object))
274 (defun remove-text-properties (start end properties &optional object))
275 (defun tl:overlay-buffer (overlay))
278 ;;; @@ visible/invisible
281 (defmacro enable-invisible ()
284 (make-local-variable 'original-selective-display)
285 (setq original-selective-display selective-display)
286 (setq selective-display t)
289 (defmacro end-of-invisible ()
290 (` (setq selective-display
291 (if (boundp 'original-selective-display)
292 original-selective-display))
295 (defun invisible-region (start end)
296 (let ((buffer-read-only nil) ;Okay even if write protected.
297 (modp (buffer-modified-p)))
300 (eq (following-char) ?\n)
305 (subst-char-in-region start end ?\n ?\^M t)
306 (set-buffer-modified-p modp)
309 (defun visible-region (start end)
310 (let ((buffer-read-only nil) ;Okay even if write protected.
311 (modp (buffer-modified-p)))
313 (subst-char-in-region start end ?\^M ?\n t)
314 (set-buffer-modified-p modp)
317 (defun invisible-p (pos)
320 (eq (following-char) ?\^M)
323 (defun next-visible-point (pos)
327 (if (eq (following-char) ?\n)
337 (defvar mouse-button-1 nil)
338 (defvar mouse-button-2 nil)
339 (defvar mouse-button-3 nil)
345 (defun char-list-to-string (char-list)
346 "Convert list of character CHAR-LIST to string. [emu-18.el]"
347 (mapconcat (function char-to-string) char-list "")
356 ;;; emu-18.el ends here