aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Richard2014-06-12 17:54:37 +0200
committerNicolas Richard2014-06-12 17:54:37 +0200
commit958d20d22a5e9b997de0bf7cc63436dc82486111 (patch)
treebddcc418c536e6d3ac3476ed6b15b64d4f98517f
parent2baa734e248de1e1f99959a8a0f25063ee2018a2 (diff)
downloademacs-958d20d22a5e9b997de0bf7cc63436dc82486111.tar.gz
emacs-958d20d22a5e9b997de0bf7cc63436dc82486111.zip
(describe-key) Mention the keymap in which the binding was found.
* lisp/help.el (help--key-binding-keymap): New function. (help--binding-locus): New function. (describe-key): Mention the keymap in which the binding was found. Fixes: debbugs:13948
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/help.el87
2 files changed, 86 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fce67e553dc..7c338149603 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12014-06-12 Nicolas Richard <theonewiththeevillook@yahoo.fr>
2
3 * help.el (help--key-binding-keymap): New function.
4 (help--binding-locus): New function.
5 (describe-key): Mention the keymap in which the binding was
6 found. (bug#13948)
7
12014-06-12 Stefan Monnier <monnier@iro.umontreal.ca> 82014-06-12 Stefan Monnier <monnier@iro.umontreal.ca>
2 9
3 * hippie-exp.el (he--all-buffers): New function. 10 * hippie-exp.el (he--all-buffers): New function.
diff --git a/lisp/help.el b/lisp/help.el
index 739eac4769d..01a569a6710 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -646,6 +646,68 @@ temporarily enables it to allow getting help on disabled items and buttons."
646 (princ (format "%s%s is undefined" key-desc mouse-msg)) 646 (princ (format "%s%s is undefined" key-desc mouse-msg))
647 (princ (format "%s%s runs the command %S" key-desc mouse-msg defn))))) 647 (princ (format "%s%s runs the command %S" key-desc mouse-msg defn)))))
648 648
649(defun help--key-binding-keymap (key &optional accept-default no-remap position)
650 "Return a keymap holding a binding for KEY within current keymaps.
651The effect of the arguments KEY, ACCEPT-DEFAULT, NO-REMAP and
652POSITION is as documented in the function `key-binding'."
653 (let* ((active-maps (current-active-maps t position))
654 map found)
655 ;; We loop over active maps like key-binding does.
656 (while (and
657 (not found)
658 (setq map (pop active-maps)))
659 (setq found (lookup-key map key accept-default))
660 (when (integerp found)
661 ;; The first `found' characters of KEY were found but not the
662 ;; whole sequence.
663 (setq found nil)))
664 (when found
665 (if (and (symbolp found)
666 (not no-remap)
667 (command-remapping found))
668 ;; The user might want to know in which map the binding is
669 ;; found, or in which map the remapping is found. The
670 ;; default is to show the latter.
671 (key-binding-keymap (vector 'remap found))
672 map))))
673
674(defun help--binding-locus (key position)
675 "Describe in which keymap KEY is defined.
676Return a symbol pointing to that keymap if one exists ; otherwise
677return nil."
678 (let ((map (key-binding-keymap key t nil position)))
679 (when map
680 (catch 'found
681 (let ((advertised-syms (nconc
682 (list 'overriding-terminal-local-map
683 'overriding-local-map)
684 (delq nil
685 (mapcar
686 (lambda (mode-and-map)
687 (let ((mode (car mode-and-map)))
688 (when (symbol-value mode)
689 (intern-soft
690 (format "%s-map" mode)))))
691 minor-mode-map-alist))
692 (list 'global-map
693 (intern-soft (format "%s-map" major-mode)))))
694 found)
695 ;; Look into these advertised symbols first.
696 (dolist (sym advertised-syms)
697 (when (and
698 (boundp sym)
699 (eq map (symbol-value sym)))
700 (throw 'found sym)))
701 ;; Only look in other symbols otherwise.
702 (mapatoms
703 (lambda (x)
704 (when (and (boundp x)
705 ;; Avoid let-bound symbols.
706 (special-variable-p x)
707 (eq (symbol-value x) map))
708 (throw 'found x))))
709 nil)))))
710
649(defun describe-key (&optional key untranslated up-event) 711(defun describe-key (&optional key untranslated up-event)
650 "Display documentation of the function invoked by KEY. 712 "Display documentation of the function invoked by KEY.
651KEY can be any kind of a key sequence; it can include keyboard events, 713KEY can be any kind of a key sequence; it can include keyboard events,
@@ -708,6 +770,7 @@ temporarily enables it to allow getting help on disabled items and buttons."
708 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers) 770 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
709 (memq 'drag modifiers)) " at that spot" "")) 771 (memq 'drag modifiers)) " at that spot" ""))
710 (defn (key-binding key t)) 772 (defn (key-binding key t))
773 key-locus key-locus-up key-locus-up-tricky
711 defn-up defn-up-tricky ev-type 774 defn-up defn-up-tricky ev-type
712 mouse-1-remapped mouse-1-tricky) 775 mouse-1-remapped mouse-1-tricky)
713 776
@@ -746,15 +809,19 @@ temporarily enables it to allow getting help on disabled items and buttons."
746 (setcar up-event (elt mouse-1-remapped 0))) 809 (setcar up-event (elt mouse-1-remapped 0)))
747 (t (setcar up-event 'mouse-2)))) 810 (t (setcar up-event 'mouse-2))))
748 (setq defn-up (key-binding sequence nil nil (event-start up-event))) 811 (setq defn-up (key-binding sequence nil nil (event-start up-event)))
812 (setq key-locus-up (help--binding-locus sequence (event-start up-event)))
749 (when mouse-1-tricky 813 (when mouse-1-tricky
750 (setq sequence (vector up-event)) 814 (setq sequence (vector up-event))
751 (aset sequence 0 'mouse-1) 815 (aset sequence 0 'mouse-1)
752 (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event)))))) 816 (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event)))
817 (setq key-locus-up-tricky (help--binding-locus sequence (event-start up-event))))))
818 (setq key-locus (help--binding-locus key (event-start event)))
753 (with-help-window (help-buffer) 819 (with-help-window (help-buffer)
754 (princ (help-key-description key untranslated)) 820 (princ (help-key-description key untranslated))
755 (princ (format "\ 821 (princ (format "%s runs the command %S%s, which is "
756%s runs the command %S, which is " 822 mouse-msg defn (if key-locus
757 mouse-msg defn)) 823 (format " (found in %s)" key-locus)
824 "")))
758 (describe-function-1 defn) 825 (describe-function-1 defn)
759 (when up-event 826 (when up-event
760 (unless (or (null defn-up) 827 (unless (or (null defn-up)
@@ -764,13 +831,15 @@ temporarily enables it to allow getting help on disabled items and buttons."
764 831
765----------------- up-event %s---------------- 832----------------- up-event %s----------------
766 833
767%s%s%s runs the command %S, which is " 834%s%s%s runs the command %S%s, which is "
768 (if mouse-1-tricky "(short click) " "") 835 (if mouse-1-tricky "(short click) " "")
769 (key-description (vector up-event)) 836 (key-description (vector up-event))
770 mouse-msg 837 mouse-msg
771 (if mouse-1-remapped 838 (if mouse-1-remapped
772 " is remapped to <mouse-2>, which" "") 839 " is remapped to <mouse-2>, which" "")
773 defn-up)) 840 defn-up (if key-locus-up
841 (format " (found in %s)" key-locus-up)
842 "")))
774 (describe-function-1 defn-up)) 843 (describe-function-1 defn-up))
775 (unless (or (null defn-up-tricky) 844 (unless (or (null defn-up-tricky)
776 (integerp defn-up-tricky) 845 (integerp defn-up-tricky)
@@ -780,10 +849,12 @@ temporarily enables it to allow getting help on disabled items and buttons."
780----------------- up-event (long click) ---------------- 849----------------- up-event (long click) ----------------
781 850
782Pressing <%S>%s for longer than %d milli-seconds 851Pressing <%S>%s for longer than %d milli-seconds
783runs the command %S, which is " 852runs the command %S%s, which is "
784 ev-type mouse-msg 853 ev-type mouse-msg
785 mouse-1-click-follows-link 854 mouse-1-click-follows-link
786 defn-up-tricky)) 855 defn-up-tricky (if key-locus-up-tricky
856 (format " (found in %s)" key-locus-up-tricky)
857 "")))
787 (describe-function-1 defn-up-tricky))))))) 858 (describe-function-1 defn-up-tricky)))))))
788 859
789(defun describe-mode (&optional buffer) 860(defun describe-mode (&optional buffer)