1 ;;; company-etags.el --- company-mode completion back-end for etags
3 ;; Copyright (C) 2009-2011, 2014 Free Software Foundation, Inc.
5 ;; Author: Nikolaj Schumacher
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
28 (eval-when-compile (require 'cl))
32 (defgroup company-etags nil
33 "Completion back-end for etags."
36 (defcustom company-etags-use-main-table-list t
37 "Always search `tags-table-list' if set.
38 If this is disabled, `company-etags' will try to find the one table for each
39 buffer automatically."
40 :type '(choice (const :tag "off" nil)
43 (defvar company-etags-modes '(c-mode objc-mode c++-mode java-mode jde-mode
44 pascal-mode perl-mode python-mode))
46 (defvar company-etags-buffer-table 'unknown)
47 (make-variable-buffer-local 'company-etags-buffer-table)
49 (defun company-etags-find-table ()
50 (let ((file (company-locate-dominating-file (or buffer-file-name
54 (list (expand-file-name file)))))
56 (defun company-etags-buffer-table ()
57 (or (and company-etags-use-main-table-list tags-table-list)
58 (if (eq company-etags-buffer-table 'unknown)
59 (setq company-etags-buffer-table (company-etags-find-table))
60 company-etags-buffer-table)))
62 (defun company-etags--candidates (prefix)
63 (let ((tags-table-list (company-etags-buffer-table))
64 (completion-ignore-case nil))
65 (and (or tags-file-name tags-table-list)
66 (fboundp 'tags-completion-table)
68 (visit-tags-table-buffer)
69 (all-completions prefix (tags-completion-table))))))
72 (defun company-etags (command &optional arg &rest ignored)
73 "`company-mode' completion back-end for etags."
74 (interactive (list 'interactive))
76 (interactive (company-begin-backend 'company-etags))
77 (prefix (and (memq major-mode company-etags-modes)
78 (not (company-in-string-or-comment))
79 (company-etags-buffer-table)
80 (or (company-grab-symbol) 'stop)))
81 (candidates (company-etags--candidates arg))
82 (location (let ((tags-table-list (company-etags-buffer-table)))
83 (when (fboundp 'find-tag-noselect)
85 (let ((buffer (find-tag-noselect arg)))
86 (cons buffer (with-current-buffer buffer (point))))))))))
88 (provide 'company-etags)
89 ;;; company-etags.el ends here