(add-hook, remove-hook): Accept optional `local' arg.
[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 (defun-maybe last (x &optional n)
419   "Return the last link of the list X.  Its car is the last element.
420 If X is nil, return nil.
421 If N is non-nil, return the Nth-to-last link of X.
422 If N is bigger than the length of X, return X."
423   (if n
424       (let ((m 0) (p x))
425         (while (consp p)
426           (setq m (1+ m) p (cdr p)))
427         (if (<= n 0) p
428           (if (< n m) (nthcdr (- m n) x) x)))
429     (while (cdr x)
430       (setq x (cdr x)))
431     x))
432
433 (defmacro-maybe save-current-buffer (&rest body)
434   "Save the current buffer; execute BODY; restore the current buffer.
435 Executes BODY just like `progn'."
436   (` (let ((orig-buffer (current-buffer)))
437        (unwind-protect
438            (progn (,@ body))
439          (set-buffer orig-buffer)))))
440
441 ;; imported from Emacs 20.2.
442 (defmacro-maybe with-current-buffer (buffer &rest body)
443   "Execute the forms in BODY with BUFFER as the current buffer.
444 The value returned is the value of the last form in BODY.
445 See also `with-temp-buffer'."
446   (` (save-current-buffer
447        (set-buffer (, buffer))
448        (,@ body))))
449
450 ;; imported from Emacs 20.2.
451 (defmacro-maybe with-temp-file (file &rest forms)
452   "Create a new buffer, evaluate FORMS there, and write the buffer to FILE.
453 The value of the last form in FORMS is returned, like `progn'.
454 See also `with-temp-buffer'."
455   (let ((temp-file (make-symbol "temp-file"))
456         (temp-buffer (make-symbol "temp-buffer")))
457     (` (let (((, temp-file) (, file))
458              ((, temp-buffer)
459               (get-buffer-create (generate-new-buffer-name " *temp file*"))))
460          (unwind-protect
461              (prog1
462                  (with-current-buffer (, temp-buffer)
463                    (,@ forms))
464                (with-current-buffer (, temp-buffer)
465                  (widen)
466                  (write-region (point-min) (point-max) (, temp-file) nil 0)))
467            (and (buffer-name (, temp-buffer))
468                 (kill-buffer (, temp-buffer))))))))
469
470 ;; imported from Emacs 20.2.
471 (defmacro-maybe with-temp-buffer (&rest forms)
472   "Create a temporary buffer, and evaluate FORMS there like `progn'.
473 See also `with-temp-file' and `with-output-to-string'."
474   (let ((temp-buffer (make-symbol "temp-buffer")))
475     (` (let (((, temp-buffer)
476               (get-buffer-create (generate-new-buffer-name " *temp*"))))
477          (unwind-protect
478              (with-current-buffer (, temp-buffer)
479                (,@ forms))
480            (and (buffer-name (, temp-buffer))
481                 (kill-buffer (, temp-buffer))))))))
482
483 (defmacro-maybe combine-after-change-calls (&rest body)
484   "Execute BODY."
485   (cons 'progn body))
486
487 ;; imported from Emacs 20.3. (cl function)
488 (defun-maybe butlast (x &optional n)
489   "Returns a copy of LIST with the last N elements removed."
490   (if (and n (<= n 0)) x
491     (nbutlast (copy-sequence x) n)))
492
493 ;; imported from Emacs 20.3. (cl function)
494 (defun-maybe nbutlast (x &optional n)
495   "Modifies LIST to remove the last N elements."
496   (let ((m (length x)))
497     (or n (setq n 1))
498     (and (< n m)
499          (progn
500            (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
501            x))))
502
503 ;; imported from XEmacs 21.
504 (defun-maybe split-string (string &optional pattern)
505   "Return a list of substrings of STRING which are separated by PATTERN.
506 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
507   (or pattern
508       (setq pattern "[ \f\t\n\r\v]+"))
509   ;; The FSF version of this function takes care not to cons in case
510   ;; of infloop.  Maybe we should synch?
511   (let (parts (start 0))
512     (while (string-match pattern string start)
513       (setq parts (cons (substring string start (match-beginning 0)) parts)
514             start (match-end 0)))
515     (nreverse (cons (substring string start) parts))))
516
517
518 ;;; @ Emacs 20.3 emulation
519 ;;;
520
521 ;; imported from Emacs 20.3.91.
522 (defvar-maybe temporary-file-directory
523   (file-name-as-directory
524    (cond ((memq system-type '(ms-dos windows-nt))
525           (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
526          ((memq system-type '(vax-vms axp-vms))
527           (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
528          (t
529           (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
530   "The directory for writing temporary files.")
531
532 (defun-maybe line-beginning-position (&optional n)
533   "Return the character position of the first character on the current line.
534 With argument N not nil or 1, move forward N - 1 lines first.
535 If scan reaches end of buffer, return that position.
536 This function does not move point."
537   (save-excursion
538     (if n
539         (forward-line (1- n))
540       )
541     (beginning-of-line)
542     (point)))
543
544 (defun-maybe line-end-position (&optional n)
545   "Return the character position of the last character on the current line.
546 With argument N not nil or 1, move forward N - 1 lines first.
547 If scan reaches end of buffer, return that position.
548 This function does not move point."
549   (save-excursion
550     (if n
551         (forward-line (1- n))
552       )
553     (end-of-line)
554     (point)))
555
556 (defun-maybe string (&rest chars)
557   "Concatenate all the argument characters and make the result a string."
558   (mapconcat (function char-to-string) chars "")
559   )
560
561     
562 ;;; @ XEmacs emulation
563 ;;;
564
565 (defun-maybe find-face (face-or-name)
566   "Retrieve the face of the given name.
567 If FACE-OR-NAME is a face object, it is simply returned.
568 Otherwise, FACE-OR-NAME should be a symbol.  If there is no such face,
569 nil is returned.  Otherwise the associated face object is returned.
570 \[XEmacs emulating function]"
571   (car (memq face-or-name (face-list)))
572   )
573
574 (defun-maybe point-at-bol (&optional n buffer)
575   "Return the character position of the first character on the current line.
576 With argument N not nil or 1, move forward N - 1 lines first.
577 If scan reaches end of buffer, return that position.
578 This function does not move point. [XEmacs emulating function]"
579   (save-excursion
580     (if buffer
581         (set-buffer buffer)
582       )
583     (line-beginning-position n)
584     ))
585
586 (defun-maybe point-at-eol (&optional n buffer)
587   "Return the character position of the last character on the current line.
588 With argument N not nil or 1, move forward N - 1 lines first.
589 If scan reaches end of buffer, return that position.
590 This function does not move point. [XEmacs emulating function]"
591   (save-excursion
592     (if buffer
593         (set-buffer buffer)
594       )
595     (line-end-position n)
596     ))
597
598 (defun-maybe functionp (obj)
599   "Returns t if OBJ is a function, nil otherwise.
600 \[XEmacs emulating function]"
601   (or (subrp obj)
602       (byte-code-function-p obj)
603       (and (symbolp obj)(fboundp obj))
604       (and (consp obj)(eq (car obj) 'lambda))
605       ))
606
607 (defsubst-maybe define-obsolete-function-alias (oldfun newfun)
608   "Define OLDFUN as an obsolete alias for function NEWFUN.
609 This makes calling OLDFUN equivalent to calling NEWFUN and marks OLDFUN
610 as obsolete. [XEmacs emulating function]"
611   (defalias oldfun newfun)
612   (make-obsolete oldfun newfun)
613   )
614
615 (when (subr-fboundp 'read-event)
616   ;; for Emacs 19 or later
617
618   (defun-maybe-cond next-command-event (&optional event prompt)
619     "Read an event object from the input stream.
620 If EVENT is non-nil, it should be an event object and will be filled
621 in and returned; otherwise a new event object will be created and
622 returned.
623 If PROMPT is non-nil, it should be a string and will be displayed in
624 the echo area while this function is waiting for an event.
625 \[XEmacs emulating function]"
626     ((subr-fboundp 'string)
627      ;; for Emacs 20.3 or later
628      (read-event prompt t)
629      )
630     (t
631      (if prompt (message prompt))
632      (read-event)
633      ))
634
635   (defsubst-maybe character-to-event (ch)
636     "Convert keystroke CH into an event structure, replete with bucky bits.
637 Note that CH (the keystroke specifier) can be an integer, a character
638 or a symbol such as 'clear. [XEmacs emulating function]"
639     ch)
640
641   (defun-maybe event-to-character (event)
642     "Return the character approximation to the given event object.
643 If the event isn't a keypress, this returns nil.
644 \[XEmacs emulating function]"
645     (cond ((symbolp event)
646            ;; mask is (BASE-TYPE MODIFIER-BITS) or nil.
647            (let ((mask (get event 'event-symbol-element-mask)))
648              (if mask
649                  (let ((base (get (car mask) 'ascii-character)))
650                    (if base
651                        (logior base (car (cdr mask)))
652                      )))))
653           ((integerp event) event)
654           ))
655   )
656
657
658 ;;; @ MULE 2 emulation
659 ;;;
660
661 (defun-maybe-cond cancel-undo-boundary ()
662   "Cancel undo boundary. [MULE 2.3 emulating function]"
663   ((boundp 'buffer-undo-list)
664    ;; for Emacs 19.7 or later
665    (if (and (consp buffer-undo-list)
666             ;; if car is nil.
667             (null (car buffer-undo-list)))
668        (setq buffer-undo-list (cdr buffer-undo-list))
669      ))
670   (t
671    ;; for anything older than Emacs 19.7.    
672    ))
673
674
675 ;;; @ end
676 ;;;
677
678 ;;; poe.el ends here