Emacs: the Free Software IDE
Emacs is well known as an editor, but calling Emacs an editor is like calling the Queen Mary a boat. The source RPM for Emacs 21.1 is some 20MB—huge for an editor. You don't have to use all of it, but sometimes it's nice to know it's there.
Emacs is heavily customizable, which makes it very flexible. For example, I am writing this article with Emacs and will spell check it with Emacs. “Well”, I hear you saying, “if it's good for writing articles, it can't be very good for developing software.” That's where Emacs' flexibility and customization come in; you can use it for either or for something completely different. Want to see a shrink, play Tetris or manipulate dates in the Mayan calendar? Emacs.
Emacs' customization comes in packages, called modes. Major modes set Emacs up to do a particular sort of thing, such as the C mode to edit C and C++ source or the psgml mode (www.lysator.liu.se/projects/about_psgml.html) to edit the documentation after you've written your program. Minor customizations provide added facilities to major modes. Show-paren mode shows matching parentheses, and auto-fill mode allows you to enter filled text without explicitly entering line breaks. Most modes have variables to control their behavior, and you can modify them temporarily or permanently.
Most users store their customizations in ~/.emacs, called the “dot Emacs” file. For the curious, mine is on the Web at w3.trib.com/~ccurley/emacs.init.html. Others can be found at “the very unofficial .emacs home”, www.dotemacs.de.
This article covers GNU Emacs version 21.1 (www.fsf.org/software/emacs/emacs.html). XEmacs (www.xemacs.org) is also available on most Linux distributions and will probably do everything I describe here.
What I will do to show off Emacs as an integrated development environment (IDE) is walk through the development of a short C program and show you how to do it. We'll write the infamous Hello World program known and loved by C programmers everywhere.
While this article shows C development, Emacs has support for other languages as well, including C++, assembly, Scheme, Java, Ada, IDL, Makefiles, Lisp (including Emacs Lisp, the language in which much of Emacs is written) and FORTRAN. And that's just what comes with Emacs. Add-on packages abound; there is even one for Forth.
In addition, you can use Emacs for many other types of files. When it comes time to document your program, you can use Emacs' psgml mode to make editing the documentation source much easier. There are modes for HTML and TeX as well.
The first thing we do is use Emacs' dired mode to create a directory to put the program in. In dired mode, we type a +, and then enter the name of the directory to create in the minibuffer at the bottom of the editor (Figure 1). Press Return and Emacs creates the directory for us.
The next thing we do is enter that directory, then create the file hello.c with the usual keystrokes for visiting a file, Ctrl-X Ctrl-F. Type the filename, hello.c, into the minibuffer and press Return. We now see Emacs ready with a new buffer for our program.
The first thing any C programmer should do upon opening a new file is enter a comment to say what the file does. So we press M-; (M- for meta, or Alt on most PC keyboards) and get a C++-style comment delimiter and the cursor ready to take our comment. The reason I get a C++ comment is because I have customized Emacs to put me into C++ mode for C. You will probably get a C-style comment delimiter, /* */, with the cursor in the middle ready for you to type in your comment. If you'd rather use C++ comments, do M-X C++-mode.
Then we add a timestamp, all defined by Emacs' timestamp minor mode. Again, this is something I have customized; you may not get it to work.
A C program has to have a main function, and so we type it in GNU style: the return type on one line, followed by the function declaration on the next. Notice as we type away that syntax highlighting takes effect (Figure 2).
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Profiles and RC Files
- Astronomy for KDE
- Understanding Ceph and Its Place in the Market
- Maru OS Brings Debian to Your Phone
- OpenSwitch Finds a New Home
- Git 2.9 Released
- SoftMaker FreeOffice
- What's Our Next Fight?
- Snappy Moves to New Platforms
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide