]> code.delx.au - gnu-emacs/commitdiff
Allow scrolling in y-or-n-p.
authorChong Yidong <cyd@gnu.org>
Sun, 9 Sep 2012 06:43:47 +0000 (14:43 +0800)
committerChong Yidong <cyd@gnu.org>
Sun, 9 Sep 2012 06:43:47 +0000 (14:43 +0800)
* lisp/replace.el (query-replace-map): Bind four new symbols for
requesting window scrolling.

* lisp/subr.el (y-or-n-p): Handle the window-scrolling bindings in
query-replace-map.

* lisp/custom.el (custom-theme-load-confirm): Use y-or-n-p.

* lisp/window.el (scroll-other-window-down): Make the arg optional.

* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): Don't bind scrolling keys
since they are now in query-replace-map.

* doc/lispref/minibuf.texi (Yes-or-No Queries): Document recentering and
scrolling in y-or-n-p.  Remove gratuitous example.

* doc/lispref/searching.texi (Search and Replace): Document window scrolling
entries in query-replace-map.

Fixes: debbugs:8948
doc/lispref/ChangeLog
doc/lispref/minibuf.texi
doc/lispref/searching.texi
etc/NEWS
lisp/ChangeLog
lisp/custom.el
lisp/emacs-lisp/map-ynp.el
lisp/replace.el
lisp/subr.el
lisp/window.el

index 57ee374af49ae1442aac308f2c5082f976e20653..79691bfb181e63d0c39fc80573651087cd0f902f 100644 (file)
@@ -1,3 +1,11 @@
+2012-09-09  Chong Yidong  <cyd@gnu.org>
+
+       * minibuf.texi (Yes-or-No Queries): Document recentering and
+       scrolling in y-or-n-p.  Remove gratuitous example.
+
+       * searching.texi (Search and Replace): Document window scrolling
+       entries in query-replace-map.
+
 2012-09-08  Chong Yidong  <cyd@gnu.org>
 
        * syntax.texi (Syntax Table Internals): Define "raw syntax
 2012-09-08  Chong Yidong  <cyd@gnu.org>
 
        * syntax.texi (Syntax Table Internals): Define "raw syntax
index 4cf096b86635554ed67010ade6f3340a2d46ec37..cdc47b7c91d0c39cf1a4d79711ad35ee9193777b 100644 (file)
@@ -1888,46 +1888,14 @@ Echo Area}), which uses the same screen space as the minibuffer.  The
 cursor moves to the echo area while the question is being asked.
 
 The answers and their meanings, even @samp{y} and @samp{n}, are not
 cursor moves to the echo area while the question is being asked.
 
 The answers and their meanings, even @samp{y} and @samp{n}, are not
-hardwired.  The keymap @code{query-replace-map} specifies them.
-@xref{Search and Replace}.
-
-In the following example, the user first types @kbd{q}, which is
-invalid.  At the next prompt the user types @kbd{y}.
-
-@c Need an interactive example, because otherwise the return value
-@c obscures the display of the valid answer.
-@smallexample
-@group
-(defun ask ()
-  (interactive)
-  (y-or-n-p "Do you need a lift? "))
-
-;; @r{After evaluation of the preceding definition, @kbd{M-x ask}}
-;;   @r{causes the following prompt to appear in the echo area:}
-@end group
-
-@group
----------- Echo area ----------
-Do you need a lift? (y or n)
----------- Echo area ----------
-@end group
-
-;; @r{If the user then types @kbd{q}, the following appears:}
-
-@group
----------- Echo area ----------
-Please answer y or n.  Do you need a lift? (y or n)
----------- Echo area ----------
-@end group
-
-;; @r{When the user types a valid answer,}
-;;   @r{it is displayed after the question:}
-
-@group
----------- Echo area ----------
-Do you need a lift? (y or n) y
----------- Echo area ----------
-@end group
+hardwired, and are specified by the keymap @code{query-replace-map}
+(@pxref{Search and Replace}).  In particular, if the user enters the
+special responses @code{recenter}, @code{scroll-up},
+@code{scroll-down}, @code{scroll-other-window}, or
+@code{scroll-other-window-down} (respectively bound to @kbd{C-l},
+@kbd{C-v}, @kbd{M-v}, @kbd{C-M-v} and @kbd{C-M-S-v} in
+@code{query-replace-map}), this function performs the specified window
+recentering or scrolling operation, and poses the question again.
 @end smallexample
 
 @noindent
 @end smallexample
 
 @noindent
