]> code.delx.au - gnu-emacs-elpa/blobdiff - company-etags.el
company-etags: not always sorted
[gnu-emacs-elpa] / company-etags.el
index 51628effaac217505a5707342c2553f371776106..88b9fca8df346c5cf413a70596d47b9372667ca0 100644 (file)
@@ -1,28 +1,35 @@
-;;; company-etags.el --- a company-mode completion back-end for etags
-;;
-;; Copyright (C) 2009 Nikolaj Schumacher
-;;
-;; This file is part of company 0.4.3.
-;;
-;; This program is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License
-;; as published by the Free Software Foundation; either version 2
-;; of the License, or (at your option) any later version.
-;;
-;; This program is distributed in the hope that it will be useful,
+;;; company-etags.el --- A company-mode completion back-end for etags
+
+;; Copyright (C) 2009-2011  Free Software Foundation, Inc.
+
+;; Author: Nikolaj Schumacher
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
-;;
+
 ;; You should have received a copy of the GNU General Public License
-;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+
+;;; Commentary:
+;;
+
+;;; Code:
 
 (require 'company)
-(eval-when-compile (require 'etags))
-(eval-when-compile (require 'cl))
+(require 'etags)
 
 (defcustom company-etags-use-main-table-list t
-  "*Always search `tags-table-list' if set.
+  "Always search `tags-table-list' if set.
 If this is disabled, `company-etags' will try to find the one table for each
 buffer automatically."
   :group 'company-mode
@@ -48,28 +55,31 @@ buffer automatically."
           (setq company-etags-buffer-table (company-etags-find-table))
         company-etags-buffer-table)))
 
+(defun company-etags--candidates (prefix)
+  (let ((tags-table-list (company-etags-buffer-table))
+        (completion-ignore-case nil))
+    (and (or tags-file-name tags-table-list)
+         (fboundp 'tags-completion-table)
+         (save-excursion
+           (visit-tags-table-buffer)
+           (all-completions prefix (tags-completion-table))))))
+
 ;;;###autoload
 (defun company-etags (command &optional arg &rest ignored)
   "A `company-mode' completion back-end for etags."
   (interactive (list 'interactive))
   (case command
-    ('interactive (company-begin-backend 'company-etags))
-    ('prefix (and (memq major-mode company-etags-modes)
-                  (not (company-in-string-or-comment))
-                  (require 'etags nil t)
-                  (company-etags-buffer-table)
-                  (or (company-grab-symbol) 'stop)))
-    ('candidates (let ((tags-table-list (company-etags-buffer-table))
-                       (completion-ignore-case nil))
-                   (and (or tags-file-name tags-table-list)
-                        (fboundp 'tags-completion-table)
-                        tags-table-list
-                        (all-completions arg (tags-completion-table)))))
-    ('location (let ((tags-table-list (company-etags-buffer-table)))
-                 (when (fboundp 'find-tag-noselect)
-                   (let ((buffer (find-tag-noselect arg)))
-                     (cons buffer (with-current-buffer buffer (point)))))))
-    ('sorted t)))
+    (interactive (company-begin-backend 'company-etags))
+    (prefix (and (memq major-mode company-etags-modes)
+                 (not (company-in-string-or-comment))
+                 (company-etags-buffer-table)
+                 (or (company-grab-symbol) 'stop)))
+    (candidates (company-etags--candidates arg))
+    (location (let ((tags-table-list (company-etags-buffer-table)))
+                (when (fboundp 'find-tag-noselect)
+                  (save-excursion
+                    (let ((buffer (find-tag-noselect arg)))
+                      (cons buffer (with-current-buffer buffer (point))))))))))
 
 (provide 'company-etags)
 ;;; company-etags.el ends here