emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 293e13a 198/433: (mmm-format-matches): Changed to allow ac


From: Dmitry Gutov
Subject: [elpa] master 293e13a 198/433: (mmm-format-matches): Changed to allow accessing any subexp, not
Date: Thu, 15 Mar 2018 19:44:01 -0400 (EDT)

branch: master
commit 293e13a5a4d7447a22ff06cdae49abe898b91a03
Author: mas <mas>
Commit: mas <mas>

    (mmm-format-matches): Changed to allow accessing any subexp, not
    limited by a numerical value of save-matches.
---
 mmm-class.el |  6 ++++--
 mmm-utils.el | 32 ++++++++++++++++++--------------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/mmm-class.el b/mmm-class.el
index c34db74..de76843 100644
--- a/mmm-class.el
+++ b/mmm-class.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2000 by Michael Abraham Shulman
 
 ;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-class.el,v 1.13 2001/01/11 00:56:08 mas Exp $
+;; Version: $Id: mmm-class.el,v 1.14 2001/01/14 01:26:09 mas Exp $
 
 ;;{{{ GPL
 
@@ -206,7 +206,9 @@ point at which the search should continue if the region is 
invalid."
                         (match-face
                          (cdr (assoc front-form match-face))))))
         (when (mmm-match-and-verify
-               (mmm-format-matches back save-matches)
+               (if save-matches
+                   (mmm-format-matches back)
+                 back)
                beg stop back-verify)
           (let ((end (mmm-match->point (not include-back) back-offset))
                 (back-form (mmm-get-form back-form)))
diff --git a/mmm-utils.el b/mmm-utils.el
index 4a60ac6..c33bf98 100644
--- a/mmm-utils.el
+++ b/mmm-utils.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2000 by Michael Abraham Shulman
 
 ;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-utils.el,v 1.7 2000/08/01 01:54:18 mas Exp $
+;; Version: $Id: mmm-utils.el,v 1.8 2001/01/14 01:26:09 mas Exp $
 
 ;;{{{ GPL
 
@@ -81,19 +81,23 @@ substituted for the corresponding REGEXP wherever it 
matches."
           (setq string (replace-match (cdr pair) t t string))))))
   string)
 
-(defun mmm-make-matches-list (count)
-  "Make a list of the most recent subexpression matches by number.
-Returns \(\(\"~0\" . \"whole-match\") \(\"~1\" . \"first-subexp\") ...)
-up until COUNT."
-  (loop for n from 0 to count
-        collect (cons (format "~%s" n) (or (match-string n) ""))))
-
-(defun mmm-format-matches (string count)
-  "Format STRING by the last COUNT matches.
-Does nothing if COUNT is nil or STRING is not a string."
-  (if (and count (stringp string))
-      (mmm-format-string string (mmm-make-matches-list count))
-    string))
+(defun mmm-format-matches (string)
+  "Format STRING by matches from the current match data.
+Strings like ~N are replaced by the Nth subexpression from the last
+global match.  Does nothing if STRING is not a string."
+  (when (and count (stringp string))
+    (let ((old-data (match-data))
+          subexp)
+      (save-match-data
+        (while (string-match "~\\([0-9]\\)" string)
+          (setq subexp (string-to-int (match-string 1 string))
+                string
+                (replace-match
+                 (save-match-data
+                   (set-match-data old-data)
+                   (match-string subexp))
+                 t t string))))))
+  string)
 
 ;;}}}
 ;;{{{ Save Keywords



reply via email to

[Prev in Thread] Current Thread [Next in Thread]