Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Strip signature on reply without standard separator
@ 2022-08-09  4:28 Satoshi Yoshida
  2022-08-09  5:56 ` Emanuel Berg
  2022-08-11  6:41 ` Satoshi Yoshida
  0 siblings, 2 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-09  4:28 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-09  4:28 Strip signature on reply without standard separator Satoshi Yoshida
@ 2022-08-09  5:56 ` Emanuel Berg
  2022-08-09  8:34   ` Satoshi Yoshida
  2022-08-11  6:41 ` Satoshi Yoshida
  1 sibling, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-08-09  5:56 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-09  5:56 ` Emanuel Berg
@ 2022-08-09  8:34   ` Satoshi Yoshida
  2022-08-09  8:52     ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-09  8:34 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-09  8:34   ` Satoshi Yoshida
@ 2022-08-09  8:52     ` Emanuel Berg
  2022-08-09  9:25       ` Satoshi Yoshida
  2022-09-11  9:46       ` Satoshi Yoshida
  0 siblings, 2 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-08-09  8:52 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-09  8:52     ` Emanuel Berg
@ 2022-08-09  9:25       ` Satoshi Yoshida
  2022-09-11  9:46       ` Satoshi Yoshida
  1 sibling, 0 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-09  9:25 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-09  4:28 Strip signature on reply without standard separator Satoshi Yoshida
  2022-08-09  5:56 ` Emanuel Berg
@ 2022-08-11  6:41 ` Satoshi Yoshida
  2022-08-11 14:48   ` Satoshi Yoshida
                     ` (2 more replies)
  1 sibling, 3 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-11  6:41 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-11  6:41 ` Satoshi Yoshida
@ 2022-08-11 14:48   ` Satoshi Yoshida
  2022-08-12  3:06     ` Satoshi Yoshida
  2022-08-11 15:26   ` Satoshi Yoshida
  2022-08-24  2:30   ` Satoshi Yoshida
  2 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-11 14:48 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-11  6:41 ` Satoshi Yoshida
  2022-08-11 14:48   ` Satoshi Yoshida
@ 2022-08-11 15:26   ` Satoshi Yoshida
  2022-08-24  2:30   ` Satoshi Yoshida
  2 siblings, 0 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-11 15:26 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-11 14:48   ` Satoshi Yoshida
@ 2022-08-12  3:06     ` Satoshi Yoshida
  0 siblings, 0 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-12  3:06 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-11  6:41 ` Satoshi Yoshida
  2022-08-11 14:48   ` Satoshi Yoshida
  2022-08-11 15:26   ` Satoshi Yoshida
@ 2022-08-24  2:30   ` Satoshi Yoshida
  2022-08-24  2:37     ` Emanuel Berg
  2 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-24  2:30 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-24  2:30   ` Satoshi Yoshida
@ 2022-08-24  2:37     ` Emanuel Berg
  2022-08-24  3:55       ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-08-24  2:37 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-24  2:37     ` Emanuel Berg
@ 2022-08-24  3:55       ` Satoshi Yoshida
  2022-08-24  5:28         ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-24  3:55 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-24  3:55       ` Satoshi Yoshida
@ 2022-08-24  5:28         ` Emanuel Berg
  2022-08-24 22:26           ` Michael Heerdegen
  2022-08-25  3:04           ` Strip signature on reply without standard separator [solved] Satoshi Yoshida
  0 siblings, 2 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-08-24  5:28 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-24  5:28         ` Emanuel Berg
@ 2022-08-24 22:26           ` Michael Heerdegen
  2022-08-25  2:10             ` Satoshi Yoshida
  2022-08-25  3:04           ` Strip signature on reply without standard separator [solved] Satoshi Yoshida
  1 sibling, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-08-24 22:26 UTC (permalink / raw)
  To: info-gnus-english

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.



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-24 22:26           ` Michael Heerdegen
@ 2022-08-25  2:10             ` Satoshi Yoshida
  0 siblings, 0 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-25  2:10 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator [solved]
  2022-08-24  5:28         ` Emanuel Berg
  2022-08-24 22:26           ` Michael Heerdegen
