comparison lisp/help.el @ 25047:b69a152b82e3

(describe-key-briefly): Handle mode line strings with local-map properties. (describe-key): Ditto. (mode-line-key-binding): New.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 23 Jul 1999 10:59:35 +0000
parents 2668e8c9f19e
children 1ad8606c8cc7
comparison
equal deleted inserted replaced
25046:dedb45548663 25047:b69a152b82e3
214 "Text continues below]") 214 "Text continues below]")
215 (newline (- n (/ n 2))))) 215 (newline (- n (/ n 2)))))
216 (goto-char (point-min)) 216 (goto-char (point-min))
217 (set-buffer-modified-p nil)))) 217 (set-buffer-modified-p nil))))
218 218
219 (defun mode-line-key-binding (key)
220 "Value is the binding of KEY in the mode line or nil if none."
221 (let (string-info defn)
222 (when (and (eq 'mode-line (aref key 0))
223 (consp (setq string-info (nth 4 (event-start (aref key 1))))))
224 (let* ((string (car string-info))
225 (pos (cdr string-info))
226 (local-map (and (> pos 0)
227 (< pos (length string))
228 (get-text-property pos 'local-map string))))
229 (setq defn (and local-map (lookup-key local-map key)))))
230 defn))
231
219 (defun describe-key-briefly (key &optional insert) 232 (defun describe-key-briefly (key &optional insert)
220 "Print the name of the function KEY invokes. KEY is a string. 233 "Print the name of the function KEY invokes. KEY is a string.
221 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." 234 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
222 (interactive "kDescribe key briefly: \nP") 235 (interactive "kDescribe key briefly: \nP")
223 (save-excursion 236 (save-excursion
234 (if (windowp window) 247 (if (windowp window)
235 (progn 248 (progn
236 (set-buffer (window-buffer window)) 249 (set-buffer (window-buffer window))
237 (goto-char position))) 250 (goto-char position)))
238 ;; Ok, now look up the key and name the command. 251 ;; Ok, now look up the key and name the command.
239 (let ((defn (key-binding key)) 252 (let ((defn (or (mode-line-key-binding key)
253 (key-binding key)))
240 (key-desc (key-description key))) 254 (key-desc (key-description key)))
241 (if (or (null defn) (integerp defn)) 255 (if (or (null defn) (integerp defn))
242 (princ (format "%s is undefined" key-desc)) 256 (princ (format "%s is undefined" key-desc))
243 (princ (format (if insert 257 (princ (format (if insert
244 "`%s' (`%s')" 258 "`%s' (`%s')"
315 position (posn-point (event-start (aref key 0))))) 329 position (posn-point (event-start (aref key 0)))))
316 (if (windowp window) 330 (if (windowp window)
317 (progn 331 (progn
318 (set-buffer (window-buffer window)) 332 (set-buffer (window-buffer window))
319 (goto-char position))) 333 (goto-char position)))
320 (let ((defn (key-binding key))) 334 (let ((defn (or (mode-line-key-binding key) (key-binding key))))
321 (if (or (null defn) (integerp defn)) 335 (if (or (null defn) (integerp defn))
322 (message "%s is undefined" (key-description key)) 336 (message "%s is undefined" (key-description key))
323 (with-output-to-temp-buffer "*Help*" 337 (with-output-to-temp-buffer "*Help*"
324 (princ (key-description key)) 338 (princ (key-description key))
325 (if (windowp window) 339 (if (windowp window)