(eval-when-compile, eval-and-compile): Reverted.
[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 (equal elt (car list))
67       (cdr list)
68     (let ((rest list)
69           (rrest (cdr list)))
70       (while (and rrest (not (equal elt (car rrest))))
71         (setq rest rrest
72               rrest (cdr rrest)))
73       (setcdr rest (cdr rrest))
74       list)))
75
76 (defun member (elt list)
77   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
78 The value is actually the tail of LIST whose car is ELT.
79 \[poe-18.el; EMACS 19 emulating function]"
80   (while (and list (not (equal elt (car list))))
81     (setq list (cdr list)))
82   list)
83
84
85 ;;; @@ buffer-local variable
86 ;;;
87
88 (defun default-boundp (symbol)
89   "Return t if SYMBOL has a non-void default value.
90 This is the value that is seen in buffers that do not have their own values
91 for this variable.
92 \[poe-18.el; EMACS 19 emulating function]"
93   (condition-case error
94       (progn
95         (default-value symbol)
96         t)
97     (void-variable nil)))
98
99
100 ;;; @@ environment variable
101 ;;;
102
103 (autoload 'setenv "env"
104   "Set the value of the environment variable named VARIABLE to VALUE.
105 VARIABLE should be a string.  VALUE is optional; if not provided or is
106 `nil', the environment variable VARIABLE will be removed.  
107 This function works by modifying `process-environment'."
108   t)
109
110
111 ;;; @@ function
112 ;;;
113
114 (defun defalias (sym newdef)
115   "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
116 Associates the function with the current load file, if any."
117   (fset sym newdef))
118
119 (defun byte-code-function-p (exp)
120   "T if OBJECT is a byte-compiled function object.
121 \[poe-18.el; EMACS 19 emulating function]"
122   (and (consp exp)
123        (let ((rest (cdr (cdr exp)))
124              elt)
125          (if (stringp (car rest))
126              (setq rest (cdr rest)))
127          (catch 'tag
128            (while rest
129              (setq elt (car rest))
130              (if (and (consp elt)
131                       (eq (car elt) 'byte-code))
132                  (throw 'tag t))
133              (setq rest (cdr rest)))))))
134
135
136 ;;; @ Compilation Features
137 ;;;
138
139 ;;; emulate all functions and macros of emacs-20.3/lisp/byte-run.el.
140 ;;; (note: jwz's original compiler and XEmacs compiler have some more
141 ;;;  macros; they are "nuked" by rms in FSF version.)
142
143 (put 'inline 'lisp-indent-hook 0)
144 (defalias-maybe 'inline 'progn)
145
146 (put 'defsubst 'lisp-indent-hook 'defun)
147 (put 'defsubst 'edebug-form-spec 'defun)
148 (defmacro-maybe defsubst (name arglist &rest body)
149   "Define an inline function.  The syntax is just like that of `defun'.
150
151 This emulating macro does not support function inlining because old \(v18\)
152 compiler does not support inlining feature.
153 \[poe-18.el; EMACS 19 emulating macro]"
154   (cons 'defun (cons name (cons arglist body))))
155
156 (defun-maybe make-obsolete (fn new)
157   "Make the byte-compiler warn that FUNCTION is obsolete.
158 The warning will say that NEW should be used instead.
159 If NEW is a string, that is the `use instead' message.
160
161 This emulating function does nothing because old \(v18\) compiler does not
162 support this feature.
163 \[poe-18.el; EMACS 19 emulating function]"
164   (interactive "aMake function obsolete: \nxObsoletion replacement: ")
165   fn)
166
167 (defun-maybe make-obsolete-variable (var new)
168   "Make the byte-compiler warn that VARIABLE is obsolete,
169 and NEW should be used instead.  If NEW is a string, then that is the
170 `use instead' message.
171
172 This emulating function does nothing because old \(v18\) compiler does not
173 support this feature.
174 \[poe-18.el; EMACS 19 emulating function]"
175   (interactive "vMake variable obsolete: \nxObsoletion replacement: ")
176   var)
177
178 (put 'dont-compile 'lisp-indent-hook 0)
179 (defmacro-maybe dont-compile (&rest body)
180   "Like `progn', but the body always runs interpreted \(not compiled\).
181 If you think you need this, you're probably making a mistake somewhere.
182 \[poe-18.el; EMACS 19 emulating macro]"
183   (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
184
185 (put 'eval-when-compile 'lisp-indent-hook 0)
186 (defmacro-maybe eval-when-compile (&rest body)
187   "Like progn, but evaluates the body at compile-time.
188
189 This emulating macro does not do compile-time evaluation at all because
190 of the limitation of old \(v18\) compiler.
191 \[poe-18.el; EMACS 19 emulating macro]"
192   (cons 'progn body))
193
194 (put 'eval-and-compile 'lisp-indent-hook 0)
195 (defmacro-maybe eval-and-compile (&rest body)
196   "Like progn, but evaluates the body at compile-time as well as at load-time.
197
198 This emulating macro does not do compile-time evaluation at all because
199 of the limitation of old \(v18\) compiler.
200 \[poe-18.el; EMACS 19 emulating macro]"
201   (cons 'progn body))
202
203
204 ;;; @ text property
205 ;;;
206
207 (defun set-text-properties (start end properties &optional object))
208
209 (defun remove-text-properties (start end properties &optional object))
210
211
212 ;;; @ file
213 ;;;
214
215 (defun make-directory-internal (dirname)
216   "Create a directory. One argument, a file name string.
217 \[poe-18.el; EMACS 19 emulating function]"
218  (let ((dir (expand-file-name dirname)))
219    (if (file-exists-p dir)
220        (error "Creating directory: %s is already exist" dir)
221      (call-process "mkdir" nil nil nil dir))))
222
223 (defun make-directory (dir &optional parents)
224   "Create the directory DIR and any nonexistent parent dirs.
225 The second (optional) argument PARENTS says whether
226 to create parent directories if they don't exist.
227 \[poe-18.el; EMACS 19 emulating function]"
228   (let ((len (length dir))
229         (p 0) p1 path)
230     (catch 'tag
231       (while (and (< p len) (string-match "[^/]*/?" dir p))
232         (setq p1 (match-end 0))
233         (if (= p1 len)
234             (throw 'tag nil))
235         (setq path (substring dir 0 p1))
236         (if (not (file-directory-p path))
237             (cond ((file-exists-p path)
238                    (error "Creating directory: %s is not directory" path))
239                   ((null parents)
240                    (error "Creating directory: %s is not exist" path))
241                   (t
242                    (make-directory-internal path))))
243         (setq p p1)))
244     (make-directory-internal dir)))
245
246 ;; Imported from files.el of EMACS 19.33.
247 (defun parse-colon-path (cd-path)
248   "Explode a colon-separated list of paths into a string list."
249   (and cd-path
250        (let (cd-prefix cd-list (cd-start 0) cd-colon)
251          (setq cd-path (concat cd-path path-separator))
252          (while (setq cd-colon (string-match path-separator cd-path cd-start))
253            (setq cd-list
254                  (nconc cd-list
255                         (list (if (= cd-start cd-colon)
256                                   nil
257                                 (substitute-in-file-name
258                                  (file-name-as-directory
259                                   (substring cd-path cd-start cd-colon)))))))
260            (setq cd-start (+ cd-colon 1)))
261          cd-list)))
262
263 ;; Imported from files.el of EMACS 19.33.
264 (defun file-relative-name (filename &optional directory)
265   "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
266   (setq filename (expand-file-name filename)
267         directory (file-name-as-directory (expand-file-name
268                                            (or directory default-directory))))
269   (let ((ancestor ""))
270     (while (not (string-match (concat "^" (regexp-quote directory)) filename))
271       (setq directory (file-name-directory (substring directory 0 -1))
272             ancestor (concat "../" ancestor)))
273     (concat ancestor (substring filename (match-end 0)))))
274
275 (or (fboundp 'si:directory-files)
276     (fset 'si:directory-files (symbol-function 'directory-files)))
277 (defun directory-files (directory &optional full match nosort)
278   "Return a list of names of files in DIRECTORY.
279 There are three optional arguments:
280 If FULL is non-nil, return absolute file names.  Otherwise return names
281  that are relative to the specified directory.
282 If MATCH is non-nil, mention only file names that match the regexp MATCH.
283 If NOSORT is dummy for compatibility.
284 \[poe-18.el; EMACS 19 emulating function]"
285   (si:directory-files directory full match))
286
287     
288 ;;; @ Display Features
289 ;;;
290
291 ;;; Imported from Emacs 19.30.
292 (defun force-mode-line-update (&optional all)
293   "Force the mode-line of the current buffer to be redisplayed.
294 With optional non-nil ALL, force redisplay of all mode-lines.
295 \[poe-18.el; Emacs 19 emulating function]"
296   (if all (save-excursion (set-buffer (other-buffer))))
297   (set-buffer-modified-p (buffer-modified-p)))
298
299
300 ;;; @ overlay
301 ;;;
302
303 (cond ((boundp 'NEMACS)
304        (defvar emu:available-face-attribute-alist
305          '(
306            ;;(bold      . inversed-region)
307            (italic    . underlined-region)
308            (underline . underlined-region)
309            ))
310
311        ;; by YAMATE Keiichirou 1994/10/28
312        (defun attribute-add-narrow-attribute (attr from to)
313          (or (consp (symbol-value attr))
314              (set attr (list 1)))
315          (let* ((attr-value (symbol-value attr))
316                 (len (car attr-value))
317                 (posfrom 1)
318                 posto)
319            (while (and (< posfrom len)
320                        (> from (nth posfrom attr-value)))
321              (setq posfrom (1+ posfrom)))
322            (setq posto posfrom)
323            (while (and (< posto len)
324                        (> to (nth posto attr-value)))
325              (setq posto (1+ posto)))
326            (if  (= posto posfrom)
327                (if (= (% posto 2) 1)
328                    (if (and (< to len)
329                             (= to (nth posto attr-value)))
330                        (set-marker (nth posto attr-value) from)
331                      (setcdr (nthcdr (1- posfrom) attr-value)
332                              (cons (set-marker-type (set-marker (make-marker)
333                                                                 from)
334                                                     'point-type)
335                                    (cons (set-marker-type
336                                           (set-marker (make-marker)
337                                                       to)
338                                           nil)
339                                          (nthcdr posto attr-value))))
340                      (setcar attr-value (+ len 2))))
341              (if (= (% posfrom 2) 0)
342                  (setq posfrom (1- posfrom))
343                (set-marker (nth posfrom attr-value) from))
344              (if (= (% posto 2) 0)
345                  nil
346                (setq posto (1- posto))
347                (set-marker (nth posto attr-value) to))
348              (setcdr (nthcdr posfrom attr-value)
349                      (nthcdr posto attr-value)))))
350        
351        (defalias 'make-overlay 'cons)
352
353        (defun overlay-put (overlay prop value)
354          (let ((ret (and (eq prop 'face)
355                          (assq value emu:available-face-attribute-alist))))
356            (if ret
357                (attribute-add-narrow-attribute (cdr ret)
358                                                (car overlay)(cdr overlay))))))
359       (t
360        (defun make-overlay (beg end &optional buffer type))
361        (defun overlay-put (overlay prop value))))
362
363 (defun overlay-buffer (overlay))
364
365
366 ;;; @ buffer
367 ;;;
368
369 (defun-maybe generate-new-buffer-name (name &optional ignore)
370   "Return a string that is the name of no existing buffer based on NAME.
371 If there is no live buffer named NAME, then return NAME.
372 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
373 until an unused name is found, and then return that name.
374 Optional second argument IGNORE specifies a name that is okay to use
375 \(if it is in the sequence to be tried)
376 even if a buffer with that name exists."
377   (if (get-buffer name)
378       (let ((n 2) new)
379         (while (get-buffer (setq new (format "%s<%d>" name n)))
380           (setq n (1+ n)))
381         new)
382     name))
383
384 (or (fboundp 'si:mark)
385     (fset 'si:mark (symbol-function 'mark)))
386 (defun mark (&optional force)
387   (si:mark))
388
389
390 ;;; @ end
391 ;;;
392
393 ;;; poe-18.el ends here