]> code.delx.au - gnu-emacs-elpa/blobdiff - company-elisp.el
* company-elisp: complete features and faces,
[gnu-emacs-elpa] / company-elisp.el
index bd03ea665f1b0da981191d873f42361fecb1ac80..1073f28cca7916fa99335ed5e48b4d23244e95e5 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
@@ -28,25 +28,26 @@ 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)
-      (fboundp symbol)))
+      (fboundp symbol)
+      (facep symbol)
+      (featurep symbol)))
 
 (defvar company-elisp-parse-limit 30)
 (defvar company-elisp-parse-depth 100)
 
 (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.")
 
@@ -110,20 +111,29 @@ Functions are offered for completion only after ' and \(."
   "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))
-    ('meta (company-elisp-doc arg))
-    ('doc-buffer (let ((symbol (intern arg)))
-                   (save-window-excursion
-                     (when (or (ignore-errors (describe-function symbol))
-                               (ignore-errors (describe-variable symbol)))
-                       (help-buffer)))))
-    ('location (let ((sym (intern arg)))
-                 (or (ignore-errors (find-definition-noselect sym nil))
-                     (ignore-errors (find-definition-noselect sym 'defvar))
-                     (ignore-errors (find-definition-noselect sym t)))))))
+    (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))
+    (meta (company-elisp-doc arg))
+    (doc-buffer (let ((symbol (intern arg)))
+                  (save-window-excursion
+                    (ignore-errors
+                      (cond
+                       ((fboundp symbol) (describe-function symbol))
+                       ((boundp symbol) (describe-variable symbol))
+                       ((featurep symbol) (describe-package symbol))
+                       ((facep symbol) (describe-face symbol))
+                       (t (signal 'user-error nil)))
+                      (help-buffer)))))
+    (location (let ((sym (intern arg)))
+                (cond
+                 ((fboundp sym) (find-definition-noselect sym nil))
+                 ((boundp sym) (find-definition-noselect sym 'defvar))
+                 ((featurep sym) (cons (find-file-noselect (find-library-name
+                                                            (symbol-name sym)))
+                                       0))
+                 ((facep sym) (find-definition-noselect sym 'defface)))))))
 
 (provide 'company-elisp)
 ;;; company-elisp.el ends here