📄 543-545.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Using the emacs Editor</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=28//-->
<!--PAGES=543-545//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="541-543.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="545-546.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Starting <I>emacs</I> by Using an Existing File
</FONT></H4>
<P>To edit or look at a file that already exists in your current directory, enter <TT><I>emacs</I></TT> followed by the filename. For example, try this with the file you created in the previous section by entering this command:</P>
<!-- CODE SNIP //-->
<PRE>
<B>emacs emacs-pract.1</B>
</PRE>
<!-- END CODE SNIP //-->
<P>You see the following:
</P>
<!-- CODE SNIP //-->
<PRE>
Things to do today.
a. Practice emacs.
b. Sort sales data and print the results.
</PRE>
<!-- END CODE SNIP //-->
<P>Look at the mini-buffer: It contains the name of the file you’re editing.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>TROUBLESHOOTING: </B><BR><B>I typed a filename I know exists, but</B> <TT><I>emacs</I></TT> <B>acts as though I’m creating a new file</B>. You may have typed the name of a file incorrectly, or you may have typed one that doesn’t exist in your current directory. If, for example, you type <TT>emacs pract1.</TT> and press <Return> but there’s no file named pract1. in your current directory, <TT>emacs</TT> still starts, but because the named file doesn’t exist, <TT>emacs</TT> acts as though you were creating a new file.
<P><B>I try to edit a file, but</B> <TT>emacs</TT> <B>displays a message about read permission being denied, and the shell prompt appears.</B> You’ve tried to edit a file you aren’t permitted to read. Also, you can’t edit a directory-that is, if you type <TT>emacs</TT> <TT><I>directory_name</I></TT>, where <TT>directory_name</TT> is the name of a directory, <TT>emacs</TT> informs you that you opened a directory and won’t let you edit it. If you try to use <TT>emacs</TT> with a binary file instead of an ASCII file, you’ll see a screen full of strange (control) characters—something you cannot read and edit. <TT>emacs</TT> expects files to be stored as plain text.</P>
<P><B>When I tried to open a file in</B> <TT><I>emacs</I></TT>, <B>I got a message about the line being too long.</B> You’re trying to use <TT>emacs</TT> on a data file or a binary file that’s just one long string of bytes.</P>
<P><B>When I try to save a file with the <Ctrl-x><Ctrl-s> keys, the terminal hangs and doesn’t respond to the keyboard.</B> Your terminal is probably responding to the flow-control characters <Ctrl-s> and <Ctrl-q>. Press <Ctrl-q> to restart your session.</P>
<P><B>I opened a file in <TT><I>emacs</I></TT>, and some strange characters appeared on-screen.</B> You may be using <TT>emacs</TT> with a file produced by a word processor.</P>
<P>In all these cases, press <Ctrl-x><Ctrl-c> to exit emacs and return to your login shell prompt. Then answer n to the prompt asking if you want to save the file. Using those keystrokes ensures that you quit <TT>emacs</TT> and make no changes to the existing file.<HR></FONT>
</BLOCKQUOTE>
</P>
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">Exiting <I>emacs</I>
</FONT></H4>
<P>As already stated, to exit <TT>emacs</TT>, press <Ctrl-x><Ctrl-c>. If you haven’t saved any changes to the file, <TT>emacs</TT> prompts you to save the buffer. If you type y, <TT>emacs</TT> saves the file and returns you to the Linux shell. If you haven’t provided a filename, emacs prompts for a filename and then exits. If you respond <I>n</I> to the request to save the buffer, <TT>emacs</TT> prompts again to make sure that you want to exit without saving the buffer. This time you must completely type out the response to the prompt—<TT><I>yes</I></TT> or <TT><I>no</I></TT>. If you answer yes, <TT>emacs</TT> returns you to Linux without saving any of the modifications you made to the buffer. Also, if you have multiple buffers open, <TT>emacs</TT> prompts you for each buffer.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>CAUTION: </B><BR>The default installation of <TT>emacs</TT> performs periodic saves while you’re editing a buffer. <TT>emacs</TT> does not, per se, make backup copies of files, although the first time you save the file, a snapshot of the file is saved in <TT>#filename#</TT>. After you press <Ctrl-x><Ctrl-s>, the original file is modified and can’t be restored to its original state. Thus, you should make your own backup copies of <TT>emacs</TT> files before starting the editing session to make sure that the automatic updates don’t inadvertently overwrite an important file to the point where you can’t recover a previous version of the file.<HR></FONT>
</BLOCKQUOTE>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>CAUTION: </B><BR>Answer <I>n</I> to the exit-without-saving prompt sparingly. When you answer <I>n</I>, all the changes you’ve made to the file since it was last saved are lost. It’s better to be safe and save the file to a different filename if you’re not sure about losing all your changes to the file.<HR></FONT>
</BLOCKQUOTE>
<P>Perhaps you aren’t quite finished with your <TT>emacs</TT> session but you need to perform other activities with Linux. In that case, you have several options:</P>
<DL>
<DD><B>•</B> You can suspend <TT>emacs</TT> and return to the Linux shell.
<DD><B>•</B> You can switch to another virtual terminal.
<DD><B>•</B> You can issue a shell command from within <TT>emacs</TT>.
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="541-543.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="545-546.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -