Skip to content

Instantly share code, notes, and snippets.

@devinprater
Last active February 7, 2024 12:04
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devinprater/a794a448ccc46e72fca63c932105c043 to your computer and use it in GitHub Desktop.
Save devinprater/a794a448ccc46e72fca63c932105c043 to your computer and use it in GitHub Desktop.
Using Emacs, and Emacspeak, on Mac

Emacs, with Emacspeak, on macOS

This guide will, through open source collaboration, spell checking, and Doctor Pepper, show users of Apple (Mac) computers how to install Emacs, Emacspeak, and link the two together for an enjoyable text editing experience, and if there is enough Doctor Pepper, how to best use the included Emacs modes for greater productivity than is provided by newer software. There will also be notes on using Emacspeak on Linux as well.

Why Emacs with Emacspeak?

From the Emacs Manual:

Gnu Emacs is the GNU incarnation of the advanced, self-documenting, customizable, extensible editor Emacs.

It is open source, and has a few maintainers who update the software. At the time of this writing, Emacs is at version 26.3.

Emacspeak is, according to its developer, the "Complete Audio Desktop." I cannot tell if he is sarcastic about this, as I’ve not yet found good applications for complete web browsing with HTML5 and JavaScript support, a good Matrix client, MUD client, audio or music editor, audio games, easy mail client, and plenty other uses for a general purpose operating system. But, for the things that Emacs does well, like text editing, file management, EBook reading, and other uses provided by downloadable packages, Emacspeak provides access easily. At the time of this writing, Emacspeak is at version 51.

Emacs has tons of documentation, and getting to it is easy. One can bring up a list of hotkeys in Emacs, pertaining to which type of file you’re working with. One can find out what a key command does, or find out if a function, like "next-line" has any key commands assigned to it. One can even browse the Emacs manual, along with any other manuals provided by other programs, to the Info program on your computer, from Emacs using Emacspeak.

Emacs is almost completely written in Emacs Lisp. In and of itself, this fact is unremarkable. More remarkable, however, is that one can run Lisp within the editor while it runs, which is exactly what a configuration file does. This gives plenty of opportunity for extending Emacs, and this is how Emacspeak is so powerful. If you do not want to write your own programs for Emacs, though, there is the "package manager" which has plenty of packages for many users and developers.

Emacs is cross-platform. It works on Windows, Linux, Mac, along with mobile devices through terminal apps. Emacspeak works by using speech servers to speak information. There are speech servers for some hardware speech synthesizers, which do not see much use nowadays, ViaVoice and eSpeak for Linux, and one for the Mac. There is a Github repository for using Emacspeak on Windows, but it hasn’t been updated since January 10, 2016. Since Emacspeak on Linux can be a complex topic, and may, depending on if you want subjectively better speech or not, cost $5 or more, I’ll focus here primarily on using Emacs, with Emacspeak, on the Mac. In the future, mobile devices and terminal apps like Termux for Android or iSH for iOS and iPadOS may provide on-the-go Emacs. For now, though, Emacspeak speech servers are limited to general purpose computer operating systems, and so, practically, is Emacspeak and its level of access to Emacs for the blind.

Emacspeak is more than a package to self-voice Emacs. It does not read the screen, but reads Emacs itself. This means that it not only knows what the name of the file is that you’re editing, but the type of file as well. It not only knows that you’re editing text, but also what formatting information is involved, what parts are highlighted, and what lines have errors. Emacspeak doesn’t only speak that information in a description either. It shows formatting and code syntax highlighting through changes in pitch and intonation, and errors using a sound.

When you read by character, the speech rate is increased so you can move faster to the part of a line you want. Instead of saying "quote deleted," it beeps as it says "quote," to speed up interaction. Instead of saying "Active Processes exist dialog" it plays a sound based on if the answer it needs is yes/no, y/n, or a short line of text, like a command or text to be placed in a heading. All these sounds and speech changes speed up interaction, give information, and make using Emacs with Emacspeak an enjoyable experience. It also doesn’t hurt that interaction across Emacs is uniform, everything is accessible through the keyboard, there are no unlabeled buttons or things only F6 or control+Tab can get to, no web applications where one must switch from Browse to Focus mode, no ribbons, or any number of accessibility stumbling blocks which riddle more modern programs. This isn’t to say that Emacs is perfect. Third-party packages can be pretty hard to use, like Md4Rd, a Reddit client. However, these packages are open source, and submitting an issue on its Github page about the inaccessibility may help in solving the problem.

