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 | |
| 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.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/subr.el | 46 | ||||
| -rw-r--r-- | src/ChangeLog | 13 | ||||
| -rw-r--r-- | src/fileio.c | 2 | ||||
| -rw-r--r-- | src/fns.c | 141 | ||||
| -rw-r--r-- | src/lisp.h | 1 |
6 files changed, 61 insertions, 146 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 |
diff --git a/src/ChangeLog b/src/ChangeLog index 9578130afd5..c866258c6fe 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2010-09-12 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * fns.c (Fy_or_n_p): Move to lisp/subr.el. | ||
| 4 | (syms_of_fns): Don't defsubr Sy_or_n_p. | ||
| 5 | * lisp.h: Don't declare Fy_or_n_p. | ||
| 6 | * fileio.c (barf_or_query_if_file_exists): Fy_or_n_p -> y-or-n-p. | ||
| 7 | |||
| 1 | 2010-09-09 Lars Magne Ingebrigtsen <larsi@gnus.org> | 8 | 2010-09-09 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 9 | ||
| 3 | * xml.c (Fxml_parse_buffer): New function to parse XML files. | 10 | * xml.c (Fxml_parse_buffer): New function to parse XML files. |
| @@ -70,8 +77,8 @@ | |||
| 70 | characters. | 77 | characters. |
| 71 | 78 | ||
| 72 | * term.c (encode_terminal_code): Fix the previous change. | 79 | * term.c (encode_terminal_code): Fix the previous change. |
| 73 | (produce_glyphs): Don't set it->char_to_display here. Don't | 80 | (produce_glyphs): Don't set it->char_to_display here. |
| 74 | handle unibyte-display-via-language-environment here. | 81 | Don't handle unibyte-display-via-language-environment here. |
| 75 | (produce_special_glyphs): Set temp_it.char_to_display before | 82 | (produce_special_glyphs): Set temp_it.char_to_display before |
| 76 | calling produce_glyphs. | 83 | calling produce_glyphs. |
| 77 | 84 | ||
| @@ -114,7 +121,7 @@ | |||
| 114 | 2010-08-29 Kenichi Handa <handa@m17n.org> | 121 | 2010-08-29 Kenichi Handa <handa@m17n.org> |
| 115 | 122 | ||
| 116 | * term.c (encode_terminal_code): Encode byte chars to the | 123 | * term.c (encode_terminal_code): Encode byte chars to the |
| 117 | correspnding bytes. | 124 | corresponding bytes. |
| 118 | 125 | ||
| 119 | 2010-08-29 Jan Djärv <jan.h.d@swipnet.se> | 126 | 2010-08-29 Jan Djärv <jan.h.d@swipnet.se> |
| 120 | 127 | ||
diff --git a/src/fileio.c b/src/fileio.c index a04cd4e76f5..3d08e881e8f 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -1842,7 +1842,7 @@ barf_or_query_if_file_exists (Lisp_Object absname, const unsigned char *querystr | |||
| 1842 | tem = format2 ("File %s already exists; %s anyway? ", | 1842 | tem = format2 ("File %s already exists; %s anyway? ", |
| 1843 | absname, build_string (querystring)); | 1843 | absname, build_string (querystring)); |
| 1844 | if (quick) | 1844 | if (quick) |
| 1845 | tem = Fy_or_n_p (tem); | 1845 | tem = call1 (intern ("y-or-n-p"), tem); |
| 1846 | else | 1846 | else |
| 1847 | tem = do_yes_or_no_p (tem); | 1847 | tem = do_yes_or_no_p (tem); |
| 1848 | UNGCPRO; | 1848 | UNGCPRO; |
| @@ -2444,146 +2444,6 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */) | |||
| 2444 | return sequence; | 2444 | return sequence; |
| 2445 | } | 2445 | } |
| 2446 | 2446 | ||
| 2447 | /* Anything that calls this function must protect from GC! */ | ||
| 2448 | |||
| 2449 | DEFUN ("y-or-n-p", Fy_or_n_p, Sy_or_n_p, 1, 1, 0, | ||
| 2450 | doc: /* Ask user a "y or n" question. Return t if answer is "y". | ||
| 2451 | Takes one argument, which is the string to display to ask the question. | ||
| 2452 | It should end in a space; `y-or-n-p' adds `(y or n) ' to it. | ||
| 2453 | No confirmation of the answer is requested; a single character is enough. | ||
| 2454 | Also accepts Space to mean yes, or Delete to mean no. \(Actually, it uses | ||
| 2455 | the bindings in `query-replace-map'; see the documentation of that variable | ||
| 2456 | for more information. In this case, the useful bindings are `act', `skip', | ||
| 2457 | `recenter', and `quit'.\) | ||
| 2458 | |||
| 2459 | Under a windowing system a dialog box will be used if `last-nonmenu-event' | ||
| 2460 | is nil and `use-dialog-box' is non-nil. */) | ||
| 2461 | (Lisp_Object prompt) | ||
| 2462 | { | ||
| 2463 | register Lisp_Object obj, key, def, map; | ||
| 2464 | register int answer; | ||
| 2465 | Lisp_Object xprompt; | ||
| 2466 | Lisp_Object args[2]; | ||
| 2467 | struct gcpro gcpro1, gcpro2; | ||
| 2468 | int count = SPECPDL_INDEX (); | ||
| 2469 | |||
| 2470 | specbind (Qcursor_in_echo_area, Qt); | ||
| 2471 | |||
| 2472 | map = Fsymbol_value (intern ("query-replace-map")); | ||
| 2473 | |||
| 2474 | CHECK_STRING (prompt); | ||
| 2475 | xprompt = prompt; | ||
| 2476 | GCPRO2 (prompt, xprompt); | ||
| 2477 | |||
| 2478 | #ifdef HAVE_WINDOW_SYSTEM | ||
| 2479 | if (display_hourglass_p) | ||
| 2480 | cancel_hourglass (); | ||
| 2481 | #endif | ||
| 2482 | |||
| 2483 | while (1) | ||
| 2484 | { | ||
| 2485 | |||
| 2486 | #ifdef HAVE_MENUS | ||
| 2487 | if (FRAME_WINDOW_P (SELECTED_FRAME ()) | ||
| 2488 | && (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) | ||
| 2489 | && use_dialog_box | ||
| 2490 | && have_menus_p ()) | ||
| 2491 | { | ||
| 2492 | Lisp_Object pane, menu; | ||
| 2493 | redisplay_preserve_echo_area (3); | ||
| 2494 | pane = Fcons (Fcons (build_string ("Yes"), Qt), | ||
| 2495 | Fcons (Fcons (build_string ("No"), Qnil), | ||
| 2496 | Qnil)); | ||
| 2497 | menu = Fcons (prompt, pane); | ||
| 2498 | obj = Fx_popup_dialog (Qt, menu, Qnil); | ||
| 2499 | answer = !NILP (obj); | ||
| 2500 | break; | ||
| 2501 | } | ||
| 2502 | #endif /* HAVE_MENUS */ | ||
| 2503 | cursor_in_echo_area = 1; | ||
| 2504 | choose_minibuf_frame (); | ||
| 2505 | |||
| 2506 | { | ||
| 2507 | Lisp_Object pargs[3]; | ||
| 2508 | |||
| 2509 | /* Colorize prompt according to `minibuffer-prompt' face. */ | ||
| 2510 | pargs[0] = build_string ("%s(y or n) "); | ||
| 2511 | pargs[1] = intern ("face"); | ||
| 2512 | pargs[2] = intern ("minibuffer-prompt"); | ||
| 2513 | args[0] = Fpropertize (3, pargs); | ||
| 2514 | args[1] = xprompt; | ||
| 2515 | Fmessage (2, args); | ||
| 2516 | } | ||
| 2517 | |||
| 2518 | if (minibuffer_auto_raise) | ||
| 2519 | { | ||
| 2520 | Lisp_Object mini_frame; | ||
| 2521 | |||
| 2522 | mini_frame = WINDOW_FRAME (XWINDOW (minibuf_window)); | ||
| 2523 | |||
| 2524 | Fraise_frame (mini_frame); | ||
| 2525 | } | ||
| 2526 | |||
| 2527 | temporarily_switch_to_single_kboard (SELECTED_FRAME ()); | ||
| 2528 | obj = read_filtered_event (1, 0, 0, 0, Qnil); | ||
| 2529 | cursor_in_echo_area = 0; | ||
| 2530 | /* If we need to quit, quit with cursor_in_echo_area = 0. */ | ||
| 2531 | QUIT; | ||
| 2532 | |||
| 2533 | key = Fmake_vector (make_number (1), obj); | ||
| 2534 | def = Flookup_key (map, key, Qt); | ||
| 2535 | |||
| 2536 | if (EQ (def, intern ("skip"))) | ||
| 2537 | { | ||
| 2538 | answer = 0; | ||
| 2539 | break; | ||
| 2540 | } | ||
| 2541 | else if (EQ (def, intern ("act"))) | ||
| 2542 | { | ||
| 2543 | answer = 1; | ||
| 2544 | break; | ||
| 2545 | } | ||
| 2546 | else if (EQ (def, intern ("recenter"))) | ||
| 2547 | { | ||
| 2548 | Frecenter (Qnil); | ||
| 2549 | xprompt = prompt; | ||
| 2550 | continue; | ||
| 2551 | } | ||
| 2552 | else if (EQ (def, intern ("quit"))) | ||
| 2553 | Vquit_flag = Qt; | ||
| 2554 | /* We want to exit this command for exit-prefix, | ||
| 2555 | and this is the only way to do it. */ | ||
| 2556 | else if (EQ (def, intern ("exit-prefix"))) | ||
| 2557 | Vquit_flag = Qt; | ||
| 2558 | |||
| 2559 | QUIT; | ||
| 2560 | |||
| 2561 | /* If we don't clear this, then the next call to read_char will | ||
| 2562 | return quit_char again, and we'll enter an infinite loop. */ | ||
| 2563 | Vquit_flag = Qnil; | ||
| 2564 | |||
| 2565 | Fding (Qnil); | ||
| 2566 | Fdiscard_input (); | ||
| 2567 | if (EQ (xprompt, prompt)) | ||
| 2568 | { | ||
| 2569 | args[0] = build_string ("Please answer y or n. "); | ||
| 2570 | args[1] = prompt; | ||
| 2571 | xprompt = Fconcat (2, args); | ||
| 2572 | } | ||
| 2573 | } | ||
| 2574 | UNGCPRO; | ||
| 2575 | |||
| 2576 | if (! noninteractive) | ||
| 2577 | { | ||
| 2578 | cursor_in_echo_area = -1; | ||
| 2579 | message_with_string (answer ? "%s(y or n) y" : "%s(y or n) n", | ||
| 2580 | xprompt, 0); | ||
| 2581 | } | ||
| 2582 | |||
| 2583 | unbind_to (count, Qnil); | ||
| 2584 | return answer ? Qt : Qnil; | ||
| 2585 | } | ||
| 2586 | |||
| 2587 | /* This is how C code calls `yes-or-no-p' and allows the user | 2447 | /* This is how C code calls `yes-or-no-p' and allows the user |
| 2588 | to redefined it. | 2448 | to redefined it. |
| 2589 | 2449 | ||
| @@ -5058,7 +4918,6 @@ this variable. */); | |||
| 5058 | defsubr (&Smapcar); | 4918 | defsubr (&Smapcar); |
| 5059 | defsubr (&Smapc); | 4919 | defsubr (&Smapc); |
| 5060 | defsubr (&Smapconcat); | 4920 | defsubr (&Smapconcat); |
| 5061 | defsubr (&Sy_or_n_p); | ||
| 5062 | defsubr (&Syes_or_no_p); | 4921 | defsubr (&Syes_or_no_p); |
| 5063 | defsubr (&Sload_average); | 4922 | defsubr (&Sload_average); |
| 5064 | defsubr (&Sfeaturep); | 4923 | defsubr (&Sfeaturep); |
diff --git a/src/lisp.h b/src/lisp.h index fc9198a5ff7..781261d9779 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2516,7 +2516,6 @@ EXFUN (Ffillarray, 2); | |||
| 2516 | EXFUN (Fnconc, MANY); | 2516 | EXFUN (Fnconc, MANY); |
| 2517 | EXFUN (Fmapcar, 2); | 2517 | EXFUN (Fmapcar, 2); |
| 2518 | EXFUN (Fmapconcat, 3); | 2518 | EXFUN (Fmapconcat, 3); |
| 2519 | EXFUN (Fy_or_n_p, 1); | ||
| 2520 | extern Lisp_Object do_yes_or_no_p (Lisp_Object); | 2519 | extern Lisp_Object do_yes_or_no_p (Lisp_Object); |
| 2521 | EXFUN (Frequire, 3); | 2520 | EXFUN (Frequire, 3); |
| 2522 | EXFUN (Fprovide, 2); | 2521 | EXFUN (Fprovide, 2); |