]> code.delx.au - gnu-emacs-elpa/blob - company-etags.el
Bumped version to 0.5.
[gnu-emacs-elpa] / company-etags.el
1 ;;; company-etags.el --- a company-mode completion back-end for etags
2 ;;
3 ;; Copyright (C) 2009-2010 Nikolaj Schumacher
4 ;;
5 ;; This file is part of company 0.5.
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-modes '(c-mode objc-mode c++-mode java-mode jde-mode
33 pascal-mode perl-mode python-mode))
34
35 (defvar company-etags-buffer-table 'unknown)
36 (make-variable-buffer-local 'company-etags-buffer-table)
37
38 (defun company-etags-find-table ()
39 (let ((file (company-locate-dominating-file (or buffer-file-name
40 default-directory)
41 "TAGS")))
42 (when file
43 (list (expand-file-name file)))))
44
45 (defun company-etags-buffer-table ()
46 (or (and company-etags-use-main-table-list tags-table-list)
47 (if (eq company-etags-buffer-table 'unknown)
48 (setq company-etags-buffer-table (company-etags-find-table))
49 company-etags-buffer-table)))
50
51 ;;;###autoload
52 (defun company-etags (command &optional arg &rest ignored)
53 "A `company-mode' completion back-end for etags."
54 (interactive (list 'interactive))
55 (case command
56 ('interactive (company-begin-backend 'company-etags))
57 ('prefix (and (memq major-mode company-etags-modes)
58 (not (company-in-string-or-comment))
59 (require 'etags nil t)
60 (company-etags-buffer-table)
61 (or (company-grab-symbol) 'stop)))
62 ('candidates (let ((tags-table-list (company-etags-buffer-table))
63 (completion-ignore-case nil))
64 (and (or tags-file-name tags-table-list)
65 (fboundp 'tags-completion-table)
66 tags-table-list
67 (all-completions arg (tags-completion-table)))))
68 ('location (let ((tags-table-list (company-etags-buffer-table)))
69 (when (fboundp 'find-tag-noselect)
70 (save-excursion
71 (let ((buffer (find-tag-noselect arg)))
72 (cons buffer (with-current-buffer buffer (point))))))))
73 ('sorted t)))
74
75 (provide 'company-etags)
76 ;;; company-etags.el ends here