Advertisement
Guest User

elmo-read-passwd

a guest
Oct 11th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.25 KB | None | 0 0
  1. (defun elmo-read-passwd (prompt &optional stars)
  2.   "Read a single line of text from user without echoing, and return it."
  3.   (let ((ans "")
  4.         (c 0)
  5.         (echo-keystrokes 0)
  6.         (cursor-in-echo-area t)
  7.         (log-message-max-size 0)
  8.         message-log-max done msg truncate)
  9.     (while (not done)
  10.       (if (or (not stars) (string= "" ans))
  11.           (setq msg prompt)
  12.         (setq msg (concat prompt (make-string (length ans) ?.)))
  13.         (setq truncate
  14.               (1+ (- (length msg) (window-width (minibuffer-window)))))
  15.         (and (> truncate 0)
  16.              (setq msg (concat "$" (substring msg (1+ truncate))))))
  17.       (message "%s" msg)
  18.       (setq c (elmo-read-char-exclusive))
  19.       (cond ((= c ?\C-g)
  20.              (setq quit-flag t
  21.                    done t))
  22.             ((or (= c ?\r) (= c ?\n) (= c ?\e))
  23.              (setq done t))
  24.             ((= c ?\C-u)
  25.              (setq ans ""))
  26.             ((and (/= c ?\b) (/= c ?\177))
  27.              (setq ans (concat ans (char-to-string c))))
  28.             ((> (length ans) 0)
  29.              (setq ans (substring ans 0 -1)))))
  30.     (if quit-flag
  31.         (prog1
  32.             (setq quit-flag nil)
  33.           (message "Quit")
  34.           (beep t))
  35.       (message "")
  36.       ans)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement