tm 7.41.2.
[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.5 1996/01/25 02:09:46 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 ;; This function is imported from AUC TeX.
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
70 ;;; @ list
71 ;;;
72
73 (defun member (elt list)
74   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
75 The value is actually the tail of LIST whose car is ELT.
76 \[emu-18.el; Emacs 19 emulating function]"
77   (while (and list (not (equal elt (car list))))
78     (setq list (cdr list)))
79   list)
80
81 (defun delete (elt list)
82   "Delete by side effect any occurrences of ELT as a member of LIST.
83 The modified LIST is returned.  Comparison is done with `equal'.
84 If the first member of LIST is ELT, deleting it is not a side effect;
85 it is simply using a different list.
86 Therefore, write `(setq foo (delete element foo))'
87 to be sure of changing the value of `foo'.
88 \[emu-18.el; Emacs 19 emulating function]"
89   (if (equal elt (car list))
90       (cdr list)
91     (let ((rest list)
92           (rrest (cdr list))
93           )
94       (while (and rrest (not (equal elt (car rrest))))
95         (setq rest rrest
96               rrest (cdr rrest))
97         )
98       (rplacd rest (cdr rrest))
99       list)))
100
101
102 ;;; @ function
103 ;;;
104
105 (defun defalias (SYM NEWDEF)
106   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
107 Associates the function with the current load file, if any.
108 \[emu-18.el; Emacs 19 emulating function]"
109   (fset SYM (symbol-function NEWDEF))
110   NEWDEF)
111
112 (defun byte-code-function-p (exp)
113   "T if OBJECT is a byte-compiled function object.
114 \[emu-18.el; Emacs 19 emulating function]"
115   (and (consp exp)
116        (let* ((rest (cdr (cdr exp))) elt)
117          (if (stringp (car rest))
118              (setq rest (cdr rest))
119            )
120          (catch 'tag
121            (while rest
122              (setq elt (car rest))
123              (if (and (consp elt)(eq (car elt) 'byte-code))
124                  (throw 'tag t)
125                )
126              (setq rest (cdr rest))
127              ))
128          )))
129
130
131 ;;; @ directory
132 ;;;
133
134 (defun make-directory-internal (dirname)
135   "Create a directory. One argument, a file name string.
136 \[emu-18.el; Emacs 19 emulating function]"
137   (if (file-exists-p dirname)
138       (error "Creating directory: %s is already exist" dirname)
139     (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
140         (error "Creating directory: no such file or directory, %s" dirname)
141       )))
142
143 (defun make-directory (dir &optional parents)
144   "Create the directory DIR and any nonexistent parent dirs.
145 The second (optional) argument PARENTS says whether
146 to create parent directories if they don't exist.
147 \[emu-18.el; Emacs 19 emulating function]"
148   (let ((len (length dir))
149         (p 0) p1 path)
150     (catch 'tag
151       (while (and (< p len) (string-match "[^/]*/?" dir p))
152         (setq p1 (match-end 0))
153         (if (= p1 len)
154             (throw 'tag nil)
155           )
156         (setq path (substring dir 0 p1))
157         (if (not (file-directory-p path))
158             (cond ((file-exists-p path)
159                    (error "Creating directory: %s is not directory" path)
160                    )
161                   ((null parents)
162                    (error "Creating directory: %s is not exist" path)
163                    )
164                   (t
165                    (make-directory-internal path)
166                    ))
167           )
168         (setq p p1)
169         ))
170     (make-directory-internal dir)
171     ))
172
173
174 ;;; @ mark
175 ;;;
176
177 (or (fboundp 'si:mark)
178     (fset 'si:mark (symbol-function 'mark)))
179 (defun mark (&optional force)
180   (si:mark)
181   )
182
183
184 ;;; @ mouse
185 ;;;
186
187 (defvar mouse-button-1 nil)
188 (defvar mouse-button-2 nil)
189 (defvar mouse-button-3 nil)
190
191
192 ;;; @ end
193 ;;;
194
195 (provide 'emu-18)
196
197 ;;; emu-18.el ends here