X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/d46490e312e95fcd2172d1cefe94706246423350..85c92c4050da1dc1dd0497b2841ac5437d775857:/lisp/subr.el diff --git a/lisp/subr.el b/lisp/subr.el index 014217edf8..826f52a85f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -93,6 +93,24 @@ If N is bigger than the length of X, return X." (while (cdr x) (setq x (cdr x))) x)) + +(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. +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)) ;;;; Keymap support. @@ -511,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 () @@ -603,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 (consp function) + (or (if (or (consp function) (byte-code-function-p function)) (member function (symbol-value hook)) (memq function (symbol-value hook))) (set hook @@ -612,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 (consp function) + (or (if (or (consp function) (byte-code-function-p function)) (member function (default-value hook)) (memq function (default-value hook))) (set-default hook @@ -730,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