Programming Environment for C-based Courses
Last modified: "January 13, 1997 20:11:46 by matt"
Emacs is Number One!
I recommend using emacs19 to do your
programming. Forget that ancient and obsolete VI stuff! Emacs is the
happening place! To run emacs19 just use the 'emacs19' command in the
departmental Unix environment. (When not working in an X windowing
environment, run version 18 of emacs, via the 'emacs' command.)
Learning emacs
Emacs is the world's most powerful editor, but this comes at a price:
Emacs has a steep learning curve. I have been using emacs for 13 years, and
pick new stuff up all the time. Still, you only need to know a little about
the editor to use it. You will pick up more powerful features as you become
more comfortable with the editor. There are four good ways to learn about
emacs:
- Run the emacs tutorial. To do this, use the Help menu, or just type
C-h t.
- Check out Keith Waclena's Web-based emacs tutorial.
- Use emacs' built-in Info facility. C-h i. Use the middle
mouse-button to select topics.
- Ask other emacs users. If you see somebody doing something neat, ask
them how they do it.
Modifications to Emacs for Programmers
There are a
couple of modifications you should make to your emacs environment to make
it C or C++ friendly:
Put the following code in your ~/.emacs file (before fiddling with your
.emacs files, always make a copy someplace safe, in case something goes
wrong):
(defvar emacs-is-version-19 (>= (string-to-int (substring emacs-version 0 2)) 19))
(if emacs-is-version-19
(progn
(load "completion") ;Turn on completion mode
(initialize-completions))) ;This defines M-Ret as complete.
(cond (window-system
(setq hilit-mode-enable-list '(not text-mode) ;Enables hilighting in all modes except text
hilit-background-mode 'light
hilit-inhibit-hooks nil
hilit-inhibit-rebinding nil)
(require 'hilit19)
))
;;; This shell-strip stuff removes the "^M" which would otherwise appear at the end of
;;; every line of output in any shell buffer, including inferior-lisp buffers.
(defun my-comint-mode-hook ()
(require 'shell)
(cond ((not (member 'shell-strip-ctrl-m comint-output-filter-functions))
(setq comint-output-filter-functions (cons 'shell-strip-ctrl-m comint-output-filter-functions)))))
(if (boundp 'comint-mode-hook)
(if (listp comint-mode-hook)
(if (not (member 'my-comint-mode-hook comint-output-filter-functions))
(setq comint-mode-hook
(append comint-mode-hook '(my-comint-mode-hook))))
(setq comint-mode-hook
(list comint-mode-hook 'my-comint-mode-hook)))
(setq comint-mode-hook (list 'my-comint-mode-hook)))
Here are some capabilities you should have:
- M-return is part of the completion system. If there are at least
three non-space characters in front of the cursor, emacs will replace that
character sequence with the most recently referenced symbol having that
prefix. Repeated M-returns will rotate through all symbols matching that
prefix. The completion functionality should work in all buffers, by the
way, not just in Lisp. This extremely powerful feature should allow you to
work with fairly long, mneumonic symbol names, as you won't have to type
them more than once. You can use the completion facility for subsequent
references.
- The TAB key should properly indent a line according to mode. So if
you are working in a C buffer, it should indent the line properly for a
C program. If you are writing a Lisp program, it should properly indent for that mode.
For a complete list of the commands within the C environment (as it called,) type C-h m.