Installing Emacs

First, let’s lay the groundwork with Emacs. You’ll need to get Homebrew, which is a community-driven package manager for the Mac. Do this by first finding the Terminal app, opening it, running a command, and following the prompts to install the package manager. If you already have Homebrew, or are running Linux, skip this step.

The Terminal app is in the Utilities folder in Finder. from Finder, press Command + Shift + U to open the Utilities folder. Begin typing "Terminal", until you hear VoiceOver say "Terminal application," and press Command + O to open the app. Alternatively, you can open it from Spotlight, using Command + Space, then typing "Terminal", and pressing Return.

Now, inside Terminal, paste the following command and press Return (Enter):

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once Homebrew is installed, you can install Emacs. We’ll use Emacs-Mac, because it works well, for me at least:

brew tap railwaycat/emacsmacport

brew cask install emacs-mac

For Linux users, use your package managers to install Emacs. For preparing to use Emacspeak, install TCL, TCLX, and TK. If you want Voxin, get that too.

This installs the "cask" Emacs-mac, which will put the Emacs app in your Applications folder. To prepare things, let’s open it. Go to Finder, and press Command + Shift + A, and find "Emacs application." Press VO + Shift + M, to open the menu, and choose "Open," and press Return. On Linux, just press Alt + F2, type Emacs, and press Return.

Even though the Mac is a general purpose computer, MacOS is becoming a bit of a pain when it comes to running apps which Apple hasn’t officially accepted, so when you open Emacs for the first time, you may only be given the option to "move to trash" or "cancel" opening the app. Cancel that, do not move to trash, then try opening the app again from the menu, and you’ll be given the option to actually open the app. Storming gatekeeper! On the record, this should not be necessary on a "pro" laptop. Apple should have learned from Windows Vista. But, the Mac has Emacs and Emacspeak speech servers, and VoiceOver is sort of okay with the Mac’s GUI, so what can you do. And no, workarounds are not fixes. But let’s move on to more positive things, which we can work with.

Setting Up Emacspeak

Setting up Emacspeak is just as easy as setting up Emacs. If you’re running Linux, replace “brew” in the following commands with your package manager’s installation commands. First, get git. In the Terminal, run:

brew install git

Once that’s done, install mplayer:

brew install mplayer

Now, you should be ready to get Emacspeak:

git clone http://www.github.com/tvraman/emacspeak/

That command may take a moment, but once it’s done, type:

cd emacspeak

That brings you to Emacspeak’s folder. Now, you have to build the program:

make config

make emacspeak

At the end, you should hear a message about how to configure Emacs to work with Emacspeak. we’ll do that part next. On Linux, make your preferred speech engine as well. For ESpeak, do

make espeak

And for ViaVoice, do:

make outloud

Linking Emacs with Emacspeak

Now, it’s time to link the two pieces of software together. To do this, make an Emacs configuration file, and add a line which loads Emacspeak whenever Emacs starts.

To create the Emacs configuration file, you can use Text edit. That’s in your Applications folder in Finder, so go to Finder, press Command + Shift + A, find Text Edit, and open it with Command + O.

One of MacoS’ differentiating aspects is its attention to detail... Well, sometimes. When writing text, some symbols are replaced by their prettier, more accurate representations. Straight quotes normally used by other operating systems are replaced by their more accurate curved versions. Two or three dashes are transformed into em-dashes and en-dashes. This is great for writing prose, but not program configurations.

Let’s turn off those handy fixes to the text, as Emacs may not know what to do with those pretty symbols. Within Text edit, before typing anything, press Command + Shift + T. This should put Text Edit into Plain Text mode, instead of Rich Text mode. VoiceOver will say "Plain Text Mode." If not, press the command again.

Now, you can finally add that line which will load Emacspeak from Emacs, so paste this into your file:

