Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic global replacement with line numbers, emacs

Tags:

emacs

I'm trying to do some debugging on some Prolog code, and I have several calls to a method.

Is it possible to do a global replace within emacs so that I could create a write statement that would displace the current line in the program?

Essentially, assuming a method call X and a write statement write(some string), could I replace all the instances of

X,

with

X, write(LINE-NUMBER)

where LINE-NUMBER was obtained through some emacs call?

Please let me know if I'm not being clear and thanks in advance.

like image 511
user1394062 Avatar asked Oct 21 '25 17:10

user1394062


1 Answers

This page has a similar example.

From it, I tried the following command

M-x replace-regexp
Replace regexp: \(word_to_replace\)
Replace regexp with: \1, write(\,(line-number-at-pos)

The replace-regexp can be heavy handed, so you must be careful with the regex you use for the pattern. M-x query-replace-regexp may be useful too, if there are not too many matches.

like image 111
dave jones Avatar answered Oct 23 '25 07:10

dave jones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!