emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master cafcfb9 10/18: Allow "C-." to jump to current symbol defin


From: Oleh Krehel
Subject: [elpa] master cafcfb9 10/18: Allow "C-." to jump to current symbol definition
Date: Mon, 20 Apr 2015 12:39:05 +0000

branch: master
commit cafcfb9b588e0dd0f0279ba027a0d33a02b1263f
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Allow "C-." to jump to current symbol definition
    
    * counsel.el (counsel-describe-map): New defvar.
    (counsel-find-symbol): New defun.
    (counsel--find-symbol): New defun - jump to definition of function or
    symbol or library.
    (counsel-describe-variable): Use `counsel-describe-map'.
    (counsel-describe-function): Use `counsel-describe-map'.
---
 counsel.el |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/counsel.el b/counsel.el
index 33364f7..ee9535a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -40,6 +40,32 @@
   (counsel--generic
    (lambda (str) (all-completions str obarray))))
 
+(defvar counsel-describe-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-.") 'counsel-find-symbol)
+    map))
+
+(defun counsel-find-symbol ()
+  "Jump to the definition of the current symbol."
+  (interactive)
+  (setq ivy--action 'counsel--find-symbol)
+  (setq ivy-exit 'done)
+  (exit-minibuffer))
+
+(defun counsel--find-symbol ()
+  (let ((sym (read ivy--current)))
+    (cond ((boundp sym)
+           (find-variable sym))
+          ((fboundp sym)
+           (find-function 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)))))
+
 (defun counsel-describe-variable (variable &optional buffer frame)
   "Forward to (`describe-variable' VARIABLE BUFFER FRAME)."
   (interactive
@@ -59,7 +85,7 @@
                                (and (boundp vv) (not (keywordp vv))))
                        (push (symbol-name vv) cands))))
                   cands)
-                nil nil nil preselect))
+                nil nil counsel-describe-map preselect))
      (list (if (equal val "")
                v
              (intern val)))))
@@ -81,7 +107,7 @@
                               (when (fboundp x)
                                 (push (symbol-name x) cands))))
                            cands)
-                         nil nil nil preselect))
+                         nil nil counsel-describe-map preselect))
      (list (if (equal val "")
                fn (intern val)))))
   (describe-function function))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]