Emacs can be used as a unified environment for software development
under UNIX. If things are set up properly, you can use it for
everything.
We'll assume you're using Emacs 19. On Athena:
add emacs19; emacs19
Buffers and files and windows
- C-x C-f
- open file in a new buffer
- C-x C-w
- write file out with a different name
- C-x C-s
- save buffer under current name
- C-x b
- switch to buffer
- C-x k
- kill current buffer
- C-g
- cancel
- C-x 2
- split current window
- C-x o
- switch to other window
- C-x 1
- make current window only window
- C-x 0
- remove current window
- C-x 5 2
- make another X window
- C-x 5 0
- delete the current X window
.emacs file and elisp
- At the core of Emacs is an interpreter for elisp, a variant
of LISP
- Emacs is configured by writing elisp code
- Single line commands can be entered with:
- ESC ESC
- enter elisp command
- .emacs file run on startup
- Add emacs19 specific things to .emacs with:
(defun startup19 () "startup for emacs19"
(...)
(...) ; Stuff for emacs19 only
(...)
(cond (window system
(...)
(...) ; Stuff for emacs19 and X only
(...)
))
)
(if (string-match "^19" emacs-version) (startup19))
- Examples in dotfiles locker on Athena:
add dotfiles; cd /mit/dotfiles/Emacs
- Enter more complicated commands in lisp-interaction-mode:
- M-x lisp-interaction-mode
- enters lisp-interaction-mode
- C-j
- executes commands in lisp-interaction-mode
Regions
- Used to select regions of text on which to perform an operation
- Select with C-SPACE then move to end
- Also select with mouse button 1 and drag
Editing C code in c-mode
M-x compile
- In c-mode, M-x compile runs make for you
- To make C-c C-c do a compile in c-mode:
;; Use C-c C-c in c-mode to do a compile
(defun my-save-and-compile ()
(interactive "")
(save-buffer 0)
(compile "make -k"))
(define-key c-mode-map "\C-c\C-c" 'my-save-and-compile)
- Middle button over an error goes to it in the source
- M-n goes to next error with:
(define-key c-mode-map "\M-n" 'next-error)
Tags
- Keeps track of what is defined where
- Generate TAGS file with:
etags *.[ch]
- To go to where a function is defined, do M-.
over the function call
- To do a query replace over all files,
do M-x tags-query-replace
- To search for something across all files, M-x tags-search
- To go to next occurance of search string, M-,
Faces and colorization
- List faces with M-x list-faces-display
- (set-face-foreground 'face "color")
- (set-face-background 'face "color")
- Use font-lock minor mode to enable hilighting
(require 'hilit19)
(font-lock-mode 1)
- Highlight active region with:
(transient-mark-mode 1)
- Example of setting C coloring:
;; comments
(hilit-translate comment 'pink)
;; string constants
(hilit-translate string 'lightsalmon)
;; "#include"
(hilit-translate include 'yellow)
;; keywords (if, for, ...)
(hilit-translate keyword 'green)
;; function definitions
(hilit-translate defun 'aquamarine2)
;; "#define"
(hilit-translate define 'yellow)
;; struct definitions
(hilit-translate decl 'gray80)
- Colorize on file writes:
;;; colorize on file writes
(if (not (memq 'hilit-rehighlight-buffer write-file-hooks))
(setq write-file-hooks
(cons 'hilit-rehighlight-buffer write-file-hooks)))
Using the shell within emacs
- Start shell with M-x shell
- For command line history, use M-p and M-n
Using GDB within emacs
- Start with M-x gdb
- For command line history, use M-p and M-n
- Some other commands:
- C-c TAB
- step one statement
- C-x C-a C-b
- in c file will set a break point at that line
![[BACK]](images/back.gif)
Prepared by
Erik Nygren (nygren@mit.edu)
and
Mike Whitson (mwhitson@mit.edu)