(load-file "~/emacspeak/emacspeak-setup.el")

This tells Emacs that, on startup, load the file "emacspeak-setup.el" in the lisp folder of the Emacspeak folder in your Home directory. Now, save that file, Command + S as .emacs.el in your Home folder, press Command + Shift + h to choose that. Do not forget the dot at the beginning. It should sound like "dot emacs dot el". When you’ve typed the name and chosen the home folder, press Return to save.

On Linux, follow any steps needed on Emacspeak's install guide. This may be a bit outdated, but it should work. After installing TCL, TCLX, and TK. Try the following in your bash configuration file:

export DTK_PROGRAM=espeak

Testing the setup

To test the file you’ve just created, open Emacs from the Applications folder, in Finder. If it worked, you’ll hear a small tune on pipe organs, and a deep ViaVoice TTS voice say "This, is Emacspeak." If not, contact a contributor.

If you find that your speech is very unresponsive, set the default voice, in System Preferences \> Accessibility \> Speech, to Alex. If that’s already set, uninstall all other voices. This has been shown, for one user that I know of, to work on Non-English MacOS setups.

Next Steps

Now that Emacs is running with Emacspeak, let’s learn to use it. the best way is to use the Emacs Tutorial by pressing Control + H, t. This means to hold control, press H, release both keys, and type t. This will open the Emacs tutorial, and Emacspeak will begin reading it. You can read line by line using the arrow keys, at first. as the tutorial continues, through, I encourage you to practice what is taught, beginning with reading by screens of text (commonly called pages).

When done with that, try customizing Emacspeak to your liking. Press C-H . You should have learned what that means in the Emacs Tutorial. The Mini buffer will allow you to type in a "group" to customize. Type "Emacspeak" and press RET.

You can navigate the resulting buffer with the arrow keys, RET to expand items, showing values, Tab to get to text areas or item pickers, and C-X C-S to save your changes. Press C-X K RET to close a file. This is how you customize Emacs, by using the "Custom" system. This is much easier than editing a configuration file; Custom does that for you.

What now?

First, Emacspeak may be speaking a little too slowly for you. You can speed it up by pressing C-U C-E d 3 or any other number from 1 to 0. You can set "Mac-speech-rate" in Emacspeak’s customization settings. If that is too slow for you, press C-u C-e d r, and type a number. I recommend starting around 350. You can also go into Emacspeak’s customization, and find the "TTS" subgroup, and set the TTS base, and TTS rate step, so you can easily set the amount Emacspeak increases speech rate from numbers used. For example, if the step is at 100, pressing C-u C-e d 2 will be at 200, if base is 100. If you get stuck along the path of a command, press the question mark (?). For example, if you are typing C-u C-e d, and press the question mark, you’ll get a list of commands starting with that. To get to help windows or other windows, press C-x o. To get rid of the other windows, not deleting buffers, press C-X 0. After that, you’re ready to go dive into using Emacs in the following sections.

You can learn more about Emacs by reading the Emacs Manual. You can read more about Emacspeak from the Emacspeak Manual. You can program in Python, do web developement in HTML, JavaScript, or PHP. You can write blog posts or Github pages in Markdown. You can write blogs, books, notes, get-things-done files, project planning files, and so on in Org-mode. You can do math in Calc. You can write Math and science papers in Tex-mode. You can do light web browsing with EWW. You can read RSS with Elfeed. You can read books with nov.el. You can browse files with DirEd. You can use Git with MaGit.

On the Control key

The Control key, labeled “C” in Emacs, is rather hard to keep pressing hundreds of times per day, on just about any keyboard. Luckily, the Mac, and just about every Linux distribution allows you to change it to the Capslock key. On Linux, look in the Keyboard settings of your control center. On the Mac, go to System Preferences, then Keyboard, then Modifier keys, then set Capslock as Control, press OK, and you’re done. You can still use VoiceOver with the Capslock key as well.

In Emacs for Mac, the version we downloaded in this guide, you can also change the command key to be control. This way, you have three control keys, which you can access for the greatest level of comfort.

