]> code.delx.au - gnu-emacs-elpa/blobdiff - company-gtags.el
Cover load errors in auto-loaded back-ends.
[gnu-emacs-elpa] / company-gtags.el
index e9aca67b68bc00af13775efca25f1e50cfb79b28..146cb129f3e5fe487be23bb43ef93d1bb00337b0 100644 (file)
@@ -2,7 +2,7 @@
 ;;
 ;; Copyright (C) 2009 Nikolaj Schumacher
 ;;
-;; This file is part of company 0.3.
+;; This file is part of company 0.3.1.
 ;;
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License
 (require 'company)
 (eval-when-compile (require 'cl))
 
-(defcustom company-gtags-gnu-global-program-name
-  (or (locate-file "global" exec-path exec-suffixes 'file-executable-p)
-      "global")
-  "*"
+(defcustom company-gtags-executable
+  (executable-find "global")
+  "*Location of GNU global executable"
   :type 'string
   :group 'company)
 
-(defvar company-gtags-symbol-regexp
-  "\\_<[A-Za-z_][A-Za-z_0-9]*\\_>")
+(define-obsolete-variable-alias
+  'company-gtags-gnu-global-program-name
+  'company-gtags-executable)
 
 (defvar company-gtags-modes '(c-mode c++-mode jde-mode java-mode php-mode))
 
-(defvar company-gtags-available 'unknown)
-(make-variable-buffer-local 'company-gtags-available)
-
-(defun company-gtags-available ()
-  (when (eq company-gtags-available 'unknown)
-    (condition-case err
-        (setq company-gtags-available
-              (= 0 (call-process company-gtags-gnu-global-program-name
-                                 nil nil nil "-c" "WHATEVER")))
-      (error
-       (message "Company: GNU Global not found")
-       (setq-default company-gtags-available nil))))
-  company-gtags-available)
-
 (defun company-gtags-fetch-tags (prefix)
   (with-temp-buffer
     (let (tags)
-      (when (= 0 (call-process "global" nil (list (current-buffer) nil)
-                               nil "-c" prefix))
+      (when (= 0 (call-process company-gtags-executable nil
+                               (list (current-buffer) nil) nil "-c" prefix))
         (goto-char (point-min))
-        (while (looking-at company-gtags-symbol-regexp)
-          (push (match-string-no-properties 0) tags)
-          (forward-line)))
-      (nreverse tags))))
+        (split-string (buffer-string) "\n" t)))))
 
 (defun company-gtags-location (tag)
   (with-temp-buffer
-    (when (= 0 (call-process "global" nil (list (current-buffer) nil)
-                               nil "-x" tag))
+    (when (= 0 (call-process company-gtags-executable nil
+                             (list (current-buffer) nil) nil "-x" tag))
         (goto-char (point-min))
         (when (looking-at (concat (regexp-quote tag)
                                   "[ \t]+\\([[:digit:]]+\\)"
   (interactive (list 'interactive))
   (case command
     ('interactive (company-begin-backend 'company-gtags))
-    ('prefix (and (memq major-mode company-gtags-modes)
+    ('prefix (and company-gtags-executable
+                  (memq major-mode company-gtags-modes)
                   (not (company-in-string-or-comment))
-                  (company-gtags-available)
-               (or (company-grab company-gtags-symbol-regexp) "")))
+                  (or (company-grab-symbol) 'stop)))
     ('candidates (company-gtags-fetch-tags arg))
     ('sorted t)
     ('location (company-gtags-location arg))))