21

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?

LWZ
  • 11,670
  • 22
  • 61
  • 79
  • 3
    Did the error message really say `use/local`? In that case you have a typo somewhere -- it should be `usr/local`. – Lindydancer Sep 27 '13 at 19:00
  • 1
    If you're using CUA-mode and other Mac-ish/Windows-y features, you may want to consider [Aquamacs](http://aquamacs.org) instead of GNU Emacs. Among many other useful features, it also comes with aspell properly configured, and lets you use the OS X system spellchecker instead if you prefer. – abarnert Oct 02 '13 at 00:05
  • See also: https://emacs.stackexchange.com/questions/33865/spelling-check-in-emacs-25-2-on-mac-os-sierra – Timur Shtatland May 12 '22 at 19:05

8 Answers8

29

Here's a working solution:

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

Enjoy!

katspaugh
  • 17,449
  • 11
  • 66
  • 103
  • 2
    Use aspell rather then ispell. –  Sep 26 '13 at 12:26
  • 1
    I see that aspell has better Unicode support. Need to check if the recipe above works the same way with aspell. – katspaugh Sep 26 '13 at 13:56
  • 1
    It should. Aspell provides the same interface as ispell, and both, ispell and flyspell, should pick it up automatically. –  Sep 26 '13 at 13:58
  • Yep, it appears `ispell` and `aspell` can be used interchangeably. By the way, Homebrew, unfortunately, doesn't have any additional dictionary packages for neither of the two. – katspaugh Sep 26 '13 at 16:31
  • Thanks! Is this a separate emacs installation or does it just adds aspell to the GNU emacs I've already have? – LWZ Sep 26 '13 at 16:49
  • @LWZ, it's separate, so you'll have to delete the other Emacs and aspell. – katspaugh Sep 26 '13 at 17:13
  • 2
    @katspaugh The dictionaries are included in the formulae themselves. Just take a look at their arguments, and select the ones you need, e.g. `brew install aspell --with-lang-de`. –  Sep 26 '13 at 17:31
  • 1
    @katspaugh By the way, install Emacs with `brew install emacs --cocoa --srgb --with-gnu-tls`. This improves color appearance, and enables encrypted network traffic for Emacs. –  Sep 26 '13 at 17:32
  • @katspaugh Now I've removed the other emacs and installed this one using your method, but when I run spell check I still got the exact same error as shown in OP. – LWZ Sep 26 '13 at 18:25
  • @katspaugh I tried removing the code but emacs couldn't find aspell. I think it's because aspell didn't "link" properly (I don't know what it means). I got a warning when I reinstall aspell. Would you mind open a chat and help me with this? – LWZ Sep 27 '13 at 07:42
  • 1
    FYI, I ran this code and got a warning that `emacs: --cocoa was deprecated; using --with-cocoa instead!` – Richard Erickson Apr 14 '17 at 15:19
  • 1
    Adding languages now fails with `invalid option: --with-lang-en`. Install with `brew install aspell`. – miguelmorin Mar 04 '19 at 07:56
12

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.

David Caldwell
  • 1,493
  • 1
  • 11
  • 7
4

I build on the answers by katspaugh, David Caldwell, and Ébe Isaac, and made it work with the latest versions.

Install aspell, for example with brew:

brew install aspell

brew symlinks to /usr/local/bin and you can verify the installation:

$ which aspell
/usr/local/bin/aspell

Now tell Emacs about this location, e.g. adding this line in ~/.emacs:

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

Launch M-x ispell in a buffer and it works.

To install with ports, see other answers.

miguelmorin
  • 5,025
  • 4
  • 29
  • 64
3

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.

Ébe Isaac
  • 11,563
  • 17
  • 64
  • 97
1

Making a symbolic link in /usr/bin on OS X 10.12 (Sierra) is not permitted or necessary (or a good idea).

$ sudo ln -s /usr/local/bin/ispell /usr/bin/ispell
ln: /usr/bin/ispell: Operation not permitted

I used that hack for years, but was finally forced to figure out the right solution when the last upgrade deleted it. I used homebrew to install ispell and apsell and would get which ever one I set in ~/.emacs with

$ cat ~/.emacs
(setq ispell-program-name "/usr/local/bin/aspell")

There is a similar discussion of this here.

alper
  • 2,919
  • 9
  • 53
  • 102
0

It also works if you use fink instead than home-brew. ispell will be in /sw/bin and the string to add to .emacs file will be:

(setq ispell-program-name "/sw/bin/ispell")

0

Installing aspell, and adding (setq ispell-program-name "/usr/local/bin/aspell") in the init.el does not work for me. I had to make a symbolic link sudo ln -s /usr/local/bin/aspell /usr/bin/ispell, then emacs flyspell-mode works OK.

prosseek
  • 182,215
  • 215
  • 566
  • 871
0

Emacs installed with brew cask install emacs will come with a built in spell checker called m-x ispell.

You have to do two things to get this to work.

  1. brew install aspell or maybe brew install aspell --with-lang-en

  2. go to emacs and evaluate this function or better yet put it in your init file (setq ispell-program-name "/usr/local/bin/aspell")

Note: the location of aspell can be found using which aspell in macOS terminal which should be equal tot step 2. above.

zack999
  • 111
  • 2