TranslateProject/sources/tech/20240115 Emacs for writers.md
DarkSun 2aa146c886 选题[tech]: 20240115 Emacs for writers
sources/tech/20240115 Emacs for writers.md
2024-01-16 05:03:27 +08:00

11 KiB
Raw Permalink Blame History

Emacs for writers

Photo by Christin Hume on Unsplash

This is an article about my journey to finding and configuring Emacs as a writers text editor and the results of my journey.

The journey begins

Sometimes, being a computer user can feel somewhat like being a treasure hunter. Think about it: youre on a quest to find that one application that perfectly suits your needs. You start your search, seeking the treasure map on some website or forum that will point you to the X marking the spot. When you finally find it, you feel like youve struck gold. This is how I felt when I discovered GNU Emacs and started using it as a journalists tool, as opposed to a programming tool or for any other task it is capable of.

Continuing with the treasure hunting parable: the path through the jungle was neither easy nor short. My goal was to find a distraction-free text editor or word processor that would work on Linux. This was several years ago, and the selection was not that extensive, even though the distraction-free trend was starting to gain momentum. There were options like Pyroom (still available today), FocusWriter (still actively developed), and AbiWord, which has a useful full-screen mode. Id stick with one or the other for a month or two, but eventually, Id encounter some limitations. I also tried using old programs like Word Perfect and WordStar in an emulated environment. It wasnt a great experience because they lacked support for Unicode, which caused additional problems with different code pages.

Then the discovery: GNU Emacs dnf install emacs. This command will install the entire package, along with the default GTK version of the software.

Unlocking Potentials

I remember seeing a screenshot somewhere and liking the simplicity. However, opening this treasure chest was far from easy. Emacs is, in many ways, idiosyncratic — its logic predates many modern editors and word processors. They warned me: the learning curve is steep, but once you get there, youll be hooked. And so it went. Trying to unlock its potential with all the shortcut combinations often felt like being a skilled lockpicker. But eventually, it clicked.

Modes

Emacs, when you first open it, isnt particularly useful for writing. Its essentially just a simple text editor with some rather intricate shortcut combinations. The magic happens in Emacs modes, and there are many to choose from. That is how you can customize Emacs to dance to your tune. Understanding the concept of modes is crucial. There are major modes and minor modes. Some are included by default and others require installation. A major mode determines the editing behavior, a minor mode is an optional feature which you can turn on or off and is not necessarily specific to a type of file.

Packages and Repositories

Emacs also has its own packages and repositories, some of which are available as packages in Fedora repositories, as well. However, enabling third-party repositories inside Emacs is often necessary. MELPA is one of the most commonly used ones. Instructions for its use are found at MELPAs Getting Started page.

Visual-line-mode

To make Emacs suitable for writing articles and books, I had to familiarize myself with several modes. Lets start with visual-line-mode. This mode is available by default and serves as a line-wrapping feature that essentially turns on word wrapping.

You can activate any major or minor mode by pressing M-x (usually ALT + x ) and then typing the name of the mode, in this case, visual-line-mode. Hitting Return completes the action and word wrapping is immediately enabled.

Spelling

Spelling is essential too, and Emacs offers a flyspell-mode. You can change the dictionary at any time by using ispell-change-dictionary , for example. You can find more information about the capabilities of FlySpell on EmacsWikis FlySpell page.

Counting

Character and word count are also crucial pieces of information for every writer. wc-mode can be your ally; you can access it on GitHub. Its a minor mode that provides a wc function and adds live word, line, and character counts to the modeline. Additionally, users can set specific goals for adding or deleting words.

Configuration

By this point, Emacs has become a respectable tool for writing, but we can continue to enhance its capabilities.

I personally dislike the shape of modern computer screens for writing preferring narrower margins for text. Emacs can be configured to accommodate this. (I cant recall the source for this particular recipe, probably from Stack Overflow.)

But before we dive into the code there is another essential aspect of Emacs we have to understand: its configuration file. Traditionally, /.emacs serves as the init file, but Emacs also looks at /.emacs.el , /.emacs.d/init.el , and /.config/emacs/init.el. These configuration file enables us to customize how Emacs functions to our preferences.

