From f52ac22eb1c09f7eae9d53d7d12d15edac56f942 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 25 Aug 2009 01:58:55 +0200 Subject: Now this is cool: support for company mode. --- elisp/geiser-company.el | 111 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 elisp/geiser-company.el (limited to 'elisp/geiser-company.el') 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 +;; 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 . + +;;; 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 -- cgit v1.2.3 From 98e199daf7b1a56179b670c192c7d244fcb2b323 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 25 Aug 2009 15:30:51 +0200 Subject: Slightly better autodoc caching (probably needs an overhaul, though). --- elisp/geiser-autodoc.el | 33 ++++++++++++++++++--------------- elisp/geiser-company.el | 8 ++++---- elisp/geiser-doc.el | 3 +-- 3 files changed, 23 insertions(+), 21 deletions(-) (limited to 'elisp/geiser-company.el') diff --git a/elisp/geiser-autodoc.el b/elisp/geiser-autodoc.el index 5aa6691..c2746a0 100644 --- a/elisp/geiser-autodoc.el +++ b/elisp/geiser-autodoc.el @@ -68,7 +68,7 @@ when `geiser-autodoc-display-module-p' is on." (make-variable-buffer-local (defvar geiser-autodoc--cached-signatures nil)) -(defun geiser-autodoc--get-signatures (funs) +(defun geiser-autodoc--get-signatures (funs &optional keep-cached) (when funs (let ((missing) (cached)) (if (not geiser-autodoc--cached-signatures) @@ -77,14 +77,16 @@ when `geiser-autodoc-display-module-p' is on." (let ((cf (assq f geiser-autodoc--cached-signatures))) (if cf (push cf cached) (push f missing))))) - (unless cached + (unless (or cached keep-cached) (setq geiser-autodoc--cached-signatures nil)) - (if (not missing) geiser-autodoc--cached-signatures + (when missing (let ((res (geiser-eval--send/result `(:eval ((:ge autodoc) (quote ,missing))) 500))) (when res - (setq geiser-autodoc--cached-signatures (append cached res)))))))) + (setq geiser-autodoc--cached-signatures + (append res (if keep-cached geiser-autodoc--cached-signatures cached)))))) + geiser-autodoc--cached-signatures))) (defun geiser-autodoc--insert-args (args current &optional pos) (dolist (a args) @@ -109,8 +111,9 @@ when `geiser-autodoc-display-module-p' is on." proc))) (propertize str 'face 'geiser-font-lock-autodoc-procedure-name))) -(defun geiser-autodoc--str (proc desc signature) - (let ((args (cdr (assoc 'args signature))) +(defun geiser-autodoc--str (desc signature) + (let ((proc (car desc)) + (args (cdr (assoc 'args signature))) (module (cdr (assoc 'module signature)))) (if (not args) (geiser-autodoc--proc-name proc module) (let ((cpos 1) @@ -140,15 +143,15 @@ when `geiser-autodoc-display-module-p' is on." (insert ")") (buffer-string)))))) -(defun geiser-autodoc--autodoc (path) - (let* ((funs (mapcar 'car path)) - (signs (geiser-autodoc--get-signatures funs))) - (when signs - (catch 'signature - (dolist (f funs) - (let ((signature (cdr (assq f signs)))) - (when signature - (throw 'signature (geiser-autodoc--str f (assq f path) signature))))))))) +(defun geiser-autodoc--autodoc (path &optional keep-cached) + (let ((signs (geiser-autodoc--get-signatures (mapcar 'car path) keep-cached)) + (p (car path)) + (s)) + (while (and path (not s)) + (unless (setq s (cdr (assq (car p) signs))) + (setq p (car path)) + (setq path (cdr path)))) + (when s (geiser-autodoc--str p s)))) ;;; Autodoc function: diff --git a/elisp/geiser-company.el b/elisp/geiser-company.el index 8ae8969..ef4ce38 100644 --- a/elisp/geiser-company.el +++ b/elisp/geiser-company.el @@ -38,7 +38,7 @@ (ignore-errors (if module (format "%s [module]" id) - (geiser-autodoc--autodoc (list (list (intern id) 0)))))) + (geiser-autodoc--autodoc (list (list (intern id) 0)) t)))) (defsubst geiser-company--doc-buffer (id module) nil) @@ -61,11 +61,11 @@ (defun geiser-company--setup (enable) (setq geiser-company--enabled-flag enable) + (when (boundp 'company-lighter) + (setq company-lighter "/C")) (when (fboundp 'company-mode) (company-mode nil) - (when enable (company-mode enable))) - (when (boundp 'company-lighter) - (setq company-lighter "/C"))) + (when enable (company-mode enable)))) (defun geiser-company--inhibit-autodoc (ignored) (setq geiser-autodoc--inhibit-flag t)) diff --git a/elisp/geiser-doc.el b/elisp/geiser-doc.el index 8e5c816..29f0de2 100644 --- a/elisp/geiser-doc.el +++ b/elisp/geiser-doc.el @@ -175,8 +175,7 @@ (message "No documentation available for '%s'" symbol) (geiser-doc--with-buffer (erase-buffer) - (geiser-doc--insert-title (geiser-autodoc--str (format "%s" symbol) - nil + (geiser-doc--insert-title (geiser-autodoc--str (list (format "%s" symbol) 0) (cdr (assoc 'signature ds)))) (newline) (insert (or (cdr (assoc 'docstring ds)) "")) -- cgit v1.2.3 From 1f933f075530a5397c6413cae307b3c372ae9a53 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Wed, 26 Aug 2009 00:57:58 +0200 Subject: Company: handling correctly the mode lighter and autodoc interaction. --- elisp/geiser-company.el | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'elisp/geiser-company.el') diff --git a/elisp/geiser-company.el b/elisp/geiser-company.el index ef4ce38..15b9cb8 100644 --- a/elisp/geiser-company.el +++ b/elisp/geiser-company.el @@ -31,6 +31,9 @@ (make-variable-buffer-local (defvar geiser-company--enabled-flag nil)) +(make-variable-buffer-local + (defvar geiser-company--autodoc-flag nil)) + (defsubst geiser-company--candidates (prefix module) (car (geiser-completion--complete prefix module))) @@ -50,28 +53,31 @@ (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))) +(defun geiser-company--prefix-at-point (module) + (when geiser-company--enabled-flag + (cond ((nth 8 (syntax-ppss)) 'stop) + ((looking-at-p "\\_>") (geiser-completion--prefix module)) + (module 'stop) + (t nil)))) ;;; Activation (defun geiser-company--setup (enable) (setq geiser-company--enabled-flag enable) - (when (boundp 'company-lighter) - (setq company-lighter "/C")) + (when (boundp 'company-default-lighter) + (set (make-local-variable 'company-default-lighter) "/C")) (when (fboundp 'company-mode) (company-mode nil) (when enable (company-mode enable)))) (defun geiser-company--inhibit-autodoc (ignored) - (setq geiser-autodoc--inhibit-flag t)) + (when (setq geiser-company--autodoc-flag geiser-autodoc-mode) + (geiser-autodoc-mode -1))) (defun geiser-company--restore-autodoc (&optional ignored) - (setq geiser-autodoc--inhibit-flag nil)) + (when geiser-company--autodoc-flag + (geiser-autodoc-mode 1))) ;;; Backends: -- cgit v1.2.3 From cee169c2de13d30f213b03578e70ca7c370e2684 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Wed, 26 Aug 2009 12:23:53 +0200 Subject: Company's go to location working also for locations in same file. --- elisp/geiser-company.el | 10 ++++++---- elisp/geiser-edit.el | 16 +++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'elisp/geiser-company.el') diff --git a/elisp/geiser-company.el b/elisp/geiser-company.el index 15b9cb8..2fb89f4 100644 --- a/elisp/geiser-company.el +++ b/elisp/geiser-company.el @@ -41,7 +41,8 @@ (ignore-errors (if module (format "%s [module]" id) - (geiser-autodoc--autodoc (list (list (intern id) 0)) t)))) + (or (geiser-autodoc--autodoc (list (list (intern id) 0)) t) + (format "%s [local id]" id))))) (defsubst geiser-company--doc-buffer (id module) nil) @@ -49,9 +50,10 @@ (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)))))) + (save-excursion + (if module + (geiser-edit-module id 'noselect) + (geiser-edit-symbol id 'noselect)))))) (defun geiser-company--prefix-at-point (module) (when geiser-company--enabled-flag diff --git a/elisp/geiser-edit.el b/elisp/geiser-edit.el index 418b6e3..0ec1669 100644 --- a/elisp/geiser-edit.el +++ b/elisp/geiser-edit.el @@ -56,6 +56,7 @@ or following links in error buffers.") (defun geiser-edit--visit-file (file method) (cond ((eq method 'window) (find-file-other-window file)) ((eq method 'frame) (find-file-other-frame file)) + ((eq method 'noselect) (find-file-noselect file t)) (t (find-file file)))) (defsubst geiser-edit--location-name (loc) @@ -126,10 +127,11 @@ or following links in error buffers.") (geiser-edit--goto-line symbol line) (when col (beginning-of-line) - (forward-char col)))) + (forward-char col)) + (cons (current-buffer) (point)))) -(defsubst geiser-edit--try-edit (symbol ret) - (geiser-edit--try-edit-location symbol (geiser-eval--retort-result ret))) +(defsubst geiser-edit--try-edit (symbol ret &optional method) + (geiser-edit--try-edit-location symbol (geiser-eval--retort-result ret) method)) ;;; Links @@ -155,13 +157,13 @@ or following links in error buffers.") (defvar geiser-edit--symbol-history nil) -(defun geiser-edit-symbol (symbol) +(defun geiser-edit-symbol (symbol &optional method) "Asks for a symbol to edit, with completion." (interactive (list (geiser-completion--read-symbol "Edit symbol: " nil geiser-edit--symbol-history))) (let ((cmd `(:eval ((:ge symbol-location) ',symbol)))) - (geiser-edit--try-edit symbol (geiser-eval--send/wait cmd)))) + (geiser-edit--try-edit symbol (geiser-eval--send/wait cmd) method))) (defun geiser-edit-symbol-at-point (&optional arg) "Opens a new window visiting the definition of the symbol at point. @@ -181,11 +183,11 @@ With prefix, asks for the symbol to edit." (pop-tag-mark) (error "No previous location for find symbol invocation"))) -(defun geiser-edit-module (module) +(defun geiser-edit-module (module &optional method) "Asks for a module and opens it in a new buffer." (interactive (list (geiser-completion--read-module))) (let ((cmd `(:eval ((:ge module-location) (:module ,module))))) - (geiser-edit--try-edit module (geiser-eval--send/wait cmd)))) + (geiser-edit--try-edit module (geiser-eval--send/wait cmd) method))) (provide 'geiser-edit) -- cgit v1.2.3 From 54ef9eae095606180a137bf2d2c11086625a7088 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Wed, 26 Aug 2009 15:13:42 +0200 Subject: Quicker metadata display in company mode. --- elisp/geiser-company.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'elisp/geiser-company.el') diff --git a/elisp/geiser-company.el b/elisp/geiser-company.el index 2fb89f4..37c2196 100644 --- a/elisp/geiser-company.el +++ b/elisp/geiser-company.el @@ -67,11 +67,8 @@ (defun geiser-company--setup (enable) (setq geiser-company--enabled-flag enable) - (when (boundp 'company-default-lighter) - (set (make-local-variable 'company-default-lighter) "/C")) - (when (fboundp 'company-mode) - (company-mode nil) - (when enable (company-mode enable)))) + (when (fboundp 'geiser-company--setup-company) + (geiser-company--setup-company enable))) (defun geiser-company--inhibit-autodoc (ignored) (when (setq geiser-company--autodoc-flag geiser-autodoc-mode) @@ -100,6 +97,11 @@ (eval-after-load "company" '(progn + (defun geiser-company--setup-company (enable) + (set (make-local-variable 'company-default-lighter) "/C") + (set (make-local-variable 'company-echo-delay) 0.01) + (company-mode nil) + (when enable (company-mode enable))) (geiser-company--make-backend company-geiser-ids nil) (geiser-company--make-backend company-geiser-modules t) (add-to-list 'company-backends geiser-company--backend) -- cgit v1.2.3