summaryrefslogtreecommitdiff
path: root/slackbook/html/emacs-modes.html
blob: ed22a3543efd59f8d7d1eb1ae8ad5e0ecef45fd4 (plain)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>Modes</title>
<meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" />
<link rel="HOME" title="Slackware Linux Essentials" href="index.html" />
<link rel="UP" title="Emacs" href="emacs.html" />
<link rel="PREVIOUS" title="Buffers" href="emacs-buffers.html" />
<link rel="NEXT" title="Basic Editing" href="emacs-basic-editing.html" />
<link rel="STYLESHEET" type="text/css" href="docbook.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"
alink="#0000FF">
<div class="NAVHEADER">
<table summary="Header navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th colspan="3" align="center">Slackware Linux Essentials</th>
</tr>

<tr>
<td width="10%" align="left" valign="bottom"><a href="emacs-buffers.html"
accesskey="P">Prev</a></td>
<td width="80%" align="center" valign="bottom">Chapter 17 Emacs</td>
<td width="10%" align="right" valign="bottom"><a href="emacs-basic-editing.html"
accesskey="N">Next</a></td>
</tr>
</table>

<hr align="LEFT" width="100%" />
</div>

<div class="SECT1">
<h1 class="SECT1"><a id="EMACS-MODES" name="EMACS-MODES">17.3 Modes</a></h1>

<p>Every buffer in Emacs has an associated mode. This mode is very different from the
idea of modes in <tt class="COMMAND">vi</tt>: a mode tells you what kind of buffer you
are in. For example, there is text-mode for normal text files, but there are also modes
such as c-mode for editing C programs, sh-mode for editing shell scripts, latex-mode for
editing <b class="APPLICATION">LaTeX</b> files, mail-mode for editing email and news
messages, etc. A mode provides special customizations and functionality that is useful
for the kind of file you are editing. It is even possible for a mode to redefine keys and
key commands. For example, in Text mode, the Tab key simply jumps to the next tab stop,
but in many programming language modes, the <b class="KEYCAP">Tab</b> key indents the
current line according to the depth of the block that line is in.</p>

<p>The modes mentioned above are called major modes. Each buffer has exactly one major
mode. Additionally, a buffer can have one or more minor modes. A minor mode provides
additional features that may be useful for certain editing tasks. For example, if you hit
the <b class="KEYCAP">INSERT</b> key, you invoke overwrite-mode, which does what you'd
expect. There is also an auto-fill-mode, which is handy in combination with text-mode or
latex-mode: it causes each line that you type to be automatically wrapped once the line
reaches a certain number of characters. Without auto-fill-mode, you have to type <b
class="KEYCAP">M</b>-<b class="KEYCAP">q</b> to fill out a paragraph. (Which you can also
use to reformat a paragraph after you've edited some text in it and it is no longer
nicely filled out.)</p>

<div class="SECT2">
<h2 class="SECT2"><a id="EMACS-OPENING-FILES" name="EMACS-OPENING-FILES">17.3.1 Opening
files</a></h2>

<p>To open a file in Emacs, type</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<kbd class="USERINPUT">C-x C-f</kbd>
</pre>
</td>
</tr>
</table>

<p>Emacs will ask you for the name of the file, filling in some default path for you
(which is usually <tt class="FILENAME">~/</tt> ). After you type the filename (you can
use <b class="KEYCAP">Tab</b> completion) and hit <b class="KEYCAP">ENTER</b> , Emacs
will open the file in a new buffer and display that buffer on the screen.</p>

<div class="NOTE">
<table class="NOTE" width="100%" border="0">
<tr>
<td width="25" align="CENTER" valign="TOP"><img src="./imagelib/admon/note.png"
hspace="5" alt="Note" /></td>
<td align="LEFT" valign="TOP">
<p>Emacs will automatically create a new buffer, it will not load the file into the
current buffer.</p>
</td>
</tr>
</table>
</div>

<p>In order to create a new file in emacs, you cannot just go typing right away. You
first have to create a buffer for it, and come up with a filename. You do this by typing
<b class="KEYCAP">C</b>-<b class="KEYCAP">x</b> <b class="KEYCAP">C</b>-<b
class="KEYCAP">f</b> and typing a filename, just as if you were opening an existing file.
Emacs will notice that the file you typed doesn't exist, and will create a new buffer and
report &#8220;(New file)&#8221; in the minibuffer.</p>

<p>When you type <b class="KEYCAP">C</b>-<b class="KEYCAP">x</b> <b
class="KEYCAP">C</b>-<b class="KEYCAP">f</b> and then enter a directory name instead of a
filename, Emacs will create a new buffer in which you will find a list of all the files
in that directory. You can move the cursor to the file that you are looking for and type
, and Emacs will open it. (There are in fact a lot more actions you can perform here,
such as deleting, renaming and moving files, etc. Emacs is now in dired-mode, which is
basically a simple file manager.)</p>

<p>When you have typed <b class="KEYCAP">C</b>-<b class="KEYCAP">x</b> <b
class="KEYCAP">C</b>-<b class="KEYCAP">f</b> and suddenly change your mind, you can type
<b class="KEYCAP">C</b>-<b class="KEYCAP">g</b> to cancel the action. <b
class="KEYCAP">C</b>-<b class="KEYCAP">g</b> works almost everywhere where you want to
cancel an action or command that you've started but don't want to finish.</p>
</div>
</div>

<div class="NAVFOOTER">
<hr align="LEFT" width="100%" />
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" align="left" valign="top"><a href="emacs-buffers.html"
accesskey="P">Prev</a></td>
<td width="34%" align="center" valign="top"><a href="index.html"
accesskey="H">Home</a></td>
<td width="33%" align="right" valign="top"><a href="emacs-basic-editing.html"
accesskey="N">Next</a></td>
</tr>

<tr>
<td width="33%" align="left" valign="top">Buffers</td>
<td width="34%" align="center" valign="top"><a href="emacs.html"
accesskey="U">Up</a></td>
<td width="33%" align="right" valign="top">Basic Editing</td>
</tr>
</table>
</div>
</body>
</html>