tm 7.15.
[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.0 1995/10/12 11:27:33 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 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 Emacs 19 emulating function]"
62   (while (and list (not (equal elt (car list))))
63     (setq list (cdr list)))
64   list)
65
66
67 ;;; @ function
68 ;;;
69
70 (defun defalias (SYM NEWDEF)
71   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
72 Associates the function with the current load file, if any.
73 \[emu-18 Emacs 19 emulating function]"
74   (fset SYM (symbol-function NEWDEF))
75   NEWDEF)
76
77 (defun byte-code-function-p (exp)
78   (let* ((rest (cdr (cdr exp))) elt)
79     (if (stringp (car rest))
80         (setq rest (cdr rest))
81       )
82     (catch 'tag
83       (while rest
84         (setq elt (car rest))
85         (if (and (consp elt)(eq (car elt) 'byte-code))
86             (throw 'tag t)
87           )
88         (setq rest (cdr rest))
89         ))))
90
91
92 ;;; @ directory
93 ;;;
94
95 (defun make-directory-internal (dirname)
96   "Create a directory. One argument, a file name string.
97 \[emu-18 Emacs 19 emulating function]"
98   (if (file-exists-p dirname)
99       (error "Creating directory: %s is already exist" dirname)
100     (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
101         (error "Creating directory: no such file or directory, %s" dirname)
102       )))
103
104 (defun make-directory (dir &optional parents)
105   "Create the directory DIR and any nonexistent parent dirs.
106 The second (optional) argument PARENTS says whether
107 to create parent directories if they don't exist.
108 \[emu-18 Emacs 19 emulating function]"
109   (let ((len (length dir))
110         (p 0) p1 path)
111     (catch 'tag
112       (while (and (< p len) (string-match "[^/]*/?" dir p))
113         (setq p1 (match-end 0))
114         (if (= p1 len)
115             (throw 'tag nil)
116           )
117         (setq path (substring dir 0 p1))
118         (if (not (file-directory-p path))
119             (cond ((file-exists-p path)
120                    (error "Creating directory: %s is not directory" path)
121                    )
122                   ((null parents)
123                    (error "Creating directory: %s is not exist" path)
124                    )
125                   (t
126                    (make-directory-internal path)
127                    ))
128           )
129         (setq p p1)
130         ))
131     (make-directory-internal dir)
132     ))
133
134
135 ;;; @ mouse
136 ;;;
137
138 (defvar mouse-button-1 nil)
139 (defvar mouse-button-2 nil)
140
141
142 ;;; @ end
143 ;;;
144
145 (provide 'emu-18)