-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcustomize_general.html
175 lines (165 loc) · 10.7 KB
/
customize_general.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>
How to learn Emacs :: General customization
</title>
<link href='emacs.css' media='all' rel='stylesheet'>
</head>
<body>
<div id='sidebar'>
<div id='info'>
<h1>How to learn Emacs</h1>
<p>By <a href="http://david.rothlis.net">David Röthlisberger</a>.<br/>
Comments welcome at <a href="mailto:david@rothlis.net?subject=How%20to%20learn%20Emacs">david@rothlis.net</a>.<br/>
Last updated 14 Apr 2012.</p>
</div>
<div id='toc'>
<!-- Table of Contents -->
<ul>
<li><a href='howtolearn.html'>1. About this guide to Emacs</a></li>
<li><a href='why.html'>2. Why Emacs</a></li>
</ul>
<p>—Basic usage—</p>
<ul>
<li><a href='install.html'>3. Install the right Emacs</a></li>
<li><a href='tutorial.html'>4. The very basics</a></li>
<li><a href='basic_c.html'>5. Basic Unix/C workflow</a></li>
</ul>
<p>—Basic customisation—</p>
<ul>
<li><a href='customize_c.html'>6. cc-mode customization</a></li>
<li><a href='customize_colors.html'>7. Fix that awful color scheme</a></li>
<li class='current'>8. General customization
<ul>
<li><a href="#ido">ido-mode</a></li>
<li><a href="#minimalism">Minimalism</a></li>
<li><a href="#elisp">Navigating Emacs Lisp</a></li>
<li><a href="#shell">shell</a></li>
<li><a href="#other">Other ideas</a></li>
</ul>
</li>
</ul>
<p>—Miscellaneous—</p>
<ul>
<li><a href='info.html'>9. Info documentation</a></li>
<li><a href='contribute_emacs.html'>10. Contributing to Emacs</a></li>
</ul>
<p>—Appendices—</p>
<ul>
<li><a href='ergonomics.html'>A. Ergonomics</a></li>
<li><a href='osx.html'>B. OS X</a></li>
<li><a href='contribute_guide.html'>C. Contributing to this guide</a></li>
<li><a href='glossary.html'>D. Glossary</a></li>
</ul>
</div>
<p>Copyright © 2012 <a href="http://david.rothlis.net">David Röthlisberger</a>.<br/>
This guide is released under the<br/>
<a rel="license" href="http://www.gnu.org/copyleft/fdl.html">GNU
Free Documentation License</a>.</p>
</div>
<div id='content2'>
<!-- Contents -->
<h1>General customization</h1>
<h2 id='ido'>ido-mode</h2>
<p>Other editors and IDEs have nice tree views of directories and files, as well
as tabs for switching between <a class='glossary' href='glossary.html#buffers'>buffers</a>. Emacs does have a rather ugly tree
view—<code><a class='glossary' href='glossary.html#keys'>M-x speedbar</a></code> if you want to see <em>how</em> ugly—but the real Emacs answer
to navigating large projects is <code>ido-mode</code>.</p>
<div class='figure'>
<div class='titlebar'><p>init.el</p></div>
<div class='window'>(ido-mode 1)
 </div>
<div class='modeline'>-U:--- <b>init.el</b> All L17 (Emacs-Lisp)----------------------------------------</div>
<div class='echoarea'><p><span class="prompt">Find file: .../readline/</span>ex<span class="cursor">{</span><span class="ido-first-match">examples/</span> | histexpand.c | text.c}</p></div>
</div>
<p><code>ido-mode</code> remaps the keybindings for <code>find-file</code> and <code>switch-to-buffer</code> to
more powerful versions of the same. You’ll only need to type a few letters of
the file or <a class='glossary' href='glossary.html#buffers'>buffer</a> name (not necessarily matching the beginning of the name,
and not necessarily adjacent letters). A list of matches, in most-recently-used
order, is displayed in the <a class='glossary' href='glossary.html#minibuffer'>minibuffer</a>; <code><right></code> and <code><left></code> (or <code><a class='glossary' href='glossary.html#keys'>C-s</a></code> and
<code><a class='glossary' href='glossary.html#keys'>C-r</a></code>) navigate amongst the matches. If nothing matches, after a brief
(and configurable) pause <code>ido</code> can search previously-used directories.</p>
<p>Because <code>RET</code> opens the first matching file, to open a directory you’ll have to
use <code><a class='glossary' href='glossary.html#keys'>C-d</a></code>. Or you could use <code><a class='glossary' href='glossary.html#keys'>C-f</a></code> (at the <code>ido-find-file</code> prompt) to drop into
normal <code>find-file</code>.</p>
<p><code>ido</code> ships with Emacs but isn’t present at all in the manual; read the online
help for the <code>ido-find-file</code> command. For more details and configuration
instructions, use <code><a class='glossary' href='glossary.html#keys'>C-h f ido-mode</a></code> to find its elisp implementation, and read
the long comment at the top of the elisp file.</p>
<p>Emacs users tend to leave <a class='glossary' href='glossary.html#buffers'>buffers</a> open when they have finished with them, and
after a while have hundreds of <a class='glossary' href='glossary.html#buffers'>buffers</a> open so <code>ido-switch-buffer</code> effectively
becomes “find file in project”.</p>
<p>To save your list of open files between invocations of Emacs, or to manage
separate sets of open files (if you’re working on several projects in
parallel), see <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Saving-Emacs-Sessions.html">“Saving Emacs Sessions”</a>
in the Emacs manual.</p>
<h2 id='minimalism'>Minimalism</h2>
<p>To make the most of your screen space, consider disabling the toolbar and
scrollbars:</p>
<div class='titlebar'><p>init.el</p></div>
<div class='window'>(tool-bar-mode -1)
(scroll-bar-mode -1)
</div>
<p>Similarly, you can disable the menu bar with <code>(menu-bar-mode -1)</code>, though I
find the menu bar useful for discovering Emacs features; major and <a class='glossary' href='glossary.html#minormode'>minor modes</a>
often add their own menu to the menu bar. As previously noted, you certainly
shouldn’t disable the menu bar on OS X; if you’d like to share your Emacs init
file among several environments you could conditionally disable <code>menu-bar-mode</code>
based on the value of variables <code>system-type</code> and <code>window-system</code>.</p>
<p>Some commands like <code>revert-buffer</code> force you to confirm by typing <code>yes</code>; it
would be nice to just type <code>y</code>. If you look at the definition of
<code>revert-buffer</code> you’ll find it calls <code>yes-or-no-p</code>, which we can redefine to
call <code>y-or-n-p</code> instead:</p>
<div class='window'>(<span class="keyword">defun</span> <span class="function-name">yes-or-no-p</span> (prompt)
 (y-or-n-p prompt))
