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?

  • 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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