index 0fa681ecb51650aedcd9226a1caad88079207f06..edd1d30e28da016647dc3140c64e0e7dab9b9cc4 100644 (file)
@@ -1796,7 +1796,13 @@ Delete the text being considered, then enter a recursive edit to replace
 it.
 
 @item recenter
 it.
 
 @item recenter
-Redisplay and center the window, then ask the same question again.
+@itemx scroll-up
+@itemx scroll-down
+@itemx scroll-other-window
+@itemx scroll-other-window-down
+Perform the specified window scroll operation, then ask the same
+question again.  Only @code{y-or-n-p} and related functions use this
+answer.
 
 @item quit
 Perform a quit right away.  Only @code{y-or-n-p} and related functions
 
 @item quit
 Perform a quit right away.  Only @code{y-or-n-p} and related functions
index 742744fc9dd93b74701cbab674c6c1b9c641675a..dac7915767d614a090a8494d5c3771918d3a1ff7 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -78,6 +78,10 @@ been adding them there, put them somewhere else, eg site-lisp.
 \f
 * Changes in Emacs 24.3
 
 \f
 * Changes in Emacs 24.3
 
+** You can now scroll the selected window in most y-or-n prompts.
+Typing C-v or M-v at a prompt scrolls forward or backward
+respectively, without leaving the y-or-n prompt.
+
 ** Help changes
 
 *** `C-h f' (describe-function) can now perform autoloading.
 ** Help changes
 
 *** `C-h f' (describe-function) can now perform autoloading.
