Lisp: Emacs Autocomplete
Today I hacked some lisp in emacs because I got two new books (Let over Lambda & Land of Lisp).
After a while when the function-definitions became more frequent I missed a language-specific autocomplete (and didn’t only want to use the built-in autocomplete that completes words you wrote earlier) and after some research I found the solution: Emacs Autocomplete. It integrates different language-dictionaries and inserts new words on the fly (with the right settings).
After installing the autocomplete into .emacs.d I inserted the following lines into my .emacs-file to enable it:
;; add .emacs.d to load path (add-to-list 'load-path "~/.emacs.d") ;; enable autocomplete (require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict") (ac-config-default) (global-auto-complete-mode t) (auto-complete-mode t)
To get a lisp-specific autocomplete you’ve got to include ac-slime (found at github): put it into your .emacs.d-folder and include it in your .emacs-file via
;; add lisp autocomplete-support (require 'ac-slime) (add-hook 'slime-mode-hook 'set-up-slime-ac)
and to switch on autocomplete globally you have to apply a “dirty fix”:
;; dirty fix for having AC everywhere
(define-globalized-minor-mode real-global-auto-complete-mode
auto-complete-mode (lambda ()
(if (not (minibufferp (current-buffer)))
(auto-complete-mode 1))))
(real-global-auto-complete-mode t)
Now only one thing is missing: the mentioned inserting of new words on the fly:
;; create and add new words to the dictionary on the fly (when (require 'auto-complete-config nil 'noerror) (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict") (setq ac-comphist-file "~/.emacs.d/ac-comphist.dat") (ac-config-default))
Hi
This is what i was looking for. i followed your instructions and added these lines of code to my .emacs file, the auto completion does still not work however. Slime is using its completion as before. Here is my emacs file:
(add-to-list ‘load-path “~/Programs/slime/”) ; your SLIME directory
(eval-after-load “slime”
‘(progn
(setq slime-lisp-implementations
‘(
;;Activate these by doing M–M-x slime and type in the desired lisp name.
;;(cmucl (“/opt/cmucl-20c/bin/lisp”) :coding-system iso-8859-1-unix)
(sbcl (“/usr/local/bin/sbcl”) :coding-system utf-8-unix) ;;for sbcl-1.0.48
;;(ccl (“/usr/local/bin/ccl”) :coding-system utf-8-unix)
;;(clisp (“/usr/bin/clisp”))
(abcl (“/home/nimaai/abcl”))))
;;common-lisp-hyperspec-root “~/my-slime-sandbox/hyperspec-7-0/HyperSpec/”)
(slime-setup ‘(;slime-banner ;added this to see what it looked like
slime-asdf ;Left out until I knew more about it
slime-autodoc
slime-editing-commands
slime-fancy-inspector
slime-fontifying-fu
slime-fuzzy
slime-indentation
slime-mdot-fu
slime-package-fu
slime-references
slime-repl
slime-sbcl-exts ;Not with cmucl??
slime-scratch
slime-xref-browser))
(slime-autodoc-mode)
;; (setq slime-complete-symbol*-fancy t)
;; (setq slime-complete-symbol-function ‘slime-fuzzy-complete-symbol)
(add-hook ‘lisp-mode-hook (lambda () (slime-mode t)))
(add-hook ‘slime-mode-hook
(lambda ()
(define-key slime-mode-map (kbd “ö”) ‘insert-parentheses)
(define-key slime-mode-map (kbd “ä”) ‘move-past-close-and-reindent)
(define-key slime-mode-map (kbd “C-t”) ‘transpose-sexps)
(define-key slime-mode-map (kbd “C-M-t”) ‘transpose-chars)
(define-key slime-mode-map (kbd “C-b”) ‘backward-sexp)
(define-key slime-mode-map (kbd “C-M-b”) ‘backward-char)
(define-key slime-mode-map (kbd “C-n”) ‘forward-sexp)
(define-key slime-mode-map (kbd “C-M-f”) ‘forward-char)
(define-key slime-mode-map (kbd “C-u”) ‘backward-up-list)
(define-key slime-mode-map (kbd “C-j”) ‘down-list)
(define-key slime-mode-map (kbd “C-p”) ‘forward-list)
(define-key slime-mode-map (kbd “C-o”) ‘backward-list)
))
;; highlight text selection (active region) (on by default in emacs 23)
(transient-mark-mode 1)
;; highlight parens
(show-paren-mode 1)
;; highlight entire expression
(setq show-paren-style ‘expression)))
;(require ‘slime)
(require ‘slime-autoloads)
(add-to-list ‘load-path “/usr/share/emacs23/site-lisp/pymacs”)
(require ‘pymacs)
(pymacs-load “ropemacs” “rope-”)
(setq ropemacs-enable-autoimport t)
;; enable autocomplete
(add-to-list ‘load-path “~/.emacs.d/vendor/auto-complete-1.2″)
(require ‘auto-complete-config)
(add-to-list ‘ac-dictionary-directories “~/.emacs.d/vendor/auto-complete-1.2/dict”)
(ac-config-default)
(global-auto-complete-mode t)
(auto-complete-mode t)
;; add lisp autocomplete-support
(add-to-list ‘load-path “~/.emacs.d”)
(require ‘ac-slime)
(add-hook ‘slime-mode-hook ‘set-up-slime-ac)
;; dirty fix for having AC everywhere
(define-globalized-minor-mode real-global-auto-complete-mode
auto-complete-mode (lambda ()
(if (not (minibufferp (current-buffer)))
(auto-complete-mode 1))))
(real-global-auto-complete-mode t)
;; create and add new words to the dictionary on the fly
(when (require ‘auto-complete-config nil ‘noerror)
(add-to-list ‘ac-dictionary-directories “~/.emacs.d/ac-dict”)
(setq ac-comphist-file “~/.emacs.d/ac-comphist.dat”)
(ac-config-default))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won’t work right.
‘(ac-modes (quote (slime-repl-mode emacs-lisp-mode lisp-interaction-mode c-mode cc-mode c++-mode clojure-mode java-mode perl-mode cperl-mode python-mode ruby-mode ecmascript-mode javascript-mode js2-mode php-mode css-mode makefile-mode sh-mode fortran-mode f90-mode ada-mode xml-mode sgml-mode)))
‘(show-paren-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won’t work right.
‘(show-paren-match ((((class color) (background light)) (:background “grey87″)))))
Sorry i am not so much emacs-versed. Any hel would be appreciated.
Did you try M-x set-up-slime-ac in your SLIME REPL?
I wonder if it could be started automatically..
somewhat off-topic, do you work with a free of charge skin with your website? i cherished it.
Sorry for the late reply. Yes, I use a free of charge skin, it’s called “INove”.