[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Raw keys in C-h k and C-h c
From: |
Stefan Monnier |
Subject: |
Raw keys in C-h k and C-h c |
Date: |
Fri, 01 Feb 2002 12:09:07 -0500 |
Any comment/objection on the patch below ?
It makes C-h c and C-k report
foo (translated from bar)
instead of just `foo' when the translated key sequence `foo' is not the same
as the raw sequence `bar'. Examples:
M-u (translated from M-U) runs the command upcase-word
or
DEL (translated from <backspace>) runs the command scroll-down
or
<f1> a (translated from ESC O P a) runs the command apropos-command
I find `translated from' a bit awkward and longish, so any other idea
is welcome.
Stefan
Index: help.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help.el,v
retrieving revision 1.243
diff -c -r1.243 help.el
*** help.el 17 Jan 2002 01:40:47 -0000 1.243
--- help.el 1 Feb 2002 17:02:56 -0000
***************
*** 445,454 ****
(setq defn (and local-map (lookup-key local-map key)))))
defn))
! (defun describe-key-briefly (key &optional insert)
"Print the name of the function KEY invokes. KEY is a string.
If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
! (interactive "kDescribe key briefly: \nP")
(save-excursion
(let ((modifiers (event-modifiers (aref key 0)))
(standard-output (if insert (current-buffer) t))
--- 443,498 ----
(setq defn (and local-map (lookup-key local-map key)))))
defn))
! (defun help-read-key (prompt)
! ;; Inspired from the C code of `call-interactively', where the 'k' case
! ;; of `interactive' is handled.
! (let* ((old (recent-keys))
! (keys (let ((cursor-in-echo-area t)) (read-key-sequence prompt)))
! ;; (viskeys (key-description keys))
! (new (recent-keys))
! (found nil)
! (n 0))
! ;; If the key sequence ends with a down-event,
! ;; discard the following up-event.
! (if (memq 'down (event-modifiers (aref keys (1- (length keys)))))
! (read-event))
!
! ;; Find the untranslated events.
! ;; (assert (>= (length new) (length old)))
! (while (and (not found) (< n (length old)))
! (let ((m n))
! (while (and (< m (length old))
! (eq (aref old m) (aref new (- m n))))
! (setq m (1+ m)))
! (if (= m (length old))
! (setq found t)
! (setq n (1+ n)))))
! (setq n (+ n (- (length new) (length old))))
!
! (list keys
! (if found
! (let ((keys (make-vector n nil)))
! (while (> n 0)
! (aset keys (- (length keys) n)
! (aref new (- (length new) n)))
! (setq n (1- n)))
! keys)))))
!
! (defun help-key-description (key untranslated)
! (let ((string (key-description key)))
! (if (not untranslated)
! string
! (let ((otherstring (key-description untranslated)))
! (if (equal string otherstring)
! string
! (format "%s (translated from %s)" string otherstring))))))
!
! (defun describe-key-briefly (key &optional insert untranslated)
"Print the name of the function KEY invokes. KEY is a string.
If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
! (interactive
! (let ((keys (help-read-key "Describe key briefly: ")))
! (list (car keys) current-prefix-arg (cadr keys))))
(save-excursion
(let ((modifiers (event-modifiers (aref key 0)))
(standard-output (if insert (current-buffer) t))
***************
*** 467,473 ****
;; Ok, now look up the key and name the command.
(let ((defn (or (string-key-binding key)
(key-binding key)))
! (key-desc (key-description key)))
(if (or (null defn) (integerp defn))
(princ (format "%s is undefined" key-desc))
(princ (format (if insert
--- 511,517 ----
;; Ok, now look up the key and name the command.
(let ((defn (or (string-key-binding key)
(key-binding key)))
! (key-desc (help-key-description key untranslated)))
(if (or (null defn) (integerp defn))
(princ (format "%s is undefined" key-desc))
(princ (format (if insert
***************
*** 479,489 ****
(if (symbolp defn) defn (prin1-to-string defn)))))))))
! (defun describe-key (key)
"Display documentation of the function invoked by KEY.
KEY should be a key sequence--when calling from a program,
pass a string or a vector."
! (interactive "kDescribe key: ")
(save-excursion
(let ((modifiers (event-modifiers (aref key 0)))
window position)
--- 523,533 ----
(if (symbolp defn) defn (prin1-to-string defn)))))))))
! (defun describe-key (key &optional untranslated)
"Display documentation of the function invoked by KEY.
KEY should be a key sequence--when calling from a program,
pass a string or a vector."
! (interactive (help-read-key "Describe key: "))
(save-excursion
(let ((modifiers (event-modifiers (aref key 0)))
window position)
***************
*** 499,508 ****
(goto-char position))
(let ((defn (or (string-key-binding key) (key-binding key))))
(if (or (null defn) (integerp defn))
! (message "%s is undefined" (key-description key))
(help-setup-xref (list #'describe-function defn) (interactive-p))
(with-output-to-temp-buffer (help-buffer)
! (princ (key-description key))
(if (windowp window)
(princ " at that spot"))
(princ " runs the command ")
--- 543,552 ----
(goto-char position))
(let ((defn (or (string-key-binding key) (key-binding key))))
(if (or (null defn) (integerp defn))
! (message "%s is undefined" (help-key-description key untranslated))
(help-setup-xref (list #'describe-function defn) (interactive-p))
(with-output-to-temp-buffer (help-buffer)
! (princ (help-key-description key untranslated))
(if (windowp window)
(princ " at that spot"))
(princ " runs the command ")
- Re: Questions round session management., Richard Stallman, 2002/02/01
- Re: Questions round session management., Tak Ota, 2002/02/01
- Re: Questions round session management., Simon Josefsson, 2002/02/01
- Re: Raw keys in C-h k and C-h c, Richard Stallman, 2002/02/01
- Re: Raw keys in C-h k and C-h c, Stefan Monnier, 2002/02/02
- Re: Raw keys in C-h k and C-h c, Kim F. Storm, 2002/02/02
- Re: Raw keys in C-h k and C-h c, Eli Zaretskii, 2002/02/03
- Re: Raw keys in C-h k and C-h c, Richard Stallman, 2002/02/10
- Re: Raw keys in C-h k and C-h c, Kim F. Storm, 2002/02/11
- Re: Raw keys in C-h k and C-h c, Richard Stallman, 2002/02/04
- Re: Raw keys in C-h k and C-h c, Stefan Monnier, 2002/02/04