changeset 44332:bdf6c2baa447

(help-key-description): New fun. (describe-key-briefly, describe-key): Use it and this-single-command-raw-keys plus new arg `untranslated'.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 02 Apr 2002 03:23:26 +0000
parents 5a8965629f02
children efbd9e76f0a4
files lisp/help.el
diffstat 1 files changed, 32 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/help.el	Mon Apr 01 23:33:40 2002 +0000
+++ b/lisp/help.el	Tue Apr 02 03:23:26 2002 +0000
@@ -350,12 +350,10 @@
   (interactive)
   (help-setup-xref (list #'view-lossage) (interactive-p))
   (with-output-to-temp-buffer (help-buffer)
-    (princ (mapconcat (function (lambda (key)
-				  (if (or (integerp key)
-					  (symbolp key)
-					  (listp key))
-				      (single-key-description key)
-				    (prin1-to-string key nil))))
+    (princ (mapconcat (lambda (key)
+			(if (or (integerp key) (symbolp key) (listp key))
+			    (single-key-description key)
+			  (prin1-to-string key nil)))
 		      (recent-keys)
 		      " "))
     (with-current-buffer standard-output
@@ -450,10 +448,24 @@
 	(setq defn (and local-map (lookup-key local-map key)))))
     defn))
 
-(defun describe-key-briefly (key &optional insert)
+(defun help-key-description (key untranslated)
+  (let ((string (key-description key)))
+    (if (or (not untranslated) (eq (aref untranslated 0) ?\e))
+	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 "kDescribe key briefly: \nP")
+If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
+If non-nil UNTRANSLATED is a vector of the untranslated events.
+It can also be a number in which case the untranslated events from
+the last key hit are used."
+  (interactive "kDescribe key briefly: \nP\np")
+  (if (numberp untranslated)
+      (setq untranslated (this-single-command-raw-keys)))
   (save-excursion
     (let ((modifiers (event-modifiers (aref key 0)))
 	  (standard-output (if insert (current-buffer) t))
@@ -472,7 +484,7 @@
       ;; 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)))
+	    (key-desc (help-key-description key untranslated)))
 	(if (or (null defn) (integerp defn) (equal defn 'undefined))
 	    (princ (format "%s is undefined" key-desc))
 	  (princ (format (if (windowp window)
@@ -482,11 +494,16 @@
 			 (if (symbolp defn) defn (prin1-to-string defn)))))))))
 
 
-(defun describe-key (key)
+(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 "kDescribe key: ")
+pass a string or a vector.
+If non-nil UNTRANSLATED is a vector of the untranslated events.
+It can also be a number in which case the untranslated events from
+the last key hit are used."
+  (interactive "kDescribe key: \np")
+  (if (numberp untranslated)
+      (setq untranslated (this-single-command-raw-keys)))
   (save-excursion
     (let ((modifiers (event-modifiers (aref key 0)))
 	  window position)
@@ -502,10 +519,10 @@
 	(goto-char position))
       (let ((defn (or (string-key-binding key) (key-binding key))))
 	(if (or (null defn) (integerp defn) (equal defn 'undefined))
-	    (message "%s is undefined" (key-description key))
+	    (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 (key-description key))
+	    (princ (help-key-description key untranslated))
 	    (if (windowp window)
 		(princ " at that spot"))
 	    (princ " runs the command ")