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

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

[elpa] master 5036f23 87/90: Make counsel-el work with "C-M-n" and "C-M-


From: Oleh Krehel
Subject: [elpa] master 5036f23 87/90: Make counsel-el work with "C-M-n" and "C-M-p"
Date: Tue, 30 Jun 2015 07:29:38 +0000

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

    Make counsel-el work with "C-M-n" and "C-M-p"
    
    * counsel.el (counsel-el): Use the whole obarray if no initial input is
      given. Filter out only function when appropriate.
    (counsel-completion-beg): New defvar.
    (counsel-completion-end): New defvar.
    (counsel--el-action): New defun.
    
    * ivy.el (ivy--reset-state): Set `ivy--full-length' to nil.
---
 counsel.el |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 ivy.el     |    1 +
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/counsel.el b/counsel.el
index c2d67d6..acc4ca5 100644
--- a/counsel.el
+++ b/counsel.el
@@ -38,8 +38,61 @@
 (defun counsel-el ()
   "Elisp completion at point."
   (interactive)
-  (counsel--generic
-   (lambda (str) (all-completions str obarray))))
+  (let* ((bnd (unless (and (looking-at ")")
+                           (eq (char-before) ?\())
+                (bounds-of-thing-at-point
+                 'symbol)))
+         (str (if bnd
+                  (buffer-substring-no-properties
+                   (car bnd)
+                   (cdr bnd))
+                ""))
+         (ivy-height 7)
+         (funp (eq (char-before (car bnd)) ?\())
+         symbol-names)
+    (if bnd
+        (progn
+          (setq counsel-completion-beg
+                (move-marker (make-marker) (car bnd)))
+          (setq counsel-completion-end
+                (move-marker (make-marker) (cdr bnd))))
+      (setq counsel-completion-beg nil)
+      (setq counsel-completion-end nil))
+    (if (string= str "")
+        (mapatoms
+         (lambda (x)
+           (when (symbolp x)
+             (push (symbol-name x) symbol-names))))
+      (setq symbol-names
+            (all-completions str obarray
+                             (and funp
+                                  (lambda (x)
+                                    (or (functionp x)
+                                        (macrop x)
+                                        (special-form-p x)))))))
+    (ivy-read "Symbol name: " symbol-names
+              :predicate (and funp #'functionp)
+              :initial-input str
+              :action #'counsel--el-action)))
+
+(defvar counsel-completion-beg nil
+  "Completion bounds start.")
+
+(defvar counsel-completion-end nil
+  "Completion bounds end.")
+
+(defun counsel--el-action (symbol)
+  "Insert SYMBOL, erasing the previous one."
+  (when (stringp symbol)
+    (when counsel-completion-beg
+      (delete-region
+       counsel-completion-beg
+       counsel-completion-end))
+    (setq counsel-completion-beg
+          (move-marker (make-marker) (point)))
+    (insert symbol)
+    (setq counsel-completion-end
+          (move-marker (make-marker) (point)))))
 
 (defvar counsel-describe-map
   (let ((map (make-sparse-keymap)))
diff --git a/ivy.el b/ivy.el
index 12b1ad2..f64782c 100644
--- a/ivy.el
+++ b/ivy.el
@@ -815,6 +815,7 @@ This is useful for recursive `ivy-read'."
     (setq ivy--subexps 0)
     (setq ivy--regexp-quote 'regexp-quote)
     (setq ivy--old-text "")
+    (setq ivy--full-length nil)
     (setq ivy-text "")
     (setq ivy-calling nil)
     (let (coll sort-fn)



reply via email to

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