1 ;;; company-gtags.el --- a company-mode completion back-end for GNU Global
3 ;; Copyright (C) 2009 Nikolaj Schumacher
5 ;; This file is part of company.
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.
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.
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/>.
21 (eval-when-compile (require 'cl))
23 (defcustom company-gtags-gnu-global-program-name
24 (or (locate-file "global" exec-path exec-suffixes 'file-executable-p)
30 (defvar company-gtags-symbol-regexp
31 "\\_<[A-Za-z_][A-Za-z_0-9]*\\_>")
33 (defvar company-gtags-modes '(c-mode c++-mode jde-mode java-mode php-mode))
35 (defvar company-gtags-available 'unknown)
36 (make-variable-buffer-local 'company-gtags-available)
38 (defun company-gtags-available ()
39 (when (eq company-gtags-available 'unknown)
41 (setq company-gtags-available
42 (= 0 (call-process company-gtags-gnu-global-program-name
43 nil nil nil "-c" "WHATEVER")))
45 (message "Company: GNU Global not found")
46 (setq-default company-gtags-available nil))))
47 company-gtags-available)
49 (defun company-gtags-fetch-tags (prefix)
52 (when (= 0 (call-process "global" nil (list (current-buffer) nil)
54 (goto-char (point-min))
55 (while (looking-at company-gtags-symbol-regexp)
56 (push (match-string-no-properties 0) tags)
60 (defun company-gtags (command &optional arg &rest ignored)
62 ('prefix (and (memq major-mode company-gtags-modes)
63 (company-gtags-available)
64 (or (company-grab company-gtags-symbol-regexp) "")))
65 ('candidates (company-gtags-fetch-tags arg))
68 (provide 'company-gtags)
69 ;;; company-gtags.el ends here