From: justbur Date: Thu, 17 Mar 2016 17:09:52 +0000 (-0400) Subject: counsel.el (counsel-mode): Allow use of describe-prefix-bindings X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/d8da9c4b6b5ed69b4967994be26ea382780e5a29 counsel.el (counsel-mode): Allow use of describe-prefix-bindings 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 --- diff --git a/counsel.el b/counsel.el index 7d11eb451..cea7f4e79 100644 --- a/counsel.el +++ b/counsel.el @@ -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 '("" "" "" "" "" "" @@ -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 " ") @@ -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)