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