From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/73744 Path: news.gmane.org!not-for-mail From: Daniel Dehennin Newsgroups: gmane.emacs.gnus.general Subject: Permit the use of regular expression match and replace in posting styles. Date: Sun, 31 Oct 2010 17:00:02 +0100 Message-ID: <87ocaajqt9.fsf@hati.baby-gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Trace: dough.gmane.org 1288540820 25990 80.91.229.12 (31 Oct 2010 16:00:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 31 Oct 2010 16:00:20 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M22113@lists.math.uh.edu Sun Oct 31 17:00:16 2010 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PCaKL-0004Rf-RY for ding-account@gmane.org; Sun, 31 Oct 2010 17:00:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1PCaKF-0002Qw-SA; Sun, 31 Oct 2010 11:00:07 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1PCaKD-0002Qc-TV for ding@lists.math.uh.edu; Sun, 31 Oct 2010 11:00:05 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.72) (envelope-from ) id 1PCaKC-0000jQ-4x for ding@lists.math.uh.edu; Sun, 31 Oct 2010 11:00:05 -0500 Original-Received: from zion.baby-gnu.org ([82.233.222.74]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1PCaKB-00035G-00 for ; Sun, 31 Oct 2010 17:00:03 +0100 Original-Received: from hati.asgardr.info ([192.168.1.2] helo=hati.baby-gnu.org) by zion.baby-gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1PCaKA-0003RF-Mt for ding@gnus.org; Sun, 31 Oct 2010 17:00:02 +0100 Organisation: Dark Church of Emacs User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) X-Spam-Score: -1.9 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:73744 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable git pull http://www.baby-gnu.org/~nebu/archives/gnus/gnus.git dad/match-sub= stitute-replacement-in-posting-style:dad/match-substitute-replacement-in-po= sting-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. =2D-- 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 =2D-- a/lisp/gnus-msg.el +++ b/lisp/gnus-msg.el @@ -1891,7 +1891,11 @@ this is a reply." (setq v (cond ((stringp value) =2D 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 =2D-- a/lisp/gnus-util.el +++ b/lisp/gnus-util.el @@ -1982,6 +1982,29 @@ Sizes are in pixels." (memq elem list)))) found)) =20 +(eval-and-compile + (cond + ((fboundp 'match-substitute-replacement) + (defalias 'gnus-match-substitute-replacement 'match-substitute-replace= ment)) + (t + (defun gnus-match-substitute-replacement (replacement &optional fixedc= ase 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) =20 ;;; gnus-util.el ends here diff --git a/texi/gnus.texi b/texi/gnus.texi index 0a0f96b..5fea3f0 100644 =2D-- 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. =20 =2DThe attribute value can be a string (used verbatim), a function with =2Dzero arguments (the return value will be used), a variable (its value =2Dwill be used) or a list (it will be @code{eval}ed and the return value =2Dwill be used). The functions and sexps are called/@code{eval}ed in the =2Dmessage buffer that is being set up. The headers of the current article =2Dare available through the @code{message-reply-headers} variable, which =2Dis a vector of the following headers: number subject from date id =2Dreferences 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}.) =20 @vindex message-reply-headers =20 =2D-=20 1.7.2.3 =2D-=20 Daniel Dehennin R=C3=A9cup=C3=A9rer ma clef GPG: gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1 --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iEYEAREKAAYFAkzNkoIACgkQb97L6l6P4FsVqgCfRqEUGlVaSNmdVWz741Vd5U1U wx0AnjKnPLk7n2fyfrwz1k3zGyc5DDnN =Ypa9 -----END PGP SIGNATURE----- --=-=-=--