]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-mode): Allow use of describe-prefix-bindings
authorjustbur <justin@burkett.cc>
Thu, 17 Mar 2016 17:09:52 +0000 (13:09 -0400)
committerjustbur <justin@burkett.cc>
Thu, 17 Mar 2016 17:09:52 +0000 (13:09 -0400)
Add option to let counsel-descbinds override describe-bindings in
counsel-mode.

counsel.el (counsel-descbinds): Make signature match describe-bindings
counsel.el (counsel--descbinds-cands): Adjust for previous change
counsel.el (counsel-mode-override-describe-bindings): New option

counsel.el

index 7d11eb451f08821bc234df9dac206d02f0954ccb..cea7f4e793c7e7e4fd21e66846f4f774f6224241 100644 (file)
@@ -632,8 +632,8 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
 (defvar counsel-descbinds-history nil
   "History for `counsel-descbinds'.")
 
-(defun counsel--descbinds-cands ()
-  (let ((buffer (current-buffer))
+(defun counsel--descbinds-cands (&optional prefix buffer)
+  (let ((buffer (or buffer (current-buffer)))
         (re-exclude (regexp-opt
                      '("<vertical-line>" "<bottom-divider>" "<right-divider>"
                        "<mode-line>" "<C-down-mouse-2>" "<left-fringe>"
@@ -642,7 +642,7 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
         res)
     (with-temp-buffer
       (let ((indent-tabs-mode t))
-        (describe-buffer-bindings buffer))
+        (describe-buffer-bindings buffer prefix))
       (goto-char (point-min))
       ;; Skip the "Key translations" section
       (re-search-forward "\f")
@@ -679,11 +679,11 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
     (counsel-info-lookup-symbol (symbol-name cmd))))
 
 ;;;###autoload
-(defun counsel-descbinds ()
+(defun counsel-descbinds (&optional prefix buffer)
   "Show a list of all defined keys, and their definitions.
 Describe the selected candidate."
   (interactive)
-  (ivy-read "Bindings: " (counsel--descbinds-cands)
+  (ivy-read "Bindings: " (counsel--descbinds-cands prefix buffer)
             :action #'counsel-descbinds-action-describe
             :history 'counsel-descbinds-history
             :caller 'counsel-descbinds))
@@ -1886,6 +1886,12 @@ An extra action allows to switch to the process buffer."
   "Map for `counsel-mode'. Remaps built-in functions to counsel
 replacements.")
 
+(defcustom counsel-mode-override-describe-bindings nil
+  "Whether to override `describe-bindings' when `counsel-mode' is
+active."
+  :group 'ivy
+  :type 'boolean)
+
 ;;;###autoload
 (define-minor-mode counsel-mode
   "Toggle Counsel mode on or off.
@@ -1895,7 +1901,13 @@ replacements. "
   :group 'ivy
   :global t
   :keymap counsel-mode-map
-  :lighter " counsel")
+  :lighter " counsel"
+  (if counsel-mode
+      (when (and (fboundp 'advice-add)
+                 counsel-mode-override-describe-bindings)
+        (advice-add #'describe-bindings :override #'counsel-descbinds))
+    (when (fboundp 'advice-remove)
+      (advice-remove #'describe-bindings #'counsel-descbinds))))
 
 (provide 'counsel)