1

In my workflow I copy emails into an orgmode file. I'd like to have head of the email formatted. In english emails (just as an explanation) I'd like to have *To:* instead of To:, because orgmode then prints the word between the two stars in bold. The word "To:" occurs at the beginning of a new line, but empty spaces may occur before the "To:" in the new line.

So the question is, can you write a function that replaces in a region (!) the words

"Von:", "Gesendet:", "An:", "Cc:", "Betreff:"

with

 "*Von:*", , "*Gesendet:*", "*An:*", "*Cc:*", "*Betreff:*" 

under the condition that the string is at the beginning of a new line, multiple empty spaces before the string are allowed.

I put the strings into "", but in the copied emails there are no "" around them, it's only Von:, of course.

Let's assume the name of the function is "email-header". I'd mark a region in a buffer and do M-x email-header and in the region all mentioned keywords shall be replaced as described.

Yeah, well, I'm only a user and hacking an example like https://stackoverflow.com/a/2592685 is far beyond my capabilities.

1 Answer 1

1

Try this, after selecting the region:

M-x query-replace-regexp
RET
^ *\(Von\|Gesendet\|Cc\):
RET
*\1*:

(where RET is the Enter key).

That will replace matches of

  • zero or more space chars; followed by either Von, Gesendet, or Cc; followed by a colon (:); followed by a space char

with

  • The matched text Von, Gesendet, or Cc, wrapped in * chars.

The \1 says to insert the text matched by the 1st regexp group.

2
  • typo: *\1* -> *\1:*
    – shynur
    Aug 22, 2023 at 5:37
  • @shynur: Thx; corrected.
    – Drew
    Aug 22, 2023 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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