Emacs for Study Part 1: Text (Scripture) Study

Table of Contents

At long last I’m producing the next of my “NOn-Programmer’s Emacs” (NOPE) editions. This post is companion to a Youtube video in the NoPE series. We’re looking at using Emacs (and in particular, Orgmode) for studying texts; in this episode of the series, we’ll be using as our example texts the LDS scriptures (official site) and some related texts. I’ve made the base files I use (org and plain-text of the scriptures) available here:

LDS Scriptures in Plain Text (Org)

I have found a variety of tools for effective study in emacs, which I will cover in three sections here:

  1. Reading
  2. Complex Views
  3. Marking Text

1 Reading

Once you have a text file in Emacs, there are a variety of tools you can use for the reading itself. The tools in this section are all generic so will work in any mode on any type of text file.

1.1 Display Theme

Themes control the general color scheme and font size in emacs. For me, the decision is mostly between whether I want a black background or a white, although there are a variety of themes available for different tastes. For instance, I prefer high-contrast use of emacs, but some people find softer contrast to be easier on the eyes for long reading.

Commands:

  • Enable a Theme : M-x load-theme
  • Disable a Theme : M-x disable-theme

1.2 Font-size

Sometimes a larger font can be a life-saver when the eyes are tired; other times, it’s useful to shrink things as you scan a whole page for some term you can’t search for.

Commands:

  • Text Larger : C-x C-=
  • Text Smaller : C-x C- -
  • Text to Normal : C-x C-0

1.3 Line truncation, Line Highlighting & Screen Size

Something I use every day is the ability to easily enable/disable line-wrapping, since reading is best if lines are wrapped but sometimes scanning and code are better with truncated lines. I use it so often that I’ve configured it as a single keystroke (the f5 key). I’ve bound f6 to highlight whatever line my cursor is on, which has most use in technical documents but could also be useful for certain readings. Both of these toggles are bound with the following lines:

