If I understand you properly, you're asking how to automate calling a command with a specific set of arguments. To do this, first take a look at the command in question: C-h f shell-command-on-region:
shell-command-on-region is an interactive compiled Lisp function in
It is bound to M-|, .
(shell-command-on-region START END ...
Here is the final elisp function that works. It automatically switches to the window and move the cursor to the bottom .
(compile (concat "g++ " (file-name-nondirectory (buffer-file-name)) " -o " (file-name-sans-extension (file-name-nondirectory (buffer-file-name))) " && ./" (file-name-...
compile uses the shell. You can chain program execution with && like g++ test.cc -o test && ./test. With the last command ./test is executed if compilation with g++ succeeds.
I'll modify your command accordingly:
(let ((src (file-name-nondirectory (buffer-file-name)))
@phils answered the question. This is just to say that the version of find-grep-dired in library find-dired+.el provides a bit more than the vanilla version:
It has two optional args, DEPTH-LIMITS and EXCLUDED-PATHS.
The interactive spec uses read-from-minibuffer, read-file-name, dired-regexp-history and find-diredp-default-fn.
find-grep-dired is an ...
The following does that and presents the results as a dired buffer:
You'll also want to know about:
(which doesn't support the -l option to grep, but is usually what I want from a recursive regexp search.)