Is there a way I can compile then run my compiled application, if its already running then exit recompile and run.

So current work flow is compile switch to terminal run binary, switch back make changes compile return to terminal Ctrl + C to kill then run again, be nice if I could do all this from inside emacs.

I guess a bash script could be an option but curious if others have this work flow and how it works ?

Currently in a golang workflow but even better if there is a generic solution.

1 point

Projectile is great for this. I use C-c P u to run projectile-run-project and it runs my run command. I use it for golang mostly. If you run it while it’s already running it will ask if you want to kill it first. I’m sure there’s a way to automate that.

permalink
report
reply
1 point

Simplest way to achieve this is by getting recompile-on-save to recompile for you. Because your process is long-running, also configure compilation-always-kill to be t.
You might also want to set compilation-ask-about-save as nil.

permalink
report
reply
1 point

Maybe do it all in the makefile? Then use projectile or something to “make”…

permalink
report
reply
1 point

I did wonder if that’s perhaps the solution, although not sure how you would get the pid in a make file to kill the running instance, make files are not something I have played with much, I will see if others have any suggestions.

permalink
report
parent
reply
1 point

There’s only one running *compilation* buffer allowed at a time, so if you use M-x compile (which I’ve had bound to C-x C-e for like 20 years), that should roughly ensure it.

In the past, I also had a bit of elisp to – IIRC – create and rename multiple compilation buffers to be able to run multiple things at once (multiple servers in a control plane).

permalink
report
parent
reply
1 point

Okay so what I think your saying is if i do something like this as the compilation command

go build main.go && ./main

Then when I run compilation again it will kill the buffer and running process and all will be good ?

permalink
report
parent
reply

Emacs

!emacs@communick.news

Create post

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

  • Windows
  • Mac OS X
  • GNU/Linux and BSD (Just get it from your distribution’s package manager)

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for “emacs” and “vi” link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

Community stats

  • 18

    Monthly active users

  • 562

    Posts

  • 2.4K

    Comments