]> code.delx.au - gnu-emacs-elpa/blob - company-etags.el
Added version number to back-ends.
[gnu-emacs-elpa] / company-etags.el
1 ;;; company-etags.el --- a company-mode completion back-end for etags
2 ;;
3 ;; Copyright (C) 2009 Nikolaj Schumacher
4 ;;
5 ;; This file is part of company 0.2.
6 ;;
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License
9 ;; as published by the Free Software Foundation; either version 2
10 ;; of the License, or (at your option) any later version.
11 ;;
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 (require 'company)
21 (eval-when-compile (require 'etags))
22 (eval-when-compile (require 'cl))
23
24 (defcustom company-etags-use-main-table-list t
25 "*Always search `tags-table-list' if set.
26 If this is disabled, `company-etags' will try to find the one table for each
27 buffer automatically."
28 :group 'company-mode
29 :type '(choice (const :tag "off" nil)
30 (const :tag "on" t)))
31
32 (defvar company-etags-symbol-regexp
33 "\\_<[A-Za-z_][A-Za-z_0-9]*\\_>")
34
35 (defvar company-etags-modes '(c-mode objc-mode c++-mode java-mode jde-mode
36 pascal-mode perl-mode python-mode))
37
38 (defvar company-etags-buffer-table 'unknown)
39 (make-variable-buffer-local 'company-etags-buffer-table)
40
41 (defun company-etags-find-table ()
42 (let ((dir (file-name-directory buffer-file-name))
43 file)
44 (while (not (or file (equal dir "/")))
45 (unless (file-exists-p (setq file (expand-file-name "TAGS" dir)))
46 (setq file nil
47 dir (file-name-directory (directory-file-name dir)))))
48 (list file)))
49
50 (defun company-etags-buffer-table ()
51 (or (and company-etags-use-main-table-list tags-table-list)
52 (if (eq company-etags-buffer-table 'unknown)
53 (setq company-etags-buffer-table (company-etags-find-table))
54 company-etags-buffer-table)))
55
56 (defun company-etags (command &optional arg &rest ignored)
57 "A `company-mode' completion back-end for etags."
58 (case command
59 ('prefix (and (memq major-mode company-etags-modes)
60 (not (company-in-string-or-comment))
61 (require 'etags nil t)
62 (company-etags-buffer-table)
63 (or (company-grab company-etags-symbol-regexp) "")))
64 ('candidates (let ((tags-table-list (company-etags-buffer-table))
65 (completion-ignore-case nil))
66 (and (fboundp 'tags-completion-table)
67 (all-completions arg (tags-completion-table)))))
68 ('location (let ((tags-table-list (company-etags-buffer-table)))
69 (when (fboundp 'find-tag-noselect)
70 (let ((buffer (find-tag-noselect arg)))
71 (cons buffer (with-current-buffer buffer (point)))))))
72 ('sorted t)))
73
74 (add-to-list 'company-backends 'company-etags)
75
76 (provide 'company-etags)
77 ;;; company-etags.el ends here
78
79