This might require more tricks than just Emacs-fu, but since Emacs is at the heart of it I hope to get some ideas on how to approach my need here.

I use Emacs/Make/gcc as my development environment. I have a script that watches my source files so that whenever a change is saved it rebuilds, run all tests and updates coverage (thanks cov-mode).

I'm normally running this in a separate terminal window so any compilation errors will show up there, when what I really want is for those errors to end up in a compilation-mode-type buffer in Emacs so I can go to next-error with one key-stroke.

Here are my attempts so far:

  • run script in a term-window - failed to get next-error to work
  • run script in a shell-window- same problem
  • run script and collect output in a file which is visited in a buffer - couldn't get that window to auto-update (can I?)

I also want to ensure that next-error is from the last "round", but since the buffer is not cleared on a ^L/clear-command you would have to step through all the errors unknowing when you are actually on a current one.


I have been exploring writing the output from the script into a file and then forcing my running Emacs to re-read it using auto-revert-mode while still keeping the *compilation*-like behaviour in that buffer. This works, but the problem is that next-error can't be reset to start from the new errors after reverting. Using C-u C-x ` just errors with "Moved past last error". Not even using the after-revert-hook to do (next-error 4 t) seems to do the trick.

How can I reset the next-error "pointer" in this scenario?

Or are there any other approaches I should try?

  • "couldn't get that window to auto-update (can I?)" -- auto-revert-mode ? – phils Jun 7 '20 at 22:34
  • You might also consider whether your compile step could actually run compile inside Emacs? – phils Jun 7 '20 at 22:37
  • @phils what are you thinking with "actually run compile inside Emacs"? Externally making Emacs run the compile through some scripting or PPC? If so how could I do that? – thoni56 Jun 8 '20 at 14:49
  • @Drew sorry about the erroneous tag... Learning. – thoni56 Jun 8 '20 at 15:00

Probably the easiest way to do this is to use emacs-client to run the compilation inside a *compilation* buffer:

utman emacs-client --eval '(compile "make debug unit test")'

utman is my script to watch for changes in source files and then run the rest as command: https://github.com/thoni56/utman, but that could be replaced with any file-watcher, or completely ignored if you just want to trigger a compile inside Emacs.

UPDATE: This doesn't really work the way I want since emacs-client terminates immediately because the compile runs asynchronously within Emacs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.