diff options
| author | Stefan Monnier | 2010-09-12 16:35:37 +0200 |
|---|---|---|
| committer | Stefan Monnier | 2010-09-12 16:35:37 +0200 |
| commit | 5616cc54c5d2f39259d5530c2e4419c4f35356eb (patch) | |
| tree | 246fcb7e4278217bf91333d9fd885220e7b6d4e0 /lisp | |
| parent | 94c7243ba432a96be1541253013669b18eed713e (diff) | |
| download | emacs-5616cc54c5d2f39259d5530c2e4419c4f35356eb.tar.gz emacs-5616cc54c5d2f39259d5530c2e4419c4f35356eb.zip | |
* lisp/subr.el (y-or-n-p): New function, moved from src/fns.c. Use read-key.
* src/fns.c (Fy_or_n_p): Move to lisp/subr.el.
(syms_of_fns): Don't defsubr Sy_or_n_p.
* src/lisp.h: Don't declare Fy_or_n_p.
* src/fileio.c (barf_or_query_if_file_exists): Fy_or_n_p -> y-or-n-p.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/subr.el | 46 |
2 files changed, 50 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ddbc0b43eed..081d9a53735 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2010-09-12 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * subr.el (y-or-n-p): New function, moved from src/fns.c. Use read-key. | ||
| 4 | |||
| 1 | 2010-09-12 Leo <sdl.web@gmail.com> | 5 | 2010-09-12 Leo <sdl.web@gmail.com> |
| 2 | 6 | ||
| 3 | * net/rcirc.el (rcirc-server-commands, rcirc-client-commands) | 7 | * net/rcirc.el (rcirc-server-commands, rcirc-client-commands) |
diff --git a/lisp/subr.el b/lisp/subr.el index 83cf7211906..f2c12a736c2 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -3358,6 +3358,52 @@ clone should be incorporated in the clone." | |||
| 3358 | (overlay-put ol2 'evaporate t) | 3358 | (overlay-put ol2 'evaporate t) |
| 3359 | (overlay-put ol2 'text-clones dups))) | 3359 | (overlay-put ol2 'text-clones dups))) |
| 3360 | 3360 | ||
| 3361 | ;;;; Misc functions moved over from the C side. | ||
| 3362 | |||
| 3363 | (defun y-or-n-p (prompt) | ||
| 3364 | "Ask user a \"y or n\" question. Return t if answer is \"y\". | ||
| 3365 | The argument PROMPT is the string to display to ask the question. | ||
| 3366 | It should end in a space; `y-or-n-p' adds `(y or n) ' to it. | ||
| 3367 | No confirmation of the answer is requested; a single character is enough. | ||
| 3368 | Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses | ||
| 3369 | the bindings in `query-replace-map'; see the documentation of that variable | ||
| 3370 | for more information. In this case, the useful bindings are `act', `skip', | ||
| 3371 | `recenter', and `quit'.\) | ||
| 3372 | |||
| 3373 | Under a windowing system a dialog box will be used if `last-nonmenu-event' | ||
| 3374 | is nil and `use-dialog-box' is non-nil." | ||
| 3375 | ;; ¡Beware! when I tried to edebug this code, Emacs got into a weird state | ||
| 3376 | ;; where all the keys were unbound (i.e. it somehow got triggered | ||
| 3377 | ;; within read-key, apparently). I had to kill it. | ||
| 3378 | (let ((answer 'none) | ||
| 3379 | (xprompt prompt)) | ||
| 3380 | (if (and (display-popup-menus-p) | ||
| 3381 | (listp last-nonmenu-event) | ||
| 3382 | use-dialog-box) | ||
| 3383 | (setq answer | ||
| 3384 | (x-popup-dialog t `(,prompt ("yes" . act) ("No" . skip)))) | ||
| 3385 | (while | ||
| 3386 | (let* ((key | ||
| 3387 | (let ((cursor-in-echo-area t)) | ||
| 3388 | (when minibuffer-auto-raise | ||
| 3389 | (raise-frame (window-frame (minibuffer-window)))) | ||
| 3390 | (read-key (propertize xprompt 'face 'minibuffer-prompt))))) | ||
| 3391 | (setq answer (lookup-key query-replace-map (vector key) t)) | ||
| 3392 | (cond | ||
| 3393 | ((memq answer '(skip act)) nil) | ||
| 3394 | ((eq answer 'recenter) (recenter) t) | ||
| 3395 | ((memq answer '(exit-prefix quit)) (signal 'quit nil) t) | ||
| 3396 | (t t))) | ||
| 3397 | (ding) | ||
| 3398 | (discard-input) | ||
| 3399 | (setq xprompt | ||
| 3400 | (if (eq answer 'recenter) prompt | ||
| 3401 | (concat "Please answer y or n. " prompt))))) | ||
| 3402 | (let ((ret (eq answer 'act))) | ||
| 3403 | (unless noninteractive | ||
| 3404 | (message "%s %s" prompt (if ret "y" "n"))) | ||
| 3405 | ret))) | ||
| 3406 | |||
| 3361 | ;;;; Mail user agents. | 3407 | ;;;; Mail user agents. |
| 3362 | 3408 | ||
| 3363 | ;; Here we include just enough for other packages to be able | 3409 | ;; Here we include just enough for other packages to be able |