I'm using "M-x compile" several times a day with the following in my ~/.emacs:
(setq compile-command "cd ~/my-dev/linux_build/ && killall gdb ; ~/my-dev/someStuff/.git/hooks/pre-commit; mv -f ../bin/my-exe /tmp 2>&1; echo ---; make -j$(nproc) APP=my-exe MODE=debug SOMEOPTION=value && date")
The main problem is that sometimes I don't want "SOMEOPTION=value" - other times I want it (I know I can just use the cursor keys to change the command before hitting enter, but I'm looking for an even faster/quicker way). So, the question is:
Is there a way to modify "M-x compile" such that it by default runs without SOMEOPTION=value and using just a single key after "M-x compile", it runs with SOMEOPTION=value? Maybe it would be nice also to be able to switch between 2 makefiles, again - using just a single keypress, e.g. the following 3 tasks should be easy and fast/quick to switch between:
- "M-x compile + enter" (default): Runs the usual command without
SOMEOPTION=value, i.e.
cd ~/my-dev/linux_build/ && killall gdb ; ~/my-dev/someStuff/.git/hooks/pre-commit; mv -f ../bin/my-exe /tmp 2>&1; echo ---; make -j$(nproc) APP=my-exe MODE=debug && date
- "M-x compile + S": Runs the usual command WITH
SOMEOPTION=value, i.e:
cd ~/my-dev/linux_build/ && killall gdb ; ~/my-dev/someStuff/.git/hooks/pre-commit; mv -f ../bin/my-exe /tmp 2>&1; echo ---; make -j$(nproc) APP=my-exe MODE=debug SOMEOPTION=value && date
- "M-x compile + M": Runs everything but using a
different makefile, i.e:
cd ~/my-dev/linux_build/ && killall gdb ; ~/my-dev/someStuff/.git/hooks/pre-commit; mv -f ../bin/my-exe /tmp 2>&1; echo ---; make -j$(nproc) -f makefileAlternative APP=my-exe MODE=debug SOMEOPTION=value && date
- (maybe something else here in the future, with a relevant keystroke after "M-x compile")
As I'm not very good at emacs programming I'm asking to learn, so I also highly appreciate a few words for background information, e.g. why a solution is good or why this cannot be achieved (if it cannot, but I'm guessing there's a way to do this). I hope some of you can help, I would appreciate it a lot as I do this many times per day...
EDIT: Based on the answer by lawlist, I've updated the first 3 example cases with i.e: "commandline-to-be-executed" in code-tag, I think this should make the question clearer (and the objective is to be able to run each case, with as few keystrokes as possible)...