]> code.delx.au - gnu-emacs-elpa/commitdiff
Added etags back-end.
authorNikolaj Schumacher <git@nschum.de>
Sun, 22 Mar 2009 11:25:04 +0000 (12:25 +0100)
committerNikolaj Schumacher <git@nschum.de>
Sun, 22 Mar 2009 15:58:59 +0000 (16:58 +0100)
company-etags.el [new file with mode: 0644]
company.el

diff --git a/company-etags.el b/company-etags.el
new file mode 100644 (file)
index 0000000..59aee11
--- /dev/null
@@ -0,0 +1,75 @@
+;;; company-etags.el --- a company-mode completion back-end for etags
+;;
+;; Copyright (C) 2009 Nikolaj Schumacher
+;;
+;; This file is part of company.
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License
+;; as published by the Free Software Foundation; either version 2
+;; of the License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+(require 'company)
+(eval-when-compile (require 'etags))
+(eval-when-compile (require 'cl))
+
+(defcustom company-etags-use-main-table-list t
+  "*Always search `tags-table-list' if set.
+If this is disabled, `company-etags' will try to find the one table for each
+buffer automatically."
+  :group 'company-mode
+  :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))
+
+(defvar company-etags-buffer-table 'unknown)
+(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)))))
+    (list file)))
+
+(defun company-etags-buffer-table ()
+  (or (and company-etags-use-main-table-list tags-table-list)
+      (if (eq company-etags-buffer-table 'unknown)
+          (setq company-etags-buffer-table (company-etags-find-table))
+        company-etags-buffer-table)))
+
+(defun company-etags (command &optional arg &rest ignored)
+  "A `company-mode' completion back-end for etags."
+  (case command
+    ('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) "")))
+    ('candidates (let ((tags-table-list (company-etags-buffer-table))
+                       (completion-ignore-case nil))
+                   (and (fboundp 'tags-completion-table)
+                        (all-completions arg (tags-completion-table)))))
+    ('sorted t)))
+
+(add-to-list 'company-backends 'company-etags)
+
+(provide 'company-etags)
+;;; company-etags.el ends here
+
+
index 8a0b89a400c1e73de43c3693b950b4435ad73344..66cbe3fcdff7af86d82c2fe7bd7e8e2c65403180 100644 (file)
@@ -56,6 +56,7 @@
 ;;
 ;;; Change Log:
 ;;
+;;    Added etags back-end.
 ;;    Added work-around for end-of-buffer bug.
 ;;    Added `company-filter-candidates'.
 ;;    More local Lisp variables are now included in the candidates.
@@ -204,8 +205,8 @@ The visualized data is stored in `company-prefix', `company-candidates',
                          (function :tag "custom function" nil))))
 
 (defcustom company-backends '(company-elisp company-nxml company-css
-                              company-semantic company-gtags company-oddmuse
-                              company-files company-dabbrev)
+                              company-semantic company-gtags company-etags
+                              company-oddmuse company-files company-dabbrev)
   "*The list of active back-ends (completion engines).
 Each back-end is a function that takes a variable number of arguments.
 The first argument is the command requested from the back-end.  It is one