* Permit the use of regular expression match and replace in posting styles.
@ 2010-10-31 16:00 Daniel Dehennin
2010-10-31 17:21 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Dehennin @ 2010-10-31 16:00 UTC (permalink / raw)
To: ding
[-- Attachment #1: Type: text/plain, Size: 4468 bytes --]
git pull http://www.baby-gnu.org/~nebu/archives/gnus/gnus.git dad/match-substitute-replacement-in-posting-style:dad/match-substitute-replacement-in-posting-style
* lisp/gnus-util.el: Define gnus-match-substitute-replacement as an
alias of match-substitute-replacement or with the definition of
match-substitute-replacement from subr.el.
* lisp/gnus-msg.el (gnus-configure-posting-styles): Use
gnus-match-substitute-replacement to replace positional parameters in
attributes.
* texi/gnus.texi (Posting Styles): Update the documentation: string values
can now be regular expressions.
---
lisp/gnus-msg.el | 6 +++++-
lisp/gnus-util.el | 23 +++++++++++++++++++++++
texi/gnus.texi | 22 ++++++++++++++--------
3 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/lisp/gnus-msg.el b/lisp/gnus-msg.el
index a7d6711..46cbc75 100644
--- a/lisp/gnus-msg.el
+++ b/lisp/gnus-msg.el
@@ -1891,7 +1891,11 @@ this is a reply."
(setq v
(cond
((stringp value)
- value)
+ (if (and (stringp match)
+ (string-match-p "\\\\[&[:digit:]]" value)
+ (match-beginning 1))
+ (gnus-match-substitute-replacement value nil nil group)
+ value))
((or (symbolp value)
(functionp value))
(cond ((functionp value)
diff --git a/lisp/gnus-util.el b/lisp/gnus-util.el
index 5bcda97..43ce739 100644
--- a/lisp/gnus-util.el
+++ b/lisp/gnus-util.el
@@ -1982,6 +1982,29 @@ Sizes are in pixels."
(memq elem list))))
found))
+(eval-and-compile
+ (cond
+ ((fboundp 'match-substitute-replacement)
+ (defalias 'gnus-match-substitute-replacement 'match-substitute-replacement))
+ (t
+ (defun gnus-match-substitute-replacement (replacement &optional fixedcase literal string subexp)
+ "Return REPLACEMENT as it will be inserted by `replace-match'.
+In other words, all back-references in the form `\\&' and `\\N'
+are substituted with actual strings matched by the last search.
+Optional FIXEDCASE, LITERAL, STRING and SUBEXP have the same
+meaning as for `replace-match'.
+
+This is the definition of match-substitute-replacement in subr.el from GNU Emacs."
+ (let ((match (match-string 0 string)))
+ (save-match-data
+ (set-match-data (mapcar (lambda (x)
+ (if (numberp x)
+ (- x (match-beginning 0))
+ x))
+ (match-data t)))
+ (replace-match replacement fixedcase literal match subexp))))
+ )))
+
(provide 'gnus-util)
;;; gnus-util.el ends here
diff --git a/texi/gnus.texi b/texi/gnus.texi
index 0a0f96b..5fea3f0 100644
--- a/texi/gnus.texi
+++ b/texi/gnus.texi
@@ -13428,14 +13428,20 @@ the headers of the article; if the value is @code{nil}, the header
name will be removed. If the attribute name is @code{eval}, the form
is evaluated, and the result is thrown away.
-The attribute value can be a string (used verbatim), a function with
-zero arguments (the return value will be used), a variable (its value
-will be used) or a list (it will be @code{eval}ed and the return value
-will be used). The functions and sexps are called/@code{eval}ed in the
-message buffer that is being set up. The headers of the current article
-are available through the @code{message-reply-headers} variable, which
-is a vector of the following headers: number subject from date id
-references chars lines xref extra.
+The attribute value can be a string, a function with zero arguments
+(the return value will be used), a variable (its value will be used)
+or a list (it will be @code{eval}ed and the return value will be
+used). The functions and sexps are called/@code{eval}ed in the
+message buffer that is being set up. The headers of the current
+article are available through the @code{message-reply-headers}
+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 the Text that
+Matched, , Text Replacement, elisp, The Emacs Lisp Reference Manual}.)
@vindex message-reply-headers
--
1.7.2.3
--
Daniel Dehennin
Récupérer ma clef GPG:
gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Permit the use of regular expression match and replace in posting styles.
2010-10-31 16:00 Permit the use of regular expression match and replace in posting styles Daniel Dehennin
@ 2010-10-31 17:21 ` Lars Magne Ingebrigtsen
2010-10-31 17:37 ` Daniel Dehennin
0 siblings, 1 reply; 4+ messages in thread
From: Lars Magne Ingebrigtsen @ 2010-10-31 17:21 UTC (permalink / raw)
To: ding
Daniel Dehennin <daniel.dehennin@baby-gnu.org> writes:
> * texi/gnus.texi (Posting Styles): Update the documentation: string values
> can now be regular expressions.
Looks good. Do you have FSF copyright assignment papers on file for
Emacs changes?
--
(domestic pets only, the antidote for overdose, milk.)
larsi@gnus.org * Lars Magne Ingebrigtsen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Permit the use of regular expression match and replace in posting styles.
2010-10-31 17:21 ` Lars Magne Ingebrigtsen
@ 2010-10-31 17:37 ` Daniel Dehennin
2010-10-31 22:00 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Dehennin @ 2010-10-31 17:37 UTC (permalink / raw)
To: ding
[-- Attachment #1: Type: text/plain, Size: 284 bytes --]
Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
> Looks good. Do you have FSF copyright assignment papers on file for
> Emacs changes?
Yes, I did it in the past.
Regards.
--
Daniel Dehennin
Récupérer ma clef GPG:
gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Permit the use of regular expression match and replace in posting styles.
2010-10-31 17:37 ` Daniel Dehennin
@ 2010-10-31 22:00 ` Lars Magne Ingebrigtsen
0 siblings, 0 replies; 4+ messages in thread
From: Lars Magne Ingebrigtsen @ 2010-10-31 22:00 UTC (permalink / raw)
To: ding
Daniel Dehennin <daniel.dehennin@baby-gnu.org> writes:
>> Looks good. Do you have FSF copyright assignment papers on file for
>> Emacs changes?
>
> Yes, I did it in the past.
Great. I've now applied and pushed your patches.
--
(domestic pets only, the antidote for overdose, milk.)
larsi@gnus.org * Lars Magne Ingebrigtsen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-31 22:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-31 16:00 Permit the use of regular expression match and replace in posting styles Daniel Dehennin
2010-10-31 17:21 ` Lars Magne Ingebrigtsen
2010-10-31 17:37 ` Daniel Dehennin
2010-10-31 22:00 ` Lars Magne Ingebrigtsen
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).