diff options
Diffstat (limited to 'lisp/simple.el')
| -rw-r--r-- | lisp/simple.el | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index cd4df60e394..49108025a40 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -636,6 +636,67 @@ column specified by the function `current-left-margin'." | |||
| 636 | (delete-horizontal-space t)) | 636 | (delete-horizontal-space t)) |
| 637 | (indent-according-to-mode))) | 637 | (indent-according-to-mode))) |
| 638 | 638 | ||
| 639 | (defcustom read-quoted-char-radix 8 | ||
| 640 | "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'. | ||
| 641 | Legitimate radix values are 8, 10 and 16." | ||
| 642 | :type '(choice (const 8) (const 10) (const 16)) | ||
| 643 | :group 'editing-basics) | ||
| 644 | |||
| 645 | (defun read-quoted-char (&optional prompt) | ||
| 646 | "Like `read-char', but do not allow quitting. | ||
| 647 | Also, if the first character read is an octal digit, | ||
| 648 | we read any number of octal digits and return the | ||
| 649 | specified character code. Any nondigit terminates the sequence. | ||
| 650 | If the terminator is RET, it is discarded; | ||
| 651 | any other terminator is used itself as input. | ||
| 652 | |||
| 653 | The optional argument PROMPT specifies a string to use to prompt the user. | ||
| 654 | The variable `read-quoted-char-radix' controls which radix to use | ||
| 655 | for numeric input." | ||
| 656 | (let ((message-log-max nil) done (first t) (code 0) translated) | ||
| 657 | (while (not done) | ||
| 658 | (let ((inhibit-quit first) | ||
| 659 | ;; Don't let C-h get the help message--only help function keys. | ||
| 660 | (help-char nil) | ||
| 661 | (help-form | ||
| 662 | "Type the special character you want to use, | ||
| 663 | or the octal character code. | ||
| 664 | RET terminates the character code and is discarded; | ||
| 665 | any other non-digit terminates the character code and is then used as input.")) | ||
| 666 | (setq translated (read-key (and prompt (format "%s-" prompt)))) | ||
| 667 | (if inhibit-quit (setq quit-flag nil))) | ||
| 668 | (if (integerp translated) | ||
| 669 | (setq translated (char-resolve-modifiers translated))) | ||
| 670 | (cond ((null translated)) | ||
| 671 | ((not (integerp translated)) | ||
| 672 | (setq unread-command-events | ||
| 673 | (listify-key-sequence (this-single-command-raw-keys)) | ||
| 674 | done t)) | ||
| 675 | ((/= (logand translated ?\M-\^@) 0) | ||
| 676 | ;; Turn a meta-character into a character with the 0200 bit set. | ||
| 677 | (setq code (logior (logand translated (lognot ?\M-\^@)) 128) | ||
| 678 | done t)) | ||
| 679 | ((and (<= ?0 translated) | ||
| 680 | (< translated (+ ?0 (min 10 read-quoted-char-radix)))) | ||
| 681 | (setq code (+ (* code read-quoted-char-radix) (- translated ?0))) | ||
| 682 | (and prompt (setq prompt (message "%s %c" prompt translated)))) | ||
| 683 | ((and (<= ?a (downcase translated)) | ||
| 684 | (< (downcase translated) | ||
| 685 | (+ ?a -10 (min 36 read-quoted-char-radix)))) | ||
| 686 | (setq code (+ (* code read-quoted-char-radix) | ||
| 687 | (+ 10 (- (downcase translated) ?a)))) | ||
| 688 | (and prompt (setq prompt (message "%s %c" prompt translated)))) | ||
| 689 | ((and (not first) (eq translated ?\C-m)) | ||
| 690 | (setq done t)) | ||
| 691 | ((not first) | ||
| 692 | (setq unread-command-events | ||
| 693 | (listify-key-sequence (this-single-command-raw-keys)) | ||
| 694 | done t)) | ||
| 695 | (t (setq code translated | ||
| 696 | done t))) | ||
| 697 | (setq first nil)) | ||
| 698 | code)) | ||
| 699 | |||
| 639 | (defun quoted-insert (arg) | 700 | (defun quoted-insert (arg) |
| 640 | "Read next input character and insert it. | 701 | "Read next input character and insert it. |
| 641 | This is useful for inserting control characters. | 702 | This is useful for inserting control characters. |