index d7f730556ac0866667b2f3df536ccae8ba0e0aeb..8f089af6f5c4cbcf84043b033349287b048eeffd 100644 (file)
@@ -1,3 +1,18 @@
+2012-09-09  Chong Yidong  <cyd@gnu.org>
+
+       * replace.el (query-replace-map): Bind four new symbols for
+       requesting window scrolling.
+
+       * subr.el (y-or-n-p): Handle the window-scrolling bindings in
+       query-replace-map (Bug#8948).
+
+       * custom.el (custom-theme-load-confirm): Use y-or-n-p.
+
+       * emacs-lisp/map-ynp.el (map-y-or-n-p): Don't bind scrolling keys
+       since they are now in query-replace-map.
+
+       * window.el (scroll-other-window-down): Make the arg optional.
+
 2012-09-09  Chong Yidong  <cyd@gnu.org>
 
        * files.el (hack-local-variables-confirm): Use quit-window to kill
 2012-09-09  Chong Yidong  <cyd@gnu.org>
 
        * files.el (hack-local-variables-confirm): Use quit-window to kill
index fb166dd35f754c0c3efd8da6612b59e40470a4f0..3eb2895888d601bbffb7296aa669b6b1e3fbbfcd 100644 (file)
@@ -1223,38 +1223,19 @@ Return t if THEME was successfully loaded, nil otherwise."
   "Query the user about loading a Custom theme that may not be safe.
 The theme should be in the current buffer.  If the user agrees,
 query also about adding HASH to `custom-safe-themes'."
   "Query the user about loading a Custom theme that may not be safe.
 The theme should be in the current buffer.  If the user agrees,
 query also about adding HASH to `custom-safe-themes'."
-  (if noninteractive
-      nil
-    (let ((exit-chars '(?y ?n ?\s))
-         window prompt char)
-      (save-window-excursion
-       (rename-buffer "*Custom Theme*" t)
-       (emacs-lisp-mode)
-       (setq window (display-buffer (current-buffer)))
-       (setq prompt
-             (format "Loading a theme can run Lisp code.  Really load?%s"
-                     (if (and window
-                              (< (line-number-at-pos (point-max))
-                                 (window-body-height)))
-                         " (y or n) "
-                       (push ?\C-v exit-chars)
-                       "\nType y or n, or C-v to scroll: ")))
-       (goto-char (point-min))
-       (while (null char)
-         (setq char (read-char-choice prompt exit-chars))
-         (when (eq char ?\C-v)
-           (if window
-               (with-selected-window window
-                 (condition-case nil
-                     (scroll-up)
-                   (error (goto-char (point-min))))))
-           (setq char nil)))
-       (when (memq char '(?\s ?y))
-         ;; Offer to save to `custom-safe-themes'.
-         (and (or custom-file user-init-file)
-              (y-or-n-p "Treat this theme as safe in future sessions? ")
-              (customize-push-and-save 'custom-safe-themes (list hash)))
-         t)))))
+  (unless noninteractive
+    (save-window-excursion
+      (rename-buffer "*Custom Theme*" t)
+      (emacs-lisp-mode)
+      (setq window (pop-to-buffer (current-buffer)))
+      (goto-char (point-min))
+      (prog1 (when (y-or-n-p "Loading a theme can run Lisp code.  Really load? ")
+              ;; Offer to save to `custom-safe-themes'.
+              (and (or custom-file user-init-file)
+                   (y-or-n-p "Treat this theme as safe in future sessions? ")
+                   (customize-push-and-save 'custom-safe-themes (list hash)))
+              t)
+       (quit-window)))))
 
 (defun custom-theme-name-valid-p (name)
   "Return t if NAME is a valid name for a Custom theme, nil otherwise.
 
 (defun custom-theme-name-valid-p (name)
   "Return t if NAME is a valid name for a Custom theme, nil otherwise.
index e7806440bf3edfe3aae2ebfc8ec1212277313eca..289751f4944393ef57cb227ecb62eef61eec8904 100644 (file)
@@ -123,16 +123,6 @@ Returns the number of actions taken."
            map
             (let ((map (make-sparse-keymap)))
               (set-keymap-parent map query-replace-map)
            map
             (let ((map (make-sparse-keymap)))
               (set-keymap-parent map query-replace-map)
-              (define-key map [?\C-\M-v] 'scroll-other-window)
-              (define-key map [M-next] 'scroll-other-window)
-              (define-key map [?\C-\M-\S-v] 'scroll-other-window-down)
-              (define-key map [M-prior] 'scroll-other-window-down)
-              ;; The above are rather inconvenient, so maybe we should
-              ;; provide the non-other keys for the other-scroll as well.
-              ;; (define-key map [?\C-v] 'scroll-other-window)
-              ;; (define-key map [next] 'scroll-other-window)
-              ;; (define-key map [?\M-v] 'scroll-other-window-down)
-              ;; (define-key map [prior] 'scroll-other-window-down)
               (dolist (elt action-alist)
                 (define-key map (vector (car elt)) (vector (nth 1 elt))))
               map)))
               (dolist (elt action-alist)
                 (define-key map (vector (car elt)) (vector (nth 1 elt))))
               map)))
index 194805a8f3e803127ff2b16246490bb479e7efed..b30b671122e314180a7da9624a2c9e96cdae367b 100644 (file)
@@ -1617,14 +1617,28 @@ E to edit the replacement string"
     (define-key map "?" 'help)
     (define-key map "\C-g" 'quit)
     (define-key map "\C-]" 'quit)
     (define-key map "?" 'help)
     (define-key map "\C-g" 'quit)
     (define-key map "\C-]" 'quit)
-    (define-key map "\e" 'exit-prefix)
+    (define-key map "\C-v" 'scroll-up)
+    (define-key map "\M-v" 'scroll-down)
+    (define-key map [next] 'scroll-up)
+    (define-key map [prior] 'scroll-down)
+    (define-key map [?\C-\M-v] 'scroll-other-window)
+    (define-key map [M-next] 'scroll-other-window)
+    (define-key map [?\C-\M-\S-v] 'scroll-other-window-down)
+    (define-key map [M-prior] 'scroll-other-window-down)
+    ;; Binding ESC would prohibit the M-v binding.  Instead, callers
+    ;; should check for ESC specially.
+    ;; (define-key map "\e" 'exit-prefix)
     (define-key map [escape] 'exit-prefix)
     map)
     (define-key map [escape] 'exit-prefix)
     map)
-  "Keymap that defines the responses to questions in `query-replace'.
+  "Keymap of responses to questions posed by commands like `query-replace'.
 The \"bindings\" in this map are not commands; they are answers.
 The valid answers include `act', `skip', `act-and-show',
 The \"bindings\" in this map are not commands; they are answers.
 The valid answers include `act', `skip', `act-and-show',
-`exit', `act-and-exit', `edit', `edit-replacement', `delete-and-edit',
-`recenter', `automatic', `backup', `exit-prefix', `quit', and `help'.")
+`act-and-exit', `exit', `exit-prefix', `recenter', `scroll-up',
+`scroll-down', `scroll-other-window', `scroll-other-window-down',
+`edit', `edit-replacement', `delete-and-edit', `automatic',
+`backup', `quit', and `help'.
+
+This keymap is used by `y-or-n-p' as well as `query-replace'.")
 
 (defvar multi-query-replace-map
   (let ((map (make-sparse-keymap)))
 
 (defvar multi-query-replace-map
   (let ((map (make-sparse-keymap)))
index 21dd270caef24456c196cebb135af22075033224..be785ff8fbae3abf10fb68b26eaee779320293d1 100644 (file)
@@ -2319,11 +2319,19 @@ floating point support."
 PROMPT is the string to display to ask the question.  It should
 end in a space; `y-or-n-p' adds \"(y or n) \" to it.
 
 PROMPT is the string to display to ask the question.  It should
 end in a space; `y-or-n-p' adds \"(y or n) \" to it.
 
-No confirmation of the answer is requested; a single character is enough.
-Also accepts Space to mean yes, or Delete to mean no.  \(Actually, it uses
-the bindings in `query-replace-map'; see the documentation of that variable
-for more information.  In this case, the useful bindings are `act', `skip',
-`recenter', and `quit'.\)
+No confirmation of the answer is requested; a single character is
+enough.  SPC also means yes, and DEL means no.
+
+To be precise, this function translates user input into responses
+by consulting the bindings in `query-replace-map'; see the
+documentation of that variable for more information.  In this
+case, the useful bindings are `act', `skip', `recenter',
+`scroll-up', `scroll-down', and `quit'.
+An `act' response means yes, and a `skip' response means no.
+A `quit' response means to invoke `keyboard-quit'.
+If the user enters `recenter', `scroll-up', or `scroll-down'
+responses, perform the requested window recentering or scrolling
+and ask again.
 
 Under a windowing system a dialog box will be used if `last-nonmenu-event'
 is nil and `use-dialog-box' is non-nil."
 
 Under a windowing system a dialog box will be used if `last-nonmenu-event'
 is nil and `use-dialog-box' is non-nil."
@@ -2355,21 +2363,33 @@ is nil and `use-dialog-box' is non-nil."
                                "" " ")
                            "(y or n) "))
       (while
                                "" " ")
                            "(y or n) "))
       (while
-          (let* ((key
+          (let* ((scroll-actions '(recenter scroll-up scroll-down
+                                  scroll-other-window scroll-other-window-down))
+                (key
                   (let ((cursor-in-echo-area t))
                     (when minibuffer-auto-raise
                       (raise-frame (window-frame (minibuffer-window))))
                   (let ((cursor-in-echo-area t))
                     (when minibuffer-auto-raise
                       (raise-frame (window-frame (minibuffer-window))))
-                    (read-key (propertize (if (eq answer 'recenter)
+                    (read-key (propertize (if (memq answer scroll-actions)
                                               prompt
                                             (concat "Please answer y or n.  "
                                                     prompt))
                                           'face 'minibuffer-prompt)))))
             (setq answer (lookup-key query-replace-map (vector key) t))
             (cond
                                               prompt
                                             (concat "Please answer y or n.  "
                                                     prompt))
                                           'face 'minibuffer-prompt)))))
             (setq answer (lookup-key query-replace-map (vector key) t))
             (cond
-             ((memq answer '(skip act)) nil)
-             ((eq answer 'recenter) (recenter) t)
-             ((memq answer '(exit-prefix quit)) (signal 'quit nil) t)
-             (t t)))
+            ((memq answer '(skip act)) nil)
+            ((eq answer 'recenter)
+             (recenter) t)
+            ((eq answer 'scroll-up)
+             (ignore-errors (scroll-up-command)) t)
+            ((eq answer 'scroll-down)
+             (ignore-errors (scroll-down-command)) t)
+            ((eq answer 'scroll-other-window)
+             (ignore-errors (scroll-other-window)) t)
+            ((eq answer 'scroll-other-window-down)
+             (ignore-errors (scroll-other-window-down)) t)
+            ((or (memq answer '(exit-prefix quit)) (eq key ?\e))
+             (signal 'quit nil) t)
+            (t t)))
         (ding)
         (discard-input))))
     (let ((ret (eq answer 'act)))
         (ding)
         (discard-input))))
     (let ((ret (eq answer 'act)))
index b071a8e9c50c1c4ba483d963f48fdc94dfd3a748..dd1f55450c3515dcc758fae4ebd929b3969f8cd0 100644 (file)
@@ -6301,7 +6301,7 @@ This is different from `scroll-down-command' that scrolls a full screen."
 (put 'scroll-down-line 'scroll-command t)
 
 \f
 (put 'scroll-down-line 'scroll-command t)
 
 \f
-(defun scroll-other-window-down (lines)
+(defun scroll-other-window-down (&optional lines)
   "Scroll the \"other window\" down.
 For more details, see the documentation for `scroll-other-window'."
   (interactive "P")
   "Scroll the \"other window\" down.
 For more details, see the documentation for `scroll-other-window'."
   (interactive "P")