@ 2022-08-25  3:04           ` Satoshi Yoshida
  2022-08-25  6:46             ` Emanuel Berg
  2022-08-27  7:19             ` Satoshi Yoshida
  1 sibling, 2 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-25  3:04 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator [solved]
  2022-08-25  3:04           ` Strip signature on reply without standard separator [solved] Satoshi Yoshida
@ 2022-08-25  6:46             ` Emanuel Berg
  2022-08-27  6:59               ` Strip signature on reply without standard separator Satoshi Yoshida
  2022-08-27  7:19             ` Satoshi Yoshida
  1 sibling, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-08-25  6:46 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-25  6:46             ` Emanuel Berg
@ 2022-08-27  6:59               ` Satoshi Yoshida
  0 siblings, 0 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-27  6:59 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-25  3:04           ` Strip signature on reply without standard separator [solved] Satoshi Yoshida
  2022-08-25  6:46             ` Emanuel Berg
@ 2022-08-27  7:19             ` Satoshi Yoshida
  2022-09-04  0:48               ` Satoshi Yoshida
  1 sibling, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-08-27  7:19 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-27  7:19             ` Satoshi Yoshida
@ 2022-09-04  0:48               ` Satoshi Yoshida
  2022-09-04  2:04                 ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-04  0:48 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-04  0:48               ` Satoshi Yoshida
@ 2022-09-04  2:04                 ` Emanuel Berg
  2022-09-06 23:36                   ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-04  2:04 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-04  2:04                 ` Emanuel Berg
@ 2022-09-06 23:36                   ` Satoshi Yoshida
  2022-09-07  1:14                     ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-06 23:36 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-06 23:36                   ` Satoshi Yoshida
@ 2022-09-07  1:14                     ` Emanuel Berg
  2022-09-15 23:50                       ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-07  1:14 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-08-09  8:52     ` Emanuel Berg
  2022-08-09  9:25       ` Satoshi Yoshida
@ 2022-09-11  9:46       ` Satoshi Yoshida
  2022-09-12  6:45         ` Satoshi Yoshida
  1 sibling, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-11  9:46 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-11  9:46       ` Satoshi Yoshida
@ 2022-09-12  6:45         ` Satoshi Yoshida
  2022-09-14  6:08           ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-12  6:45 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-12  6:45         ` Satoshi Yoshida
@ 2022-09-14  6:08           ` Emanuel Berg
  2022-09-14  7:48             ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-14  6:08 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-14  6:08           ` Emanuel Berg
@ 2022-09-14  7:48             ` Satoshi Yoshida
  0 siblings, 0 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-14  7:48 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-07  1:14                     ` Emanuel Berg
@ 2022-09-15 23:50                       ` Satoshi Yoshida
  2022-09-19  0:58                         ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-15 23:50 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-15 23:50                       ` Satoshi Yoshida
@ 2022-09-19  0:58                         ` Emanuel Berg
  2022-09-21  9:15                           ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-19  0:58 UTC (permalink / raw)
  To: 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:]]+\\)*<?%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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-19  0:58                         ` Emanuel Berg
@ 2022-09-21  9:15                           ` Satoshi Yoshida
  2022-09-21 13:15                             ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-21  9:15 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-21  9:15                           ` Satoshi Yoshida
@ 2022-09-21 13:15                             ` Emanuel Berg
  2022-09-23 21:36                               ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-21 13:15 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-21 13:15                             ` Emanuel Berg
@ 2022-09-23 21:36                               ` Satoshi Yoshida
  2022-09-24 15:29                                 ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-23 21:36 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-23 21:36                               ` Satoshi Yoshida
@ 2022-09-24 15:29                                 ` Emanuel Berg
  2022-09-25  3:32                                   ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-24 15:29 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-24 15:29                                 ` Emanuel Berg
@ 2022-09-25  3:32                                   ` Satoshi Yoshida
  2022-09-25  3:41                                     ` Emanuel Berg
  2022-09-25  9:42                                     ` Michael Heerdegen
  0 siblings, 2 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-25  3:32 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-25  3:32                                   ` Satoshi Yoshida
