1 ;;; poe.el --- Portable Outfit for Emacsen; -*-byte-compile-dynamic: t;-*-
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: emulation, compatibility, NEmacs, MULE, Emacs/mule, XEmacs
8 ;; This file is part of APEL (A Portable Emacs Library).
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.
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.
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.
27 ;; This modules does not includes MULE related features.
28 ;; MULE related features are supported by `poem'.
34 (or (boundp 'current-load-list) (setq current-load-list nil))
36 (put 'defun-maybe 'lisp-indent-function 'defun)
37 (defmacro defun-maybe (name &rest everything-else)
38 "Define NAME as a function if NAME is not defined.
39 See also the function `defun'."
40 (or (and (fboundp name)
41 (not (get name 'defun-maybe)))
42 (` (or (fboundp (quote (, name)))
44 (defun (, name) (,@ everything-else))
45 ;; This `defun' will be compiled to `fset', which does
46 ;; not update `load-history'.
47 (setq current-load-list
48 (cons (quote (, name)) current-load-list))
49 (put (quote (, name)) 'defun-maybe t))))))
51 (put 'defmacro-maybe 'lisp-indent-function 'defun)
52 (defmacro defmacro-maybe (name &rest everything-else)
53 "Define NAME as a macro if NAME is not defined.
54 See also the function `defmacro'."
55 (or (and (fboundp name)
56 (not (get name 'defmacro-maybe)))
57 (` (or (fboundp (quote (, name)))
59 (defmacro (, name) (,@ everything-else))
60 (setq current-load-list
61 (cons (quote (, name)) current-load-list))
62 (put (quote (, name)) 'defmacro-maybe t))))))
64 (put 'defsubst-maybe 'lisp-indent-function 'defun)
65 (defmacro defsubst-maybe (name &rest everything-else)
66 "Define NAME as an inline function if NAME is not defined.
67 See also the macro `defsubst'."
68 (or (and (fboundp name)
69 (not (get name 'defsubst-maybe)))
70 (` (or (fboundp (quote (, name)))
72 (defsubst (, name) (,@ everything-else))
73 (setq current-load-list
74 (cons (quote (, name)) current-load-list))
75 (put (quote (, name)) 'defsubst-maybe t))))))
77 (defmacro defalias-maybe (symbol definition)
78 "Define SYMBOL as an alias for DEFINITION if SYMBOL is not defined.
79 See also the function `defalias'."
80 (setq symbol (eval symbol))
81 (or (and (fboundp symbol)
82 (not (get symbol 'defalias-maybe)))
83 (` (or (fboundp (quote (, symbol)))
85 (defalias (quote (, symbol)) (, definition))
86 (setq current-load-list
87 (cons (quote (, symbol)) current-load-list))
88 (put (quote (, symbol)) 'defalias-maybe t))))))
90 (defmacro defvar-maybe (name &rest everything-else)
91 "Define NAME as a variable if NAME is not defined.
92 See also the function `defvar'."
93 (or (and (boundp name)
94 (not (get name 'defvar-maybe)))
95 (` (or (boundp (quote (, name)))
97 (defvar (, name) (,@ everything-else))
98 ;; byte-compiler will generate code to update
100 (put (quote (, name)) 'defvar-maybe t))))))
102 (defmacro defconst-maybe (name &rest everything-else)
103 "Define NAME as a constant variable if NAME is not defined.
104 See also the function `defconst'."
105 (or (and (boundp name)
106 (not (get name 'defconst-maybe)))
107 (` (or (boundp (quote (, name)))
109 (defconst (, name) (,@ everything-else))
110 ;; byte-compiler will generate code to update
112 (put (quote (, name)) 'defconst-maybe t))))))
114 (defmacro defun-maybe-cond (name args &optional doc &rest everything-else)
116 (setq everything-else (cons doc everything-else)
118 (or (and (fboundp name)
119 (not (get name 'defun-maybe)))
120 (` (or (fboundp (quote (, name)))
128 (` (defun (, name) (, args)
131 (` (defun (, name) (, args)
132 (,@ (cdr case))))))))
134 (setq current-load-list
135 (cons (quote (, name)) current-load-list))
136 (put (quote (, name)) 'defun-maybe t))))))
138 (defmacro defmacro-maybe-cond (name args &optional doc &rest everything-else)
140 (setq everything-else (cons doc everything-else)
142 (or (and (fboundp name)
143 (not (get name 'defmacro-maybe)))
144 (` (or (fboundp (quote (, name)))
152 (` (defmacro (, name) (, args)
155 (` (defmacro (, name) (, args)
156 (,@ (cdr case))))))))
158 (setq current-load-list
159 (cons (quote (, name)) current-load-list))
160 (put (quote (, name)) 'defmacro-maybe t))))))
162 (defun subr-fboundp (symbol)
163 "Return t if SYMBOL's function definition is a built-in function."
164 (and (fboundp symbol)
165 (subrp (symbol-function symbol))))
167 (defconst-maybe emacs-major-version (string-to-int emacs-version))
168 (defconst-maybe emacs-minor-version
170 (substring emacs-version
171 (string-match (format "%d\\." emacs-major-version)
174 (cond ((featurep 'xemacs)
175 (require 'poe-xemacs)
177 ((string-match "XEmacs" emacs-version)
179 (require 'poe-xemacs)
181 ((> emacs-major-version 20))
182 ((= emacs-major-version 20)
183 (cond ((subr-fboundp 'string)
184 ;; Emacs 20.3 or later
186 ((subr-fboundp 'concat-chars)
187 ;; Emacs 20.1 or later
188 (defalias 'string 'concat-chars)
191 ((= emacs-major-version 19)
192 ;; XXX: should do compile-time and load-time check before loading
193 ;; "localhook". But, it is difficult since "localhook" is
194 ;; already loaded via "install" at compile-time. any idea?
195 (if (< emacs-minor-version 29)
196 (require 'localhook)))
199 ;; XXX: should do compile-time and load-time check before loading
200 ;; "localhook". But, it is difficult since "localhook" is
201 ;; already loaded via "install" at compile-time. any idea?
202 (require 'localhook)))
204 ;;; `eval-when-compile' is defined in "poe-18" under v18 with old compiler.
205 (eval-when-compile (require 'static))
207 ;; imported from emacs-20.3/lisp/emacs-lisp/edebug.el.
208 ;; `def-edebug-spec' is an autoloaded macro in v19 and later.
209 (defmacro-maybe def-edebug-spec (symbol spec)
210 "Set the edebug-form-spec property of SYMBOL according to SPEC.
211 Both SYMBOL and SPEC are unevaluated. The SPEC can be 0, t, a symbol
212 \(naming a function\), or a list."
213 (` (put (quote (, symbol)) 'edebug-form-spec (quote (, spec)))))
215 (def-edebug-spec defun-maybe defun)
216 (def-edebug-spec defmacro-maybe defmacro)
217 (def-edebug-spec defsubst-maybe defun)
219 ;;; Emacs 20.1 emulation
221 ;; imported from emacs-20.3/lisp/subr.el.
222 (defmacro-maybe when (cond &rest body)
223 "If COND yields non-nil, do BODY, else return nil."
224 (list 'if cond (cons 'progn body)))
225 ;; (def-edebug-spec when (&rest form))
227 ;; imported from emacs-20.3/lisp/subr.el.
228 (defmacro-maybe unless (cond &rest body)
229 "If COND yields nil, do BODY, else return nil."
230 (cons 'if (cons cond (cons nil body))))
231 ;; (def-edebug-spec unless (&rest form))
234 ;;; @ Emacs 19.23 emulation
237 (defun-maybe minibuffer-prompt-width ()
238 "Return the display width of the minibuffer prompt."
240 (set-buffer (window-buffer (minibuffer-window)))
244 ;;; @ Emacs 19.29 emulation
247 (defvar-maybe path-separator ":"
248 "The directory separator in search paths, as a string.")
250 (defun-maybe buffer-substring-no-properties (start end)
251 "Return the characters of part of the buffer, without the text properties.
252 The two arguments START and END are character positions;
253 they can be in either order.
254 \[Emacs 19.29 emulating function]"
255 (let ((string (buffer-substring start end)))
256 (set-text-properties 0 (length string) nil string)
259 ;; imported from emacs-19.34/lisp/subr.el.
260 (defun-maybe match-string (num &optional string)
261 "Return string of text matched by last search.
262 NUM specifies which parenthesized expression in the last regexp.
263 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
264 Zero means the entire text matched by the whole regexp or whole string.
265 STRING should be given if the last search was by `string-match' on STRING.
266 \[Emacs 19.29 emulating function]"
267 (if (match-beginning num)
269 (substring string (match-beginning num) (match-end num))
270 (buffer-substring (match-beginning num) (match-end num)))))
272 (static-unless (or (featurep 'xemacs)
273 (>= emacs-major-version 20)
274 (and (= emacs-major-version 19)
275 (>= emacs-minor-version 29)))
276 ;; for Emacs 19.28 or earlier
277 (unless (fboundp 'si:read-string)
278 (fset 'si:read-string (symbol-function 'read-string))
279 (defun read-string (prompt &optional initial-input history)
280 "Read a string from the minibuffer, prompting with string PROMPT.
281 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
282 The third arg HISTORY, is dummy for compatibility.
283 See `read-from-minibuffer' for details of HISTORY argument."
284 (si:read-string prompt initial-input))
287 (defun-maybe rassoc (key list)
288 "Return non-nil if KEY is `equal' to the cdr of an element of LIST.
289 The value is actually the element of LIST whose cdr equals KEY.
290 Elements of LIST that are not conses are ignored.
291 \[Emacs 19.29 emulating function]"
294 (cond ((not (consp (car list))))
295 ((equal (cdr (car list)) key)
296 (throw 'found (car list)) ))
297 (setq list (cdr list)) )))
299 ;; imported from emacs-19.34/lisp/files.el.
300 (defun-maybe file-name-sans-extension (filename)
301 "Return FILENAME sans final \"extension\".
302 The extension, in a file name, is the part that follows the last `.'.
303 \[Emacs 19.29 emulating function]"
305 (let ((file (file-name-sans-versions (file-name-nondirectory filename)))
307 (if (string-match "\\.[^.]*\\'" file)
308 (if (setq directory (file-name-directory filename))
309 (expand-file-name (substring file 0 (match-beginning 0))
311 (substring file 0 (match-beginning 0)))
315 ;;; @ Emacs 19.30 emulation
318 ;; imported from emacs-19.34/lisp/subr.el.
319 (defun-maybe add-to-list (list-var element)
320 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
321 The test for presence of ELEMENT is done with `equal'.
322 If you want to use `add-to-list' on a variable that is not defined
323 until a certain package is loaded, you should put the call to `add-to-list'
324 into a hook function that will be run only after loading the package.
325 `eval-after-load' provides one way to do this. In some cases
326 other hooks, such as major mode hooks, can do the job.
327 \[Emacs 19.30 emulating function]"
328 (or (member element (symbol-value list-var))
329 (set list-var (cons element (symbol-value list-var)))))
331 (cond ((fboundp 'insert-file-contents-literally))
332 ((boundp 'file-name-handler-alist)
333 (defun insert-file-contents-literally
334 (filename &optional visit beg end replace)
335 "Like `insert-file-contents', q.v., but only reads in the file.
336 A buffer may be modified in several ways after reading into the buffer due
337 to advanced Emacs features, such as file-name-handlers, format decoding,
338 find-file-hooks, etc.
339 This function ensures that none of these modifications will take place.
340 \[Emacs 19.30 emulating function]"
341 (let (file-name-handler-alist)
342 (insert-file-contents filename visit beg end replace)))
345 (defalias 'insert-file-contents-literally 'insert-file-contents)
349 ;;; @ Emacs 19.31 emulation
352 (defun-maybe buffer-live-p (object)
353 "Return non-nil if OBJECT is a buffer which has not been killed.
354 Value is nil if OBJECT is not a buffer or if it has been killed.
355 \[Emacs 19.31 emulating function]"
358 (buffer-name (get-buffer object))
361 ;; imported from emacs-19.34/lisp/window.el.
362 (defmacro-maybe save-selected-window (&rest body)
363 "Execute BODY, then select the window that was selected before BODY.
364 \[Emacs 19.31 emulating function]"
366 '((save-selected-window-window (selected-window)))
367 (list 'unwind-protect
369 (list 'select-window 'save-selected-window-window))))
371 (defun-maybe-cond convert-standard-filename (filename)
372 "Convert a standard file's name to something suitable for the current OS.
373 This function's standard definition is trivial; it just returns the argument.
374 However, on some systems, the function is redefined
375 with a definition that really does change some file names.
376 Under `windows-nt' or `ms-dos', it refers `filename-replacement-alist' and
377 `filename-limit-length' for the basic filename and each parent directory name.
378 \[Emacs 19.31 emulating function]"
379 ((memq system-type '(windows-nt ms-dos))
381 (let* ((names (split-string filename "/"))
382 (drive-name (car names))
383 (filter (function (lambda (string)
384 (filename-maybe-truncate-by-size
385 (filename-special-filter string))))))
386 (cond ((eq 1 (length names))
387 (funcall filter drive-name))
388 ((string-match "^[^/]:$" drive-name)
389 (concat drive-name "/" (mapconcat filter (cdr names) "/")))
390 (t (mapconcat filter names "/")))))
394 ;;; @ Emacs 20.1 emulation
397 ;; imported from emacs-20.3/lisp/subr.el.
398 (defsubst-maybe caar (x)
399 "Return the car of the car of X."
402 ;; imported from emacs-20.3/lisp/subr.el.
403 (defsubst-maybe cadr (x)
404 "Return the car of the cdr of X."
407 ;; imported from emacs-20.3/lisp/subr.el.
408 (defsubst-maybe cdar (x)
409 "Return the cdr of the car of X."
412 ;; imported from emacs-20.3/lisp/subr.el.
413 (defsubst-maybe cddr (x)
414 "Return the cdr of the cdr of X."
417 ;; imported from emacs-20.3/lisp/subr.el.
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."
426 (setq m (1+ m) p (cdr p)))
428 (if (< n m) (nthcdr (- m n) x) x)))
433 ;; In Emacs 20.3, save-current-buffer is defined in src/editfns.c.
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)))
440 (if (buffer-live-p orig-buffer)
441 (set-buffer orig-buffer))))))
443 ;; imported from emacs-20.3/lisp/subr.el. (with macro style change)
444 (defmacro-maybe with-current-buffer (buffer &rest body)
445 "Execute the forms in BODY with BUFFER as the current buffer.
446 The value returned is the value of the last form in BODY.
447 See also `with-temp-buffer'."
448 (` (save-current-buffer
449 (set-buffer (, buffer))
452 ;; imported from emacs-20.3/lisp/subr.el. (with macro style change)
453 (defmacro-maybe with-temp-file (file &rest forms)
454 "Create a new buffer, evaluate FORMS there, and write the buffer to FILE.
455 The value of the last form in FORMS is returned, like `progn'.
456 See also `with-temp-buffer'."
457 (let ((temp-file (make-symbol "temp-file"))
458 (temp-buffer (make-symbol "temp-buffer")))
459 (` (let (((, temp-file) (, file))
461 (get-buffer-create (generate-new-buffer-name " *temp file*"))))
464 (with-current-buffer (, temp-buffer)
466 (with-current-buffer (, temp-buffer)
468 (write-region (point-min) (point-max) (, temp-file) nil 0)))
469 (and (buffer-name (, temp-buffer))
470 (kill-buffer (, temp-buffer))))))))
472 ;; imported from emacs-20.3/lisp/subr.el. (with macro style change)
473 (defmacro-maybe with-temp-buffer (&rest forms)
474 "Create a temporary buffer, and evaluate FORMS there like `progn'.
475 See also `with-temp-file' and `with-output-to-string'."
476 (let ((temp-buffer (make-symbol "temp-buffer")))
477 (` (let (((, temp-buffer)
478 (get-buffer-create (generate-new-buffer-name " *temp*"))))
480 (with-current-buffer (, temp-buffer)
482 (and (buffer-name (, temp-buffer))
483 (kill-buffer (, temp-buffer))))))))
485 (defmacro-maybe combine-after-change-calls (&rest body)
489 ;; imported from emacs-20.3/lisp/subr.el.
490 (defun-maybe functionp (object)
491 "Non-nil if OBJECT is a type of object that can be called as a function."
492 (or (subrp object) (byte-code-function-p object)
493 (eq (car-safe object) 'lambda)
494 (and (symbolp object) (fboundp object))))
496 ;; imported from emacs-20.3/lisp/emacs-lisp/cl.el.
497 (defun-maybe butlast (x &optional n)
498 "Returns a copy of LIST with the last N elements removed."
499 (if (and n (<= n 0)) x
500 (nbutlast (copy-sequence x) n)))
502 ;; imported from emacs-20.3/lisp/emacs-lisp/cl.el.
503 (defun-maybe nbutlast (x &optional n)
504 "Modifies LIST to remove the last N elements."
505 (let ((m (length x)))
509 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
512 ;; imported from XEmacs 21.
513 (defun-maybe split-string (string &optional pattern)
514 "Return a list of substrings of STRING which are separated by PATTERN.
515 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
517 (setq pattern "[ \f\t\n\r\v]+"))
518 ;; The FSF version of this function takes care not to cons in case
519 ;; of infloop. Maybe we should synch?
520 (let (parts (start 0))
521 (while (string-match pattern string start)
522 (setq parts (cons (substring string start (match-beginning 0)) parts)
523 start (match-end 0)))
524 (nreverse (cons (substring string start) parts))))
526 ;; emulating char-before of Emacs 20.
527 (static-condition-case nil
528 ;; compile-time check.
530 ;; XXX: this file is already loaded at compile-time,
531 ;; so this test will always success.
533 ;; If our definition is found at compile-time, signal an error.
534 ;; XXX: should signal more specific error.
535 (if (get 'char-before 'defun-maybe)
537 (wrong-number-of-arguments ; Mule 1.*, 2.*.
539 (or (fboundp 'si:char-before)
541 (fset 'si:char-before (symbol-function 'char-before))
542 (put 'char-before 'defun-maybe t)
543 ;; takes IGNORED for backward compatibility.
544 (defun char-before (&optional pos ignored)
546 Return character in current buffer preceding position POS.
547 POS is an integer or a buffer pointer.
548 If POS is out of range, the value is nil."
549 (si:char-before (or pos (point)))))))
550 (void-function ; non-Mule.
552 (defun-maybe char-before (&optional pos)
554 Return character in current buffer preceding position POS.
555 POS is an integer or a buffer pointer.
556 If POS is out of range, the value is nil."
559 (and (= (goto-char pos) (point))
564 (error ; found our definition at compile-time.
568 (wrong-number-of-arguments ; Mule 1.*, 2.*.
569 (or (fboundp 'si:char-before)
571 (fset 'si:char-before (symbol-function 'char-before))
572 (put 'char-before 'defun-maybe t)
573 ;; takes IGNORED for backward compatibility.
574 (defun char-before (&optional pos ignored)
576 Return character in current buffer preceding position POS.
577 POS is an integer or a buffer pointer.
578 If POS is out of range, the value is nil."
579 (si:char-before (or pos (point)))))))
580 (void-function ; non-Mule.
581 (defun-maybe char-before (&optional pos)
583 Return character in current buffer preceding position POS.
584 POS is an integer or a buffer pointer.
585 If POS is out of range, the value is nil."
588 (and (= (goto-char pos) (point))
592 (preceding-char))))))))
594 ;; emulating char-after of Emacs 20.
595 (static-condition-case nil
596 ;; compile-time check.
598 ;; XXX: this file is already loaded at compile-time,
599 ;; so this test will always success.
601 ;; If our definition is found at compile-time, signal an error.
602 ;; XXX: should signal more specific error.
603 (if (get 'char-after 'defun-maybe)
605 (wrong-number-of-arguments ; v18, v19
607 (or (fboundp 'si:char-after)
609 (fset 'si:char-after (symbol-function 'char-after))
610 (put 'char-after 'defun-maybe t)
611 (defun char-after (&optional pos)
613 Return character in current buffer at position POS.
614 POS is an integer or a buffer pointer.
615 If POS is out of range, the value is nil."
616 (si:char-after (or pos (point)))))))
617 (void-function ; NEVER happen?
619 (defun-maybe char-after (&optional pos)
621 Return character in current buffer at position POS.
622 POS is an integer or a buffer pointer.
623 If POS is out of range, the value is nil."
626 (and (= (goto-char pos) (point))
631 (error ; found our definition at compile-time.
635 (wrong-number-of-arguments ; v18, v19
636 (or (fboundp 'si:char-after)
638 (fset 'si:char-after (symbol-function 'char-after))
639 (put 'char-after 'defun-maybe t)
640 (defun char-after (&optional pos)
642 Return character in current buffer at position POS.
643 POS is an integer or a buffer pointer.
644 If POS is out of range, the value is nil."
645 (si:char-after (or pos (point)))))))
646 (void-function ; NEVER happen?
647 (defun-maybe char-after (&optional pos)
649 Return character in current buffer at position POS.
650 POS is an integer or a buffer pointer.
651 If POS is out of range, the value is nil."
654 (and (= (goto-char pos) (point))
658 (following-char))))))))
661 ;;; @ Emacs 20.3 emulation
664 ;; imported from emacs-20.3/lisp/files.el.
665 (defvar-maybe temporary-file-directory
666 (file-name-as-directory
667 (cond ((memq system-type '(ms-dos windows-nt))
668 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
669 ((memq system-type '(vax-vms axp-vms))
670 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
672 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
673 "The directory for writing temporary files.")
675 (defun-maybe line-beginning-position (&optional n)
676 "Return the character position of the first character on the current line.
677 With argument N not nil or 1, move forward N - 1 lines first.
678 If scan reaches end of buffer, return that position.
679 This function does not move point."
681 (forward-line (1- (or n 1)))
684 (defun-maybe line-end-position (&optional n)
685 "Return the character position of the last character on the current line.
686 With argument N not nil or 1, move forward N - 1 lines first.
687 If scan reaches end of buffer, return that position.
688 This function does not move point."
690 (end-of-line (or n 1))
693 (defun-maybe string (&rest chars)
694 "Concatenate all the argument characters and make the result a string."
695 (mapconcat (function char-to-string) chars ""))
698 ;;; @ XEmacs emulation
701 (defun-maybe find-face (face-or-name)
702 "Retrieve the face of the given name.
703 If FACE-OR-NAME is a face object, it is simply returned.
704 Otherwise, FACE-OR-NAME should be a symbol. If there is no such face,
705 nil is returned. Otherwise the associated face object is returned.
706 \[XEmacs emulating function]"
707 (car (memq face-or-name (face-list))))
709 (defun-maybe point-at-bol (&optional n buffer)
710 "Return the character position of the first character on the current line.
711 With argument N not nil or 1, move forward N - 1 lines first.
712 If scan reaches end of buffer, return that position.
713 This function does not move point.
714 \[XEmacs emulating function]"
716 (if buffer (set-buffer buffer))
717 (forward-line (1- (or n 1)))
720 (defun-maybe point-at-eol (&optional n buffer)
721 "Return the character position of the last character on the current line.
722 With argument N not nil or 1, move forward N - 1 lines first.
723 If scan reaches end of buffer, return that position.
724 This function does not move point.
725 \[XEmacs emulating function]"
727 (if buffer (set-buffer buffer))
728 (end-of-line (or n 1))
731 (defsubst-maybe define-obsolete-function-alias (oldfun newfun)
732 "Define OLDFUN as an obsolete alias for function NEWFUN.
733 This makes calling OLDFUN equivalent to calling NEWFUN and marks OLDFUN
735 \[XEmacs emulating function]"
736 (defalias oldfun newfun)
737 (make-obsolete oldfun newfun))
739 (when (subr-fboundp 'read-event)
740 ;; for Emacs 19 or later
742 (defun-maybe-cond next-command-event (&optional event prompt)
743 "Read an event object from the input stream.
744 If EVENT is non-nil, it should be an event object and will be filled
745 in and returned; otherwise a new event object will be created and
747 If PROMPT is non-nil, it should be a string and will be displayed in
748 the echo area while this function is waiting for an event.
749 \[XEmacs emulating function]"
750 ((subr-fboundp 'string)
751 ;; for Emacs 20.3 or later
752 (read-event prompt t)
755 (if prompt (message prompt))
759 (defsubst-maybe character-to-event (ch)
760 "Convert keystroke CH into an event structure, replete with bucky bits.
761 Note that CH (the keystroke specifier) can be an integer, a character
762 or a symbol such as 'clear. [XEmacs emulating function]"
765 (defsubst-maybe event-to-character (event)
766 "Return the character approximation to the given event object.
767 If the event isn't a keypress, this returns nil.
768 \[XEmacs emulating function]"
769 (cond ((symbolp event)
770 ;; mask is (BASE-TYPE MODIFIER-BITS) or nil.
771 (let ((mask (get event 'event-symbol-element-mask)))
773 (let ((base (get (car mask) 'ascii-character)))
775 (logior base (car (cdr mask)))
777 ((integerp event) event)))
781 ;;; @ MULE 2 emulation
784 (defun-maybe-cond cancel-undo-boundary ()
785 "Cancel undo boundary. [MULE 2.3 emulating function]"
786 ((boundp 'buffer-undo-list)
787 ;; for Emacs 19.7 or later
788 (if (and (consp buffer-undo-list)
790 (null (car buffer-undo-list)))
791 (setq buffer-undo-list (cdr buffer-undo-list))
794 ;; for anything older than Emacs 19.7.