Without delving too deeply into the technical aspects, suffice it to say that we can specify which modes should start automatically and which minor modes should be used with a major mode. Emacs uses hooks for this, and you can see how it works by checking out my init.el file (see below). This means that we can set up Emacs so that word count is always displayed when we open a text file, or we can start flyspell every time we work on it.

If theres something outside of the available modes, it can be added to the configuration file. This is the case with the margins. Adding the following to the init.el file sets the margins and assigns the F5 key to toggle the margins on or off:


    (defun my-set-margins ()
    "Set margins in current buffer."
    (setq left-margin-width 1)
    (setq right-margin-width 1))


    (add-hook 'text-mode-hook 'my-set-margins)


    (defun my-toggle-margins ()
    "Set margins in current buffer."
    (interactive)
    (if (or (> left-margin-width 0) (> right-margin-width 0))
    (progn
    (setq left-margin-width 0)
    (setq right-margin-width 0)
    (set-window-buffer (selected-window) (current-buffer)))
    (setq left-margin-width 26)
    (setq right-margin-width 26)
    (set-window-buffer (selected-window) (current-buffer))))


    (global-set-key [f5] 'my-toggle-margins)

One can also customize typographical punctuation marks. More information on this is available at Emacswiki.

You can even make every keypress sound like an old typewriter using the selectric-mode.

Keystrokes and short cuts

Now, we will delve into some intriguing details that showcase the flexibility of Emacs.

Buffers

Emacs also has its special buffer (the text you are editing in Emacs resides in an object called a buffer), where you can quickly jot down a thought, fact, or reminder. As you write, this can be very helpful. All notes can be saved in a separate file later. You can navigate between all the open buffers by pressing Ctrl + left arrow or Ctrl + right arrow.

Viewing other files/web pages

You can easily open other files, or browse the web with the built-in EWW browser ( Alt + x EWW ). Its essentially a text browser, somewhat like Lynx. It provides just what you need to check something on the web. Its so much more convenient to do all of this within Emacs itself rather than constantly switching to the systems default browser. Once you get used to it, the mouse is rarely used in Emacs.

Split screens

Shortcuts, such as Ctrl + x 3 (meaning you have to press Ctrl and x together and then 3 ), are available for use at any time. This particular shortcut splits the screen vertically into two halves, allowing you to view two different files simultaneously or scroll through the same one. Ctrl + x 2 can split the screen horizontally, and you can do this multiple times, opening many different buffers.

Keystrokes for undo, cut, and paste

Ctrl + x u is undo, Ctrl + space marks the beginning and end of a selection, somewhat like WordStar. This is one of the things I love most when writing in Emacs. Ctrl + w cuts the text, Alt + w copies it, and Ctrl + y pastes it. Ctrl + x + Ctrl + f opens a file. I did mentioned that Emacs has some interesting quirks?

There is much more

You can change the colors and themes to your liking, adjust the default font, and save your preferences. Sometimes I like to use old classical green or orange themes and change the font to CGA or VGA. Its easy to do and find; look it up.

At times, it may seem like there are no limits to customizing Emacs. What it offers is truly remarkable.

For me, I believe Ive found the perfect tool for writing. Some of the reasons are mentioned above, but there are many more.

Save that configuration

Before concluding, theres one more advantage to mention. When you find that perfect configuration file, you can simply copy it to other computers you use, and when you switch to the new one, youll have the Emacs setup you want immediately available.

Finally…

If George R. R. Martin, the author of the popular A Song of Ice and Fire series of books (which inspired the Game of Thrones TV series), decides to move away from WordStar, which he is reportedly still using, I would recommend Emacs to him. Someone else may need to configure it for him initially, but afterward, he would feel right at home. There is even a wordstar-mode if he wishes to stick to some of the WordStaresque shortcuts.

Why some avid writers, such as me, prefer the old-fashioned look of the editor is probably something another celebrity, famous TV-psychiatrist Frasier, might answer, but we are around. And when we find that perfect tool, it really feels like finding a real treasure.

P.S.

Post Scriptum: writing this article I stumbled upon this excellent resource should you like to dive into the depths of writing on Emacs. Highly recommended.


via: https://fedoramagazine.org/emacs-for-writers/

作者:odisej 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出