Use `string' before calling `insert'
[bpt/emacs.git] / lisp / subr.el
index b80df94..826f52a 100644 (file)
@@ -94,17 +94,23 @@ If N is bigger than the length of X, return X."
       (setq x (cdr x)))
     x))
 
-(defun assoc-default (el alist test default)
-  "Find object EL in a pseudo-alist ALIST.
-ALIST is a list of conses or objects.  Each element (or the element's
-car, if it. is a cons) is compared with EL by calling TEST.
-If TEST returns non-nil, the element matches;
-then `assoc-default' returns the cdr of the element (if it is a cons),
+(defun assoc-default (key alist &optional test default)
+  "Find object KEY in a pseudo-alist ALIST.
+ALIST is a list of conses or objects.  Each element (or the element's car,
+if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
+If that is non-nil, the element matches;
+then `assoc-default' returns the element's cdr, if it is a cons,
 or DEFAULT if the element is not a cons.
-If no element matches, the value is nil."
-  (dolist (rr alist)
-    (when (funcall test el (if (consp rr) (car rr) rr))
-      (return (if (consp rr) (cdr rr) default)))))
+
+If no element matches, the value is nil.
+If TEST is omitted or nil, `equal' is used."
+  (let (found (tail alist) value)
+    (while (and tail (not found))
+      (let ((elt (car tail)))
+       (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
+         (setq found t value (if (consp elt) (cdr elt) default))))
+      (setq tail (cdr tail)))
+    value))
 \f
 ;;;; Keymap support.
 
@@ -523,14 +529,9 @@ as returned by the `event-start' and `event-end' functions."
 (defalias 'compiled-function-p 'byte-code-function-p)
 (defalias 'define-function 'defalias)
 
-(defun sref (string byte-index)
-  "Obsolete function returning a character in STRING at BYTE-INDEX.
-Please convert your programs to use `aref' with character-base index."
-  (let ((byte 0) (char 0))
-    (while (< byte byte-index)
-      (setq byte (+ byte (char-bytes (aref string char)))
-           char (1+ char)))
-    (aref string char)))
+(defalias 'sref 'aref)
+(make-obsolete 'sref 'aref)
+(make-obsolete 'char-bytes "Now this function always returns 1")
 
 ;; Some programs still use this as a function.
 (defun baud-rate ()
@@ -615,7 +616,7 @@ function, it is changed to a list of functions."
          (and (local-variable-if-set-p hook)
               (not (memq t (symbol-value hook)))))
       ;; Alter the local value only.
-      (or (if (or (consp function) (compiled-function-p function))
+      (or (if (or (consp function) (byte-code-function-p function))
              (member function (symbol-value hook))
            (memq function (symbol-value hook)))
          (set hook 
@@ -624,7 +625,7 @@ function, it is changed to a list of functions."
                 (cons function (symbol-value hook)))))
     ;; Alter the global value (which is also the only value,
     ;; if the hook doesn't have a local value).
-    (or (if (or (consp function) (compiled-function-p function))
+    (or (if (or (consp function) (byte-code-function-p function))
            (member function (default-value hook))
          (memq function (default-value hook)))
        (set-default hook 
@@ -735,8 +736,6 @@ for numeric input."
   (let ((message-log-max nil) done (first t) (code 0) char)
     (while (not done)
       (let ((inhibit-quit first)
-           ;; Don't use input methods inside this function.
-           (input-method-function nil)
            ;; Don't let C-h get the help message--only help function keys.
            (help-char nil)
            (help-form
@@ -744,8 +743,7 @@ for numeric input."
 or the octal character code.
 RET terminates the character code and is discarded;
 any other non-digit terminates the character code and is then used as input."))
-       (and prompt (message "%s-" prompt))
-       (setq char (read-event))
+       (setq char (read-event (and prompt (format "%s-" prompt)) t))
        (if inhibit-quit (setq quit-flag nil)))
       ;; Translate TAB key into control-I ASCII character, and so on.
       (and char