#Emacs tip of the week

Yet another serendipitous accident I learned today.

So if you use Emacs to develop software, you probably know about the M-x compile command, which captures the log of whatever command you run and uses regular expressions to find mentions errors, along with the files (and line and column numbers) at which the error occurred.

What I just learned: you can navigate around errors in your code very rapidly by keeping your cursor in the *compilation* buffer. Use these keys to navigate quickly:

C-o has the same action as when used in Occur-mode or Dired-mode: when on an error message, similar to pressing Enter, this show exactly where the error occurred in the source code but without moving the cursor to the file, so you can stay in the *compilation* buffer and continue navigating.

M-n and M-p> to jump the cursor to the next error or previous error, same thing as pressing the tab key or shift tab key, but lets you keep your fingers on the navigation keys.

M-{ and M-} to jump to the next file or previous file. These are the same keys used by Dired to jump between marked files. Compiler errors are almost always clustered by file, and there may be dozens of errors in one file. Often, all errors can by triggered by a single error. The M-{ and M-} keys let you jump over these clusters.

This is so great for navigating stack traces!

I jump over to the *compilation* buffer, jump to the bottom of the log pressing > (greater-than), the M-p to jump to the bottom of the stack.

I press C-o to view the location of the error. "Hmm, why is the X variable less than zero, what called this function?" I press M-p to go up the stack and C-o again to see the function that called this one. "Hmm, I got X from this structure, but this structure was passed as an argument from where?" (I press M-p C-o) Oh! Silly me, I wrote "(pt - len) instead of (len - pt) in the constructor there!

Reply to this note

Please Login to reply.

Discussion

Thank you!