[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-q vs documentation

From: Richard Stallman
Subject: Re: C-q vs documentation
Date: Tue, 25 Mar 2003 21:41:28 -0500

    >     The reason why I used this-single-command-raw-keys is because CHAR has
    >     already been through key-translation-map, so pushing it back onto
    >     the unread-command-events will cause it to go through 
    >     a second time, which can result in incorrect results.
    > I don't think so.  read-event does not use key-translation-map.

    Sorry, I meant function-key-map.

Yes, I see.  So it should save the character from before
translation, and unread that.

How about this?

(defun read-quoted-char (&optional prompt)
  "Like `read-char', but do not allow quitting.
Also, if the first character read is an octal digit,
we read any number of octal digits and return the
specified character code.  Any nondigit terminates the sequence.
If the terminator is RET, it is discarded;
any other terminator is used itself as input.

The optional argument PROMPT specifies a string to use to prompt the user.
The variable `read-quoted-char-radix' controls which radix to use
for numeric input."
  (let ((message-log-max nil) done (first t) (code 0) char translated)
    (while (not done)
      (let ((inhibit-quit first)
            ;; Don't let C-h get the help message--only help function keys.
            (help-char nil)
             "Type the special character you want to use,
or the octal character code.
RET terminates the character code and is discarded;
any other non-digit terminates the character code and is then used as input."))
        (setq char (read-event (and prompt (format "%s-" prompt)) t))
        (if inhibit-quit (setq quit-flag nil)))
      ;; Translate TAB key into control-I ASCII character, and so on.
      ;; Note: `read-char' does it using the `ascii-character' property.
      ;; We could try and use read-key-sequence instead, but then C-q ESC
      ;; or C-q C-x might not return immediately since ESC or C-x might be
      ;; bound to some prefix in function-key-map or key-translation-map.
      (setq translated char)
      (let ((translation (lookup-key function-key-map (vector char))))
        (if (arrayp translation)
            (setq translated (aref translation 0))))
      (cond ((null translated))
            ((not (integerp translated))
             (setq unread-command-events (list char)
                   done t))
            ((/= (logand translated ?\M-\^@) 0)
             ;; Turn a meta-character into a character with the 0200 bit set.
             (setq code (logior (logand translated (lognot ?\M-\^@)) 128)
                   done t))
            ((and (<= ?0 translated) (< translated (+ ?0 (min 10 
             (setq code (+ (* code read-quoted-char-radix) (- translated ?0)))
             (and prompt (setq prompt (message "%s %c" prompt translated))))
            ((and (<= ?a (downcase translated))
                  (< (downcase translated) (+ ?a -10 (min 26 
             (setq code (+ (* code read-quoted-char-radix)
                           (+ 10 (- (downcase translated) ?a))))
             (and prompt (setq prompt (message "%s %c" prompt translated))))
            ((and (not first) (eq translated ?\C-m))
             (setq done t))
            ((not first)
             (setq unread-command-events (list char)
                   done t))
            (t (setq code translated
                     done t)))
      (setq first nil))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]