Gnus development mailing list
 help / color / mirror / Atom feed
* [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers
@ 2014-07-17 13:26 albert+gnus
  2014-07-17 15:58 ` Andreas Schwab
  2014-07-17 23:47 ` Katsumi Yamaoka
  0 siblings, 2 replies; 8+ messages in thread
From: albert+gnus @ 2014-07-17 13:26 UTC (permalink / raw)
  To: ding; +Cc: Albert Krewinkel

From: Albert Krewinkel <albert@zeitkraut.de>

This allows for more flexible `gnus-posting-styles':

    ;; When using subaddresses like `me+gnus@example.com', reply with
    ;; using the address the message was send to.
    (setq gnus-posting-style
          '(((header "x-original-to" "me\\(\\+.+\\)?@example.com")
             (address "me\\1@example.com"))))
---
 lisp/ChangeLog   |  5 +++++
 lisp/gnus-msg.el | 13 ++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0861557..dd6ade5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2013-07-17  Albert Krewinkel  <albert@zeitkraut.de>
+
+	* gnus-msg.el (gnus-configure-posting-style):
+	Alllow string replacements in values when matching against a header.
+
 2014-07-07  Katsumi Yamaoka  <yamaoka@jpl.org>
 
 	* gnus-start.el (gnus-dribble-read-file): Don't stop the auto-saving of
diff --git a/lisp/gnus-msg.el b/lisp/gnus-msg.el
index 1c8635c..93e9877 100644
--- a/lisp/gnus-msg.el
+++ b/lisp/gnus-msg.el
@@ -1826,7 +1826,7 @@ this is a reply."
 		      (with-current-buffer gnus-summary-buffer
 			gnus-posting-styles)
 		    gnus-posting-styles))
-	  style match attribute value v results
+	  style match attribute value v results matched-string
 	  filep name address element)
       ;; If the group has a posting-style parameter, add it at the end with a
       ;; regexp matching everything, to be sure it takes precedence over all
@@ -1846,7 +1846,9 @@ this is a reply."
 	(when (cond
 	       ((stringp match)
 		;; Regexp string match on the group name.
-		(string-match match group))
+		(when (string-match match group)
+                  (setq matched-string group)
+                  t))
 	       ((eq match 'header)
 		;; Obsolete format of header match.
 		(and (gnus-buffer-live-p gnus-article-copy)
@@ -1875,7 +1877,8 @@ this is a reply."
 			   (nnheader-narrow-to-headers)
 			   (let ((header (message-fetch-field (nth 1 match))))
 			     (and header
-				  (string-match (nth 2 match) header)))))))
+				  (string-match (nth 2 match) header)
+				  (setq matched-string header)))))))
 		 (t
 		  ;; This is a form to be evalled.
 		  (eval match)))))
