3c1fb8b17532b88b18a722f3a4f2abfd12f9c50a
[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,1995 MORIOKA Tomohiko
6 ;;;
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; Version:
9 ;;;     $Id: emu-18.el,v 7.1 1995/11/05 08:34:22 morioka Exp $
10 ;;; Keywords: emulation, compatibility
11 ;;;
12 ;;; This file is part of tl and tm (Tools for MIME).
13 ;;;
14
15 ;;; @ hook
16 ;;;
17
18 ;; This function is imported from AUC TeX.
19 (defun add-hook (hook function &optional append)
20   "Add to the value of HOOK the function FUNCTION.
21 FUNCTION is not added if already present.
22 FUNCTION is added (if necessary) at the beginning of the hook list
23 unless the optional argument APPEND is non-nil, in which case
24 FUNCTION is added at the end.
25  
26 HOOK should be a symbol, and FUNCTION may be any valid function.  If
27 HOOK is void, it is first set to nil.  If HOOK's value is a single
28 function, it is changed to a list of functions.
29 \[emu-18.el; Emacs 19 emulating function]"
30   (or (boundp hook)
31       (set hook nil)
32       )
33   ;; If the hook value is a single function, turn it into a list.
34   (let ((old (symbol-value hook)))
35     (if (or (not (listp old))
36             (eq (car old) 'lambda))
37         (set hook (list old))
38       ))
39   (or (if (consp function)
40           ;; Clever way to tell whether a given lambda-expression
41           ;; is equal to anything in the hook.
42           (let ((tail (assoc (cdr function) (symbol-value hook))))
43             (equal function tail)
44             )
45         (memq function (symbol-value hook))
46         )
47       (set hook 
48            (if append
49                (nconc (symbol-value hook) (list function))
50              (cons function (symbol-value hook))
51              ))
52       ))
53
54
55 ;;; @ list
56 ;;;
57
58 (defun member (elt list)
59   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
60 The value is actually the tail of LIST whose car is ELT.
61 \[emu-18.el; Emacs 19 emulating function]"
62   (while (and list (not (equal elt (car list))))
63     (setq list (cdr list)))
64   list)
65
66 (defun delete (elt list)
67   "Delete by side effect any occurrences of ELT as a member of LIST.
68 The modified LIST is returned.  Comparison is done with `equal'.
69 If the first member of LIST is ELT, deleting it is not a side effect;
70 it is simply using a different list.
71 Therefore, write `(setq foo (delete element foo))'
72 to be sure of changing the value of `foo'.
73 \[emu-18.el; Emacs 19 emulating function]"
74   (if (equal elt (car list))
75       (cdr list)
76     (let ((rest list)
77           (rrest (cdr list))
78           )
79       (while (and rrest (not (equal elt (car rrest))))
80         (setq rest rrest
81               rrest (cdr rrest))
82         )
83       (rplacd rest (cdr rrest))
84       list)))
85
86
87 ;;; @ function
88 ;;;
89
90 (defun defalias (SYM NEWDEF)
91   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
92 Associates the function with the current load file, if any.
93 \[emu-18.el; Emacs 19 emulating function]"
94   (fset SYM (symbol-function NEWDEF))
95   NEWDEF)
96
97 (defun byte-code-function-p (exp)
98   "T if OBJECT is a byte-compiled function object.
99 \[emu-18.el; Emacs 19 emulating function]"
100   (let* ((rest (cdr (cdr exp))) elt)
101     (if (stringp (car rest))
102         (setq rest (cdr rest))
103       )
104     (catch 'tag
105       (while rest
106         (setq elt (car rest))
107         (if (and (consp elt)(eq (car elt) 'byte-code))
108             (throw 'tag t)
109           )
110         (setq rest (cdr rest))
111         ))))
112
113
114 ;;; @ directory
115 ;;;
116
117 (defun make-directory-internal (dirname)
118   "Create a directory. One argument, a file name string.
119 \[emu-18.el; Emacs 19 emulating function]"
120   (if (file-exists-p dirname)
121       (error "Creating directory: %s is already exist" dirname)
122     (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
123         (error "Creating directory: no such file or directory, %s" dirname)
124       )))
125
126 (defun make-directory (dir &optional parents)
127   "Create the directory DIR and any nonexistent parent dirs.
128 The second (optional) argument PARENTS says whether
129 to create parent directories if they don't exist.
130 \[emu-18.el; Emacs 19 emulating function]"
131   (let ((len (length dir))
132         (p 0) p1 path)
133     (catch 'tag
134       (while (and (< p len) (string-match "[^/]*/?" dir p))
135         (setq p1 (match-end 0))
136         (if (= p1 len)
137             (throw 'tag nil)
138           )
139         (setq path (substring dir 0 p1))
140         (if (not (file-directory-p path))
141             (cond ((file-exists-p path)
142                    (error "Creating directory: %s is not directory" path)
143                    )
144                   ((null parents)
145                    (error "Creating directory: %s is not exist" path)
146                    )
147                   (t
148                    (make-directory-internal path)
149                    ))
150           )
151         (setq p p1)
152         ))
153     (make-directory-internal dir)
154     ))
155
156
157 ;;; @ mouse
158 ;;;
159
160 (defvar mouse-button-1 nil)
161 (defvar mouse-button-2 nil)
162
163
164 ;;; @ end
165 ;;;
166
167 (provide 'emu-18)