Press C-h SPC, type “mac” without quotes, and press RET. Look for the line starting with “Mac Command Modifier:”, and press RET on the beginning of the line to “unhide” that setting, expanding it for editing. Tab until Emacspeak says “Choice is const...” There, press RET, arrow down to “Control”, press RET again, then C-x C-s to save the file, saving the customizations. You may have to restart Emacs, but then you can use Command as the Control key as well; much better.

Basic Emacs usage

When you first start Emacs, you’ll be greeted with a startup screen. It’ll say something like "Welcome to GNU Emacs, a part of the GNU / Linux operating system.". You can arrow down, or Tab, through options. Don’t worry, though; Tab normally indents, but this is not a normal editable file.

At this time, if you haven’t before, you may want to open the Emacs tutorial to familiarize yourself with its use. I encourage you to practice the lessons taught there, because from now on, I will assume that you’ve gone through them. I will go over some basic usage, to acclimate you to the difference in Emacs and Windows/Mac usage. To learn about how to move around in text, and other features, see the tutorial.

Buffers

Buffers are basically documents. I say basically, because documents can’t be used to write emails, and only blind people talk about a web document to be read because screen readers and virtual buffers. You can save buffers to files on your computer, sending them from RAM to your hard drive. You can "open" a file, having its contents put into a buffer for editing. I suspect that this is what happens with all text editors, even the new emails you create are all text in buffers.

Using Buffers

Buffers can be dealt with easily in Emacs. To make a new one, just make a new file with C-x C-f, (Control + X, then Control + F). Even if it is a file not yet on the computer, its buffer is created, and you can save it to make it official. To save a buffer to a file, press C-x C-s. This can be remembered by the following: C-x is the file command, having things to do with files, windows, and closing Emacs. C-F is find, like Control + F in Windows, or Command + F in Mac. Everyone has heard of Control + S, right?

Closing buffers, called killing them in Emacs, is C-x k. Killing buffers may sound cruel, but you must remember that the culture of the twentieth century was filled with killing, so we cannot fault the Emacs programmers for using such unsanitary language in their inventions. Rest assured that no known life forms are killed by closing a buffer... That we know of. After pressing C-x k, you’ll be asked which buffer to kill. You can press RET for the current buffer, or arrow through a list of them to kill another, and press RET to officially commit buffercide.

Switching buffers is also easy, and there are a few ways of doing it. You can open the Buffer List, which has a list of buffers and their sizes, with C-x C-b. Here, you can choose a buffer with the arrow keys, and press RET to switch to one. The Buffer List stays open, though, so be aware of that. The next way is accessed with C-x b, uses the mini buffer, a small window at the bottom of the screen, to input the name of a buffer, or use the arrow keys to switch to one using completion. This is the way I switch buffers. Choose one with RET, the mini buffer goes away, and there you are, in another buffer. The quickest, but least precise way, is to press C-Right or C-left. This switches among buffers like Alt + Tab does on Windows. If you have hundreds of buffers open, though, like T. V. Raman once claimed to have, using the C-Right method will quickly become too much effort.

Searches Can Be Interactive

Have you ever searched a GameFAQs guide, looking for that section that looked something like "9.4.2.1: Letter from Harmony", and didn’t want to type it all out into your find box, were too far down into the guide to find how it was actually spelled, but remembered "9.4"? You put that in, pressed enter a good many times, until you found that section. No? Well then, you probably have a better attention span than I do. For those of us who are not so gifted blind people, but still want that same power, there is interactive search.

Interactive search, shortened to I-search, allows one to search a buffer even while typing the search. Emacspeak plays a sound as you search, letting you know that it still has found something, then a soft crack when your search now has no results. So, say you searched for "9.4.1". You’d hear that entire line, so you’d know that it isn’t anywhere near what you’re looking for. So, you may try deleting that and trying "9.4.2". This brings you closer, so you press RET and you’re there, ready to navigate down a few lines to get to where you start.

On other operating systems, you’d have to press Control + F, or Command + F, type in your search, hit Enter or Return, and then Escape so that your screen reader actually reads what you’ve found because screen readers are actually quite unintelligent. No, the screen reader find dialog isn’t any better. Then, if you’d gotten to 9.4.9.1, you’d have to do the whole thing all over again. With Emacs, you don’t even leave the search feature.

