Emacs is a very powerful and featureful editor. We encourage you to customize your emacs setup to best suit your own personal preferences and style. We can't possibly cover every imagineable feature and customization here, but we do present a few commonly asked for options. We will also cover a few features that will be on by default in your 551/751 emacs setup.
First, let us just take a look at the basic emacs
Here you can see a basic "vanilla" emacs setup (in fact, you can see at the very bottom that I just turned off rainbow delimiters to get this setup). You have syntax highlighting (the color of a word indicates its meaning in the program), and automatic nice indentation (the code is lined up cleanly according to its nesting level).
One really nice feature is rainbow delimiters, which you can see here:
What are rainbow delimiters? This is easiest to see with the three closing braces towards the end of the file, right before main. One is purple, one is light blue, and one is gray. With this feature turned on, Emacs colors each pairable item (curly braces, square brackets, and parenthesis) based on its nesting depth. This coloration makes it very easy to see which items match others.
- Drew's take on this feature: Love it!
- Status on 551/751 setup: enabled by default. If you want to turn it off, look for rainbow-delimiters-mode-enable in your .emacs (config file) and comment out that line.
Speaking of matching delimiters, whenever you have the cursor ("point" in emacs speak) on a pairable item, emacs will highlite its partner if it is properly matched. If the match is offscreen, it will show you the line it matches in the modeline at the bottom. You can see the highlighted match here, where the point is on the close curly brace of the else, and emacs highlights both that brace and the open brace that goes with it.
- Drew's take on this feature: Love it!
- Status on 551/751 setup: enabled by default. If you want to turn it it off, look for show-paren-mode in your .emacs file and comment out that line.
Some people like to have emacs insert a close brace/paren/bracket whenever they open one. This is called "electric pairs." These images show its behavior. On the left, I type a brace. On the right emacs has automatically inserted the close brace right after.
- Drew's take on this feature: Hate it! I like to type my close braces when I'm done with the block.
- Status on 551/751 setup: not enabled by default. If you want to enable this, look for electric-pair-mode in your .emacs file and uncomment that line.
Some people like to have line numbers down the left side. This is easily accomplished with linum mode, as shown in this picture:
You can also adjust the format of the line numbers (e.g., if you want a blank space after them) if you so wish.
- Drew's take on this feature: Don't really care for it: uses up space. Can see line number in status line anyways.
- Status on 551/751 setup: not enabled by default. If you want to enable this, look for global-linum-mode in your .emacs file and uncomment that line.
One really nice feature of emacs is the ability to hold multiple things on the "clipboard" (in emacs speak, "kill ring") and go back and paste things other than the most recent copy/cut. You have this feature by default (hit M-y after pasting), but can improve on it if you like by having emacs display the prior options when you hit M-y. You can see this behavior in the screen shot below. You can use the up and down arrow to select what you want, then hit enter to replace your current paste with what you selected.
- Drew's take on this feature: Nice---makes a good feature even better!
- Status on 551/751 setup: enabled by default. If you don't want this, look for popup-kill-ring in your .emacs file and comment out 12 lines there.
Another feature is "flycheck" where emacs will check the syntax of your program as you go. In the picture below, you can see that I removed a semicolon, creating a syntax error. Emacs highlights the offending area of the program, and if you move the cursor (aka "point") to it, it shows a popup telling you what is wrong.
- Drew's take on this feature: Wonderful! Who wouldn't want this?
- Status on 551/751 setup: enabled by default. If you don't want this (really??) look for flycheck in your .emacs file and comment out the lines there.
Of course, when you are ready to compile, you can do so directly within emacs. Just hit C-c C-v. The three images below show a successful compilation process. In the first, emacs prompts for the compilation command. It defaults to "make -k" which is great for any project where you have a Makefile (anything non-trival). In the second, I've edited the command, since my tiny fizzbang program doesn't have a Makefile. Emacs will remember this as long as its open if I compile again. In the third, compilation has finished successfully.
Of course, if compilation fails, emacs will display the error messages for you. By default in your 551/751 setup, it will automatically move the cursor to the first error message when this happen. Furthermore, if you move the cursor in the error messages list, emacs will jump to each error as you examine it.
- Drew's take on this feature: Compiling in emacs is impossible to live without. Scrolling to errors is nice, though sometimes the C++ compiler gives a whole bunch of irrelevant lines when it describes every possible template choice.
- Status on 551/751 setup: enabled by default. If you want to change the key binding for compile, look for the global-set-key that has 'compile as its second argument (near the top of the file). If you want to turn off the automatic jump to the first error, look for compilation-auto-jump-to-first-error and comment out that line. If you want to not have it scroll to each line automatically when you put the point on an error message, look for next-error-follow-minor-mode, and comment out those 4 lines.
Another feature is autocompetion. In the first image below, I have typed "fizz" and emacs suggests completing it with "bang" (red text on blue). It also tells me at the bottom what this completion is ("void fizzbang(int n)"). I accepted the completion by hitting TAB, resulting in the state shown in the second image. Here, emacs has shown me that the parameter is int n, and I should type the value I want, overwriting the "int n" text.
- Drew's take on this feature: Nice! This is actually part of the emacs package "company" which stands for "complete anything." It really does autocomplete pretty much anything you can think of!
- Status on 551/751 setup: enabled by default. If you want to turn this off, look for global-company-mode and comment out that line.