I use Gnus 5.13 and Emacs 28.1 I want to strip signature on reply without "-- ". I read https://www.gnus.org/manual/gnus_48.html#Article-Signature and add to .gnus.el, (setq gnus-signature-separator '( "^-- $" ; "^[ \t]*\\(--+\\|__+\\|==+\\)[ \t]*$" "^\nbest\\( regards\\| wishes\\)?.?[ \t]*$" "^\ncheers.?[ \t]*$" "^\n\\(good\\)?bye.?[ \t]*$" "^\ngood luck.?[ \t]*$" "^\n\\(kind \\|warmest \\)?regards.?[ \t]*$" "^\nrespectfully.?[ \t]*$" "^\nsincerely.?[ \t]*$" "^\nthank you.?[ \t]*$" "^\n\\(many \\)?thanks\\( in advance\\)?.?[ \t]*$" "^\n[ \t]*\\(-+[ \t]*\\)?[a-zA-Z]+.?[ \t]*\n*\\'" ) ) But I found that customizing gnus-signature-separator has no effect on reply. I'm sad. There is a solution by customizng xcite.el. It's a wonderful package. But unsuitable for my purpose. Because it needs a little bit more operation, i.e. delete cite tag "foo > " to "> " everytime. Additionally, delete "> \n" after "...said:" and "> \n" before my signature. For that reason, please show me another solution if it exists. I can't find it in archives of this mailing list and web search. I know supercite.el and mu-cite.el too. But I don't know whether I can customize these package for my purpose. -- Satoshi Yoshida
Satoshi Yoshida wrote: > I want to strip signature on reply without "-- ". I read > https://www.gnus.org/manual/gnus_48.html#Article-Signature > and add to .gnus.el, That's probably not the way to do it, I think that, i.e. `gnus-signature-separator', should be used only for the separator(s) per se and not in order to do other stuff like that, since processing is likely to be based on that and what you don't want to see last maybe appears in the middle of the mail and other such unpredicted (?) situations ... That kind of stuff you want can be done tho for sure, did you check out this chapter: (info "(gnus) Article Washing") Have a look at `article-translate-strings', `gnus-article-strip-multiple-blank-lines', and `gnus-article-prepare-hook' ... HTH! :) -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes: > That's probably not the way to do it, I think that, i.e. > `gnus-signature-separator', should be used only for the > separator(s) per se and not in order to do other stuff like > that, since processing is likely to be based on that and what > you don't want to see last maybe appears in the middle of the > mail and other such unpredicted (?) situations ... Hard to say, I want to read whole message (100%) in article buffer. Just on reply, I want to strip signature without "-- ". > That kind of stuff you want can be done tho for sure, did you > check out this chapter: > > (info "(gnus) Article Washing") > > Have a look at `article-translate-strings', > `gnus-article-strip-multiple-blank-lines', and > `gnus-article-prepare-hook' ... I read info and found `gnus-article-strip-multiple-blank-lines' and `gnus-article-prepare-hook'. Additionally, `article-translate-strings' in https://lists.gnu.org/archive/html/info-gnus-english/2015-05/msg00025.html Though my understanding is 50%, are these things useful for washing "sent from my iPhone" (for example) automatically in article buffer? > HTH! Thanks for your assistance. -- Satoshi Yoshida
Satoshi Yoshida wrote: > Hard to say, I want to read whole message (100%) in article buffer. > Just on reply, I want to strip signature without > "-- ". It is a bit confusing to call them that. It is a local redefinition by you. "HIH" for example isn't a signature if it appears above "-- " or if there is no "-- ". >> That kind of stuff you want can be done tho for sure, did >> you check out this chapter: >> >> (info "(gnus) Article Washing") >> >> Have a look at `article-translate-strings', >> `gnus-article-strip-multiple-blank-lines', and >> `gnus-article-prepare-hook' ... > > [...] Though my understanding is 50%, are these things > useful for washing "sent from my iPhone" (for example) > automatically in article buffer? Yeah, maybe that's so common a wish it should be offered built-in, even? Or is it? I have this ... (defun gnus-article-wash-more () (interactive) (article-translate-strings '(("Skickades från E-post för Windows 10" "") ("Sendt fra min iPad" "") ("Skickat från Yahoo Mail för iPhone" "") ("--8<---------------cut" "") ("here---------------start------------->8---" "") ("here---------------end--------------->8---" "") )) (gnus-article-strip-multiple-blank-lines) ) ;; (setq gnus-article-prepare-hook nil) (defun gnus-article-prepare-hook-f () (gnus-with-article-buffer (gnus-article-wash-more) )) (add-hook 'gnus-article-prepare-hook #'gnus-article-prepare-hook-f) -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes: > It is a bit confusing to call them that. It is a local > redefinition by you. "HIH" for example isn't a signature if it > appears above "-- " or if there is no "-- ". Yes. Excuse me, my word choice was bad. > (defun gnus-article-wash-more () > (interactive) > (article-translate-strings > '(("Skickades från E-post för Windows 10" "") > ("Sendt fra min iPad" "") > ("Skickat från Yahoo Mail för iPhone" "") > ("--8<---------------cut" "") > ("here---------------start------------->8---" "") > ("here---------------end--------------->8---" "") )) > (gnus-article-strip-multiple-blank-lines) ) > > ;; (setq gnus-article-prepare-hook nil) > (defun gnus-article-prepare-hook-f () > (gnus-with-article-buffer > (gnus-article-wash-more) )) > (add-hook 'gnus-article-prepare-hook #'gnus-article-prepare-hook-f) It's amazing. -- Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes: > I know supercite.el and mu-cite.el too. > But I don't know whether I can customize these package for my purpose. I solved it by customizing mu-cite.el from melpa in reference to http://roguelife.org/~tsumura/emacs/mu-cite.html https://pc11.5ch.net/test/read.cgi/unix/1114097161/ (setq mu-cite-prefix-format '("> ")) (setq mu-cite-cited-prefix-regexp "\\(^[^ \t\n<>]+>+[ \t]*\\)") (setq mu-cite-top-format '(from " writes:\n\n")) (add-hook 'mu-cite-post-cite-hook '(lambda () (save-excursion (goto-char (point-min)) (replace-regexp "^> >" ">>") (goto-char (point-min)) (replace-regexp "^> -- *\n\\(> .*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(> \n\\)+> [ \t]*\\(best\\( regards\\| wishes\\)?\\|cheers\\|\\(good\\)?bye\\|good luck\\|\\(kind \\|warmest \\)?regards\\|respectfully\\|sincerely\\|thank you\\|\\(many \\)?thanks\\( in advance\\)?.?[ \t]*\\)\n\\(> .*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(> \n\\)+> [ \t]*\\(-+[ \t]*\\)?[a-zA-Z]+[ \t]*\n\\(> \n\\)*\n-- " "\n-- ") (goto-char (point-min)) (replace-regexp "^\\(> \n\\)+\n-- " "\n-- ") ))) But I have a concern. When I compose a message, a blank line occurs on biginning of buffer. I can't block it. -- Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes: > (setq mu-cite-prefix-format '("> ")) [...] > ))) Sorry, I fixed some mistakes. (setq mu-cite-prefix-format '("> ")) (setq mu-cite-cited-prefix-regexp "\\(^[^ \t\n<>]+>+[ \t]*\\)") (setq mu-cite-top-format '(from " writes:\n\n")) (add-hook 'mu-cite-post-cite-hook '(lambda () (save-excursion (goto-char (point-min)) (replace-regexp "^> >" ">>") (goto-char (point-min)) (replace-regexp "^> -- *\n\\(>.*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(>[ \t]+\n\\)+> \\(best\\( regards\\| wishes\\)\\|cheers\\|\\(good\\)?bye\\|\\(kind \\|warmest \\)?regards\\|respectfully\\|sincerely\\).?[ \t]*\n\\(>.*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(>[ \t]+\n\\)+> [ \t]*\\(-+[ \t]*\\)?[a-zA-Z]+[ \t]*\n\\(>[ \t]+\n\\)*\n-- " "\n-- ") (goto-char (point-min)) (replace-regexp "^\\(>[> \t]+\n\\)+\n-- " "\n-- ") ))) -- Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes:
> But I have a concern. When I compose a message,
> a blank line occurs on biginning of buffer. I can't block it.
I found a side effect. When I leave this blank line,
some headers are inserted into body of archived message.
I'm disappointed.
--
Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes:
> Sorry, I fixed some mistakes.
>
> (setq mu-cite-prefix-format '("> "))
[...]
So sorry, fixed again.
(setq mu-cite-prefix-format '("> "))
(setq mu-cite-cited-prefix-regexp "\\(^[^ \t\n<>]+>+[ \t]*\\)")
(setq mu-cite-top-format '(from " writes:\n\n"))
(add-hook 'mu-cite-post-cite-hook
'(lambda ()
(save-excursion
(goto-char (point-min))
(replace-regexp "^> >" ">>")
(goto-char (point-min))
(replace-regexp "^> -- *\n\\(>.*\n\\)*" "")
(goto-char (point-min))
(replace-regexp "^\\(>[ \t]+\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\\)?\\),[ \t]*\n\\(>.*\n\\)*" "")
(goto-char (point-min))
(replace-regexp "^\\(>[ \t]+\n\\)+> [ \t]*\\(-+[ \t]*\\)?[a-zA-Z]+[ \t]*\n\\(>[ \t]+\n\\)*\n-- " "\n-- ")
(goto-char (point-min))
(replace-regexp "^\\(>[> \t]+\n\\)+\n-- " "\n-- ")
)))
--
Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes: > I solved it by customizing mu-cite.el from melpa in reference to > http://roguelife.org/~tsumura/emacs/mu-cite.html > https://pc11.5ch.net/test/read.cgi/unix/1114097161/ [...] > But I have a concern. When I compose a message, > a blank line occurs on biginning of buffer. I can't block it. Fixed. (setq mu-cite-prefix-format '("> ")) (setq mu-cite-cited-prefix-regexp "\\(^[^ \t\n<>]+>+[ \t]*\\)") (setq mu-cite-top-format '(from " writes:\n\n")) (add-hook 'mu-cite-post-cite-hook '(lambda () (save-excursion (save-excursion (goto-char (point-min)) (replace-regexp "^> >" ">>") (goto-char (point-min)) (replace-regexp "^> -- .*\n\\(>.*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(>[ \t]+\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\\)?\\),[ \t]*\n\ \\(>.*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(>[ \t]+\n\\)+> [ \t]*\ \\(-+[ \t]*\\)?[a-zA-Z]+[ \t]*\n\\(>[ \t]+\n\\)*\n-- " "\n-- ") (goto-char (point-min)) (replace-regexp "^\\(>[> \t]+\n\\)+\n-- " "\n-- ")) (goto-line 1) (delete-blank-lines)))) -- Satoshi Yoshida
Satoshi Yoshida wrote: > Fixed. Hm, "over-engineering" isn't quite the right word here ... ? > (setq mu-cite-prefix-format '("> ")) > (setq mu-cite-cited-prefix-regexp "\\(^[^ \t\n<>]+>+[ \t]*\\)") > (setq mu-cite-top-format '(from " writes:\n\n")) > (add-hook 'mu-cite-post-cite-hook > '(lambda () Don't quote lambdas ... > (save-excursion > (save-excursion ? ? > (goto-char (point-min)) > (replace-regexp "^> >" ">>") > (goto-char (point-min)) > (replace-regexp "^> -- .*\n\\(>.*\n\\)*" "") > (goto-char (point-min)) > (replace-regexp "^\\(>[ \t]+\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\\)?\\),[ \t]*\n\ > \\(>.*\n\\)*" "") > (goto-char (point-min)) > (replace-regexp "^\\(>[ \t]+\n\\)+> [ \t]*\ > \\(-+[ \t]*\\)?[a-zA-Z]+[ \t]*\n\\(>[ \t]+\n\\)*\n-- " "\n-- ") > (goto-char (point-min)) > (replace-regexp "^\\(>[> \t]+\n\\)+\n-- " "\n-- ")) > (goto-line 1) > (delete-blank-lines)))) HTH, yours truly -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes: > Hm, "over-engineering" isn't quite the right word here ... ? I searched for "over-engineering" on web. I see. I think so. >> (add-hook 'mu-cite-post-cite-hook >> '(lambda () > > Don't quote lambdas ... > >> (save-excursion >> (save-excursion > > ? > ? Thank you for your advice. (add-hook 'mu-cite-post-cite-hook (lambda nil (save-excursion (save-excursion Is this right? -- Satoshi Yoshida
Satoshi Yoshida wrote: > (add-hook 'mu-cite-post-cite-hook > (lambda nil Most people would put it (lambda () ... ) > Is this right? If you quote a lambda it is just a list with data: '(a b c) '(lambda not an anonymous function) Eval and you will see, there's no difference in principle. Lists. -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes:
> If you quote a lambda it is just a list with data:
>
> '(a b c)
>
> '(lambda not an anonymous function)
>
> Eval and you will see, there's no difference in
> principle. Lists.
Yes - and you want to make your lambda forms subject to evaluation, for
several different reasons. They are not data. You want to use the
return value, not the expression.
Michael.
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Yes - and you want to make your lambda forms subject to evaluation, for
> several different reasons. They are not data. You want to use the
> return value, not the expression.
Thank you for your easy-to-understand explanation.
--
Satoshi Yoshida
Emanuel Berg <incal@dataswamp.org> writes: > Satoshi Yoshida wrote: > >> (add-hook 'mu-cite-post-cite-hook >> (lambda nil > > Most people would put it (lambda () ... ) I understand. > If you quote a lambda it is just a list with data: > > '(a b c) > > '(lambda not an anonymous function) > > Eval and you will see, there's no difference in > principle. Lists. Thank you for your assistance. [Summary] Install mu-cite. It's easy from MELPA. And add this to .emacs (autoload 'mu-cite-original "mu-cite" nil t) ;; for all but message-mode ;(add-hook 'mail-citation-hook (function mu-cite-original)) ;; for message-mode only (setq message-cite-function (function mu-cite-original)) Add this to .gnus.el or .emacs (setq mu-cite-prefix-format '("> ")) (setq mu-cite-cited-prefix-regexp "\\(^[^ \t\n<>]+>+[ \t]*\\)") (setq mu-cite-top-format '(from " writes:\n\n")) (add-hook 'mu-cite-post-cite-hook (lambda () (save-excursion (save-excursion (goto-char (point-min)) (replace-regexp "^> >" ">>") (goto-char (point-min)) (replace-regexp "^> -- .*\n\\(>.*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(>[ \t]+\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\\)?\\),[ \t]*\n\ \\(>.*\n\\)*" "") (goto-char (point-min)) (replace-regexp "^\\(>[ \t]+\n\\)+> [ \t]*\ \\(-+[ \t]*\\)?[a-zA-Z]+[ \t]*\n\\(>[ \t]+\n\\)*\n-- " "\n-- ") (goto-char (point-min)) (replace-regexp "^\\(>[> \t]+\n\\)+\n-- " "\n-- ")) (goto-line 1) (delete-blank-lines)))) Referenced: https://melpa.org/#/mu-cite http://roguelife.org/~tsumura/emacs/mu-cite.html https://pc11.5ch.net/test/read.cgi/unix/1114097161/ -- Satoshi Yoshida
Satoshi Yoshida wrote: > (function mu-cite-original) #'mu-cite-original > (add-hook 'mu-cite-post-cite-hook > (lambda () [...] What happens if you change the code and evaluate `add-hook' again? > (save-excursion > (save-excursion ? ? > (replace-regexp "^> >" ">>") Doesn't work on "> >" ... > [ \t] [[:blank:]] ... -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes: > Satoshi Yoshida wrote: > >> (function mu-cite-original) > > #'mu-cite-original I see. >> (add-hook 'mu-cite-post-cite-hook >> (lambda () [...] > > What happens if you change the code and evaluate > `add-hook' again? I can't understand. Please give me more clue. >> (save-excursion >> (save-excursion > > ? > ? It's strange. But I can't delete a blank line at the top of buffer without it. >> (replace-regexp "^> >" ">>") > > Doesn't work on "> >" ... Same behavior as Gnus without mu-cite. >> [ \t] > > [[:blank:]] Thank you. And I'll replace [a-zA-Z] to [[:alpha:]] -- Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes:
> [Summary]
[...]
Sorry, I'll fix three problems.
1) It doesn't work well without .signature
2) "> >" in signature is replaced to ">>"
3) For example, Can't add "> " to "a>" at the top of line
in citation.
--
Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes:
> Sorry, I'll fix three problems.
>
> 1) It doesn't work well without .signature
> 2) "> >" in signature is replaced to ">>"
> 3) For example, Can't add "> " to "a>" at the top of line
> in citation.
Fixed.
Add to .emacs
(autoload 'mu-cite-original "mu-cite" nil t)
(setq message-cite-function #'mu-cite-original)
Add to .gnus.el
(setq mu-cite-prefix-format '("> "))
(setq mu-cite-cited-prefix-regexp "\\(^[^[:blank:]\n<>]+>+[[:blank:]]*\
\\)")
(setq mu-cite-top-format '(from " writes:\n\n"))
(add-hook 'mu-cite-post-cite-hook
(lambda ()
(save-excursion
(goto-char (point-min))
(replace-regexp "^\n-- \n\\(.*\n\\)*" "")
(goto-char (point-min))
(replace-regexp "^\\([^[:blank:]\n<>]+>.*\\)" "> \\1")
(goto-char (point-min))
(replace-regexp "^\\([^\n>].+\n\n\\)\\(>[[:blank:]]+\n\
\\)+" "\\1")
(goto-char (point-min))
(replace-regexp "^> >" ">>")
(goto-char (point-min))
(replace-regexp "^> -- .*\n\\(>.*\n\\)*" "")
(goto-char (point-min))
(replace-regexp "^\\(>[[: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\\)*" "")
(goto-char (point-min))
(replace-regexp "^\\(>[[:blank:]]+\n\\)+> [[:blank:]]*\
\\(-+[[:blank:]]*\\)?[[:alpha:]]+[[:blank:]]*\n\\(>[[:blank:]]+\n\
\\)*\\'" "")
(goto-char (point-min))
(replace-regexp "^\\(>[>[:blank:]]+\n\\)+\\'" "")
(ignore-errors
(goto-char (point-max))
(insert-file-contents "~/.signature")
(insert "\n-- \n"))
(goto-line 1)
(delete-blank-lines)
(set-window-start () 1))))
--
Satoshi Yoshida
Satoshi Yoshida wrote: > Add to .emacs > > (autoload 'mu-cite-original "mu-cite" nil t) > (setq message-cite-function #'mu-cite-original) > > Add to .gnus.el > > (setq mu-cite-prefix-format '("> ")) > (setq mu-cite-cited-prefix-regexp "\\(^[^[:blank:]\n<>]+>+[[:blank:]]*\ > \\)") > (setq mu-cite-top-format '(from " writes:\n\n")) > (add-hook 'mu-cite-post-cite-hook > (lambda () > (save-excursion > (goto-char (point-min)) > (replace-regexp "^\n-- \n\\(.*\n\\)*" "") > (goto-char (point-min)) > (replace-regexp "^\\([^[:blank:]\n<>]+>.*\\)" "> \\1") > (goto-char (point-min)) > (replace-regexp "^\\([^\n>].+\n\n\\)\\(>[[:blank:]]+\n\ > \\)+" "\\1") > (goto-char (point-min)) > (replace-regexp "^> >" ">>") > (goto-char (point-min)) > (replace-regexp "^> -- .*\n\\(>.*\n\\)*" "") > (goto-char (point-min)) > (replace-regexp "^\\(>[[: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\\)*" "") > (goto-char (point-min)) > (replace-regexp "^\\(>[[:blank:]]+\n\\)+> [[:blank:]]*\ > \\(-+[[:blank:]]*\\)?[[:alpha:]]+[[:blank:]]*\n\\(>[[:blank:]]+\n\ > \\)*\\'" "") > (goto-char (point-min)) > (replace-regexp "^\\(>[>[:blank:]]+\n\\)+\\'" "") > (ignore-errors > (goto-char (point-max)) > (insert-file-contents "~/.signature") > (insert "\n-- \n")) > (goto-line 1) > (delete-blank-lines) > (set-window-start () 1)))) For modular, idiomatic Elisp the TODO list would be: 1. Split into functions with names that explain what they do. 2. Instead of `replace-regexp', use (while (re-search-forward RE nil t) (replace-match STR) ) See the docstrings for those three functions. -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes:
> 1. Split into functions with names that explain what they do.
>
> 2. Instead of `replace-regexp', use
>
> (while (re-search-forward RE nil t)
> (replace-match STR) )
I see. Thank you. Is this fix right?
(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)))
(add-hook 'mu-cite-post-cite-hook
(lambda ()
(save-excursion
(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\
\\( 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\\)*" "")
(goto-char (point-min))
(re-search-forward "^\"?\\([^[:blank:]\n<>]+\\)\
\\([^\n<>]+\\)?\"? <\\([^\n<>]+\\)> writes:" nil t)
(setq first-name (match-string 1))
(setq middle-last-name (match-string 2))
(setq mail-address (match-string 3))
(strip-signature (format "^\\(>[[:blank:]]+\n\\)*>\
[[:blank:]]*\\(-+[[:blank:]]*\\)?%s\\(%s\\)?\\([[:blank:]]*\\(\n>\
[[:blank:]]+\\)*<?%s>?\\)?[[:blank:]]*\n\\(>[[:blank:]]+\n\\)*\
\\'" first-name middle-last-name mail-address) "")
(strip-signature "^\\(>[>[:blank:]]+\n\\)+\\'" "")
(ignore-errors
(goto-char (point-max))
(insert-file-contents "~/.signature")
(insert "\n-- \n"))
(goto-line 1)
(delete-blank-lines)
(set-window-start () 1))))
--
Satoshi Yoshida
Satoshi Yoshida wrote: >> 1. Split into functions with names that explain what >> they do. >> >> 2. Instead of `replace-regexp', use >> >> (while (re-search-forward RE nil t) >> (replace-match STR) ) > > I see. Thank you. Is this fix right? Make the whole thing a function that you add to the the hook. Use blank lines to separate different parts. This also makes it easier to test, you can simply call the function. And try out and optimize the different parts one by one. But only do modules when it makes sense semantically, i.e. when one can clearly say "this function does this, this other function does something different", don't split it up just because "this function is too long". One way to check if it does make sense is to write names that makes sense, when that is difficult, "hm ... what DO we call THIS function?" then that is an indication that function isn't a good idea. So while in general it's good with modules but in particular good modules are even better ;) > (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. -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes:
> (defun gnus-article-wash-more ()
> (interactive)
> (article-translate-strings
> '(("Skickades från E-post för Windows 10" "")
> ("Sendt fra min iPad" "")
> ("Skickat från Yahoo Mail för iPhone" "")
> ("--8<---------------cut" "")
> ("here---------------start------------->8---" "")
> ("here---------------end--------------->8---" "") ))
> (gnus-article-strip-multiple-blank-lines) )
>
> ;; (setq gnus-article-prepare-hook nil)
> (defun gnus-article-prepare-hook-f ()
> (gnus-with-article-buffer
> (gnus-article-wash-more) ))
> (add-hook 'gnus-article-prepare-hook #'gnus-article-prepare-hook-f)
I'm currently considering function name.
Please tell me what last "f" means. I want to use it as reference.
--
Satoshi Yoshida
Satoshi Yoshida <dynamisxar@icloud.com> writes: > Emanuel Berg <incal@dataswamp.org> writes: >> (add-hook 'gnus-article-prepare-hook #'gnus-article-prepare-hook-f) > > I'm currently considering function name. > Please tell me what last "f" means. I want to use it as reference. Maybe function? -- Satoshi Yoshida
Satoshi Yoshida wrote: >>> (add-hook 'gnus-article-prepare-hook #'gnus-article-prepare-hook-f) >> >> I'm currently considering function name. Please tell me >> what last "f" means. I want to use it as reference. > > Maybe function? Yes, correct. I got it from someone else. -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes:
> Satoshi Yoshida wrote:
>
>>>> (add-hook 'gnus-article-prepare-hook #'gnus-article-prepare-hook-f)
>>>
>>> I'm currently considering function name. Please tell me
>>> what last "f" means. I want to use it as reference.
>>
>> Maybe function?
>
> Yes, correct. I got it from someone else.
Thank you. Now I can consider good function name.
--
Satoshi Yoshida
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
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:]]+\\)*<?%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) 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
Emanuel Berg <incal@dataswamp.org> writes: > In your case, you could do > > (defun strip-signature (re &optional rep) > (or rep (setq rep "")) > ;; ... It's amazing. But I want to avoid grobal variable. Please show me the way to use let instead of setq. I don't know how to use it in this case. > 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) ) Thank you. I want to use dolist. -- Satoshi Yoshida
Satoshi Yoshida wrote: >> In your case, you could do >> >> (defun strip-signature (re &optional rep) >> (or rep (setq rep "")) >> ;; ... > > It's amazing. But I want to avoid grobal variable. > Please show me the way to use let instead of setq. > I don't know how to use it in this case. 'rep' is a formal parameter of the function, under lexical/static scope - which you should always use BTW, put ;;; -*- lexical-binding: t -*- topmost in your file (every Elisp file) if you didn't - that means you get a local variable that again is lexical/static and, equivalently, not dynamic/special. Just try - and you will fly ... ;;; -*- lexical-binding: t -*- (defun c () (message b) ) (defun a (b) (message b) (setq b "ah") (c) ) ;; (a "oh") ;; ^ eval me Also, byte-compiling this will echo a warning saying b is a free variable, and this even under dynamic/special scope where the code actually works tho (i.e. this particular use of 'a' and 'c' where 'a' is used first). >> 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) ) > > Thank you. I want to use dolist. As you see you don't need `apply' even with `dolist', no need. -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes: > Just try - and you will fly ... > > ;;; -*- lexical-binding: t -*- > > (defun c () > (message b) ) > > (defun a (b) > (message b) > (setq b "ah") > (c) ) > > ;; (a "oh") > ;; ^ eval me Error message is displayed on *Backtrace* buffer. Debugger entered--Lisp error: (void-variable b) (message b) c() a("oh") (progn (a "oh")) eval((progn (a "oh")) t) elisp--eval-last-sexp(nil) eval-last-sexp(nil) funcall-interactively(eval-last-sexp nil) call-interactively(eval-last-sexp nil nil) command-execute(eval-last-sexp) And "ah" is displayed on mini buffer in case without ";;; -*- lexical-binding: t -*-". > Also, byte-compiling this will echo a warning saying b is > a free variable, and this even under dynamic/special scope > where the code actually works tho (i.e. this particular use of > 'a' and 'c' where 'a' is used first). My understanding is 50%. Do you mean that using setq without ";;; -*- lexical-binding: t -*-" has no problem? -- Satoshi Yoshida
Satoshi Yoshida wrote: >> Just try - and you will fly ... >> >> ;;; -*- lexical-binding: t -*- >> >> (defun c () >> (message b) ) >> >> (defun a (b) >> (message b) >> (setq b "ah") >> (c) ) >> >> ;; (a "oh") >> ;; ^ eval me > > Error message is displayed on *Backtrace* buffer. Indeed, it shouldn't work with lexical/static scope since, despite `setq', b is not a global variable. So it'll be undefined in 'c'. > And "ah" is displayed on mini buffer in case without > ";;; -*- lexical-binding: t -*-". Yes, with dynamic/special scope it does work but it's not encouraged to use that unless one has a good reason. Actually, to use that _in general_ I think is never encouraged. One can still have individual variables that are global tho if and when that's called for ... >> Also, byte-compiling this will echo a warning saying b is >> a free variable, and this even under dynamic/special scope >> where the code actually works tho (i.e. this particular use >> of 'a' and 'c' where 'a' is used first). > > My understanding is 50%. That's normal and in particular in this case ... > Do you mean that using setq without ";;; -*- > lexical-binding: t -*-" has no problem? I'm saying 1) Always use lexical/static scope, i.e. put ;;; -*- lexical-binding: t -*- first in all and every new Elisp file you create. 2) In this case, since there is a formal parameter with the same name, `setq' does not create a global variable. (defun strip-signature (re &optional rep) (or rep (setq rep "")) ;; ... This is OK. Only if you misspell "rep" to something that isn't rep (or re) a global variable will be created :) -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes:
> 1) Always use lexical/static scope, i.e. put
>
> ;;; -*- lexical-binding: t -*-
>
> first in all and every new Elisp file you create.
>
> 2) In this case, since there is a formal parameter with the
> same name, `setq' does not create a global variable.
>
> (defun strip-signature (re &optional rep)
> (or rep (setq rep ""))
> ;; ...
>
> This is OK. Only if you misspell "rep" to something that isn't
> rep (or re) a global variable will be created :)
I understand. As for me, putting ";;; -*- lexical-binding: t -*-" is
difficult. Because the file (.gnus.el or .emacs) isn't new. It consists
of my code and the other parts that already exists. If I (or someone) put
";;; -*- lexical-binding: t -*-", the other parts will be influenced too.
So I want to leave my code as it is. Thank you anyway.
--
Satoshi Yoshida
Satoshi Yoshida wrote: > I understand. As for me, putting ";;; -*- lexical-binding: > t -*-" is difficult. Because the file (.gnus.el or .emacs) > isn't new. It consists of my code and the other parts that > already exists. If I (or someone) put ";;; -*- > lexical-binding: t -*-", the other parts will be > influenced too. > > So I want to leave my code as it is. Thank you anyway. Tell him ... -- underground experts united https://dataswamp.org/~incal
Satoshi Yoshida <dynamisxar@icloud.com> writes:
> I understand. As for me, putting ";;; -*- lexical-binding: t -*-" is
> difficult. Because the file (.gnus.el or .emacs) isn't new. It consists
> of my code and the other parts that already exists. If I (or someone) put
> ";;; -*- lexical-binding: t -*-", the other parts will be influenced too.
Most of the time this is not a problem at all. All Emacs sources were
converted to lexical binding like this. There are not many parts that
need special treatmeant - most of the stuff causing trouble hints at
problems and errors and style issues you should fix anyway.
If you care about your code you should do this conversion sooner or
later. Support for dynamical binding doesn't get better, and it has
advantages: you get better warnings and more efficient code.
Michael.
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Most of the time this is not a problem at all. All Emacs sources were
> converted to lexical binding like this. There are not many parts that
> need special treatmeant - most of the stuff causing trouble hints at
> problems and errors and style issues you should fix anyway.
>
> If you care about your code you should do this conversion sooner or
> later. Support for dynamical binding doesn't get better, and it has
> advantages: you get better warnings and more efficient code.
Thank you very much. It was really easy to understand. I'll premise
lexical binding on coding elisp.
--
Satoshi Yoshida
Emanuel Berg <incal@dataswamp.org> writes:
> Satoshi Yoshida wrote:
>
>> I understand. As for me, putting ";;; -*- lexical-binding:
>> t -*-" is difficult. Because the file (.gnus.el or .emacs)
>> isn't new. It consists of my code and the other parts that
>> already exists. If I (or someone) put ";;; -*-
>> lexical-binding: t -*-", the other parts will be
>> influenced too.
>>
>> So I want to leave my code as it is. Thank you anyway.
>
> Tell him ...
I see. I'll do so if I can. Thank you very much.
(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-sig (re &optional rep)
(or rep (setq rep ""))
(goto-char (point-min))
(while (re-search-forward re nil t)
(replace-match rep)))
(defun my-mu-cite-hook-function ()
(save-excursion
(goto-char (point-min))
(re-search-forward "^\\(\n-- \n\\(.*\n\\)*\\)" nil t)
(let ((my-sig (match-string 1)))
(dolist (e '(("^\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\\)*")))
(strip-sig (car e) (cadr e)))
(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) ""))
(m-addr (match-string 3)))
(strip-sig (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 m-addr))))))
(strip-sig "^\\(>[>[:blank:]]+\n\\)+\\'")
(goto-char (point-max))
(ignore-errors (insert my-sig)))))
(add-hook 'mu-cite-post-cite-hook #'my-mu-cite-hook-function)
--
Satoshi Yoshida
Satoshi Yoshida wrote: > I see. I'll do so if I can. Thank you very much. With regular expressions it will always get a bit chaotic, and with tons of them like you have it will look even more so, but that doesn't mean it _is_. I'm sure you can polish that code every day for the rest of 2022 but if it works it looks good enough to me. -- underground experts united https://dataswamp.org/~incal
Emanuel Berg <incal@dataswamp.org> writes: > I'm sure you can polish that code every day for the rest of > 2022 but if it works it looks good enough to me. Fixed some problems. (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 &optional replacement) (or replacement (setq replacement "")) (goto-char (point-min)) (while (re-search-forward regexp nil t) (replace-match replacement))) (defun my-mu-cite-hook-function () (save-excursion (goto-char (point-min)) (re-search-forward "^\\(\n-- \n\\(.*\n\\)*\\)" nil t) (let ((my-signature (match-string 1))) (dolist (e '(("^\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\\)*"))) (strip-signature (car e) (cadr e))) (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:]]*\\(-+[[: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 my-signature))))) (add-hook 'mu-cite-post-cite-hook #'my-mu-cite-hook-function) I put this code on web additionally the cases of Mew and Wanderlust. Though it's a Japanese site, please use translation site if you need. https://zenn.dev/satoshiy/articles/mu-cite-strip-signature -- Satoshi Yoshida
Satoshi Yoshida wrote: >> I'm sure you can polish that code every day for the rest of >> 2022 but if it works it looks good enough to me. > > Fixed some problems. > > (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 &optional replacement) > (or replacement (setq replacement "")) > (goto-char (point-min)) > (while (re-search-forward regexp nil t) > (replace-match replacement))) > > (defun my-mu-cite-hook-function () > (save-excursion > (goto-char (point-min)) > (re-search-forward "^\\(\n-- \n\\(.*\n\\)*\\)" nil t) > (let ((my-signature (match-string 1))) > (dolist (e '(("^\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\\)*"))) > (strip-signature (car e) (cadr e))) > (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:]]*\\(-+[[: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 my-signature))))) > > (add-hook 'mu-cite-post-cite-hook #'my-mu-cite-hook-function) Looks good to me :) -- underground experts united https://dataswamp.org/~incal