]> code.delx.au - gnu-emacs-elpa/commitdiff
company-elisp-show-locals-first: New defcustom
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 29 Mar 2013 08:36:13 +0000 (12:36 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 29 Mar 2013 08:36:13 +0000 (12:36 +0400)
NEWS.md
company-elisp.el
company-tests.el

diff --git a/NEWS.md b/NEWS.md
index 2aced04d48f308539bc013ca37fa6a20f9b91489..374f69dd2c215c1dc1b7aa732c282476d6393620 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,10 @@
 # History of user-visible changes
 
+## Next
+
+* `company-elisp-show-locals-first`: new customizable variable.
+* `company-eclim` shows more accurate and comprehensive candidates.
+
 ## 2013-03-26 (0.6.4)
 
 * `company-eclim` shows valid completions after an opening paren.
index 52126bd43331d669143649bd419ac63ce00649d9..c862edb8c57d300dc29958bba7314d0478fb7bcd 100644 (file)
@@ -37,6 +37,10 @@ Functions are offered for completion only after ' and \(."
   :type '(choice (const :tag "Off" nil)
                  (const :tag "On" t)))
 
+(defcustom company-elisp-show-locals-first t
+  "If enabled, locally bound variables and functions are displayed
+first in the candidates list.")
+
 (defun company-grab-lisp-symbol ()
   (let ((prefix (company-grab-symbol)))
     (if prefix
@@ -107,9 +111,13 @@ Functions are offered for completion only after ' and \(."
     res))
 
 (defun company-elisp-candidates (prefix)
-  (let ((predicate (company-elisp-candidates-predicate prefix)))
-    (append (company-elisp-locals prefix (eq predicate 'fboundp))
-            (company-elisp-globals prefix predicate))))
+  (let* ((predicate (company-elisp-candidates-predicate prefix))
+         (locals (company-elisp-locals prefix (eq predicate 'fboundp)))
+         (globals (company-elisp-globals prefix predicate)))
+    (if company-elisp-show-locals-first
+        (append (sort locals 'string<)
+                (sort globals 'string<))
+      (append locals globals))))
 
 (defun company-elisp-globals (prefix predicate)
   (all-completions prefix obarray predicate))
@@ -148,6 +156,7 @@ Functions are offered for completion only after ' and \(."
     (prefix (and (eq (derived-mode-p 'emacs-lisp-mode) 'emacs-lisp-mode)
                  (company-grab-lisp-symbol)))
     (candidates (company-elisp-candidates arg))
+    (sorted company-elisp-show-locals-first)
     (meta (company-elisp-doc arg))
     (doc-buffer (let ((symbol (intern arg)))
                   (save-window-excursion
index c9e52cbdc2163697c56b87838944c71c166104ef..0ca2e11f5a48b772bc9ca914c9383913c16c1946 100644 (file)
     "(let ((foo 1)
            (f| )))"
     (should (null (company-elisp-locals "f" nil)))))
+
+(ert-deftest company-elisp-show-locals-first ()
+  (company-elisp-with-buffer
+    "(let ((floo 1)
+           (flop 2)
+           (flee 3))
+       fl|)"
+    (let ((obarray [float-pi]))
+      (let (company-elisp-show-locals-first)
+        (should (eq nil (company-elisp 'sorted))))
+      (let ((company-elisp-show-locals-first t))
+        (should (eq t (company-elisp 'sorted)))
+        (should (equal '("flee" "floo" "flop" "float-pi")
+                       (company-elisp-candidates "fl")))))))