aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-04-02 03:23:26 +0000
committerStefan Monnier2002-04-02 03:23:26 +0000
commit02dfca16b129fe6573b008cc33977ec370a66aeb (patch)
tree93bba46c8d7ee39b101d880f244f000e289aa75e
parentc5e5e1f85594ae082e08aaf11a63166c3e20a332 (diff)
downloademacs-02dfca16b129fe6573b008cc33977ec370a66aeb.tar.gz
emacs-02dfca16b129fe6573b008cc33977ec370a66aeb.zip
(help-key-description): New fun.
(describe-key-briefly, describe-key): Use it and this-single-command-raw-keys plus new arg `untranslated'.
-rw-r--r--lisp/help.el47
1 files changed, 32 insertions, 15 deletions
diff --git a/lisp/help.el b/lisp/help.el
index 8ae09c07eb1..a11bc81008d 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -350,12 +350,10 @@ To record all your input on a file, use `open-dribble-file'."
350 (interactive) 350 (interactive)
351 (help-setup-xref (list #'view-lossage) (interactive-p)) 351 (help-setup-xref (list #'view-lossage) (interactive-p))
352 (with-output-to-temp-buffer (help-buffer) 352 (with-output-to-temp-buffer (help-buffer)
353 (princ (mapconcat (function (lambda (key) 353 (princ (mapconcat (lambda (key)
354 (if (or (integerp key) 354 (if (or (integerp key) (symbolp key) (listp key))
355 (symbolp key) 355 (single-key-description key)
356 (listp key)) 356 (prin1-to-string key nil)))
357 (single-key-description key)
358 (prin1-to-string key nil))))
359 (recent-keys) 357 (recent-keys)
360 " ")) 358 " "))
361 (with-current-buffer standard-output 359 (with-current-buffer standard-output
@@ -450,10 +448,24 @@ or `keymap' property, return the binding of KEY in the string's keymap."
450 (setq defn (and local-map (lookup-key local-map key))))) 448 (setq defn (and local-map (lookup-key local-map key)))))
451 defn)) 449 defn))
452 450
453(defun describe-key-briefly (key &optional insert) 451(defun help-key-description (key untranslated)
452 (let ((string (key-description key)))
453 (if (or (not untranslated) (eq (aref untranslated 0) ?\e))
454 string
455 (let ((otherstring (key-description untranslated)))
456 (if (equal string otherstring)
457 string
458 (format "%s (translated from %s)" string otherstring))))))
459
460(defun describe-key-briefly (key &optional insert untranslated)
454 "Print the name of the function KEY invokes. KEY is a string. 461 "Print the name of the function KEY invokes. KEY is a string.
455If INSERT (the prefix arg) is non-nil, insert the message in the buffer." 462If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
456 (interactive "kDescribe key briefly: \nP") 463If non-nil UNTRANSLATED is a vector of the untranslated events.
464It can also be a number in which case the untranslated events from
465the last key hit are used."
466 (interactive "kDescribe key briefly: \nP\np")
467 (if (numberp untranslated)
468 (setq untranslated (this-single-command-raw-keys)))
457 (save-excursion 469 (save-excursion
458 (let ((modifiers (event-modifiers (aref key 0))) 470 (let ((modifiers (event-modifiers (aref key 0)))
459 (standard-output (if insert (current-buffer) t)) 471 (standard-output (if insert (current-buffer) t))
@@ -472,7 +484,7 @@ If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
472 ;; Ok, now look up the key and name the command. 484 ;; Ok, now look up the key and name the command.
473 (let ((defn (or (string-key-binding key) 485 (let ((defn (or (string-key-binding key)
474 (key-binding key))) 486 (key-binding key)))
475 (key-desc (key-description key))) 487 (key-desc (help-key-description key untranslated)))
476 (if (or (null defn) (integerp defn) (equal defn 'undefined)) 488 (if (or (null defn) (integerp defn) (equal defn 'undefined))
477 (princ (format "%s is undefined" key-desc)) 489 (princ (format "%s is undefined" key-desc))
478 (princ (format (if (windowp window) 490 (princ (format (if (windowp window)
@@ -482,11 +494,16 @@ If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
482 (if (symbolp defn) defn (prin1-to-string defn))))))))) 494 (if (symbolp defn) defn (prin1-to-string defn)))))))))
483 495
484 496
485(defun describe-key (key) 497(defun describe-key (key &optional untranslated)
486 "Display documentation of the function invoked by KEY. 498 "Display documentation of the function invoked by KEY.
487KEY should be a key sequence--when calling from a program, 499KEY should be a key sequence--when calling from a program,
488pass a string or a vector." 500pass a string or a vector.
489 (interactive "kDescribe key: ") 501If non-nil UNTRANSLATED is a vector of the untranslated events.
502It can also be a number in which case the untranslated events from
503the last key hit are used."
504 (interactive "kDescribe key: \np")
505 (if (numberp untranslated)
506 (setq untranslated (this-single-command-raw-keys)))
490 (save-excursion 507 (save-excursion
491 (let ((modifiers (event-modifiers (aref key 0))) 508 (let ((modifiers (event-modifiers (aref key 0)))
492 window position) 509 window position)
@@ -502,10 +519,10 @@ pass a string or a vector."
502 (goto-char position)) 519 (goto-char position))
503 (let ((defn (or (string-key-binding key) (key-binding key)))) 520 (let ((defn (or (string-key-binding key) (key-binding key))))
504 (if (or (null defn) (integerp defn) (equal defn 'undefined)) 521 (if (or (null defn) (integerp defn) (equal defn 'undefined))
505 (message "%s is undefined" (key-description key)) 522 (message "%s is undefined" (help-key-description key untranslated))
506 (help-setup-xref (list #'describe-function defn) (interactive-p)) 523 (help-setup-xref (list #'describe-function defn) (interactive-p))
507 (with-output-to-temp-buffer (help-buffer) 524 (with-output-to-temp-buffer (help-buffer)
508 (princ (key-description key)) 525 (princ (help-key-description key untranslated))
509 (if (windowp window) 526 (if (windowp window)
510 (princ " at that spot")) 527 (princ " at that spot"))
511 (princ " runs the command ") 528 (princ " runs the command ")