From 145823ecb2d55a7ea33d4a8482b5941f189d9418 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Fri, 7 Sep 2012 18:19:58 +0800 Subject: [PATCH] Let ESC ESC quit in read-char-choice, and use it in userlock.el. * 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 | 7 +++++++ lisp/subr.el | 11 ++++++++--- lisp/userlock.el | 48 +++++++++++++++++++----------------------------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7aae8fd785..d7004237ad 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-09-07 Chong Yidong + + * 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 * subr.el (buffer-narrowed-p): New function. diff --git a/lisp/subr.el b/lisp/subr.el index 621622e70e..a3e0897e9f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -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)) diff --git a/lisp/userlock.el b/lisp/userlock.el index 705d958824..4c003e423a 100644 --- a/lisp/userlock.el +++ b/lisp/userlock.el @@ -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 () -- 2.39.2