(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>"
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")
(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))
"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.
: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)