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.

zzz777
  • 111
  • 4
  • 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 '21 at 15:32

2 Answers2

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'")))

zzz777
  • 111
  • 4
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.

phils
  • 48,657
  • 3
  • 76
  • 115