Comment changes.
[bpt/emacs.git] / lisp / subr.el
index 2d55e68..014217e 100644 (file)
@@ -516,7 +516,8 @@ as returned by the `event-start' and `event-end' functions."
 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 byte)))))
+      (setq byte (+ byte (char-bytes (aref string char)))
+           char (1+ char)))
     (aref string char)))
 
 ;; Some programs still use this as a function.
@@ -542,7 +543,7 @@ Please convert your programs to use the variable `baud-rate' directly."
 (defalias 'search-forward-regexp (symbol-function 're-search-forward))
 (defalias 'search-backward-regexp (symbol-function 're-search-backward))
 (defalias 'int-to-string 'number-to-string)
-(defalias 'set-match-data 'store-match-data)
+(defalias 'store-match-data 'set-match-data)
 
 ;;; Should this be an obsolete name?  If you decide it should, you get
 ;;; to go through all the sources and change them.
@@ -631,7 +632,7 @@ This makes no difference if the hook is not buffer-local.
 To make a hook variable buffer-local, always use
 `make-local-hook', not `make-local-variable'."
   (if (or (not (boundp hook))          ;unbound symbol, or
-         (not (default-boundp 'hook))
+         (not (default-boundp hook))
          (null (symbol-value hook))    ;value is nil, or
          (null function))              ;function is nil, then
       nil                              ;Do nothing.
@@ -663,8 +664,9 @@ until a certain package is loaded, you should put the call to `add-to-list'
 into a hook function that will be run only after loading the package.
 `eval-after-load' provides one way to do this.  In some cases
 other hooks, such as major mode hooks, can do the job."
-  (or (member element (symbol-value list-var))
-      (set list-var (cons element (symbol-value list-var)))))
+  (if (member element (symbol-value list-var))
+      (symbol-value list-var)
+    (set list-var (cons element (symbol-value list-var)))))
 \f
 ;;;; Specifying things to do after certain files are loaded.
 
@@ -762,27 +764,38 @@ any other non-digit terminates the character code and is then used as input."))
       (setq first nil))
     code))
 
-(defun read-password (prompt &optional default)
-  "Read a password, echoing `.' for each character typed.
+(defun read-passwd (prompt &optional confirm default)
+  "Read a password, prompting with PROMPT.  Echo `.' for each character typed.
 End with RET, LFD, or ESC.  DEL or C-h rubs out.  C-u kills line.
-Optional DEFAULT is password to start with."
-  (let ((pass nil)
-       (c 0)
-       (echo-keystrokes 0)
-       (cursor-in-echo-area t))
-    (while (progn (message "%s%s"
-                          prompt
-                          (make-string (length pass) ?.))
-                 (setq c (read-char))
-                 (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
-      (if (= c ?\C-u)
-         (setq pass "")
-       (if (and (/= c ?\b) (/= c ?\177))
-           (setq pass (concat pass (char-to-string c)))
-         (if (> (length pass) 0)
-             (setq pass (substring pass 0 -1))))))
-    (message nil)
-    (or pass default "")))
+Optional argument CONFIRM, if non-nil, then read it twice to make sure.
+Optional DEFAULT is a default password to use instead of empty input."
+  (if confirm
+      (let (success)
+       (while (not success)
+         (let ((first (read-passwd prompt nil default))
+               (second (read-passwd "Confirm password: " nil default)))
+           (if (equal first second)
+               (setq success first)
+             (message "Password not repeated accurately; please start over")
+             (sit-for 1))))
+       success)
+    (let ((pass nil)
+         (c 0)
+         (echo-keystrokes 0)
+         (cursor-in-echo-area t))
+      (while (progn (message "%s%s"
+                            prompt
+                            (make-string (length pass) ?.))
+                   (setq c (read-char))
+                   (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
+       (if (= c ?\C-u)
+           (setq pass "")
+         (if (and (/= c ?\b) (/= c ?\177))
+             (setq pass (concat pass (char-to-string c)))
+           (if (> (length pass) 0)
+               (setq pass (substring pass 0 -1))))))
+      (message nil)
+      (or pass default ""))))
 \f
 (defun force-mode-line-update (&optional all)
   "Force the mode-line of the current buffer to be redisplayed.
@@ -813,7 +826,7 @@ If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
            (insert-before-markers string)
            (setq insert-end (point))
            ;; If the message end is off screen, recenter now.
-           (if (< (window-end) insert-end)
+           (if (< (window-end nil t) insert-end)
                (recenter (/ (window-height) 2)))
            ;; If that pushed message start off the screen,
            ;; scroll to start it at the top of the screen.
@@ -981,7 +994,7 @@ in BODY."
   `(let ((save-match-data-internal (match-data)))
        (unwind-protect
           (progn ,@body)
-        (store-match-data save-match-data-internal))))
+        (set-match-data save-match-data-internal))))
 
 (defun match-string (num &optional string)
   "Return string of text matched by last search.
@@ -1120,8 +1133,7 @@ that you make with this function."
   (interactive "KSet key globally: \nCSet key %s to command: ")
   (or (vectorp key) (stringp key)
       (signal 'wrong-type-argument (list 'arrayp key)))
-  (define-key (current-global-map) key command)
-  nil)
+  (define-key (current-global-map) key command))
 
 (defun local-set-key (key command)
   "Give KEY a local binding as COMMAND.
@@ -1139,8 +1151,7 @@ which in most cases is shared with all other buffers in the same major mode."
        (use-local-map (setq map (make-sparse-keymap))))
     (or (vectorp key) (stringp key)
        (signal 'wrong-type-argument (list 'arrayp key)))
-    (define-key map key command))
-  nil)
+    (define-key map key command)))
 
 (defun global-unset-key (key)
   "Remove global binding of KEY.