Permit the use of regular expression match and replace in posting styles.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Sun, 31 Oct 2010 21:58:42 +0000 (22:58 +0100)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Sun, 31 Oct 2010 21:58:42 +0000 (22:58 +0100)
From Daniel Dehennin <daniel.dehennin@baby-gnu.org>.

lisp/ChangeLog
lisp/gnus-msg.el
lisp/gnus-util.el
texi/gnus.texi

index 4fc1d34..98e0343 100644 (file)
@@ -1,3 +1,8 @@
+2010-10-31  Daniel Dehennin  <daniel.dehennin@baby-gnu.org>
+
+       * gnus-msg.el (gnus-configure-posting-styles): Permit the use of
+       regular expression match and replace in posting styles.
+
 2010-10-31  Andrew Cohen  <cohen@andy.bu.edu>
 
        * nnir.el (gnus-group-make-nnir-group,nnir-run-query): Allow searching
@@ -9,7 +14,6 @@
        * gnus-srvr.el (gnus-server-mode-map): add binding "G" to search the
        server on the current line with nnir.
 
-
 2010-10-31  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * gnus-cite.el (gnus-article-foldable-buffer): Refactor out.
index a7d6711..46cbc75 100644 (file)
@@ -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)
index 5bcda97..43ce739 100644 (file)
@@ -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
index 1ad6fd4..207ca42 100644 (file)
@@ -13429,14 +13429,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