2.7. Making Emacs Work the Way You WantIf you've been reading straight through this book, you may have started a list of things you'd like to change about Emacs, such as
We're going to tell you how to give Emacs the to-do list, a list of options to
The
.emacs
file consists of Lisp statements. If you're not a Lisp programmer, you can think of each line as an incantation that
Emacs now has another way to handle customization: an interactive interface called Custom that
When you want to add a line to your .emacs file directly, take these steps:
If you make a minor typing mistake (such as
What if you make a change that
2.7.1 Hiding the Toolbar
New users may find the toolbar helpful. Others may not. It's easy to hide it by selecting Options
When Emacs sets options for you through Custom (and this is what it is doing even when you use the Options menu), it writes your
.emacs
file. If you already have a
.emacs
file, it appends to it. Custom essentially groups all of its settings in one part of the file, and it is commented to
(custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(tool-bar-mode nil nil (tool-bar))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. )
This may seem a bit bulky, but as we'll see in the
2.7.2 Turning On CUA Mode for C-x, C-c, and C-v to Cut, Copy, and PasteIf you're new to Emacs, you might be used to the Common User Access (CUA) conventions for cutting, copying, and pasting, C-x , C-c , and C-v respectively. You might reach for C-z for undo. CUA mode was once an add-on mode that you had to install separately, but it became so popular that it is now part of Emacs. It's coded in a clever way that doesn't interfere with Emacs keystrokes that are prefixed with C-x and C-c . Details on CUA mode can be found in Chapter 13.
You can turn this feature on through the Options menu to try it out. Simply choose Options
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'
(cua-mode t nil (cua-base))
'(tool-bar-mode nil nil (tool-bar)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
Interestingly, Emacs happily writes the
.emacs
file even if it is open at the time. You can watch Emacs change the file if you have it
2.7.3 Turning On Text Mode and Auto-Fill Mode AutomaticallyTo make text mode the default major mode and start auto-fill mode automatically each time you enter Emacs, add these lines to your .emacs file: (setq default-major-mode 'text-mode) (add-hook 'text-mode-hook 'turn-on-auto-fill)
The first line
If you prefer refill mode, replace the second line of code with this line: (add-hook 'text-mode-hook (lambda ( ) (refill-mode 1))) 2.7.4 Remapping KeysAnother major use of the .emacs file is to redefine things about Emacs that irritate you. You may have ergonomic concerns about Emacs; more than one person has aggravated carpal tunnel syndrome using the default bindings. You may simply be used to reaching for certain keys for certain functions and would rather change Emacs than your habits. Whatever the case, this section gives a brief introduction to key remapping; for more details, see Chapter 10.
If you use the default bindings (rather than CUA mode), you may use
C-x u
for undo.
[10]
(Undo is such a common command that it's easy to type
C-x C-u
by mistake when you undo repeatedly. Unfortunately,
C-x C-u
is a disabled command for
If you don't anticipate a big need for upcasing
(define-key global-map "\C-x\C-u" 'undo) After making this change, typing C-x C-u runs undo, just as C-x u does.
Emacs customization is extremely powerful, and you can make Emacs work just the way you want it to. A far more
The next chapter covers topics such as the many searches
2.7.5 Problems You May Encounter
|