9.8.5 Working with Lisp Fragments
Emacs Lisp mode is probably the best thing to use if you are editing entire files of Emacs Lisp code, for example, if you are programming your own mode (as described in Chapter 11) or modifying an existing one. However, if you are editing "little" pieces of Lisp code (for example, making additions or modifications to your .emacs file), Emacs has more powerful features you can use that further blur the line between writing and running code.
9.8.5.1 Commands for evaluating a line of Lisp
The first of these is the command M-: (for eval-expression). This command enables you to type a one-line Lisp expression of any kind in the minibuffer; the expression is evaluated, and the result is printed in the minibuffer. This is an excellent, quick way to check the values of Emacs variables and to experiment with "internal" Emacs functions that aren't bound to keys or that require arguments. You can use the symbol completion command M-Tabwhile you are using eval-expression.
Unfortunately (or fortunately, depending on your point of view), Emacs doesn't normally let you use eval-expression. If you try pressing M-:, you will see the message loading novice ...
in the minibuffer. Then a window pops up with a message on the order of, "You didn't really mean to type that, did you?" You get three options: press Spaceto try the command only once, yto try it and enable it for future use with no questions asked, or nto do nothing.
If you want to use eval-expression, type y. This command actually results in the following line being put in your .emacs file:
(put 'eval-expression 'disabled nil)
If you are a knowledgeable Lisp programmer, you will understand that this addition sets the property disabledof the symbol eval-expressionto nil. In other words, Emacs considers certain commands to be verboten to novice users and thus allows commands to be disabled. If you want to skip this entire procedure and just use eval-expression, simply put the above line in your .emacs file yourself (make sure you include the single quotes).
Another feature that helps you exercise Emacs Lisp code is C-x C-e(for eval-last-sexp). This command runs the line of Lisp that your cursor is on and prints its value in the minibuffer. C-x C-eis handy for testing single lines of code in an Emacs Lisp file.
9.8.5.2 Using Lisp interaction mode
An even more powerful feature is Lisp interaction mode. This is the mode the default buffer *scratch*
is in. Filenames with no suffixes normally cause Emacs to go into Lisp interaction mode, though you can change this using the variable auto-mode-alist, described earlier in this chapter and in more detail in Chapter 10. You can also put any buffer in Lisp interaction mode by typing M-x lisp-interaction-mode Enter; to create an extra Lisp interaction buffer, just type C-x b(for switch-to-buffer), supply a buffer name, and put it in Lisp interaction mode.
Lisp interaction mode is identical to Emacs Lisp mode except for one important feature: C-jis bound to the command eval-print-last-sexp. This command takes the S-expression just before point, evaluates it, and prints the result in the buffer. To get the usual newline-and-indentfunctionality attached to C-jin other modes, you must press Enter, followed by Tab.
Remember that an S-expression is any syntactically valid expression in Lisp. Therefore, you can use C-jin Lisp interaction mode to check the values of variables, enter function definitions, run functions, and so on. For example, if you type auto-save-intervaland press C-j, the value of that variable (300 by default) appears. If you type a defunand press C-jafter the last right parenthesis, Emacs stores the function defined (for future invocation) and prints its name; in this case, C-jis similar to C-M-x(for eval-defun) except that the cursor must be after (as opposed to before or in the middle of) the function being defined. If you invoke a function, Emacs evaluates (runs) the expression and responds with whatever value the function returns.
C-jin Lisp interaction mode gives you an excellent way to play with, incrementally develop, and debug Emacs Lisp code, and since Emacs Lisp is "true" Lisp, it is even useful for developing some bits of code for other Lisp systems.
Chapter 10. Customizing Emacs
As you have probably noticed throughout this book, Emacs is very powerful and very flexible. You can take advantage of that power and flexibility to configure Emacs to match your work style and preferences. We'll look at several of the most common customization tasks and also look at a few resources for more in-depth coverage than we can provide here.
You can customize Emacs in three ways: using Custom, the interactive interface; using the Options menu, which is really a backdoor to Custom; and directly by adding lines of Lisp to your .emacs file. This chapter covers all three of these methods.
No matter what method you use, though, the .emacs startup file is modified. Custom modifies it for you when you save settings through that interface. The Options menu invokes Custom behind the scenes; when you choose Save Options, Custom again modifies .emacs . Throughout the book, we have been providing lines for you to add to .emacs directly so you could adjust Emacs to your preferences.
Before we get started, we should say that the very easiest way to customize Emacs is by selecting an option from the Options menu and choosing Save Options. This menu is designed to provide easy access to changing frequently used options. For example, you may not like the Toolbar and its icons, feeling that such graphical codswallop is beneath an Emacs user. You can hide the toolbar through the Show/Hide option on the Options menu. Choosing Save Options modifies .emacs so the toolbar is hidden every time you start Emacs. And if you miss the toolbar someday, you can get it back the very same way.
After describing customization methods, this chapter goes on to discuss several generic issues relating to customization, including how to change fonts and colors, modify your key bindings, set Emacs variables, find Lisp packages to load, start modes automatically based on file suffixes, and inhibit any global customization files that may be interfering with your own .emacs settings.
Emacs now ships with a quirky graphical-but-not interface that allows you to customize most aspects of Emacs without knowing the gory details. This feature, known as Custom, can be accessed by typing M-x customor by clicking the tools icon on the toolbar.
Type: M-x custom Enter

Emacs displays the startup buffer for Custom (Mac OS X).
You can move around in a given Custom screen much the way you do in any other part of Emacs. All of the basic cursor movement commands like C-nand C-pwork just as they should. But that's only part of the story in Custom. To accomplish anything useful, you need to activate special words and phrases. Those bits of text in grey boxes that look like buttons are the words and phrases in question.
Читать дальше