Let ESC ESC quit in read-char-choice, and use it in userlock.el.
authorChong Yidong <cyd@gnu.org>
Fri, 7 Sep 2012 10:19:58 +0000 (18:19 +0800)
committerChong Yidong <cyd@gnu.org>
Fri, 7 Sep 2012 10:19:58 +0000 (18:19 +0800)
* lisp/subr.el (read-char-choice): Allow quitting via ESC ESC.

* lisp/userlock.el (ask-user-about-supersession-threat): Use
read-char-choice.

Fixes: debbugs:12093

lisp/ChangeLog
lisp/subr.el
lisp/userlock.el

index 7aae8fd..d700423 100644 (file)
@@ -1,3 +1,10 @@
+2012-09-07  Chong Yidong  <cyd@gnu.org>
+
+       * subr.el (read-char-choice): Allow quitting via ESC ESC.
+
+       * userlock.el (ask-user-about-supersession-threat): Use
+       read-char-choice (Bug#12093).
+
 2012-09-07  Chong Yidong  <cyd@gnu.org>
 
        * subr.el (buffer-narrowed-p): New function.
index 621622e..a3e0897 100644 (file)
@@ -2237,7 +2237,8 @@ keyboard-quit events while waiting for a valid input."
     (error "Called `read-char-choice' without valid char choices"))
   (let (char done show-help (helpbuf " *Char Help*"))
     (let ((cursor-in-echo-area t)
-          (executing-kbd-macro executing-kbd-macro))
+          (executing-kbd-macro executing-kbd-macro)
+         (esc-flag nil))
       (save-window-excursion         ; in case we call help-form-show
        (while (not done)
          (unless (get-text-property 0 'face prompt)
@@ -2261,8 +2262,12 @@ keyboard-quit events while waiting for a valid input."
            ;; there are no more events in the macro.  Attempt to
            ;; get an event interactively.
            (setq executing-kbd-macro nil))
-          ((and (not inhibit-keyboard-quit) (eq char ?\C-g))
-           (keyboard-quit))))))
+          ((not inhibit-keyboard-quit)
+           (cond
+            ((and (null esc-flag) (eq char ?\e))
+             (setq esc-flag t))
+            ((memq char '(?\C-g ?\e))
+             (keyboard-quit))))))))
     ;; Display the question with the answer.  But without cursor-in-echo-area.
     (message "%s%s" prompt (char-to-string char))
     char))
index 705d958..4c003e4 100644 (file)
@@ -108,37 +108,27 @@ You can rewrite this to use any criterion you like to choose which one to do.
 The buffer in question is current when this function is called."
   (discard-input)
   (save-window-excursion
-    (let (answer)
+    (let ((prompt
+          (format "%s changed on disk; \
+really edit the buffer? (y, n, r or C-h) "
+                  (file-name-nondirectory fn)))
+         (choices '(?y ?n ?r ?? ?\C-h))
+         answer)
       (while (null answer)
-       (message "%s changed on disk; really edit the buffer? (y, n, r or C-h) "
-                (file-name-nondirectory fn))
-       (let ((tem (downcase (let ((cursor-in-echo-area t))
-                              (read-char-exclusive)))))
-         (setq answer
-               (if (= tem help-char)
-                   'help
-                 (cdr (assoc tem '((?n . yield)
-                                   (?\C-g . yield)
-                                   (?y . proceed)
-                                   (?r . revert)
-                                   (?? . help))))))
-         (cond ((null answer)
-                (beep)
-                (message "Please type y, n or r; or ? for help")
-                (sit-for 3))
-               ((eq answer 'help)
-                (ask-user-about-supersession-help)
-                (setq answer nil))
-               ((eq answer 'revert)
-                (revert-buffer nil (not (buffer-modified-p)))
-                                       ; ask confirmation if buffer modified
-                (signal 'file-supersession
-                        (list "File reverted" fn)))
-               ((eq answer 'yield)
-                (signal 'file-supersession
-                        (list "File changed on disk" fn))))))
+       (setq answer (read-char-choice prompt choices))
+       (cond ((memq answer '(?? ?\C-h))
+              (ask-user-about-supersession-help)
+              (setq answer nil))
+             ((eq answer ?r)
+              ;; Ask for confirmation if buffer modified
+              (revert-buffer nil (not (buffer-modified-p)))
+              (signal 'file-supersession
+                      (list "File reverted" fn)))
+             ((eq answer ?n)
+              (signal 'file-supersession
+                      (list "File changed on disk" fn)))))
       (message
-        "File on disk now will become a backup file if you save these changes.")
+       "File on disk now will become a backup file if you save these changes.")
       (setq buffer-backed-up nil))))
 
 (defun ask-user-about-supersession-help ()