</div>
<p>Or more simply:</p>
<div class='window'>(<span class="keyword">defalias</span> '<span class="function-name">yes-or-no-p</span> 'y-or-n-p)
</div>
<p>Another thing everyone does the second they install Emacs is to prevent the
creation of a “<code>~</code>”-suffixed backup file on every save:</p>
<div class='window'>(setq make-backup-files nil)
</div>
<p>Rely on your version control system for backups instead.</p>
<h2 id='elisp'>Navigating Emacs Lisp</h2>
<p>In the last couple of chapters I have encouraged you to discover Emacs
functionality by studying the elisp code directly. To make the job easier we
already saw <code>show-paren-mode</code> and <code>eldoc-mode</code>; let’s enable them globally
because they’re useful in other programming languages too.</p>
<div class='window'>(show-paren-mode 1)
(eldoc-mode 1)
</div>
<p>We’ll also re-bind <code>M-.</code> from its default <code>find-tag</code> to
<code>find-function-at-point</code>, but only for elisp files, for which you don’t need a
tags table because Emacs already knows all about every elisp function it has
loaded.</p>
<div class='window'>(define-key emacs-lisp-mode-map
 (kbd <span class="string">"M-."</span>) 'find-function-at-point)
</div>
<p>If you plan on <em>writing</em> a lot of Lisp, <code>paredit-mode</code> is great for always
keeping your parentheses balanced, and for moving whole forms around when
refactoring—but it does take some getting used to.</p>
<h2 id='shell'>shell</h2>
<p>If you ever tried to run a program like git under <code><a class='glossary' href='glossary.html#keys'>M-x shell</a></code>, you will have
come across the warning “terminal is not fully functional” followed by unusable
behavior. This is because git sends its output through a pager (probably
<code>less</code>), which requires a real terminal emulator.</p>
<p>Setting the <code>PAGER</code> environment variable to <code>/bin/cat</code> (but only inside Emacs)
solves this problem:</p>
<div class='titlebar'><p>init.el</p></div>
<div class='window'>(setenv <span class="string">"PAGER"</span> <span class="string">"/bin/cat"</span>)
</div>
<p>This also allows you to use <code>git grep</code> from <code><a class='glossary' href='glossary.html#keys'>M-x grep</a></code>.</p>
<p>Make sure you don’t override <code>PAGER</code> in your <code>~/.gitconfig</code> file or the
<code>GIT_PAGER</code> environment variable (and <code>MANPAGER</code> for the <code>man</code> program, etc).</p>
<p>If you need to make customizations in your <code>~/.bashrc</code> file (or the
corresponding file for your shell of choice) you can test for the environment
variable <code>INSIDE_EMACS</code>. To configure which shell Emacs uses, see <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Interactive-Shell.html">the manual</a>.</p>
<h2 id='other'>Other ideas</h2>
<p>Other customizations you might like to make are covered by the Emacs manual:</p>
<ul>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Minor-Modes.html">Minor Modes</a>.</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Uniquify.html">Making Buffer Names Unique</a>.</li>
<li><a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Cursor-Display.html">Displaying The Cursor</a>
(in particular <code>global-hl-line-mode</code>).</li>
</ul>
<p>For further inspiration you might want to look at other people’s init files,
widely available on the <a href="http://www.emacswiki.org/emacs/CategoryDotEmacs">Emacs wiki</a> and on the <a href="http://sites.google.com/site/steveyegge2/my-dot-emacs-file">internet at
large</a>. Some of
the customizations I have presented here came from the <a href="http://github.com/technomancy/emacs-starter-kit">Emacs Starter Kit</a>, a collection of elisp files
to provide “a more pleasant set of defaults than you get normally with Emacs”.</p>
<!-- Contents -->
<p class='next'><a rel='next' href='info.html'>Next: Info documentation</a></p>
</div>
</body>
</html>