1 ;;; paranoid.el -- even more paranoid password prompter
3 ;; Copyright (C) 1998 Ray Jones
5 ;; Author: Ray Jones, rjones@pobox.com
6 ;; Keywords: password, comint
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program; if not, you can either send email to this
21 ;; program's maintainer or write to: The Free Software Foundation,
22 ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
26 ;; taken from comint.el, so it doesn't have to be loaded in its
27 ;; entirety, and made a little more paranoid.
29 ;; (defun comint-read-noecho (prompt &optional stars) ...)
30 (defun prompt-paranoidly (prompt)
32 "Read a single line of text from user without echoing, and return
33 it. Prompt with argument PROMPT, a string. Input ends with RET, LFD,
34 or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if
35 `inhibit-quit' is set because e.g. this function was called from a
36 process filter and C-g is pressed, this function returns nil rather
39 Note that the keystrokes comprising the text can still be recovered
40 \(temporarily) with \\[view-lossage]. Some people find this worrysome.
41 Once the caller uses the password, it can erase the password
42 by doing \(fillarray STRING 0)."
47 (cursor-in-echo-area t)
52 ;; Use this instead of `read-char' to avoid "Non-character input-event".
53 (setq c (read-char-exclusive))
55 ;; This function may get called from a process filter, where
56 ;; inhibit-quit is set. In later versions of emacs read-char
57 ;; may clear quit-flag itself and return C-g. That would make
58 ;; it impossible to quit this loop in a simple way, so
59 ;; re-enable it here (for backward-compatibility the check for
60 ;; quit-flag below would still be necessary, so this seems
61 ;; like the simplest way to do things).
65 ((or (= c ?\r) (= c ?\n) (= c ?\e))
70 ((and (/= c ?\b) (/= c ?\177))
71 (setq newans (concat ans (char-to-string c)))
75 (setq newans (substring ans 0 -1))
79 ;; Emulate a true quit, except that we have to return a value.