Mercurial > emacs
comparison lisp/help.el @ 17917:2a41f677885f
(describe-key-briefly, where-is): Prefix arg means
insert help text into current buffer.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 22 May 1997 06:20:42 +0000 |
parents | 0000a992fd24 |
children | ac6884f51b58 |
comparison
equal
deleted
inserted
replaced
17916:2cfc28884664 | 17917:2a41f677885f |
---|---|
166 "Text continues below]") | 166 "Text continues below]") |
167 (newline (- n (/ n 2))))) | 167 (newline (- n (/ n 2))))) |
168 (goto-char (point-min)) | 168 (goto-char (point-min)) |
169 (set-buffer-modified-p nil)))) | 169 (set-buffer-modified-p nil)))) |
170 | 170 |
171 (defun describe-key-briefly (key) | 171 (defun describe-key-briefly (key &optional insert) |
172 "Print the name of the function KEY invokes. KEY is a string." | 172 "Print the name of the function KEY invokes. KEY is a string. |
173 (interactive "kDescribe key briefly: ") | 173 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." |
174 (interactive "kDescribe key briefly: \nP") | |
174 ;; If this key seq ends with a down event, discard the | 175 ;; If this key seq ends with a down event, discard the |
175 ;; following click or drag event. Otherwise that would | 176 ;; following click or drag event. Otherwise that would |
176 ;; erase the message. | 177 ;; erase the message. |
177 (let ((type (aref key (1- (length key))))) | 178 (let ((type (aref key (1- (length key))))) |
178 (if (listp type) (setq type (car type))) | 179 (if (listp type) (setq type (car type))) |
179 (and (symbolp type) | 180 (and (symbolp type) |
180 (memq 'down (event-modifiers type)) | 181 (memq 'down (event-modifiers type)) |
181 (read-event))) | 182 (read-event))) |
182 (save-excursion | 183 (save-excursion |
183 (let ((modifiers (event-modifiers (aref key 0))) | 184 (let ((modifiers (event-modifiers (aref key 0))) |
185 (standard-output (if insert (current-buffer) t)) | |
184 window position) | 186 window position) |
185 ;; For a mouse button event, go to the button it applies to | 187 ;; For a mouse button event, go to the button it applies to |
186 ;; to get the right key bindings. And go to the right place | 188 ;; to get the right key bindings. And go to the right place |
187 ;; in case the keymap depends on where you clicked. | 189 ;; in case the keymap depends on where you clicked. |
188 (if (or (memq 'click modifiers) (memq 'down modifiers) | 190 (if (or (memq 'click modifiers) (memq 'down modifiers) |
192 (if (windowp window) | 194 (if (windowp window) |
193 (progn | 195 (progn |
194 (set-buffer (window-buffer window)) | 196 (set-buffer (window-buffer window)) |
195 (goto-char position))) | 197 (goto-char position))) |
196 ;; Ok, now look up the key and name the command. | 198 ;; Ok, now look up the key and name the command. |
197 (let ((defn (key-binding key))) | 199 (let ((defn (key-binding key)) |
200 (key-desc (key-description key))) | |
198 (if (or (null defn) (integerp defn)) | 201 (if (or (null defn) (integerp defn)) |
199 (message "%s is undefined" (key-description key)) | 202 (princ (format "%s is undefined" key-desc)) |
200 (message (if (windowp window) | 203 (princ (format (if insert |
201 "%s at that spot runs the command %s" | 204 "%s (%s)" |
202 "%s runs the command %s") | 205 (if (windowp window) |
203 (key-description key) | 206 "%s at that spot runs the command %s" |
204 (if (symbolp defn) defn (prin1-to-string defn)))))))) | 207 "%s runs the command %s")) |
208 key-desc | |
209 (if (symbolp defn) defn (prin1-to-string defn))))))))) | |
205 | 210 |
206 (defun print-help-return-message (&optional function) | 211 (defun print-help-return-message (&optional function) |
207 "Display or return message saying how to restore windows after help command. | 212 "Display or return message saying how to restore windows after help command. |
208 Computes a message and applies the optional argument FUNCTION to it. | 213 Computes a message and applies the optional argument FUNCTION to it. |
209 If FUNCTION is nil, applies `message' to it, thus printing it." | 214 If FUNCTION is nil, applies `message' to it, thus printing it." |
644 (help-mode) | 649 (help-mode) |
645 ;; Return the text we displayed. | 650 ;; Return the text we displayed. |
646 (buffer-string)))) | 651 (buffer-string)))) |
647 (message "You did not specify a variable"))) | 652 (message "You did not specify a variable"))) |
648 | 653 |
649 (defun where-is (definition) | 654 (defun where-is (definition &optional insert) |
650 "Print message listing key sequences that invoke specified command. | 655 "Print message listing key sequences that invoke specified command. |
651 Argument is a command definition, usually a symbol with a function definition." | 656 Argument is a command definition, usually a symbol with a function definition. |
657 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." | |
652 (interactive | 658 (interactive |
653 (let ((fn (function-called-at-point)) | 659 (let ((fn (function-called-at-point)) |
654 (enable-recursive-minibuffers t) | 660 (enable-recursive-minibuffers t) |
655 val) | 661 val) |
656 (setq val (completing-read (if fn | 662 (setq val (completing-read (if fn |
657 (format "Where is command (default %s): " fn) | 663 (format "Where is command (default %s): " fn) |
658 "Where is command: ") | 664 "Where is command: ") |
659 obarray 'fboundp t)) | 665 obarray 'fboundp t)) |
660 (list (if (equal val "") | 666 (list (if (equal val "") |
661 fn (intern val))))) | 667 fn (intern val)) |
668 current-prefix-arg))) | |
662 (let* ((keys (where-is-internal definition overriding-local-map nil nil)) | 669 (let* ((keys (where-is-internal definition overriding-local-map nil nil)) |
663 (keys1 (mapconcat 'key-description keys ", "))) | 670 (keys1 (mapconcat 'key-description keys ", ")) |
664 (if (> (length keys1) 0) | 671 (standard-output (if insert (current-buffer) t))) |
665 (message "%s is on %s" definition keys1) | 672 (if insert |
666 (message "%s is not on any key" definition))) | 673 (if (> (length keys1) 0) |
674 (princ (format "%s (%s)" keys1 definition)) | |
675 (princ (format "M-x %s RET" definition))) | |
676 (if (> (length keys1) 0) | |
677 (princ (format "%s is on %s" definition keys1)) | |
678 (princ (format "%s is not on any key" definition))))) | |
667 nil) | 679 nil) |
668 | 680 |
669 (defun locate-library (library &optional nosuffix path interactive-call) | 681 (defun locate-library (library &optional nosuffix path interactive-call) |
670 "Show the precise file name of Emacs library LIBRARY. | 682 "Show the precise file name of Emacs library LIBRARY. |
671 This command searches the directories in `load-path' like `M-x load-library' | 683 This command searches the directories in `load-path' like `M-x load-library' |