From 044bf06af94ea9f45029161ee631ac559d0945f2 Mon Sep 17 00:00:00 2001 From: Nikolaj Schumacher Date: Thu, 19 Mar 2009 14:03:46 +0100 Subject: [PATCH] Speed up line replacement. --- company-gtags.el | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ company.el | 6 ++-- 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 company-gtags.el diff --git a/company-gtags.el b/company-gtags.el new file mode 100644 index 000000000..607ae3918 --- /dev/null +++ b/company-gtags.el @@ -0,0 +1,71 @@ +;;; company-gtags.el --- a company-mode completion back-end for GNU Global +;; +;; Copyright (C) 2009 Nikolaj Schumacher +;; +;; This file is part of company. +;; +;; 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, +;; 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 . + +(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") + "*" + :type 'string + :group 'company) + +(defvar company-gtags-symbol-regexp + "\\_<[A-Za-z_][A-Za-z_0-9]*\\_>") + +(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)) + (goto-char (point-min)) + (while (looking-at company-gtags-symbol-regexp) + (push (match-string-no-properties 0) tags) + (forward-line))) + (nreverse tags)))) + +(defun company-gtags (command &optional arg &rest ignored) + (case command + ('prefix (and (memq major-mode company-gtags-modes) + (company-gtags-available) + (or (company-grab company-gtags-symbol-regexp) ""))) + ('candidates (company-gtags-fetch-tags arg)) + ('sorted t))) + +(provide 'company-gtags) +;;; company-gtags.el ends here + + diff --git a/company.el b/company.el index 45a94d808..628ced934 100644 --- a/company.el +++ b/company.el @@ -132,7 +132,7 @@ (function :tag "custom function" nil)))) (defcustom company-backends '(company-elisp company-nxml company-css - company-semantic company-oddmuse + company-semantic company-gtags company-oddmuse company-files company-dabbrev) "*" :group 'company @@ -748,7 +748,7 @@ (push (buffer-substring beg end) lines)) (nreverse lines))) -(defun company-modify-line (old new offset) +(defsubst company-modify-line (old new offset) (concat (company-safe-substring old 0 offset) new (company-safe-substring old (+ offset (length new))))) @@ -760,7 +760,7 @@ (push (company-modify-line (pop old) (pop lines) column) new)) ;; Append whole new lines. (while lines - (push (company-modify-line "" (pop lines) column) new)) + (push (concat (company-space-string column) (pop lines)) new)) (concat (when nl "\n") (mapconcat 'identity (nreverse new) "\n") "\n"))) -- 2.39.2