@ 2022-09-25  3:41                                     ` Emanuel Berg
  2022-09-26  8:03                                       ` Satoshi Yoshida
  2022-09-25  9:42                                     ` Michael Heerdegen
  1 sibling, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-25  3:41 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-25  3:32                                   ` Satoshi Yoshida
  2022-09-25  3:41                                     ` Emanuel Berg
@ 2022-09-25  9:42                                     ` Michael Heerdegen
  2022-09-26  7:56                                       ` Satoshi Yoshida
  1 sibling, 1 reply; 41+ messages in thread
From: Michael Heerdegen @ 2022-09-25  9:42 UTC (permalink / raw)
  To: info-gnus-english

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.



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-25  9:42                                     ` Michael Heerdegen
@ 2022-09-26  7:56                                       ` Satoshi Yoshida
  0 siblings, 0 replies; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-26  7:56 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-25  3:41                                     ` Emanuel Berg
@ 2022-09-26  8:03                                       ` Satoshi Yoshida
  2022-09-26 12:28                                         ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-09-26  8:03 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-26  8:03                                       ` Satoshi Yoshida
@ 2022-09-26 12:28                                         ` Emanuel Berg
  2022-10-22  6:16                                           ` Satoshi Yoshida
  0 siblings, 1 reply; 41+ messages in thread
From: Emanuel Berg @ 2022-09-26 12:28 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-09-26 12:28                                         ` Emanuel Berg
@ 2022-10-22  6:16                                           ` Satoshi Yoshida
  2022-10-23 23:45                                             ` Emanuel Berg
  0 siblings, 1 reply; 41+ messages in thread
From: Satoshi Yoshida @ 2022-10-22  6:16 UTC (permalink / raw)
  To: info-gnus-english

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


^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: Strip signature on reply without standard separator
  2022-10-22  6:16                                           ` Satoshi Yoshida
@ 2022-10-23 23:45                                             ` Emanuel Berg
  0 siblings, 0 replies; 41+ messages in thread
From: Emanuel Berg @ 2022-10-23 23:45 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2022-10-24  3:42 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09  4:28 Strip signature on reply without standard separator Satoshi Yoshida
2022-08-09  5:56 ` Emanuel Berg
2022-08-09  8:34   ` Satoshi Yoshida
2022-08-09  8:52     ` Emanuel Berg
2022-08-09  9:25       ` Satoshi Yoshida
2022-09-11  9:46       ` Satoshi Yoshida
2022-09-12  6:45         ` Satoshi Yoshida
2022-09-14  6:08           ` Emanuel Berg
2022-09-14  7:48             ` Satoshi Yoshida
2022-08-11  6:41 ` Satoshi Yoshida
2022-08-11 14:48   ` Satoshi Yoshida
2022-08-12  3:06     ` Satoshi Yoshida
2022-08-11 15:26   ` Satoshi Yoshida
2022-08-24  2:30   ` Satoshi Yoshida
2022-08-24  2:37     ` Emanuel Berg
2022-08-24  3:55       ` Satoshi Yoshida
2022-08-24  5:28         ` Emanuel Berg
2022-08-24 22:26           ` Michael Heerdegen
2022-08-25  2:10             ` Satoshi Yoshida
2022-08-25  3:04           ` Strip signature on reply without standard separator [solved] Satoshi Yoshida
2022-08-25  6:46             ` Emanuel Berg
2022-08-27  6:59               ` Strip signature on reply without standard separator Satoshi Yoshida
2022-08-27  7:19             ` Satoshi Yoshida
2022-09-04  0:48               ` Satoshi Yoshida
2022-09-04  2:04                 ` Emanuel Berg
2022-09-06 23:36                   ` Satoshi Yoshida
2022-09-07  1:14                     ` Emanuel Berg
2022-09-15 23:50                       ` Satoshi Yoshida
2022-09-19  0:58                         ` Emanuel Berg
2022-09-21  9:15                           ` Satoshi Yoshida
2022-09-21 13:15                             ` Emanuel Berg
2022-09-23 21:36                               ` Satoshi Yoshida
2022-09-24 15:29                                 ` Emanuel Berg
2022-09-25  3:32                                   ` Satoshi Yoshida
2022-09-25  3:41                                     ` Emanuel Berg
2022-09-26  8:03                                       ` Satoshi Yoshida
2022-09-26 12:28                                         ` Emanuel Berg
2022-10-22  6:16                                           ` Satoshi Yoshida
2022-10-23 23:45                                             ` Emanuel Berg
2022-09-25  9:42                                     ` Michael Heerdegen
2022-09-26  7:56                                       ` Satoshi Yoshida

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).