3Monkeys on Emacs: Part 1 – Introduction

Introduction

I have been an Emacs user for the better part of 17 years or so. Even so, there are quite a few things I’ve learned and forgotten along the way and perhaps even more that I never learned. I am writing the series of articles to not only provide a tutorial for the beginning Emacs user, but to also dig in and uncover features that I haven’t used for some time and features I never knew about. For the time being, I will be discussing just Emacs and not XEmacs, if it becomes necessary or requested to cover XEmacs, I will consider it at that time.

Vi – Well any time you mention Emacs, there is inevitably a Vi/Vim/GVim user in the room, and just inevitably a Holy War between the two breaks out. I really do not want to start a Holy War here, therefore, I am inviting one or more Vi advocates to step up and be a guest author and contribute similar articles from a Vi perspective. If you are willing to do this please contact me.

Some Fundamentals

In any editor there are a few fundamental operations you must be able to perform, create a new file, edit an existing file, and save a file. Emacs provides several ways to do these, the most common being command keystrokes within Emacs itself, other methods are issuing the verbose command or in an XWindows session selecting from a menu.

  • Creating or Opening a File
    More often referred to as visiting a file or finding a file, can be accomplished by simply specifying one or more filenames on the command prompt when starting Emacs.
    For example:

    	% emacs foo.txt bar.csv

    This command will start emacs and open both foo.txt and bar.csv into editing buffers. If either file does not exist on disk, emacs will still create a new buffer for the specified file. It is important to realize the all editing in emacs is done in buffers and not on files directly. To have changes to a buffer reflected in the file on disk, you must save the buffer.

    Perhaps the most common way of visiting (opening) a file, is to use the keystroke command sequence C-x C-f. This is a two-key or extended command. The C- indicates that you must hold down the Control (Ctrl) key then press the following key, in the case of C-x that would be x. Many keystroke commands are of the extended command type and begin with C-x. When this command is executed you are prompted for a filename in the echo area, a small usually one line area at the bottom of the Emacs screen. Simply enter the files name and press return to visit the file and load a buffer with its contents. Emacs supports tab completion, so as you type the name of the file you can press tab to either complete unique portions of the filename, or if there are no unique portions Emacs will open a completions buffer listing the legal possibilities. Again if the file you specify does not exist a new buffer associated with that filename will be created.

    You can also choose to verbosely run the command. To run a verbose command, start by entering command mode by issuing the keystroke command M-x, where M-x indicates to press and hold down the Meta (Esc) key and then press x. This will allow you to execute Emacs commands directly from the echo area. The command for opening a file is find-file, simply type this in the echo area using tab completion if desired and press return. This will provide the same prompt in the echo area as the Cx C-f keystroke command described above.

    Finally, if your system supports it, you can select the visit file menu item from the Emacs menu. This operation is strongly tied to the type of system you happen to be running on so I will not cover menu items in detail.

  • Saving a File
    Saving a file is generally performed with the keystroke command, C-x C-s. This will save the current buffer to disk if the buffer was associated with a file to begin with. Certain buffers are not associated with on disk files however, if you save a buffer of this type, Emacs will prompt you for a file name in the echo area. Such buffers could be scratch or shell buffers. The verbose command for saving a buffer is save-buffer. If you wish to save the buffer to file of a different name, use the C-x C-w keystroke command. Emacs will prompt you for the new name in the echo area. The verbose command for saving a buffer to a new filename is write-file.

The next article in this series will cover navigating through a buffer.

Next in this series: Part 2 – Basic Navigation and Editing

Until next time…

-3Monkeys

Popularity: 14% [?]

  • DZone
  • StumbleUpon
  • Technorati
  • del.icio.us
  • Slashdot
  • Digg
  • Reddit
  • NewsVine
  • SphereIt
  • e-mail
  • Facebook
  • Google Bookmarks
  • Live
  • Propeller
1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (2 votes, average: 8.50 out of 10)
Loading ... Loading ...

3 Responses to “3Monkeys on Emacs: Part 1 – Introduction”

  1. Article Series on Emacs :: The Geek’s Blog Says:

    [...] Part 1 – Introduction [...]

  2. Ronald Molsan Says:

    Hi webmaster – This is by far the best looking site I’ve seen. It was completely easy to navigate and it was easy to look for the information I needed. Fantastic layout and great content! Every site should have that. Awesome job

  3. Joao Brito Says:

    Hi, 3 Monkeys, I’m learning emacs and I’d like to thank you for the great useful information. I hope emacs is worth the effort, for anyone who has used windows for almos 20 years. I plan to use pure text instead of all pims and calendars and evernotes which I’m tired of.

Leave a Reply