+;; (read-string PROMPT &optional INITIAL-INPUT HISTORY)
+;; Emacs 19.29/XEmacs 19.14(?) and later takes optional 3rd arg HISTORY.
+(static-unless (or (featurep 'xemacs)
+ (>= emacs-major-version 20)
+ (and (= emacs-major-version 19)
+ (>= emacs-minor-version 29)))
+ (or (fboundp 'si:read-string)
+ (progn
+ (fset 'si:read-string (symbol-function 'read-string))
+ (defun read-string (prompt &optional initial-input history)
+ "\
+Read a string from the minibuffer, prompting with string PROMPT.
+If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
+The third arg HISTORY, is dummy for compatibility.
+See `read-from-minibuffer' for details of HISTORY argument."
+ (si:read-string prompt initial-input)))))
+
+;; (completing-read prompt table &optional
+;; FSF Emacs
+;; --19.7 : predicate require-match init
+;; 19.7 --19.34 : predicate require-match init hist
+;; 20.1 -- : predicate require-match init hist def inherit-input-method
+;; XEmacs
+;; --19.(?): predicate require-match init
+;; --21.2 : predicate require-match init hist
+;; 21.2 -- : predicate require-match init hist def
+;; )
+
+;; We support following API.
+;; (completing-read prompt table
+;; &optional predicate require-match init hist def)
+(static-cond
+ ;; add 'hist' and 'def' argument.
+ ((< emacs-major-version 19)
+ (or (fboundp 'si:completing-read)
+ (progn
+ (fset 'si:completing-read (symbol-function 'completing-read))
+ (defun completing-read
+ (prompt table &optional predicate require-match init
+ hist def)
+ "Read a string in the minibuffer, with completion.
+PROMPT is a string to prompt with; normally it ends in a colon and a space.
+TABLE is an alist whose elements' cars are strings, or an obarray.
+PREDICATE limits completion to a subset of TABLE.
+See `try-completion' and `all-completions' for more details
+ on completion, TABLE, and PREDICATE.
+
+If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
+ the input is (or completes to) an element of TABLE or is null.
+ If it is also not t, Return does not exit if it does non-null completion.
+If the input is null, `completing-read' returns an empty string,
+ regardless of the value of REQUIRE-MATCH.
+
+If INIT is non-nil, insert it in the minibuffer initially.
+ If it is (STRING . POSITION), the initial input
+ is STRING, but point is placed POSITION characters into the string.
+HIST is ignored in this implementation.
+DEF, if non-nil, is the default value.
+
+Completion ignores case if the ambient value of
+ `completion-ignore-case' is non-nil."
+ (let ((string (si:completing-read prompt table predicate
+ require-match init)))
+ (if (and (string= string "") def)
+ def string))))))
+ ;; add 'def' argument.
+ ((or (and (featurep 'xemacs)
+ (or (and (eq emacs-major-version 21)
+ (< emacs-minor-version 2))
+ (< emacs-major-version 21)))
+ (< emacs-major-version 20))
+ (or (fboundp 'si:completing-read)
+ (progn
+ (fset 'si:completing-read (symbol-function 'completing-read))
+ (defun completing-read
+ (prompt table &optional predicate require-match init
+ hist def)
+ "Read a string in the minibuffer, with completion.
+PROMPT is a string to prompt with; normally it ends in a colon and a space.
+TABLE is an alist whose elements' cars are strings, or an obarray.
+PREDICATE limits completion to a subset of TABLE.
+See `try-completion' and `all-completions' for more details
+ on completion, TABLE, and PREDICATE.
+
+If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
+ the input is (or completes to) an element of TABLE or is null.
+ If it is also not t, Return does not exit if it does non-null completion.
+If the input is null, `completing-read' returns an empty string,
+ regardless of the value of REQUIRE-MATCH.
+
+If INIT is non-nil, insert it in the minibuffer initially.
+ If it is (STRING . POSITION), the initial input
+ is STRING, but point is placed POSITION characters into the string.
+HIST, if non-nil, specifies a history list
+ and optionally the initial position in the list.
+ It can be a symbol, which is the history list variable to use,
+ or it can be a cons cell (HISTVAR . HISTPOS).
+ In that case, HISTVAR is the history list variable to use,
+ and HISTPOS is the initial position (the position in the list
+ which INIT corresponds to).
+ Positions are counted starting from 1 at the beginning of the list.
+DEF, if non-nil, is the default value.
+
+Completion ignores case if the ambient value of
+ `completion-ignore-case' is non-nil."
+ (let ((string (si:completing-read prompt table predicate
+ require-match init hist)))
+ (if (and (string= string "") def)
+ def string)))))))
+
+;; v18: (string-to-int STRING)
+;; v19: (string-to-number STRING)
+;; v20: (string-to-number STRING &optional BASE)
+;;
+;; XXX: `string-to-number' of Emacs 20.3 and earlier is broken.
+;; (string-to-number "1e1" 16) => 10.0, should be 481.
+(static-condition-case nil
+ ;; compile-time check.
+ (if (= (string-to-number "1e1" 16) 481)
+ (if (get 'string-to-number 'defun-maybe)
+ (error "`string-to-number' is already redefined"))
+ (error "`string-to-number' is broken"))
+ (error
+ ;; load-time check.
+ (or (fboundp 'si:string-to-number)
+ (progn
+ (if (fboundp 'string-to-number)
+ (fset 'si:string-to-number (symbol-function 'string-to-number))
+ (fset 'si:string-to-number (symbol-function 'string-to-int))
+ ;; XXX: In v18, this causes infinite loop while byte-compiling.
+ ;; (defalias 'string-to-int 'string-to-number)
+ )
+ (put 'string-to-number 'defun-maybe t)
+ (defun string-to-number (string &optional base)
+ "\
+Convert STRING to a number by parsing it as a decimal number.
+This parses both integers and floating point numbers.
+It ignores leading spaces and tabs.
+
+If BASE, interpret STRING as a number in that base. If BASE isn't
+present, base 10 is used. BASE must be between 2 and 16 (inclusive).
+If the base used is not 10, floating point is not recognized."
+ (if (or (null base) (= base 10))
+ (si:string-to-number string)
+ (if (or (< base 2)(> base 16))
+ (signal 'args-out-of-range (cons base nil)))
+ (let ((len (length string))
+ (pos 0))
+ ;; skip leading whitespace.
+ (while (and (< pos len)
+ (memq (aref string pos) '(?\ ?\t)))
+ (setq pos (1+ pos)))
+ (if (= pos len)
+ 0
+ (let ((number 0)(negative 1)
+ chr num)
+ (if (eq (aref string pos) ?-)
+ (setq negative -1
+ pos (1+ pos))
+ (if (eq (aref string pos) ?+)
+ (setq pos (1+ pos))))
+ (while (and (< pos len)
+ (setq chr (aref string pos)
+ num (cond
+ ((and (<= ?0 chr)(<= chr ?9))
+ (- chr ?0))
+ ((and (<= ?A chr)(<= chr ?F))
+ (+ (- chr ?A) 10))
+ ((and (<= ?a chr)(<= chr ?f))
+ (+ (- chr ?a) 10))
+ (t nil)))
+ (< num base))
+ (setq number (+ (* number base) num)
+ pos (1+ pos)))
+ (* negative number))))))))))
+
+;; Emacs 20.1 and 20.2: (concat-chars &rest CHARS)
+;; Emacs 20.3/XEmacs 21.0 and later: (string &rest CHARS)
+(static-cond
+ ((and (fboundp 'string)
+ (subrp (symbol-function 'string)))
+ ;; Emacs 20.3/XEmacs 21.0 and later.
+ )
+ ((and (fboundp 'concat-chars)
+ (subrp (symbol-function 'concat-chars)))
+ ;; Emacs 20.1 and 20.2.
+ (defalias 'string 'concat-chars))
+ (t
+ ;; Use `defun-maybe' to update `load-history'.
+ (defun-maybe string (&rest chars)
+ "Concatenate all the argument characters and make the result a string."
+ ;; We cannot use (apply 'concat chars) here because `concat' does not
+ ;; work with multibyte chars on Mule 1.* and 2.*.
+ (mapconcat (function char-to-string) chars ""))))
+
+;; Mule: (char-before POS)
+;; v20: (char-before &optional POS)
+(static-condition-case nil
+ ;; compile-time check.
+ (progn
+ (char-before)
+ (if (get 'char-before 'defun-maybe)
+ (error "`char-before' is already defined")))
+ (wrong-number-of-arguments ; Mule.
+ ;; load-time check.
+ (or (fboundp 'si:char-before)
+ (progn
+ (fset 'si:char-before (symbol-function 'char-before))
+ (put 'char-before 'defun-maybe t)
+ ;; takes IGNORED for backward compatibility.
+ (defun char-before (&optional pos ignored)
+ "\
+Return character in current buffer preceding position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (si:char-before (or pos (point)))))))
+ (void-function ; non-Mule.
+ ;; load-time check.
+ (defun-maybe char-before (&optional pos)
+ "\
+Return character in current buffer preceding position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (if pos
+ (save-excursion
+ (and (= (goto-char pos) (point))
+ (not (bobp))
+ (preceding-char)))
+ (and (not (bobp))
+ (preceding-char)))))
+ (error ; found our definition at compile-time.
+ ;; load-time check.
+ (condition-case nil
+ (char-before)
+ (wrong-number-of-arguments ; Mule.
+ (or (fboundp 'si:char-before)
+ (progn
+ (fset 'si:char-before (symbol-function 'char-before))
+ (put 'char-before 'defun-maybe t)
+ ;; takes IGNORED for backward compatibility.
+ (defun char-before (&optional pos ignored)
+ "\
+Return character in current buffer preceding position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (si:char-before (or pos (point)))))))
+ (void-function ; non-Mule.
+ (defun-maybe char-before (&optional pos)
+ "\
+Return character in current buffer preceding position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (if pos
+ (save-excursion
+ (and (= (goto-char pos) (point))
+ (not (bobp))
+ (preceding-char)))
+ (and (not (bobp))
+ (preceding-char))))))))
+
+;; v18, v19: (char-after POS)
+;; v20: (char-after &optional POS)
+(static-condition-case nil
+ ;; compile-time check.
+ (progn
+ (char-after)
+ (if (get 'char-after 'defun-maybe)
+ (error "`char-after' is already redefined")))
+ (wrong-number-of-arguments ; v18, v19
+ ;; load-time check.
+ (or (fboundp 'si:char-after)
+ (progn
+ (fset 'si:char-after (symbol-function 'char-after))
+ (put 'char-after 'defun-maybe t)
+ (defun char-after (&optional pos)
+ "\
+Return character in current buffer at position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (si:char-after (or pos (point)))))))
+ (void-function ; NEVER happen?
+ ;; load-time check.
+ (defun-maybe char-after (&optional pos)
+ "\
+Return character in current buffer at position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (if pos
+ (save-excursion
+ (and (= (goto-char pos) (point))
+ (not (eobp))
+ (following-char)))
+ (and (not (eobp))
+ (following-char)))))
+ (error ; found our definition at compile-time.
+ ;; load-time check.
+ (condition-case nil
+ (char-after)
+ (wrong-number-of-arguments ; v18, v19
+ (or (fboundp 'si:char-after)
+ (progn
+ (fset 'si:char-after (symbol-function 'char-after))
+ (put 'char-after 'defun-maybe t)
+ (defun char-after (&optional pos)
+ "\
+Return character in current buffer at position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (si:char-after (or pos (point)))))))
+ (void-function ; NEVER happen?
+ (defun-maybe char-after (&optional pos)
+ "\
+Return character in current buffer at position POS.
+POS is an integer or a buffer pointer.
+If POS is out of range, the value is nil."
+ (if pos
+ (save-excursion
+ (and (= (goto-char pos) (point))
+ (not (eobp))
+ (following-char)))
+ (and (not (eobp))
+ (following-char))))))))
+
+;; Emacs 19.29 and later: (buffer-substring-no-properties START END)