1

I'm editing a .rb file with about 3000 lines of code.

This file has about 30+ statements that does a .create(

create() appears in many ways:
as part of another expression: puts Foo.create(...)

or

multiline:

Foo.create( baa: "baz" ) etc

We suspect there might be a bug close to the create()s, so we want to add a line containing the word "byebug" to the preceding line of any line containing create(

Can Emacs help me do this easily?

Drew
  • 75,699
  • 9
  • 109
  • 225
american-ninja-warrior
  • 3,773
  • 2
  • 21
  • 40
  • I would suggest `regex-builder` to help you build the regex that will match the string to replace. Then `replace-regexp` to do the replace. – Nsukami _ Mar 13 '18 at 23:06

1 Answers1

1

we want to add a line containing the word "byebug" to the preceding line of any line containing create(

Here's a replace-regexp approach:

M-x query-replace-regexp RET ^.*create( RET byebug C-qC-j \& RET

phils
  • 48,657
  • 3
  • 76
  • 115