]> code.delx.au - gnu-emacs-elpa/blobdiff - company-elisp.el
Release 0.6.5
[gnu-emacs-elpa] / company-elisp.el
index 52126bd43331d669143649bd419ac63ce00649d9..e4baca1706ef7791b2e2497d30ec84d9596ff30a 100644 (file)
@@ -1,6 +1,6 @@
-;;; company-elisp.el --- A company-mode completion back-end for emacs-lisp-mode
+;;; company-elisp.el --- A company-mode completion back-end for emacs-lisp-mode -*- lexical-binding: t -*-
 
-;; Copyright (C) 2009, 2011-2012  Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2011-2013  Free Software Foundation, Inc.
 
 ;; Author: Nikolaj Schumacher
 
@@ -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,16 @@ 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))
+         (locals (loop for local in locals
+                       when (not (member local globals))
+                       collect local)))
+    (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))
@@ -124,8 +135,12 @@ Functions are offered for completion only after ' and \(."
                   (save-excursion
                     (ignore-errors
                       (up-list -2)
-                      (forward-char 1)
-                      (looking-at " *(")))))
+                      (and (save-excursion
+                             (forward-char 1)
+                             (looking-at "[ \t\n]*("))
+                           (prog1 (search-backward "(")
+                             (forward-char 1))
+                           (looking-at company-elisp-var-binding-regexp))))))
             'fboundp
           'boundp)
       'company-elisp-predicate)))
@@ -148,6 +163,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