@@ -1896,10 +1899,10 @@ this is a reply."
 	    (setq v
 		  (cond
 		   ((stringp value)
-		    (if (and (stringp match)
+		    (if (and matched-string
 			     (gnus-string-match-p "\\\\[&[:digit:]]" value)
 			     (match-beginning 1))
-			(gnus-match-substitute-replacement value nil nil group)
+			(gnus-match-substitute-replacement value nil nil matched-string)
 		      value))
 		   ((or (symbolp value)
 			(functionp value))
-- 
2.0.1




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

* Re: [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers
  2014-07-17 13:26 [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers albert+gnus
@ 2014-07-17 15:58 ` Andreas Schwab
  2014-07-17 23:47 ` Katsumi Yamaoka
  1 sibling, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2014-07-17 15:58 UTC (permalink / raw)
  To: albert+gnus; +Cc: ding, Albert Krewinkel

albert+gnus@zeitkraut.de writes:

> +	Alllow string replacements in values when matching against a header.

s/Alllow/Allow/

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



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

* Re: [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers
  2014-07-17 13:26 [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers albert+gnus
  2014-07-17 15:58 ` Andreas Schwab
@ 2014-07-17 23:47 ` Katsumi Yamaoka
  2014-07-18  5:03   ` Albert Krewinkel
  2014-07-18  7:29   ` [PATCH 1/2] " albert+gnus
  1 sibling, 2 replies; 8+ messages in thread
From: Katsumi Yamaoka @ 2014-07-17 23:47 UTC (permalink / raw)
  To: albert+gnus; +Cc: ding, Albert Krewinkel

On Thu, 17 Jul 2014 15:26:29 +0200, Albert Krewinkel wrote:
> This allows for more flexible `gnus-posting-styles':

>     ;; When using subaddresses like `me+gnus@example.com', reply with
>     ;; using the address the message was send to.
>     (setq gnus-posting-style
>           '(((header "x-original-to" "me\\(\\+.+\\)?@example.com")
>              (address "me\\1@example.com"))))

Looks useful, and looks like more than `tiny change'.  So, you'd
better to have a copyright assignment on Emacs with FSF, I think.

<https://www.gnu.org/licenses/why-assign.html>
<http://wiki.list.org/display/DEV/GNU+copyright+assignment+request+form>

In addition, you will need to add a document for the feature to
the Info section: (info "(gnus)Posting Styles")




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

* Re: [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers
  2014-07-17 23:47 ` Katsumi Yamaoka
@ 2014-07-18  5:03   ` Albert Krewinkel
  2014-07-18  7:29   ` [PATCH 1/2] " albert+gnus
  1 sibling, 0 replies; 8+ messages in thread
From: Albert Krewinkel @ 2014-07-18  5:03 UTC (permalink / raw)
  To: Katsumi Yamaoka; +Cc: ding

Katsumi Yamaoka <yamaoka@jpl.org> writes:

> On Thu, 17 Jul 2014 15:26:29 +0200, Albert Krewinkel wrote:
>> This allows for more flexible `gnus-posting-styles':
>
>>     ;; When using subaddresses like `me+gnus@example.com', reply with
>>     ;; using the address the message was send to.
>>     (setq gnus-posting-style
>>           '(((header "x-original-to" "me\\(\\+.+\\)?@example.com")
>>              (address "me\\1@example.com"))))
>
> Looks useful, and looks like more than `tiny change'.  So, you'd
> better to have a copyright assignment on Emacs with FSF, I think.

Thank you for your answer!

I already completed the assignment process; the mail address I used back
then was krewinkel ät moltkeplatz.de.  I can look up the assignment
number should you need it.

> In addition, you will need to add a document for the feature to
> the Info section: (info "(gnus)Posting Styles")

I hope to have a new patch ready by tonight, fixing the typos and adding
the info documentation.

Thanks again!

-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124



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

* [PATCH 1/2] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers
  2014-07-17 23:47 ` Katsumi Yamaoka
  2014-07-18  5:03   ` Albert Krewinkel
@ 2014-07-18  7:29   ` albert+gnus
  2014-07-18  7:29     ` [PATCH 2/2] gnus.texi (Posting Styles): Document string replacement when matching against headers albert+gnus
  1 sibling, 1 reply; 8+ messages in thread
From: albert+gnus @ 2014-07-18  7:29 UTC (permalink / raw)
  To: ding

From: Albert Krewinkel <albert@zeitkraut.de>

This allows for more flexible `gnus-posting-styles':

    ;; When using subaddresses (like me+gnus@example.com), reply from
    ;; the address the message was send to.
    (setq gnus-posting-style
          '(((header "x-original-to" "me\\(\\+.+\\)?@example.com")
             (address "me\\1@example.com"))))
---
 lisp/ChangeLog   |  5 +++++
 lisp/gnus-msg.el | 13 ++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0861557..408318d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2013-07-17  Albert Krewinkel  <albert@zeitkraut.de>
+
+	* gnus-msg.el (gnus-configure-posting-style):
+	Allow string replacements in values when matching against a header.
+
 2014-07-07  Katsumi Yamaoka  <yamaoka@jpl.org>
 
 	* gnus-start.el (gnus-dribble-read-file): Don't stop the auto-saving of
diff --git a/lisp/gnus-msg.el b/lisp/gnus-msg.el
index 1c8635c..93e9877 100644
--- a/lisp/gnus-msg.el
+++ b/lisp/gnus-msg.el
@@ -1826,7 +1826,7 @@ this is a reply."
 		      (with-current-buffer gnus-summary-buffer
 			gnus-posting-styles)
 		    gnus-posting-styles))
-	  style match attribute value v results
+	  style match attribute value v results matched-string
 	  filep name address element)
       ;; If the group has a posting-style parameter, add it at the end with a
       ;; regexp matching everything, to be sure it takes precedence over all
