Update autoload checksums.
[bpt/emacs.git] / lisp / subr.el
index 0dda4b0..ee95f48 100644 (file)
@@ -1,7 +1,7 @@
 ;;; subr.el --- basic lisp subroutines for Emacs
 
 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1999, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: internal
@@ -68,7 +68,7 @@ the end of FILE must be all on the same line.  For example:
 \(declare-function c-end-of-defun \"progmodes/cc-cmds.el\"
                   \(&optional arg))
 
-For more information, see Info node `elisp(Declaring Functions)'."
+For more information, see Info node `(elisp)Declaring Functions'."
   ;; Does nothing - byte-compile-declare-function does the work.
   nil)
 
@@ -558,7 +558,8 @@ Don't call this function; it is for internal use only."
 (defun keymap-canonicalize (map)
   "Return an equivalent keymap, without inheritance."
   (let ((bindings ())
-        (ranges ()))
+        (ranges ())
+       (prompt (keymap-prompt map)))
     (while (keymapp map)
       (setq map (map-keymap-internal
                  (lambda (key item)
@@ -567,8 +568,7 @@ Don't call this function; it is for internal use only."
                        (push (cons key item) ranges)
                      (push (cons key item) bindings)))
                  map)))
-    (setq map (funcall (if ranges 'make-keymap 'make-sparse-keymap)
-                       (keymap-prompt map)))
+    (setq map (funcall (if ranges 'make-keymap 'make-sparse-keymap) prompt))
     (dolist (binding ranges)
       ;; Treat char-ranges specially.
       (define-key map (vector (car binding)) (cdr binding)))
@@ -1076,6 +1076,8 @@ to reread, so it now uses nil to mean `no event', instead of -1."
 (defalias 'search-backward-regexp (symbol-function 're-search-backward))
 (defalias 'int-to-string 'number-to-string)
 (defalias 'store-match-data 'set-match-data)
+(defalias 'chmod 'set-file-modes)
+(defalias 'mkdir 'make-directory)
 ;; These are the XEmacs names:
 (defalias 'point-at-eol 'line-end-position)
 (defalias 'point-at-bol 'line-beginning-position)
@@ -1781,7 +1783,9 @@ If optional CONFIRM is non-nil, read the password twice to make sure.
 Optional DEFAULT is a default password to use instead of empty input.
 
 This function echoes `.' for each character that the user types.
-The user ends with RET, LFD, or ESC.  DEL or C-h rubs out.  C-u kills line.
+
+The user ends with RET, LFD, or ESC.  DEL or C-h rubs out.
+C-y yanks the current kill.  C-u kills line.
 C-g quits; if `inhibit-quit' was non-nil around this function,
 then it returns nil if the user types C-g, but quit-flag remains set.
 
@@ -1809,30 +1813,48 @@ by doing (clear-string STRING)."
            (c 0)
            (echo-keystrokes 0)
            (cursor-in-echo-area t)
-           (message-log-max nil))
+           (message-log-max nil)
+           (stop-keys (list 'return ?\r ?\n ?\e))
+           (rubout-keys (list 'backspace ?\b ?\177)))
        (add-text-properties 0 (length prompt)
                             minibuffer-prompt-properties prompt)
        (while (progn (message "%s%s"
                               prompt
                               (make-string (length pass) ?.))
-                     (setq c (read-char-exclusive nil t))
-                     (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
+                     ;; We used to use read-char-exclusive, but that
+                     ;; gives funny behavior when the user presses,
+                     ;; e.g., the arrow keys.
+                     (setq c (read-event nil t))
+                     (not (memq c stop-keys)))
          (clear-this-command-keys)
-         (if (= c ?\C-u)
-             (progn
-               (and (arrayp pass) (clear-string pass))
-               (setq pass ""))
-           (if (and (/= c ?\b) (/= c ?\177))
-               (let* ((new-char (char-to-string c))
-                      (new-pass (concat pass new-char)))
-                 (and (arrayp pass) (clear-string pass))
-                 (clear-string new-char)
-                 (setq c ?\0)
-                 (setq pass new-pass))
-             (if (> (length pass) 0)
-                 (let ((new-pass (substring pass 0 -1)))
-                   (and (arrayp pass) (clear-string pass))
-                   (setq pass new-pass))))))
+         (cond ((memq c rubout-keys) ; rubout
+                (when (> (length pass) 0)
+                  (let ((new-pass (substring pass 0 -1)))
+                    (and (arrayp pass) (clear-string pass))
+                    (setq pass new-pass))))
+               ((not (numberp c)))
+               ((= c ?\C-u) ; kill line
+                (and (arrayp pass) (clear-string pass))
+                (setq pass ""))
+               ((= c ?\C-y) ; yank
+                (let* ((str (condition-case nil
+                                (current-kill 0)
+                              (error nil)))
+                       new-pass)
+                  (when str
+                    (setq new-pass
+                          (concat pass
+                                  (substring-no-properties str)))
+                    (and (arrayp pass) (clear-string pass))
+                    (setq c ?\0)
+                    (setq pass new-pass))))
+               ((characterp c) ; insert char
+                (let* ((new-char (char-to-string c))
+                       (new-pass (concat pass new-char)))
+                  (and (arrayp pass) (clear-string pass))
+                  (clear-string new-char)
+                  (setq c ?\0)
+                  (setq pass new-pass)))))
        (message nil)
        (or pass default "")))))
 
@@ -2169,10 +2191,12 @@ directory if it does not exist."
          (at-home (and old-name (expand-file-name old-name home))))
      (if (and at-home (file-readable-p at-home))
         at-home
-       (unless (or purify-flag ;; don't create dir while dumping
-                  (file-accessible-directory-p
-                   (directory-file-name user-emacs-directory)))
-        (make-directory user-emacs-directory t)) ;; don't catch errors
+       ;; Make sure `user-emacs-directory' exists,
+       ;; unless we're in batch mode or dumping Emacs
+       (or noninteractive
+          purify-flag
+          (file-accessible-directory-p (directory-file-name user-emacs-directory))
+          (make-directory user-emacs-directory))
        (expand-file-name new-name user-emacs-directory)))))
 
 \f
