Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs on mac os x, how to get spell check to work

I'm moving from Windows to Mac, and I've spent the whole night trying to get emacs to work.

I've installed GNU emacs and simply copied over my Windows .emacs file, which seems to work ok, except for spell check. I installed cocoAspell and followed this setup instruction to add the path and change ispell to aspell, but when I run spell check, I got

Error: The file "/use/local/lib/aspell-0.60/english" can not be opened for reading.

and FlySpell does not work either.

It seems like it's looking at the wrong directory, but I already have

(setq ispell-program-name "aspell"
      ispell-dictionary "english"
      ispell-dictionary-alist
      (let ((default '("[A-Za-z]" "[^A-Za-z]" "[']" nil
                       ("-B" "-d" "english" "--dict-dir"
                        "/Library/Application Support/cocoAspell/aspell6-en-6.0-0")
                       nil iso-8859-1)))
        `((nil ,@default)
          ("english" ,@default))))

which points to the right dictionary directory "/Library/Application Support/cocoAspell/aspell6-en-6.0-0". I can't figure out why I got the error and how to fix it.


Update:

Now I have removed my GNU emacs and cocoAspell, and re-installed (and linked) emacs/aspell using homebrew as @katspaugh suggested. I removed the code shown above, leave only

(setq ispell-program-name "aspell")

Now when I run spell check, I got

Searching for program: No such file or directory, aspell

I have already linked aspell with brew link aspell, why it still cannot find it?

like image 629
LWZ Avatar asked Sep 26 '13 07:09

LWZ


3 Answers

I use aspell from Homebrew. Simply:

brew install aspell --with-lang-en

Then, make sure your brew bin directory is in your Emacs exec-path variable. If you use /usr/local as your brew prefix then it will just work since that path is included in exec-path by default. Otherwise you'll need this somewhere in your .emacs:

  (setq exec-path (append "/path/to/brew/bin" exec-path)))

You can also accomplish the same thing using the customize interface with "M-x customize-variable RET exec-path RET" and then using the gui to add a path.

This will work on any Emacs, including the one from Emacs for Mac OS X, the one from brew, or the system Emacs.

like image 39
David Caldwell Avatar answered Oct 02 '22 07:10

David Caldwell


Here's a working solution:

  • Install Homebrew
  • brew install emacs --with-cocoa --with-gnutls
  • brew install aspell
  • open -a Emacs
  • M-x ispell

Enjoy!

like image 180
katspaugh Avatar answered Oct 02 '22 09:10

katspaugh


Here is a MacPorts solution to the problem. (Credits to this link)

$ sudo port install aspell

Then install one of aspell's dictionaries for the respective language support

$ sudo port install aspell-dict-en

Then add the following line to your init.el or .emacs file.

(setq ispell-program-name "/opt/local/bin/aspell")

It worked for me.

Note: "sudo ports install ispell" works as well, but it is not as efficient and flexible as aspell.

like image 20
Ébe Isaac Avatar answered Oct 02 '22 09:10

Ébe Isaac