@@ -1562,17 +1562,55 @@ BUFFER should be a buffer or a buffer name."
1562
1562
(insert " \n The parent category table is:" )
1563
1563
(describe-vector table 'help-describe-category-set ))))))
1564
1564
1565
+ (defun help-fns-find-keymap-name (keymap )
1566
+ " Find the name of the variable with value KEYMAP.
1567
+ Return nil if KEYMAP is not a valid keymap, or if there is no
1568
+ variable with value KEYMAP."
1569
+ (when (keymapp keymap)
1570
+ (let ((name (catch 'found-keymap
1571
+ (mapatoms (lambda (symb )
1572
+ (when (and (boundp symb)
1573
+ (eq (symbol-value symb) keymap)
1574
+ (not (eq symb 'keymap ))
1575
+ (throw 'found-keymap symb)))))
1576
+ nil )))
1577
+ ; ; Follow aliasing.
1578
+ (or (ignore-errors (indirect-variable name)) name))))
1579
+
1580
+ (defun help-fns--most-relevant-active-keymap ()
1581
+ " Return the name of the most relevant active keymap.
1582
+ The heuristic to determine which keymap is most likely to be
1583
+ relevant to a user follows this order:
1584
+
1585
+ 1. 'keymap' text property at point
1586
+ 2. 'local-map' text property at point
1587
+ 3. the `current-local-map'
1588
+
1589
+ This is used to set the default value for the interactive prompt
1590
+ in `describe-keymap' . See also `Searching the Active Keymaps'."
1591
+ (help-fns-find-keymap-name (or (get-char-property (point ) 'keymap )
1592
+ (if (get-text-property (point ) 'local-map )
1593
+ (get-char-property (point ) 'local-map )
1594
+ (current-local-map )))))
1595
+
1565
1596
;;;### autoload
1566
1597
(defun describe-keymap (keymap )
1567
1598
" Describe key bindings in KEYMAP.
1568
1599
When called interactively, prompt for a variable that has a
1569
1600
keymap value."
1570
- (interactive (list
1571
- (intern (completing-read " Keymap: " obarray
1572
- (lambda (m )
1573
- (and (boundp m)
1574
- (keymapp (symbol-value m))))
1575
- t nil 'variable-name-history ))))
1601
+ (interactive
1602
+ (let* ((km (help-fns--most-relevant-active-keymap))
1603
+ (val (completing-read
1604
+ (format " Keymap (default %s ): " km)
1605
+ obarray
1606
+ (lambda (m ) (and (boundp m) (keymapp (symbol-value m))))
1607
+ t nil 'keymap-name-history
1608
+ (symbol-name km))))
1609
+ (unless (equal val " " )
1610
+ (setq km (intern val)))
1611
+ (unless (and km (keymapp (symbol-value km)))
1612
+ (user-error " Not a keymap: %s" km))
1613
+ (list km)))
1576
1614
(let (used-gentemp)
1577
1615
(unless (and (symbolp keymap)
1578
1616
(boundp keymap)
0 commit comments