@@ -2497,17 +2521,18 @@ also `with-temp-buffer'."
   "Execute the forms in BODY with WINDOW as the selected window.
 The value returned is the value of the last form in BODY.
 
-This macro saves and restores the current buffer, since otherwise
-its normal operation could potentially make a different
-buffer current.  It does not alter the buffer list ordering.
-
-This macro saves and restores the selected window, as well as
-the selected window in each frame.  If the previously selected
-window of some frame is no longer live at the end of BODY, that
-frame's selected window is left alone.  If the selected window is
-no longer live, then whatever window is selected at the end of
-BODY remains selected.
-See also `with-temp-buffer'."
+This macro saves and restores the selected window, as well as the
+selected window of each frame.  It does not change the order of
+recently selected windows.  If the previously selected window of
+some frame is no longer live at the end of BODY, that frame's
+selected window is left alone.  If the selected window is no
+longer live, then whatever window is selected at the end of BODY
+remains selected.
+
+This macro uses `save-current-buffer' to save and restore the
+current buffer, since otherwise its normal operation could
+potentially make a different buffer current.  It does not alter
+the buffer list ordering."
   (declare (indent 1) (debug t))
   ;; Most of this code is a copy of save-selected-window.
   `(let ((save-selected-window-window (selected-window))
@@ -2524,26 +2549,28 @@ See also `with-temp-buffer'."
         (dolist (elt save-selected-window-alist)
           (and (frame-live-p (car elt))
                (window-live-p (cadr elt))
-               (set-frame-selected-window (car elt) (cadr elt))))
-        (if (window-live-p save-selected-window-window)
-            (select-window save-selected-window-window 'norecord))))))
+               (set-frame-selected-window (car elt) (cadr elt) 'norecord)))
+        (when (window-live-p save-selected-window-window)
+          (select-window save-selected-window-window 'norecord))))))
 
 (defmacro with-selected-frame (frame &rest body)
   "Execute the forms in BODY with FRAME as the selected frame.
 The value returned is the value of the last form in BODY.
-See also `with-temp-buffer'."
+
+This macro neither changes the order of recently selected windows
+nor the buffer list."
   (declare (indent 1) (debug t))
   (let ((old-frame (make-symbol "old-frame"))
        (old-buffer (make-symbol "old-buffer")))
     `(let ((,old-frame (selected-frame))
           (,old-buffer (current-buffer)))
        (unwind-protect
-          (progn (select-frame ,frame)
+          (progn (select-frame ,frame 'norecord)
                  ,@body)
-        (if (frame-live-p ,old-frame)
-            (select-frame ,old-frame))
-        (if (buffer-live-p ,old-buffer)
-            (set-buffer ,old-buffer))))))
+        (when (frame-live-p ,old-frame)
+          (select-frame ,old-frame 'norecord))
+        (when (buffer-live-p ,old-buffer)
+          (set-buffer ,old-buffer))))))
 
 (defmacro with-temp-file (file &rest body)
   "Create a new buffer, evaluate BODY there, and write the buffer to FILE.
@@ -2770,9 +2797,11 @@ LIMIT if non-nil speeds up the search by specifying a minimum
 starting position, to avoid checking matches that would start
 before LIMIT.
 
-If GREEDY is non-nil, extend the match backwards as far as possible,
-stopping when a single additional previous character cannot be part
-of a match for REGEXP."
+If GREEDY is non-nil, extend the match backwards as far as
+possible, stopping when a single additional previous character
+cannot be part of a match for REGEXP.  When the match is
+extended, its starting position is allowed to occur before
+LIMIT."
   (let ((start (point))
        (pos
         (save-excursion