[net.emacs] getpass needed

lear@topaz.RUTGERS.EDU (eliot lear) (10/23/86)

Hi..  I am a relative novice working with emacs and was wondering
if there is a method available from gnu to turn off echo (preferably
in the minibuffer).  Reason I ask is that I am attempting to write
some form of library for encrypted files.

				Thanks in advance,

					    eliot lear

-- 

[lear@rutgers.rutgers.edu]
[{allegra,seismo}!rutgers!lear]

weemba@brahms (Matthew P Wiener) (10/24/86)

Note-I originally posted an erroneous version, now cancelled.

In article <6431@topaz.RUTGERS.EDU> lear@topaz.RUTGERS.EDU (eliot lear) writes:
>Hi..  I am a relative novice working with emacs and was wondering
>if there is a method available from gnu to turn off echo (preferably
>in the minibuffer).  Reason I ask is that I am attempting to write
>some form of library for encrypted files.

The following library should do the trick.  You turn off echoing by binding
the individual letters yourself.  Just load the library, and then invoke with
(read-string-no-echo "Key: ") or whatever prompt you wish to use.

ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720
Without NNTP, the brahms gang itself would be impossible.  --Erik E Fair
------------------------------------------------------------------------
;;; GNU Emacs library to read in passwords from the minibuffer
;;; Standard GNU copying privileges apply

;; We need to define our own minibuffer keymap.
(setq minibuffer-local-no-echo-map (copy-keymap minibuffer-local-map))

;; We trap all printing characters.
(let ((i ?\040))
  (while (< i ?\177)
    (nconc minibuffer-local-no-echo-map (list (cons i 'read-char-no-echo)))
    (setq i (1+ i))))

;; We provide for the delete character.
(nconc minibuffer-local-no-echo-map '((?\177 . delete-char-no-echo)))

;; This function squirrels each typed-in character away.
(defun read-char-no-echo () (interactive)
  (setq no-echo-list (append no-echo-list (list (this-command-keys)))))

;; This function erases the last character from the input list.
(defun delete-char-no-echo () (interactive)
  (setq no-echo-list (nreverse (cdr (nreverse no-echo-list)))))

;; This is the function the user actually uses.
(defun read-string-no-echo (prompt)
  "Get a password from the minibuffer, prompting with PROMPT."
  (let (no-echo-list)
    (read-from-minibuffer prompt nil minibuffer-local-no-echo-map)
    (mapconcat 'identity no-echo-list nil)))

weemba@brahms (Matthew P Wiener) (10/25/86)

Summary:
Expires:
Sender:
Followup-To:
Distribution:
Keywords:

The version of read-string-no-echo I recently posted used a sparse keymap,
which is a pretty dumb butt thing to do for this application.  So change
the first several lines, the ones defining the keymap, to the following:

(setq minibuffer-local-no-echo-map
      (vconcat (make-vector ?\040 nil)
	       (make-vector ?\140 'read-char-no-echo)))

(mapcar '(lambda (x) (aset minibuffer-local-no-echo-map (car x) (cdr x)))
	(cdr minibuffer-local-map))

(aset minibuffer-local-no-echo-map ?\177 'delete-char-no-echo)

This will load and run quicker.  Hopefully beginners might gain something
by comparing the two, so please excuse the repetition.

ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720
   Hark! The herald angels sing / Beechan's pills are just the thing.
     Peace on earth and mercy mild / Two for man and one for child.