emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r107874: * lisp/subr.el (read-passwd)


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r107874: * lisp/subr.el (read-passwd): Use read-string.
Date: Wed, 11 Apr 2012 14:13:20 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 107874
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2012-04-11 14:13:20 -0400
message:
  * lisp/subr.el (read-passwd): Use read-string.
modified:
  lisp/ChangeLog
  lisp/subr.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-04-11 16:09:39 +0000
+++ b/lisp/ChangeLog    2012-04-11 18:13:20 +0000
@@ -1,3 +1,7 @@
+2012-04-11  Stefan Monnier  <address@hidden>
+
+       * subr.el (read-passwd): Use read-string.
+
 2012-04-11  Lars Magne Ingebrigtsen  <address@hidden>
 
        * vcursor.el (vcursor-move): Increase the priority of the overlay

=== modified file 'lisp/subr.el'
--- a/lisp/subr.el      2012-04-09 13:05:48 +0000
+++ b/lisp/subr.el      2012-04-11 18:13:20 +0000
@@ -871,6 +871,7 @@
 (defsubst eventp (obj)
   "True if the argument is an event object."
   (or (and (integerp obj)
+           ;; FIXME: Why bother?
           ;; Filter out integers too large to be events.
           ;; M is the biggest modifier.
           (zerop (logand obj (lognot (1- (lsh ?\M-\^@ 1)))))
@@ -1989,6 +1990,10 @@
 So escape sequences and keyboard encoding are taken into account.
 When there's an ambiguity because the key looks like the prefix of
 some sort of escape sequence, the ambiguity is resolved via `read-key-delay'."
+  ;; This overriding-terminal-local-map binding also happens to
+  ;; disable quail's input methods, so although read-key-sequence
+  ;; always inherits the input method, in practice read-key does not
+  ;; inherit the input method (at least not if it's based on quail).
   (let ((overriding-terminal-local-map read-key-empty-map)
        (overriding-local-map nil)
         (echo-keystrokes 0)
@@ -2093,77 +2098,45 @@
 
 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-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.
-
 Once the caller uses the password, it can erase the password
 by doing (clear-string STRING)."
-  (with-local-quit
-    (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)
-                 (progn
-                   (and (arrayp second) (clear-string second))
-                   (setq success first))
-               (and (arrayp first) (clear-string first))
-               (and (arrayp second) (clear-string second))
-               (message "Password not repeated accurately; please start over")
-               (sit-for 1))))
-         success)
-      (let ((pass nil)
-           ;; Copy it so that add-text-properties won't modify
-           ;; the object that was passed in by the caller.
-           (prompt (copy-sequence prompt))
-           (c 0)
-           (echo-keystrokes 0)
-           (cursor-in-echo-area t)
-           (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-key))
-                     (not (memq c stop-keys)))
-         (clear-this-command-keys)
-         (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))))
-                ((eq c ?\C-g) (keyboard-quit))
-               ((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 "")))))
+  (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)
+                (progn
+                  (and (arrayp second) (clear-string second))
+                  (setq success first))
+              (and (arrayp first) (clear-string first))
+              (and (arrayp second) (clear-string second))
+              (message "Password not repeated accurately; please start over")
+              (sit-for 1))))
+        success)
+    (let (minibuf)
+      (minibuffer-with-setup-hook
+          (lambda ()
+            (setq minibuf (current-buffer))
+            ;; Turn off electricity.
+            (set (make-local-variable 'post-self-insert-hook) nil)
+            (add-hook 'after-change-functions
+                      (lambda (beg end len)
+                        (clear-this-command-keys)
+                        (setq beg (min end (max (minibuffer-prompt-end)
+                                                beg)))
+                        (dotimes (i (- end beg))
+                          (put-text-property (+ i beg) (+ 1 i beg)
+                                             'display (string ?.))))
+                      nil t))
+        (unwind-protect
+            (read-string prompt nil
+                         (let ((sym (make-symbol "forget-history")))
+                           (set sym nil)
+                           sym)
+                         default)
+          (when (buffer-live-p minibuf)
+            (with-current-buffer minibuf (erase-buffer))))))))
 
 ;; This should be used by `call-interactively' for `n' specs.
 (defun read-number (prompt &optional default)
@@ -3557,8 +3530,7 @@
 To replace only the first match (if any), make REGEXP match up to \\'
 and replace a sub-expression, e.g.
   (replace-regexp-in-string \"\\\\(foo\\\\).*\\\\'\" \"bar\" \" foo foo\" nil 
nil 1)
-    => \" bar foo\"
-"
+    => \" bar foo\""
 
   ;; To avoid excessive consing from multiple matches in long strings,
   ;; don't just call `replace-match' continually.  Walk down the


reply via email to

[Prev in Thread] Current Thread [Next in Thread]