tm 7.45.
[elisp/apel.git] / emu-18.el
1 ;;;
2 ;;; emu-18.el --- Emacs 19.* emulation module for Emacs 18.*
3 ;;;
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
6 ;;;
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Version:
9 ;;;     $Id: emu-18.el,v 7.8 1996/02/26 01:14:28 morioka Exp $
10 ;;; Keywords: emulation, compatibility
11 ;;;
12 ;;; This file is part of tl (Tiny Library).
13 ;;;
14 ;;; This program is free software; you can redistribute it and/or
15 ;;; modify it under the terms of the GNU General Public License as
16 ;;; published by the Free Software Foundation; either version 2, or
17 ;;; (at your option) any later version.
18 ;;;
19 ;;; This program is distributed in the hope that it will be useful,
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 ;;; General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with This program.  If not, write to the Free Software
26 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;;;
28 ;;; Code:
29
30 ;;; @ hook
31 ;;;
32
33 ;; These function are imported from Emacs 19.28.
34 (defun add-hook (hook function &optional append)
35   "Add to the value of HOOK the function FUNCTION.
36 FUNCTION is not added if already present.
37 FUNCTION is added (if necessary) at the beginning of the hook list
38 unless the optional argument APPEND is non-nil, in which case
39 FUNCTION is added at the end.
40  
41 HOOK should be a symbol, and FUNCTION may be any valid function.  If
42 HOOK is void, it is first set to nil.  If HOOK's value is a single
43 function, it is changed to a list of functions.
44 \[emu-18.el; Emacs 19 emulating function]"
45   (or (boundp hook)
46       (set hook nil)
47       )
48   ;; If the hook value is a single function, turn it into a list.
49   (let ((old (symbol-value hook)))
50     (if (or (not (listp old))
51             (eq (car old) 'lambda))
52         (set hook (list old))
53       ))
54   (or (if (consp function)
55           ;; Clever way to tell whether a given lambda-expression
56           ;; is equal to anything in the hook.
57           (let ((tail (assoc (cdr function) (symbol-value hook))))
58             (equal function tail)
59             )
60         (memq function (symbol-value hook))
61         )
62       (set hook 
63            (if append
64                (nconc (symbol-value hook) (list function))
65              (cons function (symbol-value hook))
66              ))
67       ))
68
69 (defun remove-hook (hook function)
70   "Remove from the value of HOOK the function FUNCTION.
71 HOOK should be a symbol, and FUNCTION may be any valid function.  If
72 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
73 list of hooks to run in HOOK, then nothing is done.  See `add-hook'.
74 \[emu-18.el; Emacs 19 emulating function]"
75   (if (or (not (boundp hook))           ;unbound symbol, or
76           (null (symbol-value hook))    ;value is nil, or
77           (null function))              ;function is nil, then
78       nil                               ;Do nothing.
79     (let ((hook-value (symbol-value hook)))
80       (if (consp hook-value)
81           (setq hook-value (delete function hook-value))
82         (if (equal hook-value function)
83             (setq hook-value nil)
84           ))
85       (set hook hook-value)
86       )))
87
88
89 ;;; @ list
90 ;;;
91
92 (defun member (elt list)
93   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
94 The value is actually the tail of LIST whose car is ELT.
95 \[emu-18.el; Emacs 19 emulating function]"
96   (while (and list (not (equal elt (car list))))
97     (setq list (cdr list)))
98   list)
99
100 (defun delete (elt list)
101   "Delete by side effect any occurrences of ELT as a member of LIST.
102 The modified LIST is returned.  Comparison is done with `equal'.
103 If the first member of LIST is ELT, deleting it is not a side effect;
104 it is simply using a different list.
105 Therefore, write `(setq foo (delete element foo))'
106 to be sure of changing the value of `foo'.
107 \[emu-18.el; Emacs 19 emulating function]"
108   (if (equal elt (car list))
109       (cdr list)
110     (let ((rest list)
111           (rrest (cdr list))
112           )
113       (while (and rrest (not (equal elt (car rrest))))
114         (setq rest rrest
115               rrest (cdr rrest))
116         )
117       (rplacd rest (cdr rrest))
118       list)))
119
120
121 ;;; @ function
122 ;;;
123
124 (defun defalias (sym newdef)
125   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
126 Associates the function with the current load file, if any.
127 \[emu-18.el; Emacs 19 emulating function]"
128   (fset sym newdef)
129   )
130
131 (defun byte-code-function-p (exp)
132   "T if OBJECT is a byte-compiled function object.
133 \[emu-18.el; Emacs 19 emulating function]"
134   (and (consp exp)
135        (let* ((rest (cdr (cdr exp))) elt)
136          (if (stringp (car rest))
137              (setq rest (cdr rest))
138            )
139          (catch 'tag
140            (while rest
141              (setq elt (car rest))
142              (if (and (consp elt)(eq (car elt) 'byte-code))
143                  (throw 'tag t)
144                )
145              (setq rest (cdr rest))
146              ))
147          )))
148
149
150 ;;; @ directory
151 ;;;
152
153 (defun make-directory-internal (dirname)
154   "Create a directory. One argument, a file name string.
155 \[emu-18.el; Emacs 19 emulating function]"
156   (if (file-exists-p dirname)
157       (error "Creating directory: %s is already exist" dirname)
158     (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
159         (error "Creating directory: no such file or directory, %s" dirname)
160       )))
161
162 (defun make-directory (dir &optional parents)
163   "Create the directory DIR and any nonexistent parent dirs.
164 The second (optional) argument PARENTS says whether
165 to create parent directories if they don't exist.
166 \[emu-18.el; Emacs 19 emulating function]"
167   (let ((len (length dir))
168         (p 0) p1 path)
169     (catch 'tag
170       (while (and (< p len) (string-match "[^/]*/?" dir p))
171         (setq p1 (match-end 0))
172         (if (= p1 len)
173             (throw 'tag nil)
174           )
175         (setq path (substring dir 0 p1))
176         (if (not (file-directory-p path))
177             (cond ((file-exists-p path)
178                    (error "Creating directory: %s is not directory" path)
179                    )
180                   ((null parents)
181                    (error "Creating directory: %s is not exist" path)
182                    )
183                   (t
184                    (make-directory-internal path)
185                    ))
186           )
187         (setq p p1)
188         ))
189     (make-directory-internal dir)
190     ))
191
192
193 ;;; @ mark
194 ;;;
195
196 (or (fboundp 'si:mark)
197     (fset 'si:mark (symbol-function 'mark)))
198 (defun mark (&optional force)
199   (si:mark)
200   )
201
202
203 ;;; @ text property
204 ;;;
205
206 (defun tl:set-text-properties (start end props &optional object))
207 (defun tl:overlay-buffer (overlay))
208
209
210 ;;; @ mouse
211 ;;;
212
213 (defvar mouse-button-1 nil)
214 (defvar mouse-button-2 nil)
215 (defvar mouse-button-3 nil)
216
217
218 ;;; @ end
219 ;;;
220
221 (provide 'emu-18)
222
223 ;;; emu-18.el ends here