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