So, how do you get to this I-search? Press C-S. There, type the search until you hear what you want. Notice that you don’t have to type a full search phrase or even word if you find what you’re looking for before then. If you have, and that’s not the occurrence of that phrase you want, press C-s again. To search backward, press C-r.

When you’ve found what you’re looking for, press RET, and you’re there. For more on searching, see the Search section of the Emacs Manual

Selecting, Cutting, Copying, and Pasting

So, you know how to type, you know how to move by character, word, and line from the tutorial, and you can even move through whole screens. You even know how to search with great power, but what about cut, copy, and paste?

Mark and Point

In Emacs, everything has a term. This term is different between Emacs and other systems. For example, consider the cursor. In Emacs, it is called "point," named from the period used to show where the cursor is in even older text editors.

"Mark" is the beginning of the selection. It is like pressing Insert + F9 in NVDA. You can "mark" a "region" of text to be selected, then act upon it. For more on Mark, see Mark in the Emacs Manual. To begin selecting, press C-SPC. Move to the place you want the region to end, and simply use the action you want to perform:

  • Delete: Deletes (kills in Emacs terms), the text in the region, and places it in the ring of text able to be pasted, or in Emacs terms, yanked.
  • C-w: cuts (kills) the text into a place where it can later be retrieved.
  • C-y: Yanks (pastes) the text from the latest kill into the buffer. Change with M-y.
  • M-w: Copies the text of the buffer into the kill ring without deleting it from the buffer, thus "copying" it.

For more information, see killing and moving text in the Emacs manual.

Quitting and leaving

If you start to press a command which you don’t mean to, or want to quit a running command, press C-g. This quits the thing you’re doing. It does not close a file, but it does cancel selection.

To close Emacs and take a break from all this for a while, press C-x C-c. If you have any unsaved files, don’t worry, you’ll be asked to save them before Emacs closes. If Emacs says there are active processes, choose to close those too, as that’s just Emacspeak.

Getting Packages

Packages are like addons, plugins, scripts, applets, gadgets, or apps. They extend the function of Emacs. You can get them through the package manager. If you want, you can even add new repositories to get packages from. To get to the package manager, press C-h p. This means "help with packages." You may here "Package refresh done. 16 packages can be upgraded; type ‘U’ to mark them for upgrading."

As you hear, 16 packages can be updated, and "Capital U" tells Emacs to upgrade them. We’ll get to how you can tell, in most cases, when to use lowercase and uppercase letters for commands later on. Press "n" to move to the next package in the list, or "p" to move backward. Press "i" to mark packaged for installing. When done, press "x" to install. You can find more keyboard commands by pressing C-h m.

Writing with Markdown

If you’re anything like me, which you probably aren’t, you eventually learn, through programs not using definition lists correctly, or aside HTML elements being mangled into plain divider elements, that Org-mode, discussed later, will not convert cleanly to Markdown. So, with the depressing knowledge that you’ll have to convert all of your courses from HTML exported by Org-mode into Markdown, and you recognize that Markdown, even with its less abundant syntax and the horror of having to use two asterisks for bolding all those hotkeys instead of one, has soundly defeated your efforts to find anything objectively better, simpler, and ubiquitous, you grudgingly come to respect markdown.

So, you resolutely learn Markdown, find that, in most circumstances, it does its job rather well, learn Markdown-mode, and you might just be coming to terms with having to do definition lists, tables, and side notes in HTML. Great. Thanks a lot, Github. But how does Emacs, with Emacspeak, help?

headings, italics, and bold

Markdown uses symbols to show formatting, like HTML, Latex, Org-mode, ASCII Doc, XML, and any other markup language. Some are easier than others, and even in Markdown, there are variations. PHP-Extra Markdown allows definition lists and tables to be made in plain, readable text, while Common Mark does not, for some reason. But you didn’t come here to read about Markdown, so I’ll let you research that on your own. I can’t spoil the blind community too much, after all. At least, I dearly hope not.

Emacs’ Markdown-mode should be built in. This section will be updated later.

Contact contributors

Devin Prater

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment