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