views:

8149

answers:

12

Currently my workflow with Emacs when I am coding in C or C++ involves three windows. The largest on the right contains the file I am working with. The left is split into two, the bottom being a shell which I use to type in compile or make commands, and the top is often some sort of documentation or README file that I want to consult while I am working. Now I know there are some pretty expert Emacs users out there, and I am curious what other Emacs functionally is useful if the intention is to use it as a complete IDE. Specifically, most IDEs usually fulfill these functions is some form or another:

  • Source code editor
  • Compiler
  • Debugging
  • Documentation Lookup
  • Version Control
  • OO features like class lookup and object inspector

For a few of these, it's pretty obvious how Emacs can fit these functions, but what about the rest? Also, if a specific language must be focused on, I'd say it should be C++.

Edit: One user pointed out that I should have been more specific when I said 'what about the rest'. Mostly I was curious about efficient version control, as well as documentation lookup. For example, in SLIME it is fairly easy to do a quick hyperspec lookup on a Lisp function. Is there a quick way to look up something in C++ STL documentation (if I forgot the exact sytanx of hash_map, for example)?

+11  A: 

Instead of running a make command in the shell window, have you tried M-x compile? It will run your make command, display errors, and in many cases make it very easy to jump to the line of code that caused the error if the output includes filenames and line numbers.

If you're a fan of IDEs, you might also want to look at emacs' speedbar package (M-x speedbar). And, if you haven't already, learn about how to use tags tables to navigate your code.

Bryan Oakley
+24  A: 

You'll have to be specific as to what you mean by "the rest". Except for the object inspector (that I"m aware of), emacs does all the above quite easily:

  • editor (obvious)
  • compiler - just run M-x compile and enter your compile command. From there on, you can just C-x compile and use the default. Emacs will capture C/C++ compiler errors (works best with GCC) and help you navigate to lines with warnings or errors.
  • Debugging - similarly, when you want to debug, type M-x gdb and it will create a gdb buffer with special bindings
  • Documentation Lookup - emacs has excellent CScope bindings for code navigation. For other documentation: Emacs also has a manpage reader, and for everything else, there's the web and books.
  • version control - there are lots of Emacs bindings for various VCS backends (CVS, SCCS, RCS, SVN, GIT all come to mind)

Edit: I realize my answer about documentation lookup really pertained to code navigation. Here's some more to-the-point info: Looking up manpages, info manuals, and Elisp documentation from within emacs, Looking up Qt documentation from within Emacs. Google searching will no doubt reveal further examples.

As the second link shows, looking up functions (and whatever) in other documentation can be done, even if not supported out of the box.

Ben Collins
shouldn't that be "M-x compile"?
Svante
Yes, M-x is correct. That's what I meant.
Ben Collins
I think GNU global is superior over CScope these days:http://www.gnu.org/software/global/
Jürgen Hötzel
@Jürgen Hötzel: I haven't used actively Emacs in a while. At the time, I used GNU global in conjunction with CScope, IIRC. I wouldn't be suprised if global has out-evolved CScope though.
Ben Collins
+5  A: 

I agree that you should learn about M-x compile (bind that and M-x next-error to a short key sequence).

Learn about the bindings for version control (e.g. vc-diff, vc-next-action, etc.)

Look into registers. You not only can remember locations in buffers but whole window configurations (C-x r w -- window-configuration-to-register).

HD
+10  A: 

I have to recommend Emacs Code Browser as a more "traditional" IDE style environment for emacs.

EDIT: I also now recommend Magit highly over the standard VCS interface in emacs.

docgnome
+2  A: 

compile, next-error, and previous-error are all pretty important commands for C++ development in Emacs (works great on grep output too). Etags, visit-tags-table, and find-tag are important as well. completion.el is one of the great unsung hacks of the 20th century, and can speed up your C++ hacking by an order of magnitude. Oh and let's not forget ediff.

I've yet to learn how to use version control without visiting a shell, but now that I'm running commits so much more frequently (with git) I will probably have to.

jfm3
+3  A: 

A starting point (which may be non-obvious) for exploring the VC features of Emacs is M-x vc-next-action.

It does the "next logical version control operation" on the current file, depending on the state of the file and the VC backend. So if the file is not under version control, it registers it, if the file has been changed, the changes are submitted etc.

It takes a little getting used to, but I find it very useful.

Default keybinding is C-x v v

Chopmo
+5  A: 

For version control, there are several things that you can use, depending on what version control system you use. But some of the functionality is common to all of them.

vc.el is the built-in way to handle version control at a file level. It has backends for most version control systems. For instance, the Subversion backend comes with Emacs, and there are git backends and others available from other sources.

The most useful command is C-x v v (vc-next-action) that does the appropriate next action for the file you are visiting. This might mean updating from the repository or commiting your changes, vc.el also rebinds C-x C-q to check in and out files if you are using a system that needs it (like RCS).

