Lisp: Emacs Autocomplete

Integrate emacs autocomplete
Emacs Autocomplete provides dictionaries for many languages and inserts new words on the fly (with the correct settings).
Install it to .emacs.d and insert the following lines into your .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)

Lisp-specific autocomplete
Put ac-slime into your .emacs.d-folder and paste the following snippet into your .emacs-file:

;; add lisp autocomplete-support
(require 'ac-slime)
(add-hook 'slime-mode-hook 'set-up-slime-ac)

Global autocomplete
Globally enable autocomplete by pasting the following snippet into your .emacs-file:

(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)

Insert new words on the fly
Insert new words on the fly by pasting the following snippet into your .emacs-file:

;; 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))
Advertisements
Lisp: Emacs Autocomplete

2 thoughts on “Lisp: Emacs Autocomplete

  1. mentus says:

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s