Книга: Learning GNU Emacs, 3rd Edition
10.5 Setting Emacs Variables
10.5 Setting Emacs Variables
Now we will get into ways to affect Emacs' behavior—not just its user interface. The easiest way to do so is by setting variables that control various things. We already saw examples of this like auto-save-interval in Chapter 2. To set the value of a variable, use the setq function in your .emacs, as in:
(setq auto-save-interval 800)
Although auto-save-interval takes an integer (number) value, many Emacs variables take true or false values, called Boolean in computer parlance. In Emacs Lisp, t is the true value, and nil is the false value, although in most cases, anything other than nil is taken to mean true. Emacs variables can take other types of values, and here is how to specify them:
• Strings of characters are surrounded by double quotes. We saw examples of strings in the arguments to key binding commands earlier in this chapter.
• Characters are specified like strings but with a ? preceding them, and they are not surrounded by double quotes. Thus, ?x and ?C-c are character values x and C-c, respectively.
• Symbols are given by a single quote followed by a symbol name—for example, 'never (see the variable version-control in Appendix A).
A list of useful Emacs variables, grouped by category, appears in Appendix A, with descriptions and default values. Emacs has more than 2,500 variables—many more than are covered in Appendix A. If there is something about Emacs that you want to customize, a variable probably controls the feature (especially if what you want to change involves a number or a true-or-false condition). To find out whether any variables relate to what you want to do, you can use the apropos-variable command described in Chapter 14 to look for variables and their descriptions.
Several Emacs variables can have different values for each buffer (local values, in Emacs parlance) as well as a default value. Such variables assume their default values in buffers where the local values are not specified. A common example is starting a new text document. The local value for the left-margin variable has not been set, so Emacs uses the default value for left-margin. You can change the local value in this buffer if you like. But start a new document in a new buffer and you'll find that left-margin is back to the default value—because the second buffer's local value has not been set.
As you might expect, you can set both the default and local values of such variables. When you set the value of a variable such as left-margin or case-fold-search with setq, you are actually setting the local value. The way to set default values is to use setq-default instead of setq, as in:
(setq-default left-margin 4)
Unfortunately, there is no general way to tell whether a variable has just one global value or has default and local values (except, of course, by looking at the Lisp code for the mode). Therefore the best strategy is to use a plain setq, unless you find from experience that a particular variable doesn't seem to take on the value you setq it to—in which case you should use setq-default. For example, if you put the line:
(setq case-fold-search nil)
in your .emacs file, you will find that Emacs still ignores case differences in search commands as if this variable were still t; instead, you should use setq-default.
- Chapter 10. Customizing Emacs
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- Setting up default policies
- Setting up user specified chains in the filter table
- Для чего нужны папки Windows, Documents and Settings, Program Files и Temp?
- После переустановки Windows нет доступа к папке Мои документы или нельзя удалить оставшуюся от старой системы папку Docu...
- 10.2 Modifying the .emacs File Directly
- CHAPTER 22 Setting Up a Proxy Server
- Setting the Time Zone
- Using Environment Variables
- Working with emacs
- Setting Up an SSH Server