Other very useful commands are C-x v l and C-x v = that show you the log and current diff for the file you are using.

But for real productivity, you should avoid using the single-file vc.el commands other than for simple things. There are several packages that can give you an overview of the status of your whole tree, and give you more power, and not to mention the ability to create coherent commits spanning several files.

Most of these are heavily influenced or based on the original pcl-cvs/pcvs for CVS. There are even two of them that comes with subversion, psvn.el and dsvn.el. There are packages for git etc.

dkagedal
+5  A: 

You can find detailed description of emacs & version control integration on my site. I'm also working on article about using Emacs as Development Environment for many languages - C/C++, Java, Perl, Lisp/Scheme, Erlang, etc...

Alex Ott
+4  A: 

There are corners of emacs that once discovered make you more productive in ways you never thought of. As others have mentioned, using tags is a fantastic and fast way to zoom around your source code and using M-/ (dabbrev-expand) often does exactly what you expect when completing a variable name.

Using occur is useful to get a buffer with all occurences of a regular expression in a buffer. That's really handy when refactoring code and looking for fragments of code or uses of variables, or if you use TODO markers in your source files and you want to visit them all.

flush-lines, sort-numeric-fields, replace-regexp and rectangle functions can be really useful for taking a dump from some tool and converting it to useful data such as an elisp program or a comma delimited spreadsheet.

I wrote a page about IDE like things you can do with emacs

http://justinsboringpage.blogspot.com/2007/09/11-visual-studio-tricks-in-emacs.html

Learning elisp is a another great way to answer for yourself what else emacs can do beyond what a typical IDE can do.

For example I've blogged about writing Perforce helper functions like blame (writing your own means you can make it behave exactly as you want)...

http://justinsboringpage.blogspot.com/2009/01/who-changed-line-your-working-on-last.html

I've also written code that dynamically creates comments for a function at point, that matches the coding standards I'm working with.

None of my elisp code is particularly great, and most of it exists already in libraries, but it's really useful to be able to make emacs do custom stuff that just comes up during a working day.

justinhj
+1  A: 

On documentation lookup: that depends on your programming language(s).

C libraries and system calls are typically documented in man pages. For that you can use M-x man. Some things may be documented better in info pages; use M-x info.

For elisp itself, use C-h f. For python, use >>> help(<function, class, module>) in the interpreter.

I find that most other languages offer documentation in html form. For that, try an embedded browser (I use w3m). Set your BROWSER environment variable to a wrapper script around emacsclient -e "(w3m-goto-url-new-session \"$@\")" (on *nix), in case something might open a browser and you want it opened inside emacs.

Jonas Kölker
+1  A: 

You might also find tabbar useful. It emulates the only behavior I missed when moving from Eclipse to Emacs. Bound to "," and "." for moving to the previous and next tab bar, it relives you from switching the buffer by Ctrl-x b all the time.

Unfortunately, the mentioned web page does not provide the correct version to download. Most Ubuntu versions, however, deliver it in their emacs-goodies packages.

wr
Cool, I was looking for a way to get a newer version of tabbar. For those that aren't on Ubuntu, you can find it here. http://packages.ubuntu.com/karmic/emacs-goodies-el
Ibrahim
+1  A: 

There's a TFS.el for emacs integration into Microsoft TFS. It works with any TFS, including the TFS that runs Codeplex.com.

Basic steps to setup:

  1. Place tfs.el in your load-path.

  2. In your .emacs file:

    (require 'tfs)
    (setq tfs/tf-exe  "c:\\vs2008\\common7\\ide\\tf.exe")
    (setq tfs/login "/login:domain\\userid,password")
          -or-
    (setq tfs/login (getenv "TFSLOGIN"))  ;; if you have this set
    
  3. also in your .emacs file, set local or global key bindings for tfs commands. like so:

    (global-set-key  "\C-xvo" 'tfs/checkout)
    (global-set-key  "\C-xvi" 'tfs/checkin)
    (global-set-key  "\C-xvp" 'tfs/properties)
    (global-set-key  "\C-xvr" 'tfs/rename)
    (global-set-key  "\C-xvg" 'tfs/get)
    (global-set-key  "\C-xvh" 'tfs/history)
    (global-set-key  "\C-xvu" 'tfs/undo)
    (global-set-key  "\C-xvd" 'tfs/diff)
    (global-set-key  "\C-xv-" 'tfs/delete)
    (global-set-key  "\C-xv+" 'tfs/add)
    (global-set-key  "\C-xvs" 'tfs/status)
    (global-set-key  "\C-xva" 'tfs/annotate)
    (global-set-key  "\C-xvw" 'tfs/workitem)
    
Cheeso