Warn if the new custom library is not found at the compile time.
[elisp/apel.git] / poe-18.el
1 ;;; poe-18.el --- poe API implementation for Emacs 18.*
2
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: emulation, compatibility
7
8 ;; This file is part of APEL (A Portable Emacs Library).
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; Note to developers:
28 ;;
29 ;; If old (v18) compiler is used, top-level macros are expanded at
30 ;; *load-time*, not compile-time.  So, you cannot use macros defined
31 ;; in this file using `defmacro-maybe'.  In addition, due to this
32 ;; limitation, `eval-when-compile' and `eval-and-compile' provided by
33 ;; this file do not do compile-time evaluation at all.
34
35 ;;; Code:
36
37 (provide 'poe-18)                       ; beware of circular dependency.
38 (require 'poe)                          ; load definitions of `*-maybe'.
39
40 ;;; @ for EMACS 18.55
41 ;;;
42
43 (defvar-maybe buffer-undo-list nil)
44
45
46 ;;; @ Emacs 19 emulation
47 ;;;
48
49 (defvar-maybe data-directory exec-directory)
50
51
52 ;;; @ Lisp Language
53 ;;;
54
55 ;;; @@ list
56 ;;;
57
58 (defun delete (elt list)
59   "Delete by side effect any occurrences of ELT as a member of LIST.
60 The modified LIST is returned.  Comparison is done with `equal'.
61 If the first member of LIST is ELT, deleting it is not a side effect;
62 it is simply using a different list.
63 Therefore, write `(setq foo (delete element foo))'
64 to be sure of changing the value of `foo'.
65 \[poe-18.el; EMACS 19 emulating function]"
66   (if list
67       (if (equal elt (car list))
68           (cdr list)
69         (let ((rest list)
70               (rrest (cdr list)))
71           (while (and rrest (not (equal elt (car rrest))))
72             (setq rest rrest
73                   rrest (cdr rrest)))
74           (setcdr rest (cdr rrest))
75           list))))
76
77 (defun member (elt list)
78   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
79 The value is actually the tail of LIST whose car is ELT.
80 \[poe-18.el; EMACS 19 emulating function]"
81   (while (and list (not (equal elt (car list))))
82     (setq list (cdr list)))
83   list)
84
85
86 ;;; @@ buffer-local variable
87 ;;;
88
89 (defun default-boundp (symbol)
90   "Return t if SYMBOL has a non-void default value.
91 This is the value that is seen in buffers that do not have their own values
92 for this variable.
93 \[poe-18.el; EMACS 19 emulating function]"
94   (condition-case error
95       (progn
96         (default-value symbol)
97         t)
98     (void-variable nil)))
99
100
101 ;;; @@ environment variable
102 ;;;
103
104 (autoload 'setenv "env"
105   "Set the value of the environment variable named VARIABLE to VALUE.
106 VARIABLE should be a string.  VALUE is optional; if not provided or is
107 `nil', the environment variable VARIABLE will be removed.
108 This function works by modifying `process-environment'."
109   t)
110
111
112 ;;; @@ function
113 ;;;
114
115 (defun defalias (sym newdef)
116   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
117 Associates the function with the current load file, if any."
118   (fset sym newdef))
119
120 (defun byte-code-function-p (exp)
121   "T if OBJECT is a byte-compiled function object.
122 \[poe-18.el; EMACS 19 emulating function]"
123   (and (consp exp)
124        (let ((rest (cdr (cdr exp)))
125              elt)
126          (if (stringp (car rest))
127              (setq rest (cdr rest)))
128          (catch 'tag
129            (while rest
130              (setq elt (car rest))
131              (if (and (consp elt)
132                       (eq (car elt) 'byte-code))
133                  (throw 'tag t))
134              (setq rest (cdr rest)))))))
135
136
137 ;;; @ Compilation Features
138 ;;;
139
140 ;;; emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
141 ;;; (note: jwz's original compiler and XEmacs compiler have some more
142 ;;;  macros; they are "nuked" by rms in FSF version.)
143
144 (put 'inline 'lisp-indent-hook 0)
145 (defmacro inline (&rest body)
146   "Eval BODY forms sequentially and return value of last one.
147
148 This emulating macro does not support function inlining because old \(v18\)
149 compiler does not support inlining feature.
150 \[poe-18.el; EMACS 19 emulating macro]"
151   (` (progn (,@ body))))
152
153 (put 'defsubst 'lisp-indent-hook 'defun)
154 (put 'defsubst 'edebug-form-spec 'defun)
155 (defmacro-maybe defsubst (name arglist &rest body)
156   "Define an inline function.  The syntax is just like that of `defun'.
157
158 This emulating macro does not support function inlining because old \(v18\)
159 compiler does not support inlining feature.
160 \[poe-18.el; EMACS 19 emulating macro]"
161   (cons 'defun (cons name (cons arglist body))))
162
163 (defun-maybe make-obsolete (fn new)
164   "Make the byte-compiler warn that FUNCTION is obsolete.
165 The warning will say that NEW should be used instead.
166 If NEW is a string, that is the `use instead' message.
167
168 This emulating function does nothing because old \(v18\) compiler does not
169 support this feature.
170 \[poe-18.el; EMACS 19 emulating function]"
171   (interactive "aMake function obsolete: \nxObsoletion replacement: ")
172   fn)
173
174 (defun-maybe make-obsolete-variable (var new)
175   "Make the byte-compiler warn that VARIABLE is obsolete,
176 and NEW should be used instead.  If NEW is a string, then that is the
177 `use instead' message.
178
179 This emulating function does nothing because old \(v18\) compiler does not
180 support this feature.
181 \[poe-18.el; EMACS 19 emulating function]"
182   (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
183   var)
184
185 (put 'dont-compile 'lisp-indent-hook 0)
186 (defmacro-maybe dont-compile (&rest body)
187   "Like `progn', but the body always runs interpreted \(not compiled\).
188 If you think you need this, you're probably making a mistake somewhere.
189 \[poe-18.el; EMACS 19 emulating macro]"
190   (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
191
192 (put 'eval-when-compile 'lisp-indent-hook 0)
193 (defmacro-maybe eval-when-compile (&rest body)
194   "Like progn, but evaluates the body at compile-time.
195
196 This emulating macro does not do compile-time evaluation at all because
197 of the limitation of old \(v18\) compiler.
198 \[poe-18.el; EMACS 19 emulating macro]"
199   (cons 'progn body))
200
201 (put 'eval-and-compile 'lisp-indent-hook 0)
202 (defmacro-maybe eval-and-compile (&rest body)
203   "Like progn, but evaluates the body at compile-time as well as at load-time.
204
205 This emulating macro does not do compile-time evaluation at all because
206 of the limitation of old \(v18\) compiler.
207 \[poe-18.el; EMACS 19 emulating macro]"
208   (cons 'progn body))
209
210
211 ;;; @ text property
212 ;;;
213
214 (defun set-text-properties (start end properties &optional object))
215
216 (defun remove-text-properties (start end properties &optional object))
217
218 (defun get-text-property (position prop &optional object))
219
220 (defun add-text-properties (start end properties &optional object))
221
222 (defun put-text-property (start end property value &optional object))
223
224 (defun next-property-change (position &optional object limit))
225
226 (defun text-properties-at (position &optional object))
227
228 ;;; @ file
229 ;;;
230
231 (defun make-directory-internal (dirname)
232   "Create a directory. One argument, a file name string.
233 \[poe-18.el; EMACS 19 emulating function]"
234  (let ((dir (expand-file-name dirname)))
235    (if (file-exists-p dir)
236        (error "Creating directory: %s is already exist" dir)
237      (call-process "mkdir" nil nil nil dir))))
238
239 (defun make-directory (dir &optional parents)
240   "Create the directory DIR and any nonexistent parent dirs.
241 The second (optional) argument PARENTS says whether
242 to create parent directories if they don't exist.
243 \[poe-18.el; EMACS 19 emulating function]"
244   (let ((len (length dir))
245         (p 0) p1 path)
246     (catch 'tag
247       (while (and (< p len) (string-match "[^/]*/?" dir p))
248         (setq p1 (match-end 0))
249         (if (= p1 len)
250             (throw 'tag nil))
251         (setq path (substring dir 0 p1))
252         (if (not (file-directory-p path))
253             (cond ((file-exists-p path)
254                    (error "Creating directory: %s is not directory" path))
255                   ((null parents)
256                    (error "Creating directory: %s is not exist" path))
257                   (t
258                    (make-directory-internal path))))
259         (setq p p1)))
260     (make-directory-internal dir)))
261
262 ;; Imported from files.el of EMACS 19.33.
263 (defun parse-colon-path (cd-path)
264   "Explode a colon-separated list of paths into a string list."
265   (and cd-path
266        (let (cd-prefix cd-list (cd-start 0) cd-colon)
267          (setq cd-path (concat cd-path path-separator))
268          (while (setq cd-colon (string-match path-separator cd-path cd-start))
269            (setq cd-list
270                  (nconc cd-list
271                         (list (if (= cd-start cd-colon)
272                                   nil
273                                 (substitute-in-file-name
274                                  (file-name-as-directory
275                                   (substring cd-path cd-start cd-colon)))))))
276            (setq cd-start (+ cd-colon 1)))
277          cd-list)))
278
279 ;; Imported from files.el of EMACS 19.33.
280 (defun file-relative-name (filename &optional directory)
281   "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
282   (setq filename (expand-file-name filename)
283         directory (file-name-as-directory (expand-file-name
284                                            (or directory default-directory))))
285   (let ((ancestor ""))
286     (while (not (string-match (concat "^" (regexp-quote directory)) filename))
287       (setq directory (file-name-directory (substring directory 0 -1))
288             ancestor (concat "../" ancestor)))
289     (concat ancestor (substring filename (match-end 0)))))
290
291 (or (fboundp 'si:directory-files)
292     (fset 'si:directory-files (symbol-function 'directory-files)))
293 (defun directory-files (directory &optional full match nosort)
294   "Return a list of names of files in DIRECTORY.
295 There are three optional arguments:
296 If FULL is non-nil, return absolute file names.  Otherwise return names
297  that are relative to the specified directory.
298 If MATCH is non-nil, mention only file names that match the regexp MATCH.
299 If NOSORT is dummy for compatibility.
300 \[poe-18.el; EMACS 19 emulating function]"
301   (si:directory-files directory full match))
302
303 (defun file-executable-p (filename)
304   "Return t if FILENAME can be executed by you.
305 For a directory, this means you can access files in that directory.
306 \[poe-18.el; EMACS 19 emulating function]"
307   (if (file-exists-p filename)
308       (let ((process (start-process "test" nil "test" "-x" filename)))
309         (while (eq 'run (process-status process)))
310         (zerop (process-exit-status process)))))
311
312
313 ;;; @ Display Features
314 ;;;
315
316 ;;; Imported from Emacs 19.30.
317 (defun force-mode-line-update (&optional all)
318   "Force the mode-line of the current buffer to be redisplayed.
319 With optional non-nil ALL, force redisplay of all mode-lines.
320 \[poe-18.el; Emacs 19 emulating function]"
321   (if all (save-excursion (set-buffer (other-buffer))))
322   (set-buffer-modified-p (buffer-modified-p)))
323
324
325 ;;; @ overlay
326 ;;;
327
328 (cond ((boundp 'NEMACS)
329        (defvar emu:available-face-attribute-alist
330          '(
331            ;;(bold      . inversed-region)
332            (italic    . underlined-region)
333            (underline . underlined-region)
334            ))
335
336        ;; by YAMATE Keiichirou 1994/10/28
337        (defun attribute-add-narrow-attribute (attr from to)
338          (or (consp (symbol-value attr))
339              (set attr (list 1)))
340          (let* ((attr-value (symbol-value attr))
341                 (len (car attr-value))
342                 (posfrom 1)
343                 posto)
344            (while (and (< posfrom len)
345                        (> from (nth posfrom attr-value)))
346              (setq posfrom (1+ posfrom)))
347            (setq posto posfrom)
348            (while (and (< posto len)
349                        (> to (nth posto attr-value)))
350              (setq posto (1+ posto)))
351            (if  (= posto posfrom)
352                (if (= (% posto 2) 1)
353                    (if (and (< to len)
354                             (= to (nth posto attr-value)))
355                        (set-marker (nth posto attr-value) from)
356                      (setcdr (nthcdr (1- posfrom) attr-value)
357                              (cons (set-marker-type (set-marker (make-marker)
358                                                                 from)
359                                                     'point-type)
360                                    (cons (set-marker-type
361                                           (set-marker (make-marker)
362                                                       to)
363                                           nil)
364                                          (nthcdr posto attr-value))))
365                      (setcar attr-value (+ len 2))))
366              (if (= (% posfrom 2) 0)
367                  (setq posfrom (1- posfrom))
368                (set-marker (nth posfrom attr-value) from))
369              (if (= (% posto 2) 0)
370                  nil
371                (setq posto (1- posto))
372                (set-marker (nth posto attr-value) to))
373              (setcdr (nthcdr posfrom attr-value)
374                      (nthcdr posto attr-value)))))
375
376        (defalias 'make-overlay 'cons)
377
378        (defun overlay-put (overlay prop value)
379          (let ((ret (and (eq prop 'face)
380                          (assq value emu:available-face-attribute-alist))))
381            (if ret
382                (attribute-add-narrow-attribute (cdr ret)
383                                                (car overlay)(cdr overlay))))))
384       (t
385        (defun make-overlay (beg end &optional buffer type))
386        (defun overlay-put (overlay prop value))))
387
388 (defun overlay-buffer (overlay))
389
390
391 ;;; @ buffer
392 ;;;
393
394 (defun-maybe generate-new-buffer-name (name &optional ignore)
395   "Return a string that is the name of no existing buffer based on NAME.
396 If there is no live buffer named NAME, then return NAME.
397 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
398 until an unused name is found, and then return that name.
399 Optional second argument IGNORE specifies a name that is okay to use
400 \(if it is in the sequence to be tried)
401 even if a buffer with that name exists."
402   (if (get-buffer name)
403       (let ((n 2) new)
404         (while (get-buffer (setq new (format "%s<%d>" name n)))
405           (setq n (1+ n)))
406         new)
407     name))
408
409 (or (fboundp 'si:mark)
410     (fset 'si:mark (symbol-function 'mark)))
411 (defun mark (&optional force)
412   (si:mark))
413
414
415 ;;; @ end
416 ;;;
417
418 ;;; poe-18.el ends here