I have to live with a build system that moves pieces of source around before running make. I have a function that pipes output of make through a sed to remap file references back to the source tree.

(defun mybuild ()
  "Run mybuild"
  (compile "mybuild | sed -e 's/path-x/path-y/' -e ..."))

My problem is that the sed expression is getting too long and it does not look elegant.

Are there any nice solutions to this problem, e.g. set compilation-filter function that will have one sed/regexp expression per line?

Also, I do not want to have a global change in compilation filter for all invocations of compile command.

I suspect that the solution could be as simple defining sed command as a multi line string and then use in compile command expression.

  • 2
    sed has a -f switch that allows you to put all that in a file (and if you are lucky, never have to look at it again - ever :-) )
    – NickD
    Sep 15, 2021 at 15:32

2 Answers 2


Found a solution: use concat to build sed string

(defun mksed ()
   "sed -e 's/path-x/path-y'"
   " -e 's/path-a/path-b'")))


Are there any nice solutions to this problem, e.g. ... one sed/regexp expression per line?

Escaped newlines are removed from the double-quoted read syntax for strings, so you can do this:

(defun mybuild ()
  "Run mybuild"
  (compile "mybuild | sed \
-e 's/path-x/path-y/' \
-e ..."))

If you wanted to protect against potential shell quoting issues, you could do something like:

(defun mybuild ()
  "Run mybuild"
    "mybuild | sed -e %s"
    (mapconcat #'shell-quote-argument
               " -e "))))

Personally I'd make it all part of the mybuild script, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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