summaryrefslogtreecommitdiff
path: root/elisp/geiser-company.el
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2009-08-25 01:58:55 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2009-08-25 01:58:55 +0200
commit91841a63fb0cf3c8a0a6ed1e9086b72097cd44e4 (patch)
treecc22f354204c9e912f1dc7e39f40f933ce51ab1c /elisp/geiser-company.el
parente0dd77a67b8e7c7d2d56aa353967249cc1e19f1e (diff)
downloadgeiser-91841a63fb0cf3c8a0a6ed1e9086b72097cd44e4.tar.gz
geiser-91841a63fb0cf3c8a0a6ed1e9086b72097cd44e4.tar.bz2
Now this is cool: support for company mode.
Diffstat (limited to 'elisp/geiser-company.el')
-rw-r--r--elisp/geiser-company.el111
1 files changed, 111 insertions, 0 deletions
diff --git a/elisp/geiser-company.el b/elisp/geiser-company.el
new file mode 100644
index 0000000..8ae8969
--- /dev/null
+++ b/elisp/geiser-company.el
@@ -0,0 +1,111 @@
+;; geiser-company.el -- integration with company-mode
+
+;; Copyright (C) 2009 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Start date: Mon Aug 24, 2009 12:44
+
+;; This file 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.
+
+;; This file 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/>.
+
+;;; Code:
+
+(require 'geiser-autodoc)
+(require 'geiser-completion)
+(require 'geiser-edit)
+(require 'geiser-base)
+
+
+;;; Helpers:
+
+(make-variable-buffer-local
+ (defvar geiser-company--enabled-flag nil))
+
+(defsubst geiser-company--candidates (prefix module)
+ (car (geiser-completion--complete prefix module)))
+
+(defsubst geiser-company--doc (id module)
+ (ignore-errors
+ (if module
+ (format "%s [module]" id)
+ (geiser-autodoc--autodoc (list (list (intern id) 0))))))
+
+(defsubst geiser-company--doc-buffer (id module)
+ nil)
+
+(defun geiser-company--location (id module)
+ (ignore-errors
+ (let ((id (intern id)))
+ (save-current-buffer
+ (if module (geiser-edit-module id) (geiser-edit-symbol id))
+ (cons (current-buffer) (point))))))
+
+(defsubst geiser-company--prefix-at-point (module)
+ (and geiser-company--enabled-flag
+ (looking-at-p "\\_>")
+ (not (nth 8 (syntax-ppss)))
+ (geiser-completion--prefix module)))
+
+
+;;; Activation
+
+(defun geiser-company--setup (enable)
+ (setq geiser-company--enabled-flag enable)
+ (when (fboundp 'company-mode)
+ (company-mode nil)
+ (when enable (company-mode enable)))
+ (when (boundp 'company-lighter)
+ (setq company-lighter "/C")))
+
+(defun geiser-company--inhibit-autodoc (ignored)
+ (setq geiser-autodoc--inhibit-flag t))
+
+(defun geiser-company--restore-autodoc (&optional ignored)
+ (setq geiser-autodoc--inhibit-flag nil))
+
+
+;;; Backends:
+(defmacro geiser-company--make-backend (name mod)
+ `(defun ,name (command &optional arg &rest ignored)
+ "A `company-mode' completion back-end for `geiser-mode'."
+ (interactive (list 'interactive))
+ (case command
+ ('interactive (company-begin-backend ',name))
+ ('prefix (geiser-company--prefix-at-point ,mod))
+ ('candidates (geiser-company--candidates arg ,mod))
+ ('meta (geiser-company--doc arg ,mod))
+ ('doc-buffer (geiser-company--doc-buffer arg ,mod))
+ ('location (geiser-company--location arg ,mod))
+ ('sorted t))))
+
+(defvar geiser-company--backend '(company-geiser-ids company-geiser-modules))
+
+(eval-after-load "company"
+ '(progn
+ (geiser-company--make-backend company-geiser-ids nil)
+ (geiser-company--make-backend company-geiser-modules t)
+ (add-to-list 'company-backends geiser-company--backend)
+ (add-hook 'company-completion-finished-hook 'geiser-company--restore-autodoc)
+ (add-hook 'company-completion-cancelled-hook 'geiser-company--restore-autodoc)
+ (add-hook 'company-completion-started-hook 'geiser-company--inhibit-autodoc)))
+
+
+;;; Reload support:
+
+(defun geiser-company-unload-function ()
+ (when (boundp 'company-backends)
+ (setq company-backends (remove geiser-company--backend company-backends))))
+
+
+(provide 'geiser-company)
+;;; geiser-company.el ends here