Cool Emacs Trick

I looked around for valgrind integration into Emacs recently but I didn’t see anything out there. I had a great idea! — compilation-mode should integrate with shell-mode so I can run valgrind and then next-error will walk through the problems.

Well, it turns out this idea is so great that it has been implemented already. Yay Emacs! Unfortunately the feature is rather obscure; I had to dig around in the source to find it, and it wasn’t obvious that it handled valgrind — it does, but the valgrind error regexp is the same as one for the JVM, so it is misleadingly named “java”.

To enable this, enable compilation-shell-minor-mode in your shell-mode buffer. It will automatically start highlighting the appropriate messages, and mouse-2 will go to the source file.

I’m pretty happy about this idea of using shell mode in this way. It has that nice, integrated, “plastic” feeling I’ve come to associate with the joy of Emacs. I’ve always liked the idea of a “notebook-like” shell, where commands and structured, or even graphical, output are intermixed; this feels a little like that

What’s left? Two things I think… first, Emacs should automatically enable this minor mode when you type “make”, “valgrind”, “ant”, etc, in a shell mode buffer; meanwhile I’m just going to enable this from the mode hook.

Second, I think it would be awesome if running gdb in shell mode somehow auto-started Emacs’ gdb mode. I generally find it a pain to start (but not use) gdb in Emacs, since typically I have a complicated setup on the command line — a particular directory, command line, sometimes an environment; Emacs could simplify this. I wrote a minor mode last night that will recognize when you type “gdb” in the shell and will automatically run it in Emacs instead… I’ll post it soon, or send email if you want it.

One Comment

  • Be sure to publish these things on ELPA 🙂

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.