* lisp/subr.el (read-passwd): Use read-string.
This commit is contained in:
parent
c4fc691b6e
commit
088be6fbd2
2 changed files with 47 additions and 71 deletions
|
@ -1,3 +1,7 @@
|
|||
2012-04-11 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||
|
||||
* subr.el (read-passwd): Use read-string.
|
||||
|
||||
2012-04-11 Lars Magne Ingebrigtsen <larsi@gnus.org>
|
||||
|
||||
* vcursor.el (vcursor-move): Increase the priority of the overlay
|
||||
|
|
114
lisp/subr.el
114
lisp/subr.el
|
@ -871,6 +871,7 @@ The normal global definition of the character C-x indirects to this keymap.")
|
|||
(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 @@ obey the input decoding and translations usually done by `read-key-sequence'.
|
|||
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 @@ 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-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 @@ of STRING.
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue