[slime-devel] Slime contrib for completion via company-mode

Hello, here is a slime contrib I use for completion in slime via company-mode (see http://www.emacswiki.org/emacs/CompanyMode). It provides an automatic, timer based completion popup at point and scores high in the eye candy department. Ole -- Ole Arndt http://www.sugarshark.com ;;; slime-company.el --- slime completion backend for company mode ;; ;; Copyright (C) 2009 Ole Arndt ;; ;; Author: Ole Arndt <ole@sugarshark.com> ;; Keywords: convenience, lisp, abbrev ;; ;; 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 3 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 <http://www.gnu.org/licenses/>. ;; ;;; Commentary: ;; ;; This is a backend implementation for the completion package ;; company-mode by Nikolaj Schumacher. More info about this package ;; is available at http://nschum.de/src/emacs/company-mode ;; Company-mode is also available at the ELPA http://tromey.com/elpa ;; ;; The backend is installed into the list of company-backends, but ;; you have to enable company-mode manually (or in lisp-mode-hook). ;; ;;; Installation: ;; ;; Add this to your .emacs: ;; ;; (add-to-list 'load-path "<directory-of-this-file>") ;; (add-hook 'slime-load-hook (lambda () (require 'slime-company))) ;; ;; or use: (slime-setup 'slime-fancy 'slime-company) ;; ;; I also have the following, IMO more convenient keybindings for ;; company mode in my .emacs: ;; ;; (define-key company-active-map (kbd "\C-n") 'company-select-next) ;; (define-key company-active-map (kbd "\C-p") 'company-select-previous) ;; (define-key company-active-map (kbd "\C-d") 'company-show-doc-buffer) ;; (define-key company-active-map (kbd "\C-v") 'company-show-location) ;; (define-key company-active-map (kbd "<tab>") 'company-complete) ;; (define-key company-active-map (kbd "\C-g") '(lambda () ;; (interactive) ;; (company-abort))) ;; ;;; Code: (require 'company) (defun slime-company-backend (command &optional arg &rest ignored) (case command ('prefix (and (eq (derived-mode-p 'lisp-mode) 'lisp-mode) (company-grab-lisp-symbol))) ('candidates (first (slime-simple-completions arg))) ('meta (let ((arglist (slime-eval `(swank:arglist-for-echo-area (quote ((,arg))))))) (when arglist (slime-fontify-string arglist)))) ('doc-buffer (let ((doc (slime-eval `(swank:describe-symbol ,arg)))) (with-current-buffer (company-doc-buffer) (insert doc) (goto-char (point-min)) (current-buffer)))) ('location nil) ('sorted nil))) (add-to-list 'company-backends 'slime-company-backend) (provide 'slime-company) ;;; slime-company.el ends here

Here all it takes to use Dr.Cubitt's `completion-ui' package with SLIME. Completion-UI is available at <URL:http://www.dr-qubit.org/emacs.php#completion> In the code shown below I'm using the contrib function `slime-completions' from contrib/slime-c-p-c, which must be enabled. You may prefer to replace (slime-completions prefix) with (slime-simple-completions prefix) if you did not wish to use slime-c-p-c, [slime-c-p-c is broken in new emacsen by default but it work OK via completion-ui as shown] (completion-ui-register-source (lambda (prefix &optional maxnum) (let* ((completions-from-swank (slime-completions prefix)) ; <--- (completions (car completions-from-swank))) (if maxnum (butlast completions (- (length completions) maxnum)) completions))) :prefix-function (lambda () "Return prefix string at point for completion." (let* ((end (point)) (beg (save-excursion (backward-sexp 1) (while (= (char-syntax (following-char)) ?\') (forward-char 1)) (point)))) (buffer-substring-no-properties beg end))) :name 'lisp-symbol-swank) (defun default-slime-completion-ui-bindings () "Enable `complete-lisp-symbol-swank' which is registered via completion-ui on the M-TAB and TAB keys in `slime-mode' and `slime-repl-mode' respectively." (define-key slime-mode-map "\C-[\C-i" 'complete-lisp-symbol-swank) (define-key slime-repl-mode-map "\t" 'complete-lisp-symbol-swank)) (default-slime-completion-ui-bindings)
participants (2)
-
Madhu
-
Ole Arndt