[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strip signature on reply without standard separator
From: |
Satoshi Yoshida |
Subject: |
Re: Strip signature on reply without standard separator |
Date: |
Fri, 16 Sep 2022 08:50:56 +0900 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Emanuel Berg <incal@dataswamp.org> writes:
> Make the whole thing a function that you add to the the hook.
I see. About function name, I refered to
https://ayatakesi.github.io/lispref/28.2/elisp-ja.html#Setting-Hooks
>> (strip-signature "^\n-- \n\\(.*\n\\)*" "")
>> (strip-signature "^\\([^[:blank:]\n<>]+>.*\\)" "> \\1")
>> (strip-signature "^\\([^\n>].+\n\n\\)\\(>[[:blank:]]+\n\\\)+" "\\1")
>> (strip-signature "^> >" ">>")
>> (strip-signature "^> -- .*\n\\(>.*\n\\)*" "")
>> (strip-signature "^\\(>[[:blank:]]+\n\\)+> \\(best\
>
> Here it may be a better idea to have those REs in a list and
> then iterate that (a loop) instead of calling the same
> function so many times.
I consulted members of https://emacs-jp.github.io/ on slack.
Many thanks for their kind help.
(setq mu-cite-prefix-format '("> "))
(setq mu-cite-cited-prefix-regexp "\\(^[^[:blank:]\n<>]+>+[[:blank:]]*\\)")
(setq mu-cite-top-format '(from " writes:\n\n"))
(defun strip-signature (regexp replacement)
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(replace-match replacement)))
(defun my-mu-cite-hook-function ()
(save-excursion
(dolist (elm '(("^\n-- \n\\(.*\n\\)*" "")
("^\\([^[:blank:]\n<>]+>.*\\)" "> \\1")
("^\\([^\n>].+\n\n\\)\\(>[[:blank:]]+\n\\)+" "\\1")
("^> >" ">>")
("^> -- .*\n\\(>.*\n\\)*" "")
("^\\(>[[:blank:]]+\n\\)+> \\(best\\( regards\
\\| wishes\\)?\\|cheers\\|\\(good\\)?bye\\|good luck\\|\\(kind \\|warm\
\\(est\\)? \\)?regards\\|respectfully\\|\\(yours \\)?sincerely\\( yours\
\\)?\\|thank you\\( very much\\)?\\|\\(many \\)?thanks\\( in advance\
\\| very much\\)?\\),[[:blank:]]*\n\\(>.*\n\\)*" "")))
(apply #'strip-signature elm))
(goto-char (point-min))
(when (re-search-forward "^\"?\\([^[:blank:]\n<>]+\\)\\([^\n<>]+\\)?\"? \
<\\([^\n<>]+\\)> writes:" nil t)
(let ((first-name (match-string 1))
(middle-last-name (or (match-string 2) ""))
(mail-address (match-string 3)))
(strip-signature (apply #'format "^\\(>[[:blank:]]+\n\\)*>\
[[:blank:]]*\\(-+[[:blank:]]*\\)?%s\\(%s\\)?\\([[:blank:]]*\\(\n>\
[[:blank:]]+\\)*<?%s>?\\)?[[:blank:]]*\n\\(>[[:blank:]]+\n\\)*\\'\
" (mapcar #'regexp-quote (list first-name middle-last-name mail-address))) "")))
(strip-signature "^\\(>[>[:blank:]]+\n\\)+\\'" "")
(goto-char (point-max))
(ignore-errors
(insert-file-contents "~/.signature")
(insert "\n-- \n"))))
(add-hook 'mu-cite-post-cite-hook #'my-mu-cite-hook-function)
--
Satoshi Yoshida
- Re: Strip signature on reply without standard separator, Satoshi Yoshida, 2022/09/03
- Re: Strip signature on reply without standard separator, Emanuel Berg, 2022/09/03
- Re: Strip signature on reply without standard separator, Satoshi Yoshida, 2022/09/06
- Re: Strip signature on reply without standard separator, Emanuel Berg, 2022/09/06
- Re: Strip signature on reply without standard separator,
Satoshi Yoshida <=
- Re: Strip signature on reply without standard separator, Emanuel Berg, 2022/09/18
- Re: Strip signature on reply without standard separator, Satoshi Yoshida, 2022/09/21
- Re: Strip signature on reply without standard separator, Emanuel Berg, 2022/09/21
- Re: Strip signature on reply without standard separator, Satoshi Yoshida, 2022/09/23
- Re: Strip signature on reply without standard separator, Emanuel Berg, 2022/09/24
- Re: Strip signature on reply without standard separator, Satoshi Yoshida, 2022/09/24
- Re: Strip signature on reply without standard separator, Emanuel Berg, 2022/09/24
- Re: Strip signature on reply without standard separator, Satoshi Yoshida, 2022/09/26
- Re: Strip signature on reply without standard separator, Emanuel Berg, 2022/09/26
- Re: Strip signature on reply without standard separator, Michael Heerdegen, 2022/09/25