Mercurial > hg > xemacs-beta
comparison lisp/cmdloop.el @ 5922:4b055de36bb9 cygwin
merging heads 2
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Fri, 27 Feb 2015 17:47:15 +0000 |
parents | 0e9f791cc655 |
children | c87b776ab0e1 |
comparison
equal
deleted
inserted
replaced
5921:68639fb08af8 | 5922:4b055de36bb9 |
---|---|
518 (if (should-use-dialog-box-p) | 518 (if (should-use-dialog-box-p) |
519 (yes-or-no-p-dialog-box prompt) | 519 (yes-or-no-p-dialog-box prompt) |
520 (y-or-n-p-minibuf prompt))) | 520 (y-or-n-p-minibuf prompt))) |
521 | 521 |
522 | 522 |
523 | 523 (labels |
524 (defun read-char () | 524 ((read-char-1 (errorp prompt inherit-input-method seconds) |
525 "Read a character from the command input (keyboard or macro). | 525 "Return a character from command input or the current macro. |
526 If a mouse click or non-ASCII character is detected, an error is | 526 Look up said input in `function-key-map' as appropriate. |
527 signalled. The character typed is returned as an ASCII value. This | 527 |
528 is most likely the wrong thing for you to be using: consider using | 528 PROMPT is a prompt for `next-command-event', which see. |
529 the `next-command-event' function instead." | 529 |
530 (save-excursion | 530 If ERRORP is non-nil, error if the key sequence has no character equivalent. |
531 (let ((event (next-command-event))) | 531 Otherwise, loop, discarding non-character keystrokes or mouse movements. |
532 (or inhibit-quit | 532 |
533 (and (event-matches-key-specifier-p event (quit-char)) | 533 If INHERIT-INPUT-METHOD is non-nil, and a Quail input method is active in |
534 (signal 'quit nil))) | 534 the current buffer, use its translation when choosing a character to return. |
535 (prog1 (or (event-to-character event) | 535 |
536 ;; Kludge. If the event we read was a mouse-release, | 536 If SECONDS is non-nil, only wait that number of seconds for input. If no |
537 ;; discard it and read the next one. | 537 input is received in that time, return nil." |
538 (if (button-release-event-p event) | 538 (let ((timeout |
539 (event-to-character (next-command-event event))) | 539 (if seconds |
540 (error "Key read has no ASCII equivalent %S" event)) | 540 (add-timeout seconds #'(lambda (ignore) |
541 ;; this is not necessary, but is marginally more efficient than GC. | 541 (return-from read-char-1 nil)) |
542 (deallocate-event event))))) | 542 nil))) |
543 | 543 (events []) binding character) |
544 (defun read-char-exclusive () | 544 (unwind-protect |
545 "Read a character from the command input (keyboard or macro). | 545 (while t |
546 If a mouse click or non-ASCII character is detected, it is discarded. | 546 ;; Read keystrokes scanning `function-key-map'. |
547 The character typed is returned as an ASCII value. This is most likely | 547 (while (keymapp |
548 the wrong thing for you to be using: consider using the | 548 (setq binding |
549 `next-command-event' function instead." | 549 (lookup-key |
550 (let (event ch) | 550 function-key-map |
551 (while (progn | 551 (setq events |
552 (setq event (next-command-event)) | 552 (vconcat events (list |
553 (or inhibit-quit | 553 (next-key-event |
554 (and (event-matches-key-specifier-p event (quit-char)) | 554 nil prompt)))))))) |
555 (signal 'quit nil))) | 555 (when binding |
556 (setq ch (event-to-character event)) | 556 ;; Found something in function-key-map. If it's a function |
557 (deallocate-event event) | 557 ;; (e.g. synthesize-keysym), call it. |
558 (null ch))) | 558 (if (functionp binding) |
559 ch)) | 559 (setq binding (funcall binding nil))) |
560 (setq events (map 'vector #'character-to-event binding))) | |
561 ;; Put the remaining keystrokes back on the input queue. | |
562 (setq unread-command-events | |
563 (nconc (reduce #'cons events :start 1 :from-end t | |
564 :initial-value nil) | |
565 unread-command-events)) | |
566 (unless inhibit-quit | |
567 (and (event-matches-key-specifier-p (aref events 0) | |
568 (quit-char)) | |
569 (signal 'quit nil))) | |
570 (if (setq character (event-to-character (aref events 0))) | |
571 (progn | |
572 ;; If we have a character (the usual case), deallocate | |
573 ;; the event and return the character. | |
574 (deallocate-event (aref events 0)) | |
575 ;; Handle quail, if we've been asked to (maybe we | |
576 ;; should default to this). | |
577 (if (and inherit-input-method (and-boundp 'quail-mode | |
578 quail-mode)) | |
579 (with-fboundp | |
580 '(quail-map-definition quail-lookup-key) | |
581 (let ((binding | |
582 (quail-map-definition | |
583 (quail-lookup-key (string character))))) | |
584 (if (characterp binding) | |
585 (return-from read-char-1 binding)) | |
586 ;; #### Bug, we don't allow users to select from | |
587 ;; among multiple characters that may be input | |
588 ;; with the same key sequence. | |
589 (if (and (consp binding) | |
590 (characterp | |
591 (aref (cdr binding) (caar binding)))) | |
592 (return-from read-char-1 | |
593 (aref (cdr binding) (caar binding))))))) | |
594 (return-from read-char-1 character))) | |
595 (if errorp | |
596 (error 'invalid-key-binding "Not a character keystroke" | |
597 (aref events 0))) | |
598 ;; If we're not erroring, loop until we get a character | |
599 (setq events [])) | |
600 (if timeout (disable-timeout timeout)))))) | |
601 ;; Because of byte compiler limitations, each function has its own copy of | |
602 ;; #'read-char-1, so why not inline it. | |
603 (declare (inline read-char-1)) | |
604 | |
605 (defun read-char (&optional prompt inherit-input-method seconds) | |
606 "Read a character from the command input (keyboard or macro). | |
607 If a mouse click or non-character keystroke is detected, signal an error. | |
608 The character typed is returned as a Lisp object. This is most likely the | |
609 wrong thing for you to be using: consider using the `next-command-event' | |
610 function instead. | |
611 | |
612 PROMPT is a prompt, as used by `next-command-event'. | |
613 | |
614 If INHERIT-INPUT-METHOD is non-nil, and a Quail input method is active in | |
615 the current buffer, use its translation for the character returned. | |
616 | |
617 If SECONDS is non-nil, only wait that number of seconds for input. If no | |
618 input is received in that time, return nil." | |
619 (read-char-1 t prompt inherit-input-method seconds)) | |
620 | |
621 (defun read-char-exclusive (&optional prompt inherit-input-method seconds) | |
622 "Read a character from the command input (keyboard or macro). | |
623 | |
624 If a mouse click or a non-character keystroke is detected, it is discarded. | |
625 The character typed is returned as a Lisp object. This is most likely the | |
626 wrong thing for you to be using: consider using the `next-command-event' | |
627 function instead. | |
628 | |
629 PROMPT is a prompt, as used by `next-command-event'. | |
630 | |
631 If INHERIT-INPUT-METHOD is non-nil, and a Quail input method is active in | |
632 the current buffer, use its translation for the character returned. | |
633 | |
634 If SECONDS is non-nil, only wait that number of seconds for input. If no | |
635 input is received in that time, return nil." | |
636 (read-char-1 nil prompt inherit-input-method seconds))) | |
560 | 637 |
561 ;;;; Input and display facilities. | 638 ;;;; Input and display facilities. |
562 | 639 |
563 ;; BEGIN SYNCHED WITH FSF 21.2. | 640 ;; BEGIN SYNCHED WITH FSF 21.2. |
564 | 641 |