-->
Previous Table of Contents Next


Starting emacs by Using an Existing File

To edit or look at a file that already exists in your current directory, enter emacs followed by the filename. For example, try this with the file you created in the previous section by entering this command:


emacs emacs-pract.1

You see the following:


Things to do today.

a. Practice emacs.

b. Sort sales data and print the results.

Look at the mini-buffer: It contains the name of the file you’re editing.


TROUBLESHOOTING:  
I typed a filename I know exists, but emacs acts as though I’m creating a new file. 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 emacs pract1. and press <Return> but there’s no file named pract1. in your current directory, emacs still starts, but because the named file doesn’t exist, emacs acts as though you were creating a new file.

I try to edit a file, but emacs displays a message about read permission being denied, and the shell prompt appears. 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 emacs directory_name, where directory_name is the name of a directory, emacs informs you that you opened a directory and won’t let you edit it. If you try to use emacs 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. emacs expects files to be stored as plain text.

When I tried to open a file in emacs, I got a message about the line being too long. You’re trying to use emacs on a data file or a binary file that’s just one long string of bytes.

When I try to save a file with the <Ctrl-x><Ctrl-s> keys, the terminal hangs and doesn’t respond to the keyboard. Your terminal is probably responding to the flow-control characters <Ctrl-s> and <Ctrl-q>. Press <Ctrl-q> to restart your session.

I opened a file in emacs, and some strange characters appeared on-screen. You may be using emacs with a file produced by a word processor.

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 emacs and make no changes to the existing file.


Exiting emacs

As already stated, to exit emacs, press <Ctrl-x><Ctrl-c>. If you haven’t saved any changes to the file, emacs prompts you to save the buffer. If you type y, emacs 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 n to the request to save the buffer, emacs 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—yes or no. If you answer yes, emacs returns you to Linux without saving any of the modifications you made to the buffer. Also, if you have multiple buffers open, emacs prompts you for each buffer.


CAUTION:  
The default installation of emacs performs periodic saves while you’re editing a buffer. emacs 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 #filename#. 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 emacs 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.


CAUTION:  
Answer n to the exit-without-saving prompt sparingly. When you answer n, 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.

Perhaps you aren’t quite finished with your emacs session but you need to perform other activities with Linux. In that case, you have several options:

  You can suspend emacs and return to the Linux shell.
  You can switch to another virtual terminal.
  You can issue a shell command from within emacs.


Previous Table of Contents Next