From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2369 invoked from network); 19 Sep 2022 00:58:52 -0000 Received: from lists.gnu.org (209.51.188.17) by inbox.vuxu.org with ESMTPUTF8; 19 Sep 2022 00:58:52 -0000 Received: from localhost ([::1]:34750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oa57Z-00081W-A9 for ml@inbox.vuxu.org; Sun, 18 Sep 2022 20:58:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oa57V-000819-Gs for info-gnus-english@gnu.org; Sun, 18 Sep 2022 20:58:45 -0400 Received: from ciao.gmane.io ([116.202.254.214]:40876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oa57T-0000Ph-No for info-gnus-english@gnu.org; Sun, 18 Sep 2022 20:58:45 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1oa57Q-000AW6-9i for info-gnus-english@gnu.org; Mon, 19 Sep 2022 02:58:40 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: info-gnus-english@gnu.org To: info-gnus-english@gnu.org From: Emanuel Berg Subject: Re: Strip signature on reply without standard separator Date: Mon, 19 Sep 2022 02:58:34 +0200 Message-ID: <87illkyybp.fsf@dataswamp.org> References: <87y1vykpl2.fsf@icloud.com> <87zggbz3ho.fsf@icloud.com> <87bksaz837.fsf@icloud.com> <87a67ul62m.fsf@dataswamp.org> <87mtbufg7e.fsf@icloud.com> <875yii2oru.fsf@dataswamp.org> <875yih6n25.fsf_-_@icloud.com> <878rnaw3tw.fsf_-_@icloud.com> <87mtbgarre.fsf@icloud.com> <87czcb6gjp.fsf@dataswamp.org> <87r10onki5.fsf@icloud.com> <8735d47zos.fsf@dataswamp.org> <87fsgsgpsv.fsf@icloud.com> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cancel-Lock: sha1:uVWQj6Jd83iCjoP51CAYVoIVknI= Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=gegu-info-gnus-english@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: info-gnus-english@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Announcements and discussions for GNUS, the GNU Emacs Usenet newsreader \(in English\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: info-gnus-english-bounces+ml=inbox.vuxu.org@gnu.org Sender: "info-gnus-english" Satoshi Yoshida wrote: > I consulted members of https://emacs-jp.github.io/ on slack. > Many thanks for their kind help. Good to hear from Emacs Japan, I love Japanese technology <3 > (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\\)*" "") This can be made look better (reduce programmer's reading and typing code) by making the second formal parameter to strip-signature &optional, it'd then default to nil which your function could treat as "don't replace, just drop". That way you don't have to give those ugly "" as arguments all the time. But it's absolutely not wrong the way you have it. In general, if the last argument can be nil for no, empty, nothing, or does not apply, this argument can safely be made optional from the above perspective. Be sure to try it for type (or set it to, e.g. 0, if nil implies that) before using it as an integer or string tho, as (integerp nil) ; nil (stringp nil) ; nil See this file: https://dataswamp.org/~incal/emacs-init/dwim.el In your case, you could do (defun strip-signature (re &optional rep) (or rep (setq rep "")) ;; ... and not have to change anything else. > ("^\\([^[: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)) Okay, I dare say most people would write that (dolist (e '((1 2) (3 4))) (message "%s %s" (car e) (cadr e)) ) Or maybe (require 'cl-lib) (cl-loop for (a b) in '((x y) (i j)) do (message "%s %s" a b) ) > (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:]]+\\)*?\\)?[[: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) I'm sure you can develop it along the same and other lines but you have understood the message, good. REs are very useful and you got a lot of practice on those. But also a piece of code that did what you wanted. -- underground experts united https://dataswamp.org/~incal