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