(global-set-key (kbd "<f5>") 'toggle-truncate-lines) ;; Linewrap?
(global-set-key (kbd "<f6>") 'global-hl-line-mode) ;; Highlight current line

Finally one of the extremely useful features of emacs is the ability to incrementally search. This means that as you type the thing for which to search, it matches as it goes; and repeating the search key (bound by default to C-s (forward) and C-r (backward) you move to the next match. These are usually to be used instead of moving forward and backward, up and down by one character at a time (unless you are very close to the target text).

1.5 Bookmarks

Out-of-the-box emacs offers a fully functional bookmarking facility: it will save your document and your position in the document, and in one keystroke it will update it to your current position. If you are working through something lengthy or have documents you return to often, this is a must-use. If it appeals to you, there is the add-on package Bookmark Plus that supports large-scale bookmarking (hundreds) and allows bookmark tagging (as in your favorite browsers).

  • bookmark-set : C-x r m (set or update a bookmark for the current document)
  • bookmark-bmenu-list : C-x r l (lists all your bookmarks and allows you to edit/go-to them)
  • bookmark-jump : C-x r b (quickly jumps to a bookmark of your specification, without stopping at the list)

1.6 Window Size

Because I work on a laptop most of the time, I usually use full-screen view for my emacs window. but when I’m reading this is too wide for comfort; with line-wrapping enabled, shrinking the screen is second nature. The actual shortcut key for this will depend on your operating system (it’s not an emacs command). I configure my KDE Linux to match Gnome default bindings so Alt+Space drops the window context menu and “X” toggles maximization. On Windows, the menu is dropped by using the menu key (the one opposite the Windows key). Of course, this is only necessary if I’m not using split screens, when I use a full-screen view (see the next section).

2 Advanced Reading

2.1 View Mode

When you know you’ll only be reading a document and will not need to edit, enabling view-mode is a useful way of simplifying navigation. In view mode, SPACE moves a page down, BACKSPACE moves a page up, ENTER moves the page single line down and y moves a single line up. In addition, searches are shortcut to the single keys s (forward search) and r (backward search); all of this amounts to easy, swift reading navigation.

  • view-mode

  • SPACE / BACKSPACE

  • ENTER / y

  • s / r

I find that I like to use view mode with read-only documents so I’ve combined their keys (C-x C-q) with the following code, which also causes read-only docs to start in view mode by default:

(global-set-key (kbd "C-x C-q") 'view-mode)
(setq view-read-only t)

2.2 Narrowing & Widening

If you are in a large document and want to work in just a single area–for example, you want your searches to be bounded to just one chapter of the Old Testament–narrowing your view is a powerful option. Simply select an area of text and use the “narrow” command to make the rest of the page effectively disappear; now all find-and-replace, search, and navigation commands will be constrained to this area instead of the whole document. Don’t worry; the rest of the document remains untouched by anything you do, and saving will not cause anything to be deleted. This can be useful in conjunction with indirect buffers (next).

  • narrow-to-region : C-x n n
  • widen : C-x n w (this undoes the narrowing)

2.3 Indirect buffers: changing font sizes and reading options

When you narrow to a region, all changes effect every frame viewing that buffer. This means that if you want to have another window open in another place of the same file you’re out of luck, or if you change font-size it will effect everything viewing the buffer. The solution to this is the indirect buffer, which opens a copy of something that will share all edits (any permanent changes effect the true file) but can be viewed differently: in orgmode, you can collapse separate areas; in any mode you can view different areas; and you can change the font-size independently of the original. However, saving still saves to the original file, and anything you type will show up in both views of the file. Check the video; it’s pretty handy.

  • clone-indirect-buffer-other-window : C-x 4 c

You can kill the indirect buffer window any time in the usual way (such as C-x k).

2.4 Vertical Split screen for comparison

Emacs makes it very easy to split screens either horizontally or vertically any number of times, which allows some creative customization of your screen real estate. For scripture study, the obvious use is for side-by-side comparison. For example, in the image we are comparing one of the “Isaiah Chapters” of 2 Nephi with the original in Isaiah.

  • split-window-right : C-x 3
  • delete-window : C-x 0

With all the split-window commands you can close the current window (as long as it’s not the last one) with C-x 0.

2.5 Horizontal Split screen for place-keeping

Often I wonder to myself, “what did that other part say?” and I want to search for another section (or even another file), but I don’t want to lose my current spot. Splitting horizontally is ideal for this; I use it as a sort of cognitive bookmark to I can see where I was a moment ago. In some cases vertical splitting might be just as good, but usually it’s less disorienting to split horizontally where I don’t need to worry about the text-wrap changing.

  • split-window-below : C-x 2
  • enlarge-window : C-x \^
  • balance-windows : C-x +

All windows can be increased manually via the enlarge-window command, which can take arguments to change size by greater (or negative) amounts. This is one of the few cases, though, where it’s often easier to just use the mouse to drag the window borders where you want them, if you need a different size. The balance-windows command restores the window alignment to an even split.

If you feel a need to use sophisticated window setups and don’t want to lose them, you can look into winner mode, which is included with emacs but needs to be enabled, and allows you to restore windows.

3 Marking Text

The above are some nice features, but perhaps the real reason you’d want to do studying in emacs is for the ability to mark and edit text (emacs is, after all, a text editor). Unlike the previous sections, which introduce concepts and commands useful in any kind of document, this section is going to draw on the features of the inimitable orgmode (included with emacs). I’ll keep it simple and just introduce the three primary text editing features I use.

3.1 Orgmode Text Formatting

Once in an orgmode document (either a document named .org or you’ve used the org-mode command) you have a small but practical range of six formatting functions: asterisk, underline, italic, strikethrough, code, squiggly. While you may miss options for colored highlighting at first (such as provided by many PDF programs or scripture apps), disciplined use will find that these options convey most of the information you are likely to need for an at-a-glance view. More importantly, they export gracefully, meaning that if you use org to generate HTML, Word documents, LaTeX code, or any of its other capabilities, they will convert to something equivalent. Since orgmode is built around plain text you can either start and end the text in question with whatever formatting symbol you want (enclose it in asterisks to make the whole passage bold), or execute org-emphasize and select the option from a list.

  • org-emphasize : C-c C-x C-f

3.2 Adding Footnotes

The reason those six formatting options are usually sufficient is that orgmode makes it simple to insert linking footnotes containing any more verbose statements you care to include.1

  • org-footnote-action : C-c C-x f (not to be confused with org-emphasize, where you hold the CTRL key through the whole sequence)

The footnote-action command will insert a footnote at point and take you to where you can fill it in. Issue the command again and it will return you to where you came from. If you are on an already existing footnote, it will jump you back and forth to and from the definition. If you use a prefix with it, it will offer you a menu of options.

Related to footnotes, orgmode has full support for links. These can be links to sections of a file, emails (if you use emacs for email), files on your computer, or websites/URLs. This makes the orgmode notes a consolidated place for anything you need. I use the recommended (but not pre-installed) shortcut for creating links, which works in any buffer (not just org) to create a link, and can than be inserted into org files.

  • org-store-link : C-c l (works in any type of emacs window once you set it globally, below)
  • org-insert-link : C-c C-l Inserts the link into an org file, prompting for a name.

To configure org-store-link so that it works everywhere with the C-c l sequence, put the following into your init file:

(global-set-key (kbd "C-c l") 'org-store-link)

3.4 Orgmode Inline Images

In the video I showed how to add an image to an org file and display it inline. This is a nifty feature that will come into its own in the next video on academic/research reading, but it’s handy in any number of cases. In an orgmode buffer, it a link is structured as follows:

[[file:PATH/TO/IMAGE/image.gif][display text]]

And that will create a link like you see on any web page. However, if you do the same without any display text, you can then use org-toggle-inline-images (which is set to C-x C-v C-v by default) and display that image itself in the buffer.

[[file:PATH/TO/IMAGE/image.gif]]

4 Conclusion

This concludes this reference post on reading and studying with Emacs. Like all emacs users, I’m always open to suggestions and other tricks of the trade, so feel free to comment below with tips, suggestions, and questions. Enjoy! #EmacsAllTheThings

Footnotes

1 Here is an example footnote.

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist