[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d996215 038/272: Add counsel-descbinds
From: |
Oleh Krehel |
Subject: |
[elpa] master d996215 038/272: Add counsel-descbinds |
Date: |
Mon, 25 Apr 2016 10:13:15 +0000 |
branch: master
commit d996215c9e2757deae391619839037cbbdfa7b9c
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add counsel-descbinds
* ivy.el (ivy-read-action): Update prompt for "C-M-a".
* counsel.el (counsel--find-symbol): Use ivy-window.
(counsel--descbinds-cands): New defun.
(counsel-descbinds-history): New defvar.
(counsel-descbinds-action-describe): New defun.
(counsel-descbinds-action-find): New defun.
(counsel-descbinds-action-info): New defun.
(counsel-descbinds): New command. Very similar to `counsel-M-x', except
that only bound commands are displayed.
Fixes #332
---
counsel.el | 109 ++++++++++++++++++++++++++++++++++++++++++++++++------------
ivy.el | 4 ++-
2 files changed, 90 insertions(+), 23 deletions(-)
diff --git a/counsel.el b/counsel.el
index 6a97b70..e9baba0 100644
--- a/counsel.el
+++ b/counsel.el
@@ -148,28 +148,29 @@
(defun counsel--find-symbol (x)
"Find symbol definition that corresponds to string X."
- (with-no-warnings
- (ring-insert find-tag-marker-ring (point-marker)))
- (let ((full-name (get-text-property 0 'full-name x)))
- (if full-name
- (find-library full-name)
- (let ((sym (read x)))
- (cond ((and (eq (ivy-state-caller ivy-last)
- 'counsel-describe-variable)
- (boundp sym))
- (find-variable sym))
- ((fboundp sym)
- (find-function sym))
- ((boundp sym)
- (find-variable sym))
- ((or (featurep sym)
- (locate-library
- (prin1-to-string sym)))
- (find-library
- (prin1-to-string sym)))
- (t
- (error "Couldn't fild definition of %s"
- sym)))))))
+ (with-ivy-window
+ (with-no-warnings
+ (ring-insert find-tag-marker-ring (point-marker)))
+ (let ((full-name (get-text-property 0 'full-name x)))
+ (if full-name
+ (find-library full-name)
+ (let ((sym (read x)))
+ (cond ((and (eq (ivy-state-caller ivy-last)
+ 'counsel-describe-variable)
+ (boundp sym))
+ (find-variable sym))
+ ((fboundp sym)
+ (find-function sym))
+ ((boundp sym)
+ (find-variable sym))
+ ((or (featurep sym)
+ (locate-library
+ (prin1-to-string sym)))
+ (find-library
+ (prin1-to-string sym)))
+ (t
+ (error "Couldn't fild definition of %s"
+ sym))))))))
(defvar counsel-describe-symbol-history nil
"History for `counsel-describe-variable' and `counsel-describe-function'.")
@@ -1340,6 +1341,70 @@ PREFIX is used to create the key."
(with-ivy-window
(goto-char pos))))))
+(defun counsel--descbinds-cands ()
+ (let ((buffer (current-buffer))
+ (re-exclude (regexp-opt
+ '("<vertical-line>" "<bottom-divider>" "<right-divider>"
+ "<mode-line>" "<C-down-mouse-2>" "<left-fringe>"
+ "<right-fringe>" "<header-line>"
+ "<vertical-scroll-bar>" "<horizontal-scroll-bar>")))
+ res)
+ (with-temp-buffer
+ (let ((indent-tabs-mode t))
+ (describe-buffer-bindings buffer))
+ (goto-char (point-min))
+ ;; Skip the "Key translations" section
+ (re-search-forward "")
+ (forward-char 1)
+ (while (not (eobp))
+ (when (looking-at "^\\([^\t\n]+\\)\t+\\(.*\\)$")
+ (let ((key (match-string 1))
+ (fun (match-string 2))
+ cmd)
+ (unless (or (member fun '("??" "self-insert-command"))
+ (string-match re-exclude key)
+ (not (or (commandp (setq cmd (intern-soft fun)))
+ (member fun '("Prefix Command")))))
+ (push
+ (cons (format
+ "%-15s %s"
+ (propertize key 'face 'font-lock-builtin-face)
+ fun)
+ (cons key cmd))
+ res))))
+ (forward-line 1)))
+ (nreverse res)))
+
+(defvar counsel-descbinds-history nil
+ "History for `counsel-descbinds'.")
+
+(defun counsel-descbinds-action-describe (x)
+ (let ((cmd (cdr x)))
+ (describe-function cmd)))
+
+(defun counsel-descbinds-action-find (x)
+ (let ((cmd (cdr x)))
+ (counsel--find-symbol (symbol-name cmd))))
+
+(defun counsel-descbinds-action-info (x)
+ (let ((cmd (cdr x)))
+ (counsel-info-lookup-symbol (symbol-name cmd))))
+
+;;;###autoload
+(defun counsel-descbinds ()
+ "Show a list of all defined keys, and their definitions.
+Describe the selected candidate."
+ (interactive)
+ (ivy-read "Bindings: " (counsel--descbinds-cands)
+ :action #'counsel-descbinds-action-describe
+ :caller 'counsel-descbinds
+ :history 'counsel-descbinds-history))
+
+(ivy-set-actions
+ 'counsel-descbinds
+ '(("d" counsel-descbinds-action-find "definition")
+ ("i" counsel-descbinds-action-info "info")))
+
(provide 'counsel)
;;; counsel.el ends here
diff --git a/ivy.el b/ivy.el
index 6ff1e87..33c9017 100644
--- a/ivy.el
+++ b/ivy.el
@@ -372,7 +372,9 @@ When non-nil, it should contain at least one %d.")
(interactive)
(let ((actions (ivy-state-action ivy-last)))
(unless (null (ivy--actionp actions))
- (let* ((hint (concat ivy--current
+ (let* ((hint (concat (if (eq this-command 'ivy-read-action)
+ "Select action: "
+ ivy--current)
"\n"
(mapconcat
(lambda (x)
- [elpa] master d1216eb 036/272: Add the '!' behavior into `ivy--regex-ignore-order', (continued)
- [elpa] master d1216eb 036/272: Add the '!' behavior into `ivy--regex-ignore-order', Oleh Krehel, 2016/04/25
- [elpa] master 66e00ed 034/272: counsel: Add counsel-up-directory to find-file-map, Oleh Krehel, 2016/04/25
- [elpa] master e23c175 039/272: Insert intermediate candidates during async completions, Oleh Krehel, 2016/04/25
- [elpa] master bc4d4a8 043/272: swiper.el (swiper-font-lock-exclude): Add sauron-mode, Oleh Krehel, 2016/04/25
- [elpa] master 93d1adc 026/272: Properly support matching ignoring order, Oleh Krehel, 2016/04/25
- [elpa] master 9a6b5fd 042/272: Add rcirc-mode to swiper-font-lock-ensure-exclude, Oleh Krehel, 2016/04/25
- [elpa] master ec7da3f 075/272: ivy.el (ivy-help-file): Improve location, Oleh Krehel, 2016/04/25
- [elpa] master c76c005 045/272: Add feedback for sole ivy completion., Oleh Krehel, 2016/04/25
- [elpa] master 59c5f16 044/272: Special case empty ivy-count-format completion., Oleh Krehel, 2016/04/25
- [elpa] master 569c11e 017/272: ivy.el (ivy-completion-in-region): Use compact ivy-count-format, Oleh Krehel, 2016/04/25
- [elpa] master d996215 038/272: Add counsel-descbinds,
Oleh Krehel <=
- [elpa] master 9ef344d 062/272: use imenu API to jump to position. required by org-mode, Oleh Krehel, 2016/04/25
- [elpa] master 0a9780b 046/272: ivy.el (ivy--recompute-index): Update cl-position logic, Oleh Krehel, 2016/04/25
- [elpa] master 407ce2c 051/272: counsel.el (counsel-list-processes): New command, Oleh Krehel, 2016/04/25
- [elpa] master e3e1f51 052/272: ivy.el (ivy-ffap-url-functions): Customize "C-x C-f M-n", Oleh Krehel, 2016/04/25
- [elpa] master b39f409 056/272: counsel.el (counsel-unicode-char): Display hex codes in left column, Oleh Krehel, 2016/04/25
- [elpa] master eab714f 054/272: counsel.el (counsel-at-git-issue-p): New defun, Oleh Krehel, 2016/04/25
- [elpa] master 4696b89 057/272: ivy.el (ivy-switch-buffer-other-window): New command, Oleh Krehel, 2016/04/25
- [elpa] master 763d42b 048/272: Initialize `ivy-last` to empty state., Oleh Krehel, 2016/04/25
- [elpa] master c0c0f63 060/272: ivy.el (ivy-read): Fix extra actions for completing-read, Oleh Krehel, 2016/04/25
- [elpa] master 5f4bc14 058/272: counsel.el (counsel-rhythmbox-current-song): Preselect the current song, Oleh Krehel, 2016/04/25