6

Spellcheck in Aquamacs works much better than either the default aspell or the improved hunspell.

Example typo: whtehr

Here are the suggestions provided by the various engines when I do flyspell-auto-correct-word.

Aspell: Corrections: whiter water watery whet White where white whatever whitener whets waiter etc. (i.e. it never gets to whether)

Hunspell: Corrections: Tehran (i.e. it never gets to whether)

Aquamacs: Corrections: whether (i.e. it gets to whether on the first try)

According to this page, "Aquamacs 2.0 and onwards uses the Mac OSX spell-checking system." It's not clear from the page whether the Mac OSX spell-checking system in question is CocoAspell, or if CocoAspell is recommended for version 1.9 and below.

So, how do I direct GNU Emacs to use the same spellchecker that Aquamacs uses?

2

2 Answers 2

5

The patches (referred to below) were created by @lawlist from select portions of the Aquamacs:

https://github.com/davidswelt/aquamacs-emacs

To enable native spellchecking on OSX in the vanilla/generic version of Emacs, it is necessary to patch the C-source-code prior building, and a few lisp files also need to be modified. The patch is too big to post in an answer on stackexchange.com.

The following procedure assumes the necessary tools have already been installed on OSX to build and patch, etc. -- e.g., git, recent versions of automake and autoconf, xcode, etc.


EMACS-25 BRANCH -- NOVEMBER 1, 2016:

The following patch and minimal testing was performed on the emacs-25 branch built --with-ns as of commit dated November 1, 2016: 5043e0a7e06dbf6507a59736e55bdde69d9a2a4e

From a terminal, type: git clone -b emacs-25 git://git.sv.gnu.org/emacs.git

Visit: https://gist.github.com/lawlist/dfc75240cc06c66f19f48eaa3e570d7c

Click the "Download ZIP" button, and save the zipped patch file somewhere on your computer.

Extract the ZIP archive you just downloaded and save nsspellchecker_emacs25.diff to the .../emacs root source-code directory that was cloned in the first step above.

From a terminal, cd over to the root .../emacs source-code directory.

;; The patch may become outdated, so this example includes a hard reset to go back to November 1, 2016. [Certain bug fixes are still being made to Emacs 25 by the development team, which may cause the patch to become outdated.]

From a terminal, type: git reset --hard 5043e0a7e06dbf6507a59736e55bdde69d9a2a4e

;; After performing a hard reset successfully, the message in the terminal will say: "HEAD is now at 5043e0a Fix documentation for 'eudc-options-file'"

From a terminal, type: git apply nsspellchecker_emacs25.diff

From a terminal, type: ./autogen.sh

From a terminal, type: ./configure --with-ns

From a terminal, type: make

From a terminal, type: make install

;; With Finder.app, navigate over to .../emacs/nextstep and try out your new Emacs.app

;; Open your new Emacs.app and type M-x eval-expression RET (require 'flyspell) RET

;; In a *scratch* buffer, type something spelled correctly and something spelled wrong.

;; Type: M-x ns-start-spellchecker or M-x ispell-buffer

;; Play a little with the pop-up spellchecker and have fun.

;; Custom words are saved to: ~/Library/Spelling/LocalDictionary


Previous answer that applies to the master branch as of May 29, 2016:

The following patch and minimal testing was performed on master branch built --with-ns as of commit dated May 29, 2016: 76fb19b359dec8556dc66dbac3ad3d333feea3c3

From a terminal, type: git clone -b master git://git.sv.gnu.org/emacs.git

Visit: https://gist.github.com/lawlist/6a9b281870fcc114ad3c6c1dca121f95

Click the "Download ZIP" button, and save the zipped patch file somewhere on your computer.

Extract the ZIP archive you just downloaded and save nsspellchecker.diff to the .../emacs root source-code directory that was cloned in the first step above.

From a terminal, cd over to the root .../emacs source-code directory.

;; The patch will soon become outdated, so this example includes a hard reset to go back to May 29, 2016. [I will not be updating/maintaining the patch as Emacs master branch changes several times each day.]

From a terminal, type: git reset --hard 76fb19b359dec8556dc66dbac3ad3d333feea3c3

;; After performing a hard reset successfully, the message in the terminal will say: "HEAD is now at 76fb19b * lisp/wid-edit.el (link): Remove :follow-link property (bug#22434)"

From a terminal, type: git apply nsspellchecker.diff

4
  • Wow, this is amazing! Is there a way to make this work with other versions of Emacs? I use emacs-mac-port (brew install emacs-mac). May 30, 2016 at 17:52
  • 2
    The patch only applies to Emacs master branch as of May 29, 2016, and it may continue to work for a few days or weeks until someone changes one of the files in the master branch that would make the patch obsolete. It is possible to save the patched flyspell.el and ispell.el elsewhere, to reduce the size of the patch and make things more manageable to keep a patch updated or to port it over to another version of Emacs. It boils down to finding someone motivated to invest the time making the conversion. The majority of the magic is just a few functions that can be copied into the source.
    – lawlist
    May 30, 2016 at 18:26
  • 1
    I know emacs-mac-port does not shy away from make changes to source, for pixel wise scrolling, etc. Making this patch/method known on their end could be a way to see if they'd invest the time in maintaining it?
    – sooheon
    May 30, 2016 at 18:52
  • Any chance of having the patch for Emacs 26? I tried implementing the changes but can't get them to work. I did get Emacs to compile by changing calls to add-to-list to push, but I get many warnings and when I try to use the ns-spell-checker, I do get a window pop up but Emacs complains that some variables aren't defined.
    – Daniel
    Apr 7, 2018 at 7:32
2

Building upon lawlist's answer, I've applied the necessary changes for Emacs 26 (as of 7th April 2018).

The patched source code can be found here: https://github.com/dangom/emacs/tree/ns-spellchecker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.