@@ -1846,7 +1846,9 @@ this is a reply."
 	(when (cond
 	       ((stringp match)
 		;; Regexp string match on the group name.
-		(string-match match group))
+		(when (string-match match group)
+                  (setq matched-string group)
+                  t))
 	       ((eq match 'header)
 		;; Obsolete format of header match.
 		(and (gnus-buffer-live-p gnus-article-copy)
@@ -1875,7 +1877,8 @@ this is a reply."
 			   (nnheader-narrow-to-headers)
 			   (let ((header (message-fetch-field (nth 1 match))))
 			     (and header
-				  (string-match (nth 2 match) header)))))))
+				  (string-match (nth 2 match) header)
+				  (setq matched-string header)))))))
 		 (t
 		  ;; This is a form to be evalled.
 		  (eval match)))))
@@ -1896,10 +1899,10 @@ this is a reply."
 	    (setq v
 		  (cond
 		   ((stringp value)
-		    (if (and (stringp match)
+		    (if (and matched-string
 			     (gnus-string-match-p "\\\\[&[:digit:]]" value)
 			     (match-beginning 1))
-			(gnus-match-substitute-replacement value nil nil group)
+			(gnus-match-substitute-replacement value nil nil matched-string)
 		      value))
 		   ((or (symbolp value)
 			(functionp value))
-- 
2.0.1




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

* [PATCH 2/2] gnus.texi (Posting Styles): Document string replacement when matching against headers
  2014-07-18  7:29   ` [PATCH 1/2] " albert+gnus
@ 2014-07-18  7:29     ` albert+gnus
  2014-07-18  8:20       ` Katsumi Yamaoka
  0 siblings, 1 reply; 8+ messages in thread
From: albert+gnus @ 2014-07-18  7:29 UTC (permalink / raw)
  To: ding

From: Albert Krewinkel <albert@zeitkraut.de>

---
 texi/ChangeLog |  5 +++++
 texi/gnus.texi | 14 ++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/texi/ChangeLog b/texi/ChangeLog
index 530ff58..0666dfd 100644
--- a/texi/ChangeLog
+++ b/texi/ChangeLog
@@ -1,3 +1,8 @@
+2014-07-18  Albert Krewinkel  <albert+gnus@zeitkraut.de>
+
+	* gnus.texi (Posting Styles): Document the possibility to perform
+	string replacements when matching against headers.
+
 2014-06-11  Katsumi Yamaoka  <yamaoka@jpl.org>
 
 	* Makefile.in (.texi, makeinfo): Don't split info files.
diff --git a/texi/gnus.texi b/texi/gnus.texi
index 9165112..9601a53 100644
--- a/texi/gnus.texi
+++ b/texi/gnus.texi
@@ -12813,10 +12813,12 @@ variable, which is a vector of the following headers: number subject
 from date id references chars lines xref extra.
 
 In the case of a string value, if the @code{match} is a regular
-expression, a @samp{gnus-match-substitute-replacement} is proceed on
-the value to replace the positional parameters @samp{\@var{n}} by the
-corresponding parenthetical matches (see @xref{Replacing Match,,
-Replacing the Text that Matched, elisp, The Emacs Lisp Reference Manual}.)
+expression, or if it takes the form @code{(header @var{match}
+@var{regexp})}, a @samp{gnus-match-substitute-replacement} is proceed
+on the value to replace the positional parameters @samp{\@var{n}} by
+the corresponding parenthetical matches (see @xref{Replacing Match,,
+Replacing the Text that Matched, elisp, The Emacs Lisp Reference
+Manual}.)
 
 @vindex message-reply-headers
 
@@ -12848,6 +12850,10 @@ So here's a new example:
         ;; @r{If I'm replying to Larsi, set the Organization header.}
         ((header "from" "larsi.*org")
          (Organization "Somewhere, Inc."))
+        ;; @r{Reply to a message from the same subaddress the message}
+        ;; @r{was sent to.}
+        ((header "x-original-to" "me\\(\\+.+\\)@@example.org")
+         (address "me\\1@@example.org"))
         ((posting-from-work-p) ;; @r{A user defined function}
          (signature-file "~/.work-signature")
          (address "user@@bar.foo")
-- 
2.0.1




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

* Re: [PATCH 2/2] gnus.texi (Posting Styles): Document string replacement when matching against headers
  2014-07-18  7:29     ` [PATCH 2/2] gnus.texi (Posting Styles): Document string replacement when matching against headers albert+gnus
@ 2014-07-18  8:20       ` Katsumi Yamaoka
  0 siblings, 0 replies; 8+ messages in thread
From: Katsumi Yamaoka @ 2014-07-18  8:20 UTC (permalink / raw)
  To: albert+gnus; +Cc: ding

On Fri, 18 Jul 2014 09:29:42 +0200, albert+gnus@zeitkraut.de wrote:
> +2013-07-17  Albert Krewinkel  <albert@zeitkraut.de>
> +
> +	* gnus-msg.el (gnus-configure-posting-style):
> +	Allow string replacements in values when matching against a header.
> +
On Fri, 18 Jul 2014 09:29:43 +0200, albert+gnus@zeitkraut.de wrote:
> +2014-07-18  Albert Krewinkel  <albert+gnus@zeitkraut.de>
> +
> +	* gnus.texi (Posting Styles): Document the possibility to perform
> +	string replacements when matching against headers.
> +

Perfect!  I've installed your patches in the Gnus Git master and
also the Emacs trunk.  Thank you.



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

* [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers
@ 2014-07-17  9:26 Albert Krewinkel
  0 siblings, 0 replies; 8+ messages in thread
From: Albert Krewinkel @ 2014-07-17  9:26 UTC (permalink / raw)
  To: ding; +Cc: Albert Krewinkel

This allows for more flexible `gnus-posting-styles':

    ;; When using subaddresses like `me+gnus@example.com', reply with
    ;; using the address the message was send to.
    (setq gnus-posting-style
          '(((header "x-original-to" "me\\(\\+.+\\)?@example.com")
             (address "me\\1@example.com"))))
---
 lisp/ChangeLog   |  5 +++++
 lisp/gnus-msg.el | 13 ++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0861557..dd6ade5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2013-07-17  Albert Krewinkel  <albert@zeitkraut.de>
+
+	* gnus-msg.el (gnus-configure-posting-style):
+	Alllow string replacements in values when matching against a header.
+
 2014-07-07  Katsumi Yamaoka  <yamaoka@jpl.org>
 
 	* gnus-start.el (gnus-dribble-read-file): Don't stop the auto-saving of
diff --git a/lisp/gnus-msg.el b/lisp/gnus-msg.el
index 1c8635c..93e9877 100644
--- a/lisp/gnus-msg.el
+++ b/lisp/gnus-msg.el
@@ -1826,7 +1826,7 @@ this is a reply."
 		      (with-current-buffer gnus-summary-buffer
 			gnus-posting-styles)
 		    gnus-posting-styles))
-	  style match attribute value v results
+	  style match attribute value v results matched-string
 	  filep name address element)
       ;; If the group has a posting-style parameter, add it at the end with a
       ;; regexp matching everything, to be sure it takes precedence over all
@@ -1846,7 +1846,9 @@ this is a reply."
 	(when (cond
 	       ((stringp match)
 		;; Regexp string match on the group name.
-		(string-match match group))
+		(when (string-match match group)
+                  (setq matched-string group)
+                  t))
 	       ((eq match 'header)
 		;; Obsolete format of header match.
 		(and (gnus-buffer-live-p gnus-article-copy)
@@ -1875,7 +1877,8 @@ this is a reply."
 			   (nnheader-narrow-to-headers)
 			   (let ((header (message-fetch-field (nth 1 match))))
 			     (and header
-				  (string-match (nth 2 match) header)))))))
+				  (string-match (nth 2 match) header)
+				  (setq matched-string header)))))))
 		 (t
 		  ;; This is a form to be evalled.
 		  (eval match)))))
@@ -1896,10 +1899,10 @@ this is a reply."
 	    (setq v
 		  (cond
 		   ((stringp value)
-		    (if (and (stringp match)
+		    (if (and matched-string
 			     (gnus-string-match-p "\\\\[&[:digit:]]" value)
 			     (match-beginning 1))
-			(gnus-match-substitute-replacement value nil nil group)
+			(gnus-match-substitute-replacement value nil nil matched-string)
 		      value))
 		   ((or (symbolp value)
 			(functionp value))
-- 
2.0.1




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

end of thread, other threads:[~2014-07-18  8:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-17 13:26 [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers albert+gnus
2014-07-17 15:58 ` Andreas Schwab
2014-07-17 23:47 ` Katsumi Yamaoka
2014-07-18  5:03   ` Albert Krewinkel
2014-07-18  7:29   ` [PATCH 1/2] " albert+gnus
2014-07-18  7:29     ` [PATCH 2/2] gnus.texi (Posting Styles): Document string replacement when matching against headers albert+gnus
2014-07-18  8:20       ` Katsumi Yamaoka
  -- strict thread matches above, loose matches on Subject: below --
2014-07-17  9:26 [PATCH] gnus-msg.el (gnus-configure-posting-style): Allow string replacement when matching headers Albert Krewinkel

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).