]> rtime.felk.cvut.cz Git - sojka/company-mode.git/blobdiff - company-etags.el
Bumped version to 0.4.2.
[sojka/company-mode.git] / company-etags.el
index f7d71dcdf1e5ffc6e97b083cb408d4338e2f639f..c6e534790ae669d0581701d742f01f94da11c5f4 100644 (file)
@@ -2,7 +2,7 @@
 ;;
 ;; Copyright (C) 2009 Nikolaj Schumacher
 ;;
-;; This file is part of company 0.2.
+;; This file is part of company 0.4.2.
 ;;
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License
@@ -29,9 +29,6 @@ buffer automatically."
   :type '(choice (const :tag "off" nil)
                  (const :tag "on" t)))
 
-(defvar company-etags-symbol-regexp
-  "\\_<[A-Za-z_][A-Za-z_0-9]*\\_>")
-
 (defvar company-etags-modes '(c-mode objc-mode c++-mode java-mode jde-mode
                               pascal-mode perl-mode python-mode))
 
@@ -39,14 +36,11 @@ buffer automatically."
 (make-variable-buffer-local 'company-etags-buffer-table)
 
 (defun company-etags-find-table ()
-  (let ((dir (file-name-directory buffer-file-name))
-        file)
-    (while (not (or file (equal dir "/")))
-      (unless (file-exists-p (setq file (expand-file-name "TAGS" dir)))
-        (setq file nil
-              dir (file-name-directory (directory-file-name dir)))))
+  (let ((file (company-locate-dominating-file (or buffer-file-name
+                                                  default-directory)
+                                              "TAGS")))
     (when file
-      (list file))))
+      (list (expand-file-name file)))))
 
 (defun company-etags-buffer-table ()
   (or (and company-etags-use-main-table-list tags-table-list)
@@ -54,17 +48,22 @@ buffer automatically."
           (setq company-etags-buffer-table (company-etags-find-table))
         company-etags-buffer-table)))
 
+;;;###autoload
 (defun company-etags (command &optional arg &rest ignored)
   "A `company-mode' completion back-end for etags."
+  (interactive (list 'interactive))
   (case command
+    ('interactive (company-begin-backend 'company-etags))
     ('prefix (and (memq major-mode company-etags-modes)
                   (not (company-in-string-or-comment))
                   (require 'etags nil t)
                   (company-etags-buffer-table)
-                  (or (company-grab company-etags-symbol-regexp) "")))
+                  (or (company-grab-symbol) 'stop)))
     ('candidates (let ((tags-table-list (company-etags-buffer-table))
                        (completion-ignore-case nil))
-                   (and (fboundp 'tags-completion-table)
+                   (and (or tags-file-name tags-table-list)
+                        (fboundp 'tags-completion-table)
+                        tags-table-list
                         (all-completions arg (tags-completion-table)))))
     ('location (let ((tags-table-list (company-etags-buffer-table)))
                  (when (fboundp 'find-tag-noselect)
@@ -72,9 +71,5 @@ buffer automatically."
                      (cons buffer (with-current-buffer buffer (point)))))))
     ('sorted t)))
 
-(add-to-list 'company-backends 'company-etags)
-
 (provide 'company-etags)
 ;;; company-etags.el ends here
-
-