(defun-maybe, defmacro-maybe, defalias-maybe, defsubst-maybe,
[elisp/apel.git] / poe.el
1 ;;; poe.el --- Portable Outfit for Emacsen; -*-byte-compile-dynamic: t;-*-
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, NEmacs, MULE, Emacs/mule, XEmacs
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 GNU Emacs; 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 ;; This modules does not includes MULE related features.
28 ;; MULE related features are supported by `poem'.
29
30 ;;; Code:
31
32 (provide 'poe)
33
34 (or (boundp 'current-load-list) (setq current-load-list nil))
35
36 (put 'defun-maybe 'lisp-indent-function 'defun)
37 (defmacro defun-maybe (name &rest everything-else)
38   "Define NAME as a function if NAME is not defined.
39 See also the function `defun'."
40   (or (and (fboundp name)
41            (not (get name 'defun-maybe)))
42       (` (or (fboundp (quote (, name)))
43              (prog1
44                  (defun (, name) (,@ everything-else))
45                ;; This `defun' will be compiled to `fset', which does
46                ;; not update `load-history'.
47                (setq current-load-list
48                      (cons (quote (, name)) current-load-list))
49                (put (quote (, name)) 'defun-maybe t))))))
50
51 (put 'defmacro-maybe 'lisp-indent-function 'defun)
52 (defmacro defmacro-maybe (name &rest everything-else)
53   "Define NAME as a macro if NAME is not defined.
54 See also the function `defmacro'."
55   (or (and (fboundp name)
56            (not (get name 'defmacro-maybe)))
57       (` (or (fboundp (quote (, name)))
58              (prog1
59                  (defmacro (, name) (,@ everything-else))
60                (setq current-load-list
61                      (cons (quote (, name)) current-load-list))
62                (put (quote (, name)) 'defmacro-maybe t))))))
63
64 (put 'defsubst-maybe 'lisp-indent-function 'defun)
65 (defmacro defsubst-maybe (name &rest everything-else)
66   "Define NAME as an inline function if NAME is not defined.
67 See also the macro `defsubst'."
68   (or (and (fboundp name)
69            (not (get name 'defsubst-maybe)))
70       (` (or (fboundp (quote (, name)))
71              (prog1
72                  (defsubst (, name) (,@ everything-else))
73                (setq current-load-list
74                      (cons (quote (, name)) current-load-list))
75                (put (quote (, name)) 'defsubst-maybe t))))))
76
77 (defmacro defalias-maybe (symbol definition)
78   "Define SYMBOL as an alias for DEFINITION if SYMBOL is not defined.
79 See also the function `defalias'."
80   (setq symbol (eval symbol))
81   (or (and (fboundp symbol)
82            (not (get symbol 'defalias-maybe)))
83       (` (or (fboundp (quote (, symbol)))
84              (prog1
85                  (defalias (quote (, symbol)) (, definition))
86                (setq current-load-list
87                      (cons (quote (, symbol)) current-load-list))
88                (put (quote (, symbol)) 'defalias-maybe t))))))
89
90 (defmacro defvar-maybe (name &rest everything-else)
91   "Define NAME as a variable if NAME is not defined.
92 See also the function `defvar'."
93   (or (and (boundp name)
94            (not (get name 'defvar-maybe)))
95       (` (or (boundp (quote (, name)))
96              (prog1
97                  (defvar (, name) (,@ everything-else))
98                ;; byte-compiler will generate code to update
99                ;; `load-history'.
100                (put (quote (, name)) 'defvar-maybe t))))))
101
102 (defmacro defconst-maybe (name &rest everything-else)
103   "Define NAME as a constant variable if NAME is not defined.
104 See also the function `defconst'."
105   (or (and (boundp name)
106            (not (get name 'defconst-maybe)))
107       (` (or (boundp (quote (, name)))
108              (prog1
109                  (defconst (, name) (,@ everything-else))
110                ;; byte-compiler will generate code to update
111                ;; `load-history'.
112                (put (quote (, name)) 'defconst-maybe t))))))
113
114 (defmacro defun-maybe-cond (name args &optional doc &rest everything-else)
115   (or (stringp doc)
116       (setq everything-else (cons doc everything-else)
117             doc nil))
118   (or (and (fboundp name)
119            (not (get name 'defun-maybe)))
120       (` (or (fboundp (quote (, name)))
121              (prog1
122                  (cond
123                   (,@ (mapcar
124                        (function
125                         (lambda (case)
126                           (list (car case)
127                                 (if doc
128                                     (` (defun (, name) (, args)
129                                          (, doc)
130                                          (,@ (cdr case))))
131                                   (` (defun (, name) (, args)
132                                        (,@ (cdr case))))))))
133                        everything-else)))
134                (setq current-load-list
135                      (cons (quote (, name)) current-load-list))
136                (put (quote (, name)) 'defun-maybe t))))))
137
138 (defmacro defmacro-maybe-cond (name args &optional doc &rest everything-else)
139   (or (stringp doc)
140       (setq everything-else (cons doc everything-else)
141             doc nil))
142   (or (and (fboundp name)
143            (not (get name 'defmacro-maybe)))
144       (` (or (fboundp (quote (, name)))
145              (prog1
146                  (cond
147                   (,@ (mapcar
148                        (function
149                         (lambda (case)
150                           (list (car case)
151                                 (if doc
152                                     (` (defmacro (, name) (, args)
153                                          (, doc)
154                                          (,@ (cdr case))))
155                                   (` (defmacro (, name) (, args)
156                                        (,@ (cdr case))))))))
157                        everything-else)))
158                (setq current-load-list
159                      (cons (quote (, name)) current-load-list))
160                (put (quote (, name)) 'defmacro-maybe t))))))
161
162 (defun subr-fboundp (symbol)
163   "Return t if SYMBOL's function definition is a built-in function."
164   (and (fboundp symbol)
165        (subrp (symbol-function symbol))))
166
167 (defconst-maybe emacs-major-version (string-to-int emacs-version))
168 (defconst-maybe emacs-minor-version
169   (string-to-int
170    (substring emacs-version
171               (string-match (format "%d\\." emacs-major-version)
172                             emacs-version))))
173
174 (cond ((featurep 'xemacs)
175        (require 'poe-xemacs)
176        )
177       ((string-match "XEmacs" emacs-version)
178        (provide 'xemacs)
179        (require 'poe-xemacs)
180        )
181       ((> emacs-major-version 20))
182       ((= emacs-major-version 20)
183        (cond ((subr-fboundp 'string)
184               ;; Emacs 20.3 or later
185               )
186              ((subr-fboundp 'concat-chars)
187               ;; Emacs 20.1 or later
188               (defalias 'string 'concat-chars)
189               ))
190        )
191       ((= emacs-major-version 19)
192        ;; XXX: should do compile-time and load-time check before loading
193        ;;      "localhook".  But, it is difficult since "localhook" is
194        ;;      already loaded via "install" at compile-time.  any idea?
195        (if (< emacs-minor-version 29)
196            (require 'localhook)))
197       (t
198        (require 'poe-18)
199        ;; XXX: should do compile-time and load-time check before loading
200        ;;      "localhook".  But, it is difficult since "localhook" is
201        ;;      already loaded via "install" at compile-time.  any idea?
202        (require 'localhook)))
203
204 ;;; `eval-when-compile' is defined in "poe-18" under v18 with old compiler.
205 (eval-when-compile (require 'static))
206
207 ;; imported from emacs-20.3/lisp/emacs-lisp/edebug.el.
208 ;; `def-edebug-spec' is an autoloaded macro in v19 and later.
209 (defmacro-maybe def-edebug-spec (symbol spec)
210   "Set the edebug-form-spec property of SYMBOL according to SPEC.
211 Both SYMBOL and SPEC are unevaluated. The SPEC can be 0, t, a symbol
212 \(naming a function\), or a list."
213   (` (put (quote (, symbol)) 'edebug-form-spec (quote (, spec)))))
214
215 (def-edebug-spec defun-maybe defun)
216 (def-edebug-spec defmacro-maybe defmacro)
217 (def-edebug-spec defsubst-maybe defun)
218
219 ;;; Emacs 20.1 emulation
220
221 ;; imported from emacs-20.3/lisp/subr.el.
222 (defmacro-maybe when (cond &rest body)
223   "If COND yields non-nil, do BODY, else return nil."
224   (list 'if cond (cons 'progn body)))
225 ;; (def-edebug-spec when (&rest form))
226
227 ;; imported from emacs-20.3/lisp/subr.el.
228 (defmacro-maybe unless (cond &rest body)
229   "If COND yields nil, do BODY, else return nil."
230   (cons 'if (cons cond (cons nil body))))
231 ;; (def-edebug-spec unless (&rest form))
232
233
234 ;;; @ Emacs 19.23 emulation
235 ;;;
236
237 (defun-maybe minibuffer-prompt-width ()
238   "Return the display width of the minibuffer prompt."
239   (save-excursion
240     (set-buffer (window-buffer (minibuffer-window)))
241     (current-column)))
242
243
244 ;;; @ Emacs 19.29 emulation
245 ;;;
246
247 (defvar-maybe path-separator ":"
248   "The directory separator in search paths, as a string.")
249
250 (defun-maybe buffer-substring-no-properties (start end)
251   "Return the characters of part of the buffer, without the text properties.
252 The two arguments START and END are character positions;
253 they can be in either order.
254 \[Emacs 19.29 emulating function]"
255   (let ((string (buffer-substring start end)))
256     (set-text-properties 0 (length string) nil string)
257     string))
258
259 ;; imported from emacs-19.34/lisp/subr.el.
260 (defun-maybe match-string (num &optional string)
261   "Return string of text matched by last search.
262 NUM specifies which parenthesized expression in the last regexp.
263  Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
264 Zero means the entire text matched by the whole regexp or whole string.
265 STRING should be given if the last search was by `string-match' on STRING.
266 \[Emacs 19.29 emulating function]"
267   (if (match-beginning num)
268       (if string
269           (substring string (match-beginning num) (match-end num))
270         (buffer-substring (match-beginning num) (match-end num)))))
271
272 (static-unless (or (featurep 'xemacs)
273                    (>= emacs-major-version 20)
274                    (and (= emacs-major-version 19)
275                         (>= emacs-minor-version 29)))
276   ;; for Emacs 19.28 or earlier
277   (unless (fboundp 'si:read-string)
278     (fset 'si:read-string (symbol-function 'read-string))
279     (defun read-string (prompt &optional initial-input history)
280       "Read a string from the minibuffer, prompting with string PROMPT.
281 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
282 The third arg HISTORY, is dummy for compatibility.
283 See `read-from-minibuffer' for details of HISTORY argument."
284       (si:read-string prompt initial-input))
285     ))
286
287 (defun-maybe rassoc (key list)
288   "Return non-nil if KEY is `equal' to the cdr of an element of LIST.
289 The value is actually the element of LIST whose cdr equals KEY.
290 \[Emacs 19.29 emulating function]"
291   (catch 'found
292     (while list
293       (if (equal (cdr (car list)) key)
294           (throw 'found (car list)))
295       (setq list (cdr list)))))
296
297 ;; imported from emacs-19.34/lisp/files.el.
298 (defun-maybe file-name-sans-extension (filename)
299   "Return FILENAME sans final \"extension\".
300 The extension, in a file name, is the part that follows the last `.'.
301 \[Emacs 19.29 emulating function]"
302   (save-match-data
303     (let ((file (file-name-sans-versions (file-name-nondirectory filename)))
304           directory)
305       (if (string-match "\\.[^.]*\\'" file)
306           (if (setq directory (file-name-directory filename))
307               (expand-file-name (substring file 0 (match-beginning 0))
308                                 directory)
309             (substring file 0 (match-beginning 0)))
310         filename))))
311
312
313 ;;; @ Emacs 19.30 emulation
314 ;;;
315
316 ;; imported from emacs-19.34/lisp/subr.el.
317 (defun-maybe add-to-list (list-var element)
318   "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
319 The test for presence of ELEMENT is done with `equal'.
320 If you want to use `add-to-list' on a variable that is not defined
321 until a certain package is loaded, you should put the call to `add-to-list'
322 into a hook function that will be run only after loading the package.
323 `eval-after-load' provides one way to do this.  In some cases
324 other hooks, such as major mode hooks, can do the job.
325 \[Emacs 19.30 emulating function]"
326   (or (member element (symbol-value list-var))
327       (set list-var (cons element (symbol-value list-var)))))
328
329 (cond ((fboundp 'insert-file-contents-literally))
330       ((boundp 'file-name-handler-alist)
331        (defun insert-file-contents-literally
332          (filename &optional visit beg end replace)
333          "Like `insert-file-contents', q.v., but only reads in the file.
334 A buffer may be modified in several ways after reading into the buffer due
335 to advanced Emacs features, such as file-name-handlers, format decoding,
336 find-file-hooks, etc.
337   This function ensures that none of these modifications will take place.
338 \[Emacs 19.30 emulating function]"
339          (let (file-name-handler-alist)
340            (insert-file-contents filename visit beg end replace)))
341        )
342       (t
343        (defalias 'insert-file-contents-literally 'insert-file-contents)
344        ))
345
346
347 ;;; @ Emacs 19.31 emulation
348 ;;;
349
350 (defun-maybe buffer-live-p (object)
351   "Return non-nil if OBJECT is a buffer which has not been killed.
352 Value is nil if OBJECT is not a buffer or if it has been killed.
353 \[Emacs 19.31 emulating function]"
354   (and object
355        (get-buffer object)
356        (buffer-name (get-buffer object))
357        t))
358
359 ;; imported from emacs-19.34/lisp/window.el.
360 (defmacro-maybe save-selected-window (&rest body)
361   "Execute BODY, then select the window that was selected before BODY.
362 \[Emacs 19.31 emulating function]"
363   (list 'let
364         '((save-selected-window-window (selected-window)))
365         (list 'unwind-protect
366               (cons 'progn body)
367               (list 'select-window 'save-selected-window-window))))
368
369
370 ;;; @ Emacs 20.1 emulation
371 ;;;
372
373 ;; imported from emacs-20.3/lisp/subr.el.
374 (defsubst-maybe caar (x)
375   "Return the car of the car of X."
376   (car (car x)))
377
378 ;; imported from emacs-20.3/lisp/subr.el.
379 (defsubst-maybe cadr (x)
380   "Return the car of the cdr of X."
381   (car (cdr x)))
382
383 ;; imported from emacs-20.3/lisp/subr.el.
384 (defsubst-maybe cdar (x)
385   "Return the cdr of the car of X."
386   (cdr (car x)))
387
388 ;; imported from emacs-20.3/lisp/subr.el.
389 (defsubst-maybe cddr (x)
390   "Return the cdr of the cdr of X."
391   (cdr (cdr x)))
392
393 ;; imported from emacs-20.3/lisp/subr.el.
394 (defun-maybe last (x &optional n)
395   "Return the last link of the list X.  Its car is the last element.
396 If X is nil, return nil.
397 If N is non-nil, return the Nth-to-last link of X.
398 If N is bigger than the length of X, return X."
399   (if n
400       (let ((m 0) (p x))
401         (while (consp p)
402           (setq m (1+ m) p (cdr p)))
403         (if (<= n 0) p
404           (if (< n m) (nthcdr (- m n) x) x)))
405     (while (cdr x)
406       (setq x (cdr x)))
407     x))
408
409 ;; In Emacs 20.3, save-current-buffer is defined in src/editfns.c.
410 (defmacro-maybe save-current-buffer (&rest body)
411   "Save the current buffer; execute BODY; restore the current buffer.
412 Executes BODY just like `progn'."
413   (` (let ((orig-buffer (current-buffer)))
414        (unwind-protect
415            (progn (,@ body))
416          (if (buffer-live-p orig-buffer)
417              (set-buffer orig-buffer))))))
418
419 ;; imported from emacs-20.3/lisp/subr.el. (with macro style change)
420 (defmacro-maybe with-current-buffer (buffer &rest body)
421   "Execute the forms in BODY with BUFFER as the current buffer.
422 The value returned is the value of the last form in BODY.
423 See also `with-temp-buffer'."
424   (` (save-current-buffer
425        (set-buffer (, buffer))
426        (,@ body))))
427
428 ;; imported from emacs-20.3/lisp/subr.el. (with macro style change)
429 (defmacro-maybe with-temp-file (file &rest forms)
430   "Create a new buffer, evaluate FORMS there, and write the buffer to FILE.
431 The value of the last form in FORMS is returned, like `progn'.
432 See also `with-temp-buffer'."
433   (let ((temp-file (make-symbol "temp-file"))
434         (temp-buffer (make-symbol "temp-buffer")))
435     (` (let (((, temp-file) (, file))
436              ((, temp-buffer)
437               (get-buffer-create (generate-new-buffer-name " *temp file*"))))
438          (unwind-protect
439              (prog1
440                  (with-current-buffer (, temp-buffer)
441                    (,@ forms))
442                (with-current-buffer (, temp-buffer)
443                  (widen)
444                  (write-region (point-min) (point-max) (, temp-file) nil 0)))
445            (and (buffer-name (, temp-buffer))
446                 (kill-buffer (, temp-buffer))))))))
447
448 ;; imported from emacs-20.3/lisp/subr.el. (with macro style change)
449 (defmacro-maybe with-temp-buffer (&rest forms)
450   "Create a temporary buffer, and evaluate FORMS there like `progn'.
451 See also `with-temp-file' and `with-output-to-string'."
452   (let ((temp-buffer (make-symbol "temp-buffer")))
453     (` (let (((, temp-buffer)
454               (get-buffer-create (generate-new-buffer-name " *temp*"))))
455          (unwind-protect
456              (with-current-buffer (, temp-buffer)
457                (,@ forms))
458            (and (buffer-name (, temp-buffer))
459                 (kill-buffer (, temp-buffer))))))))
460
461 (defmacro-maybe combine-after-change-calls (&rest body)
462   "Execute BODY."
463   (cons 'progn body))
464
465 ;; imported from emacs-20.3/lisp/subr.el.
466 (defun-maybe functionp (object)
467   "Non-nil if OBJECT is a type of object that can be called as a function."
468   (or (subrp object) (byte-code-function-p object)
469       (eq (car-safe object) 'lambda)
470       (and (symbolp object) (fboundp object))))
471
472 ;; imported from emacs-20.3/lisp/emacs-lisp/cl.el.
473 (defun-maybe butlast (x &optional n)
474   "Returns a copy of LIST with the last N elements removed."
475   (if (and n (<= n 0)) x
476     (nbutlast (copy-sequence x) n)))
477
478 ;; imported from emacs-20.3/lisp/emacs-lisp/cl.el.
479 (defun-maybe nbutlast (x &optional n)
480   "Modifies LIST to remove the last N elements."
481   (let ((m (length x)))
482     (or n (setq n 1))
483     (and (< n m)
484          (progn
485            (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
486            x))))
487
488 ;; imported from XEmacs 21.
489 (defun-maybe split-string (string &optional pattern)
490   "Return a list of substrings of STRING which are separated by PATTERN.
491 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
492   (or pattern
493       (setq pattern "[ \f\t\n\r\v]+"))
494   ;; The FSF version of this function takes care not to cons in case
495   ;; of infloop.  Maybe we should synch?
496   (let (parts (start 0))
497     (while (string-match pattern string start)
498       (setq parts (cons (substring string start (match-beginning 0)) parts)
499             start (match-end 0)))
500     (nreverse (cons (substring string start) parts))))
501
502 ;; emulating char-before of Emacs 20.
503 (static-condition-case nil
504     ;; compile-time check.
505     (progn
506       ;; XXX: this file is already loaded at compile-time,
507       ;; so this test will always success.
508       (char-before)
509       ;; If our definition is found at compile-time, signal an error.
510       ;; XXX: should signal more specific error. 
511       (if (get 'char-before 'defun-maybe)
512           (error "")))
513   (wrong-number-of-arguments            ; Mule 1.*, 2.*.
514    ;; load-time check.
515    (or (fboundp 'si:char-before)
516        (progn
517          (fset 'si:char-before (symbol-function 'char-before))
518          (put 'char-before 'defun-maybe t)
519          ;; takes IGNORED for backward compatibility.
520          (defun char-before (&optional pos ignored)
521            "\
522 Return character in current buffer preceding position POS.
523 POS is an integer or a buffer pointer.
524 If POS is out of range, the value is nil."
525            (si:char-before (or pos (point)))))))
526   (void-function                        ; non-Mule.
527    ;; load-time check.
528    (defun-maybe char-before (&optional pos)
529      "\
530 Return character in current buffer preceding position POS.
531 POS is an integer or a buffer pointer.
532 If POS is out of range, the value is nil."
533      (if pos
534          (save-excursion
535            (and (= (goto-char pos) (point))
536                 (not (bobp))
537                 (preceding-char)))
538        (and (not (bobp))
539             (preceding-char)))))
540   (error                                ; found our definition at compile-time.
541    ;; load-time check.
542    (condition-case nil
543        (char-before)
544      (wrong-number-of-arguments         ; Mule 1.*, 2.*.
545       (or (fboundp 'si:char-before)
546           (progn
547             (fset 'si:char-before (symbol-function 'char-before))
548             (put 'char-before 'defun-maybe t)
549             ;; takes IGNORED for backward compatibility.
550             (defun char-before (&optional pos ignored)
551               "\
552 Return character in current buffer preceding position POS.
553 POS is an integer or a buffer pointer.
554 If POS is out of range, the value is nil."
555               (si:char-before (or pos (point)))))))
556      (void-function                     ; non-Mule.
557       (defun-maybe char-before (&optional pos)
558         "\
559 Return character in current buffer preceding position POS.
560 POS is an integer or a buffer pointer.
561 If POS is out of range, the value is nil."
562         (if pos
563             (save-excursion
564               (and (= (goto-char pos) (point))
565                    (not (bobp))
566                    (preceding-char)))
567           (and (not (bobp))
568                (preceding-char))))))))
569
570 ;; emulating char-after of Emacs 20.
571 (static-condition-case nil
572     ;; compile-time check.
573     (progn
574       ;; XXX: this file is already loaded at compile-time,
575       ;; so this test will always success.
576       (char-after)
577       ;; If our definition is found at compile-time, signal an error.
578       ;; XXX: should signal more specific error. 
579       (if (get 'char-after 'defun-maybe)
580           (error "")))
581   (wrong-number-of-arguments            ; v18, v19
582    ;; load-time check.
583    (or (fboundp 'si:char-after)
584        (progn
585          (fset 'si:char-after (symbol-function 'char-after))
586          (put 'char-after 'defun-maybe t)
587          (defun char-after (&optional pos)
588            "\
589 Return character in current buffer at position POS.
590 POS is an integer or a buffer pointer.
591 If POS is out of range, the value is nil."
592            (si:char-after (or pos (point)))))))
593   (void-function                        ; NEVER happen?
594    ;; load-time check.
595    (defun-maybe char-after (&optional pos)
596      "\
597 Return character in current buffer at position POS.
598 POS is an integer or a buffer pointer.
599 If POS is out of range, the value is nil."
600      (if pos
601          (save-excursion
602            (and (= (goto-char pos) (point))
603                 (not (eobp))
604                 (following-char)))
605        (and (not (eobp))
606             (following-char)))))
607   (error                                ; found our definition at compile-time.
608    ;; load-time check.
609    (condition-case nil
610        (char-after)
611      (wrong-number-of-arguments         ; v18, v19
612       (or (fboundp 'si:char-after)
613           (progn
614             (fset 'si:char-after (symbol-function 'char-after))
615             (put 'char-after 'defun-maybe t)
616             (defun char-after (&optional pos)
617               "\
618 Return character in current buffer at position POS.
619 POS is an integer or a buffer pointer.
620 If POS is out of range, the value is nil."
621               (si:char-after (or pos (point)))))))
622      (void-function                     ; NEVER happen?
623       (defun-maybe char-after (&optional pos)
624         "\
625 Return character in current buffer at position POS.
626 POS is an integer or a buffer pointer.
627 If POS is out of range, the value is nil."
628         (if pos
629             (save-excursion
630               (and (= (goto-char pos) (point))
631                    (not (eobp))
632                    (following-char)))
633           (and (not (eobp))
634                (following-char))))))))
635
636
637 ;;; @ Emacs 20.3 emulation
638 ;;;
639
640 ;; imported from emacs-20.3/lisp/files.el.
641 (defvar-maybe temporary-file-directory
642   (file-name-as-directory
643    (cond ((memq system-type '(ms-dos windows-nt))
644           (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
645          ((memq system-type '(vax-vms axp-vms))
646           (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
647          (t
648           (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
649   "The directory for writing temporary files.")
650
651 (defun-maybe line-beginning-position (&optional n)
652   "Return the character position of the first character on the current line.
653 With argument N not nil or 1, move forward N - 1 lines first.
654 If scan reaches end of buffer, return that position.
655 This function does not move point."
656   (save-excursion
657     (forward-line (1- (or n 1)))
658     (point)))
659
660 (defun-maybe line-end-position (&optional n)
661   "Return the character position of the last character on the current line.
662 With argument N not nil or 1, move forward N - 1 lines first.
663 If scan reaches end of buffer, return that position.
664 This function does not move point."
665   (save-excursion
666     (end-of-line (or n 1))
667     (point)))
668
669 (defun-maybe string (&rest chars)
670   "Concatenate all the argument characters and make the result a string."
671   (mapconcat (function char-to-string) chars ""))
672
673     
674 ;;; @ XEmacs emulation
675 ;;;
676
677 (defun-maybe find-face (face-or-name)
678   "Retrieve the face of the given name.
679 If FACE-OR-NAME is a face object, it is simply returned.
680 Otherwise, FACE-OR-NAME should be a symbol.  If there is no such face,
681 nil is returned.  Otherwise the associated face object is returned.
682 \[XEmacs emulating function]"
683   (car (memq face-or-name (face-list))))
684
685 (defun-maybe point-at-bol (&optional n buffer)
686   "Return the character position of the first character on the current line.
687 With argument N not nil or 1, move forward N - 1 lines first.
688 If scan reaches end of buffer, return that position.
689 This function does not move point.
690 \[XEmacs emulating function]"
691   (save-excursion
692     (if buffer (set-buffer buffer))
693     (forward-line (1- (or n 1)))
694     (point)))
695
696 (defun-maybe point-at-eol (&optional n buffer)
697   "Return the character position of the last character on the current line.
698 With argument N not nil or 1, move forward N - 1 lines first.
699 If scan reaches end of buffer, return that position.
700 This function does not move point.
701 \[XEmacs emulating function]"
702   (save-excursion
703     (if buffer (set-buffer buffer))
704     (end-of-line (or n 1))
705     (point)))
706
707 (defsubst-maybe define-obsolete-function-alias (oldfun newfun)
708   "Define OLDFUN as an obsolete alias for function NEWFUN.
709 This makes calling OLDFUN equivalent to calling NEWFUN and marks OLDFUN
710 as obsolete.
711 \[XEmacs emulating function]"
712   (defalias oldfun newfun)
713   (make-obsolete oldfun newfun))
714
715 (when (subr-fboundp 'read-event)
716   ;; for Emacs 19 or later
717
718   (defun-maybe-cond next-command-event (&optional event prompt)
719     "Read an event object from the input stream.
720 If EVENT is non-nil, it should be an event object and will be filled
721 in and returned; otherwise a new event object will be created and
722 returned.
723 If PROMPT is non-nil, it should be a string and will be displayed in
724 the echo area while this function is waiting for an event.
725 \[XEmacs emulating function]"
726     ((subr-fboundp 'string)
727      ;; for Emacs 20.3 or later
728      (read-event prompt t)
729      )
730     (t
731      (if prompt (message prompt))
732      (read-event)
733      ))
734
735   (defsubst-maybe character-to-event (ch)
736     "Convert keystroke CH into an event structure, replete with bucky bits.
737 Note that CH (the keystroke specifier) can be an integer, a character
738 or a symbol such as 'clear. [XEmacs emulating function]"
739     ch)
740
741   (defsubst-maybe event-to-character (event)
742     "Return the character approximation to the given event object.
743 If the event isn't a keypress, this returns nil.
744 \[XEmacs emulating function]"
745     (cond ((symbolp event)
746            ;; mask is (BASE-TYPE MODIFIER-BITS) or nil.
747            (let ((mask (get event 'event-symbol-element-mask)))
748              (if mask
749                  (let ((base (get (car mask) 'ascii-character)))
750                    (if base
751                        (logior base (car (cdr mask)))
752                      )))))
753           ((integerp event) event)))
754   )
755
756
757 ;;; @ MULE 2 emulation
758 ;;;
759
760 (defun-maybe-cond cancel-undo-boundary ()
761   "Cancel undo boundary. [MULE 2.3 emulating function]"
762   ((boundp 'buffer-undo-list)
763    ;; for Emacs 19.7 or later
764    (if (and (consp buffer-undo-list)
765             ;; if car is nil.
766             (null (car buffer-undo-list)))
767        (setq buffer-undo-list (cdr buffer-undo-list))
768      ))
769   (t
770    ;; for anything older than Emacs 19.7.    
771    ))
772
773
774 ;;; @ end
775 ;;;
776
777 ;;; poe.el ends here