1

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"
  (interactive)
  (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.

1
  • 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
    Commented Sep 15, 2021 at 15:32

2 Answers 2

0

Found a solution: use concat to build sed string

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

0

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"
  (interactive)
  (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"
  (interactive)
  (compile
   (format
    "mybuild | sed -e %s"
    (mapconcat #'shell-quote-argument
               '("s/path-x/path-y/"
                 "s/foo/bar/"
                 "...")
               " -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.