comparison lisp/cmdloop.el @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents 38ef5a6da799
children fd36a980d701
comparison
equal deleted inserted replaced
5117:3742ea8250b5 5118:e0db3c197671
181 ;;#### Must be done later in the loadup sequence 181 ;;#### Must be done later in the loadup sequence
182 ;(define-key (symbol-function 'help-command) "e" 'describe-last-error) 182 ;(define-key (symbol-function 'help-command) "e" 'describe-last-error)
183 183
184 184
185 (defun truncate-command-history-for-gc () 185 (defun truncate-command-history-for-gc ()
186 (let ((tail (nthcdr 30 command-history))) 186 ;; We should try to avoid accessing any bindings to speak of in this
187 (if tail (setcdr tail nil))) 187 ;; function; as this hook is called asynchronously, the search for
188 (let ((tail (nthcdr 30 values))) 188 ;; those bindings might search local bindings from essentially
189 (if tail (setcdr tail nil))) 189 ;; arbitrary functions. We force the body of the function to run at
190 ) 190 ;; command-loop level, where the danger of local bindings is much
191 ;; reduced; the code can still do its job because the command history
192 ;; and values list will not grow before then anyway.
193 ;;
194 ;; Nothing is done in batch mode, both because it is a waste of time
195 ;; (there is no command loop!) and because this any GCs during dumping
196 ;; will invoke this code, and if it were to enqueue an eval event,
197 ;; the portable dumper would try to dump it and fail.
198 (if (not (noninteractive))
199 (enqueue-eval-event
200 (lambda (arg)
201 (let ((tail (nthcdr 30 command-history)))
202 (if tail (setcdr tail nil)))
203 (let ((tail (nthcdr 30 values)))
204 (if tail (setcdr tail nil))))
205 nil)))
191 206
192 (add-hook 'pre-gc-hook 'truncate-command-history-for-gc) 207 (add-hook 'pre-gc-hook 'truncate-command-history-for-gc)
193 208
194 209
195 ;;;; Object-oriented programming at its finest 210 ;;;; Object-oriented programming at its finest
471 Takes one argument, which is the string to display to ask the question. 486 Takes one argument, which is the string to display to ask the question.
472 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it. 487 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
473 The user must confirm the answer with RET, 488 The user must confirm the answer with RET,
474 and can edit it until it as been confirmed." 489 and can edit it until it as been confirmed."
475 (if (should-use-dialog-box-p) 490 (if (should-use-dialog-box-p)
476 (yes-or-no-p-dialog-box prompt) 491 ;; and-fboundp is redundant, since yes-or-no-p-dialog-box is only
492 ;; bound if (featurep 'dialog). But it eliminates a compile-time
493 ;; warning.
494 (and-fboundp #'yes-or-no-p-dialog-box (yes-or-no-p-dialog-box prompt))
477 (yes-or-no-p-minibuf prompt))) 495 (yes-or-no-p-minibuf prompt)))
478 496
479 (defun y-or-n-p (prompt) 497 (defun y-or-n-p (prompt)
480 "Ask user a \"y or n\" question. Return t if answer is \"y\". 498 "Ask user a \"y or n\" question. Return t if answer is \"y\".
481 Takes one argument, which is the string to display to ask the question. 499 Takes one argument, which is the string to display to ask the question.
540 Legitimate radix values are 8, 10 and 16." 558 Legitimate radix values are 8, 10 and 16."
541 :type '(choice (const 8) (const 10) (const 16)) 559 :type '(choice (const 8) (const 10) (const 16))
542 :group 'editing-basics) 560 :group 'editing-basics)
543 561
544 (defun read-quoted-char (&optional prompt) 562 (defun read-quoted-char (&optional prompt)
563 ;; XEmacs change; description of the character code input
545 "Like `read-char', but do not allow quitting. 564 "Like `read-char', but do not allow quitting.
546 Also, if the first character read is an octal digit, 565
547 we read any number of octal digits and return the 566 Also, if the first character read is a digit of base (the value of)
548 specified character code. Any nondigit terminates the sequence. 567 `read-quoted-char-radix', we read as many of such digits as are
549 If the terminator is RET, it is discarded; 568 typed and return a character with the corresponding Unicode code
550 any other terminator is used itself as input. 569 point. Any input that is not a digit (in the base used) terminates
570 the sequence. If the terminator is RET, it is discarded; any other
571 terminator is used itself as input.
551 572
552 The optional argument PROMPT specifies a string to use to prompt the user. 573 The optional argument PROMPT specifies a string to use to prompt the user.
553 The variable `read-quoted-char-radix' controls which radix to use 574 The variable `read-quoted-char-radix' controls which radix to use
554 for numeric input." 575 for numeric input."
555 (let (;(message-log-max nil) 576 (let (;(message-log-max nil)
556 done (first t) (code 0) char event 577 done (first t) (code 0) char event
557 (prompt (and prompt (gettext prompt))) 578 (prompt (and prompt (gettext prompt)))
558 ) 579 )
559 (while (not done) 580 (while (not done)
560 (let ((inhibit-quit first) 581 (let ((inhibit-quit first)
561 ;; Don't let C-h get the help message--only help function keys. 582 ;; Don't let C-h get the help message--only help
583 ;; function keys.
584 ;; XEmacs: we don't support the help function keys as of
585 ;; 2006-04-16. GNU have a Vhelp_event_list in addition
586 ;; to help-char in src/keyboard.c, and it's only useful
587 ;; to set help-form while help-char is nil when that
588 ;; functionality is available.
562 (help-char nil) 589 (help-char nil)
563 (help-form 590 (help-form (format
564 "Type the special character you want to use, 591 "Type the special character you want to use,
565 or the octal character code. 592 or the character code, base %d (the value of `read-quoted-char-radix')
566 RET terminates the character code and is discarded; 593 RET terminates the character code and is discarded;
567 any other non-digit terminates the character code and is then used as input.")) 594 any other non-digit terminates the character code and is then used as input."
595 read-quoted-char-radix)))
568 (and prompt (display-message 'prompt (format "%s-" prompt))) 596 (and prompt (display-message 'prompt (format "%s-" prompt)))
569 (setq event (next-command-event) 597 (setq event (next-command-event)
570 char (or (event-to-character event) 598 ;; If event-to-character fails, this is fine, we handle that
571 (signal 'error 599 ;; with the (null char) cond branch below.
572 (list "key read cannot be inserted in a buffer" 600 char (event-to-character event))
573 event))))
574 (if inhibit-quit (setq quit-flag nil))) 601 (if inhibit-quit (setq quit-flag nil)))
575 ;; Translate TAB key into control-I ASCII character, and so on. 602 ;; Translate TAB key into control-I ASCII character, and so on.
576 (and char 603 (and char
577 (let ((translated (lookup-key function-key-map (vector char)))) 604 (let ((translated (lookup-key function-key-map (vector char))))
578 (if (arrayp translated) 605 (if (arrayp translated)
579 (setq char (aref translated 0))))) 606 (setq char (aref translated 0)))))
580 (cond ((null char)) 607 (cond ((null char))
581 ((not (characterp char)) 608 ((not (characterp char))
582 (setq unread-command-events (list char) 609 ;; XEmacs change; event instead of char.
610 (setq unread-command-events (list event)
583 done t)) 611 done t))
584 ; ((/= (logand char ?\M-\^@) 0) 612 ; ((/= (logand char ?\M-\^@) 0)
585 ; ;; Turn a meta-character into a character with the 0200 bit set. 613 ; ;; Turn a meta-character into a character with the 0200 bit set.
586 ; (setq code (logior (logand char (lognot ?\M-\^@)) 128) 614 ; (setq code (logior (logand char (lognot ?\M-\^@)) 128)
587 ; done t)) 615 ; done t))
596 (and prompt (setq prompt (display-message 'prompt 624 (and prompt (setq prompt (display-message 'prompt
597 (format "%s %c" prompt char))))) 625 (format "%s %c" prompt char)))))
598 ((and (not first) (eq char ?\C-m)) 626 ((and (not first) (eq char ?\C-m))
599 (setq done t)) 627 (setq done t))
600 ((not first) 628 ((not first)
601 (setq unread-command-events (list char) 629 ;; XEmacs change; event instead of char.
630 (setq unread-command-events (list event)
602 done t)) 631 done t))
603 (t (setq code (char-to-int char) 632 (t (setq code (char-to-int char)
604 done t))) 633 done t)))
605 (setq first nil)) 634 (setq first nil))
606 (int-to-char code))) 635 ;; XEmacs change; unicode-to-char instead of int-to-char
636 (unicode-to-char code)))
607 637
608 ;; in passwd.el. 638 ;; in passwd.el.
609 ; (defun read-passwd (prompt &optional confirm default) 639 ; (defun read-passwd (prompt &optional confirm default)
610 ; "Read a password, prompting with PROMPT. Echo `.' for each character typed. 640 ; "Read a password, prompting with PROMPT. Echo `.' for each character typed.
611 ; End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. 641 ; End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line.