e9ea96bc9684dffbe6090312254e809ce93f1d15
[elisp/apel.git] / emu-18.el
1 ;;;
2 ;;; emu-18: Emacs 19.* emulation module for Emacs 18.*
3 ;;;
4 ;;; $Id: emu-18.el,v 4.0 1995/09/05 16:44:57 morioka Exp $
5 ;;;
6
7 ;; This function is imported from AUC TeX.
8 (defun add-hook (hook function &optional append)
9   "Add to the value of HOOK the function FUNCTION.
10 FUNCTION is not added if already present.
11 FUNCTION is added (if necessary) at the beginning of the hook list
12 unless the optional argument APPEND is non-nil, in which case
13 FUNCTION is added at the end.
14  
15 HOOK should be a symbol, and FUNCTION may be any valid function.  If
16 HOOK is void, it is first set to nil.  If HOOK's value is a single
17 function, it is changed to a list of functions.
18 \[emu-18 Emacs 19 emulating function]"
19   (or (boundp hook)
20       (set hook nil)
21       )
22   ;; If the hook value is a single function, turn it into a list.
23   (let ((old (symbol-value hook)))
24     (if (or (not (listp old))
25             (eq (car old) 'lambda))
26         (set hook (list old))
27       ))
28   (or (if (consp function)
29           ;; Clever way to tell whether a given lambda-expression
30           ;; is equal to anything in the hook.
31           (let ((tail (assoc (cdr function) (symbol-value hook))))
32             (equal function tail)
33             )
34         (memq function (symbol-value hook))
35         )
36       (set hook 
37            (if append
38                (nconc (symbol-value hook) (list function))
39              (cons function (symbol-value hook))
40              ))
41       ))
42
43 (defun member (elt list)
44   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
45 The value is actually the tail of LIST whose car is ELT.
46 \[emu-18 Emacs 19 emulating function]"
47   (while (and list (not (equal elt (car list))))
48     (setq list (cdr list)))
49   list)
50
51 (defun defalias (SYM NEWDEF)
52   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
53 Associates the function with the current load file, if any.
54 \[emu-18 Emacs 19 emulating function]"
55   (fset SYM (symbol-function NEWDEF))
56   NEWDEF)
57
58 (defun make-directory-internal (dirname)
59   "Create a directory. One argument, a file name string.
60 \[emu-18 Emacs 19 emulating function]"
61   (if (file-exists-p dirname)
62       (error "Creating directory: %s is already exist" dirname)
63     (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
64         (error "Creating directory: no such file or directory, %s" dirname)
65       )))
66
67 (defun make-directory (dir &optional parents)
68   "Create the directory DIR and any nonexistent parent dirs.
69 The second (optional) argument PARENTS says whether
70 to create parent directories if they don't exist.
71 \[emu-18 Emacs 19 emulating function]"
72   (let ((len (length dir))
73         (p 0) p1 path)
74     (catch 'tag
75       (while (and (< p len) (string-match "[^/]*/?" dir p))
76         (setq p1 (match-end 0))
77         (if (= p1 len)
78             (throw 'tag nil)
79           )
80         (setq path (substring dir 0 p1))
81         (if (not (file-directory-p path))
82             (cond ((file-exists-p path)
83                    (error "Creating directory: %s is not directory" path)
84                    )
85                   ((null parents)
86                    (error "Creating directory: %s is not exist" path)
87                    )
88                   (t
89                    (make-directory-internal path)
90                    ))
91           )
92         (setq p p1)
93         ))
94     (make-directory-internal dir)
95     ))
96
97 (provide 'emu-18)