]> rtime.felk.cvut.cz Git - sojka/company-mode.git/blobdiff - company-elisp.el
Bumped version to 0.5.
[sojka/company-mode.git] / company-elisp.el
index 112fd1113b2acb78ff44e29f08cd5de5b59b7773..a10fe464ce13a8d10cb52e816807ce712d345251 100644 (file)
@@ -2,7 +2,7 @@
 ;;
 ;; Copyright (C) 2009 Nikolaj Schumacher
 ;;
-;; This file is part of company 0.2.1.
+;; This file is part of company 0.5.
 ;;
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License
@@ -19,6 +19,7 @@
 
 (require 'company)
 (eval-when-compile (require 'cl))
+(require 'help-mode)
 
 (defcustom company-elisp-detect-function-context t
   "*If enabled, offer lisp functions only in appropriate contexts.
@@ -27,14 +28,13 @@ Functions are offered for completion only after ' and \(."
   :type '(choice (const :tag "Off" nil)
                  (const :tag "On" t)))
 
-(defvar company-lisp-symbol-regexp
-  "\\_<\\(\\sw\\|\\s_\\)+\\_>\\=")
-
 (defun company-grab-lisp-symbol ()
-  (let ((prefix (or (company-grab company-lisp-symbol-regexp) "")))
-    (unless (and (company-in-string-or-comment (- (point) (length prefix)))
-                 (/= (char-before (- (point) (length prefix))) ?`))
-      prefix)))
+  (let ((prefix (company-grab-symbol)))
+    (if prefix
+        (unless (and (company-in-string-or-comment)
+                     (/= (char-before (- (point) (length prefix))) ?`))
+          prefix)
+      'stop)))
 
 (defun company-elisp-predicate (symbol)
   (or (boundp symbol)
@@ -45,7 +45,7 @@ Functions are offered for completion only after ' and \(."
 
 (defvar company-elisp-binding-regexp
   (concat "([ \t\n]*\\_<" (regexp-opt '("let" "defun" "defmacro" "defsubst"
-                                        "lambda" "lexical-let"))
+                                        "lambda" "lexical-let" "flet" "labels"))
           "\\*?")
   "Regular expression matching sexps containing variable bindings.")
 
@@ -104,9 +104,12 @@ Functions are offered for completion only after ' and \(."
          (string-match ".*$" doc)
          (match-string 0 doc))))
 
+;;;###autoload
 (defun company-elisp (command &optional arg &rest ignored)
   "A `company-mode' completion back-end for `emacs-lisp-mode'."
+  (interactive (list 'interactive))
   (case command
+    ('interactive (company-begin-backend 'company-elisp))
     ('prefix (and (eq (derived-mode-p 'emacs-lisp-mode) 'emacs-lisp-mode)
                   (company-grab-lisp-symbol)))
     ('candidates (company-elisp-candidates arg))