Now, the trick is to have the expression be handled as an operation and not as an arbitrary string, and that's where the " \," prefix comes into play. The emacs lisp expression is " (+ 21 (string-to-number \1))", which means "convert the \1 match that is a string into its numerical value and add 21 to it".īut, wasn't \1 supposed to match +, which is a number? Well, yes, but really it's just digits, hence strings, that have no numerical value whatsoever, so first, we need the expression to convert them to a numerical value before adding 21 to them. In emacs, I can replace the match with that: Notice that in emacs, " (" and " )" need to be escaped, also I could have used the class.Īnd now I need to replace that with the expression that will add 21 to the number. Since there are no instances of fn:\d+ without the brackets that are not footnotes, I figured I could just be searching for that string: The org-mode footnotes all look like, where " 12" is the note number that I need to replace with an incremented number. In emacs, however, everything can be interpreted as an expression, hence you can insert code wherever you want and get the result from that code right in the document. For ex, in my case, add 21 to the matching number, which seems pretty trivial, when you think of it, but doing that will involve other technologies, like using perl or some other command line thing. Mostly because the interface is clearer than emacs, and the regexp feels more modern ( \d vs )īut one thing you can't do in BBEdit is to send commands to the replace string.
I usually use BBedit for any serious regex work. But then, for the final delivery I needed to put all that in one big file and was faced with the fact that all my footnotes would need to be re-indexed manually because each file had notes starting at 1. So I decided to write each chapter in a different org file, and send them one by one to my director. I've resumed studies last year, trying to finish an MA in Japan Studies I started 25 years ago.įor the first year, I only have to write a 30ish pages dissertation on my subject (representation of women in kendo magazines in Japan) and I decided to go the emacs + org-mode way, with the easy export to ODF function that's packaged with the thing. Not strictly related to translation but here is what's happening. ) when the correct function name is (string-to-number. Last but not least, I noticed that the whole post was originally written with (string-as-number.
That regex-replace improvement was mentionned in Stevve Yegge's emacs 22 introduction, back in 2006. June 28 update: using \#1 instead of (string-to-number \1)Ī reader on reddit mentionned that the manual also had the " \#d" construct to replace the often used (string-to-number \d) function.