unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Borja Tarraso <borja.tarraso.hueso@googlemail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Harald Hanche-Olsen <hanche@math.ntnu.no>,
	emacs-devel@gnu.org, Andreas Schwab <schwab@linux-m68k.org>,
	Borja Tarraso <borja.tarraso.hueso@googlemail.com>,
	davazp@es.gnu.org
Subject: Re: Possible emacs bug when type password fields
Date: Thu, 14 May 2009 01:35:26 +0100	[thread overview]
Message-ID: <87hbzocyi9.fsf@gmail.com> (raw)
In-Reply-To: <jwvprekh0lm.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 07 May 2009 21:01:30 -0400")


Hi Stefan,

I was looking at the code with some friend. Adding some extra condition
to catch C-g problem is fixed.

The problem was in read-key function; this function does not control C-g as
it is using read-key-sequence (as documentation is menction: "A C-g
typed while in this function is treated like any other character, and
`quit-flag' is not set") so it explains why this is happening, as
is not reading each key and inserting, instead of that, it allows to the
user writing on that buffer and obtaining the content later.

Probably lots of things have dependency of read-key, for this reason it
was added this extra condition... but i don't know really if it's the
best solution.


==> Full diffs:


*** emacs/lisp/subr.el	2009-02-14 09:06:56.000000000 +0000
--- emacs_hack/lisp/subr.el	2009-05-14 01:29:52.000000000 +0100
***************
*** 1721,1726 ****
--- 1721,1767 ----
  

  ;;;; Input and display facilities.
  
+ (defconst read-key-empty-map (make-sparse-keymap))
+ (defvar read-key-delay 0.1)
+ 
+ (defun read-key (&optional prompt)
+   "Read a key from the keyboard.
+ Contrary to `read-event' this will not return a raw event but instead will
+ 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'."
+   (let ((overriding-terminal-local-map read-key-empty-map)
+ 	(overriding-local-map nil)
+ 	(old-global-map (current-global-map))
+         (timer (run-with-idle-timer
+                 ;; Wait long enough that Emacs has the time to receive and
+                 ;; process all the raw events associated with the single-key.
+                 ;; But don't wait too long, or the user may find the delay
+                 ;; annoying (or keep hitting more keys which may then get
+                 ;; lost or misinterpreted).
+                 ;; This is only relevant for keys which Emacs perceives as
+                 ;; "prefixes", such as C-x (because of the C-x 8 map in
+                 ;; key-translate-table and the C-x @ map in function-key-map)
+                 ;; or ESC (because of terminal escape sequences in
+                 ;; input-decode-map).
+                 read-key-delay t
+                 (lambda ()
+                   (let ((keys (this-command-keys-vector)))
+                     (unless (zerop (length keys))
+                       ;; `keys' is non-empty, so the user has hit at least
+                       ;; one key; there's no point waiting any longer, even
+                       ;; though read-key-sequence thinks we should wait
+                       ;; for more input to decide how to interpret the
+                       ;; current input.
+                       (throw 'read-key keys)))))))
+     (unwind-protect
+         (progn
+ 	  (use-global-map read-key-empty-map)
+ 	  (aref	(catch 'read-key (read-key-sequence prompt nil t)) 0))
+       (cancel-timer timer)
+       (use-global-map old-global-map))))
+ 
  (defvar read-quoted-char-radix 8
    "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
  Legitimate radix values are 8, 10 and 16.")
***************
*** 1837,1846 ****
  	(while (progn (message "%s%s"
  			       prompt
  			       (make-string (length pass) ?.))
! 		      ;; We used to use read-char-exclusive, but that
! 		      ;; gives funny behavior when the user presses,
! 		      ;; e.g., the arrow keys.
! 		      (setq c (read-event nil t))
  		      (not (memq c stop-keys)))
  	  (clear-this-command-keys)
  	  (cond ((memq c rubout-keys) ; rubout
--- 1878,1884 ----
  	(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
***************
*** 1848,1855 ****
  		   (let ((new-pass (substring pass 0 -1)))
  		     (and (arrayp pass) (clear-string pass))
  		     (setq pass new-pass))))
  		((not (numberp c)))
! 		((= c ?\C-u) ; kill line
  		 (and (arrayp pass) (clear-string pass))
  		 (setq pass ""))
  		((= c ?\C-y) ; yank
--- 1886,1895 ----
  		   (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)))
! 		((eq c ?\C-u) ; kill line
  		 (and (arrayp pass) (clear-string pass))
  		 (setq pass ""))
  		((= c ?\C-y) ; yank


==> End.

Thanks!

Borja Tarraso

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Near :-) this time works fine, i can write from the beginning, however
>> C-g stills does not work, when I press C-g it writes another additional
>> character.
>
> Hmm... this is odd, I cannot reproduce it.  Can you try and single-step
> through that code to see why the (eq c ?\C-g) test fails?
> To do that, just move point to inside the function and hit C-u M-C-x
> (which marks the function for interactive debugging) and then do
> M-: (read-password "toto: ").
> Once in the debugger, use `n' or SPC to advance through the code.
>
>
>         Stefan




      reply	other threads:[~2009-05-14  0:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-01 11:13 Possible emacs bug when type password fields Borja Tarraso Hueso
2009-05-01 16:42 ` Harald Hanche-Olsen
2009-05-01 19:57   ` Stefan Monnier
2009-05-01 21:28     ` Harald Hanche-Olsen
2009-05-05 18:36     ` Borja Tarraso
2009-05-06  1:21       ` Stefan Monnier
2009-05-06  8:57         ` Andreas Schwab
2009-05-06 14:25           ` Stefan Monnier
2009-05-06 15:08             ` Harald Hanche-Olsen
2009-05-06 15:08             ` Andreas Schwab
2009-05-06 18:58               ` Stefan Monnier
2009-05-07 20:53               ` Borja Tarraso
2009-05-08  1:01                 ` Stefan Monnier
2009-05-14  0:35                   ` Borja Tarraso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hbzocyi9.fsf@gmail.com \
    --to=borja.tarraso.hueso@googlemail.com \
    --cc=davazp@es.gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=hanche@math.ntnu.no \
    --cc=monnier@iro.umontreal.ca \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).