Einar's blog
29 april 2023

Offline dictionary lookups within Emacs

There is a dictionary-mode in Emacs. It used to be a separate package, but now comes as part of Emacs. The availability of the full text of the Webster 1913 dictionary within it has been much lauded in the Emacsphere by wordsmiths eager to vary their outpourings' formulations. The usual way to use it is to (setq dictionary-server "dict.org") in init.el (or equivalents) to tell Emacs to look up dictionary definitions from the internet when used. There are a lot of dictionaries in dict.org. However, I am not always online. I like to keep as much functionality as possible available to me offline to not become over-reliant on the internet or loose functionality when not at home.

The solution is simply to install the dictd server and the dictionary packages you want on your computer. In Debian, these are available as dictd and a number of packages that supply dictd-dictionary for it. In Arch, dictd is an ordinary package in the community repo, but the dictionaries has to be added through the AUR. The dictd server and related dictionary files are however not available yet for GNU Guix. The Arch Wiki has an excellent page on dictd if you want more information on its usage. Once installed, you can just change the aforementioned dictionary-server variable from "dict.org" to "localhost" and Emacs will find your installed dictionaries. Depending on the distro, you may also have to systemctl enable dictd.service and systemctl start dictd.service to make certain dictd runs at every startup as well as immediately.

The selection of freely available Norwegian Bokmål dictionaries is rather slim. I only found an English - Norwegian dictionary that seemed slightly useful to me. I wish there was as Norwegian Bokmål - English dictionary as well since that would sometimes be useful for me even if I have a decent English vocabulary. There are some dictionaries from other European languages to Norwegian Bokmål, but I seldom use other languages than English these days. (I used to play opera, cantatas and masses and then those would have been useful to me.) There is also a Norwegian Nynorsk - Norwegian Bokmål dictionary by freedict. It could occasionally be useful when I read very old Nynorsk (Landsmaal). I wish there were a comprehensive Norwegian Bokmål dictionary with word definitions, synonyms, IPA pronunciation, example of usage and expressions. I would use it especially for synonyms and spelling. Since I have lived and worked some years in Denmark and Sweden, my Bokmål spelling isn't as good as it used to be.

English is well covered by the GNU version of the Collaborative International Dictionary of English (dict-gcide) that includes the full text of the 1913 Webster's Unabridged Dictionary, the 1906 Century Dictionary and some other additions. I also installed WordNet (dict-wn) for synonyms. There are also some good computer term dictionaries like the Jargon File (dict-jargon), Virtual Entity of Relevant Acronyms (dict-vera) and the Free On Line Dictionary of Computing (dict-foldoc). With those dictionaries installed, English is well covered. I miss a dictionary with both British and American spelling and also IPA pronunciation since I try to stick with British spelling and pronunciation (not always successfully) even if I hear and read a lot of American English.

I use both M-x dictionary-search and M-x dictionary-lookup-definition. The former lets you write in a search term while the latter looks up the word at point. The latter is obviously very useful while reading while the former may be more useful when writing, except if you want to find a synonym while revising your text where the latter becomes useful again. There is no need to change dictionary language for dictionary-mode unless you have installed too many dictionaries or dictionaries of languages with a lot of collision of vocabulary and spelling. Norwegian and English share a lot of vocabulary, but seldom collide in spelling. If you need to or want to, it is possible to change dictionary inside the dictionary-mode buffer to limit the number of entries you get.

Combined with recently setting up flyspell-prog-mode for prog-mode and flyspell-mode for text-mode and (setq ispell-dictionary "british") in my init.el, I now feel more confident than before when writing text in Emacs, whether in code or not. It's nice with spell checking for variable names and comments. Maybe I should add a toggle function with a keybinding for ispell-local-dictionary between "british" and "nb" to avoid the stress of M-xing ispell-change-dictionary when I occasionally write Norwegian Bokmål. (Or is it "M-xxing" from "to M-x" since consonants are doubled before grammatical endings in English, although not always in American English? Or even "emexxing", "emexing", "emmexxing" or "emexxing" for a more phonetic spelling? Neither a dictionary-lookup-definition nor ispell seems to have anything close to it even if it is one of the most obvious verbs to Emacs users. Maybe my confidence in these tools was premature?)

All content is licensed as Creative Commons Attribution-ShareAlike.