From: Daniel Dehennin <daniel.dehennin@baby-gnu.org>
To: ding@gnus.org
Subject: Permit the use of regular expression match and replace in posting styles.
Date: Sun, 31 Oct 2010 17:00:02 +0100 [thread overview]
Message-ID: <87ocaajqt9.fsf@hati.baby-gnu.org> (raw)
[-- 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 --]
next reply other threads:[~2010-10-31 16:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-31 16:00 Daniel Dehennin [this message]
2010-10-31 17:21 ` Lars Magne Ingebrigtsen
2010-10-31 17:37 ` Daniel Dehennin
2010-10-31 22:00 ` Lars Magne Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ocaajqt9.fsf@hati.baby-gnu.org \
--to=daniel.dehennin@baby-gnu.org \
--cc=ding@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).