Andy's Cafe

Emacs Allows elisp in Find Replaces

Last updated :

Problem

You have a massive list of tuples (like 800 tuples) and you need to increment the number of one slot in the tuple.

Start with this:

(1, a), (2, b), (3, c), (4, d), (5, e)  (400, aaabbbccc)

But you want:

(2, a), (3, b), (4, c), (5, d), (6, e)  (401, aaabbbccc)

Solution

query-replace-regexp in emacs allows you to run any elisp you want on the match.

M-x query-replace-regex from (\([0-9]+\) to (\,(+ 1 (string-to-number \1)) emacs is backwards from every other regex engine. ( is match a literal paren. \( … \) is a capture group.

So then the replace is:

Reply via email

Tags

#emacs