branch: externals/compat
commit 071ce274a4cf63d54b061f478a14e56bea00d01f
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    compat-25: Add save-mark-and-excursion
---
 NEWS.org        |  1 +
 compat-25.el    |  5 +++++
 compat-tests.el | 15 +++++++++++++++
 compat.texi     |  7 +++++++
 4 files changed, 28 insertions(+)

diff --git a/NEWS.org b/NEWS.org
index aff8a96c8c..0a370bbcd0 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -4,6 +4,7 @@
 
 - compat-25: Add ~hash-table-empty-p~.
 - compat-25: Add ~macroexp-parse-body~ and ~macroexp-quote~.
+- compat-25: Add ~save-mark-and-excursion~.
 - compat-27: Add ~date-ordinal-to-time~.
 - compat-27: Add ~make-decoded-time~.
 - compat-27: Add ~ring-resize~.
diff --git a/compat-25.el b/compat-25.el
index b25288a29d..f0ac3acf4d 100644
--- a/compat-25.el
+++ b/compat-25.el
@@ -70,6 +70,11 @@ usage: (bool-vector &rest OBJECTS)"
             ?\\ ?/))
       (aref name (1- (length name)))))
 
+;;;; Defined in simple.el
+
+;; `save-excursion' behaved like `save-mark-and-excursion' before 25.1.
+(compat-defalias save-mark-and-excursion save-excursion)
+
 ;;;; Defined in subr.el
 
 (compat-defun string-greaterp (string1 string2) ;; 
<compat-tests:string-greaterp>
diff --git a/compat-tests.el b/compat-tests.el
index 8a2e9802da..fd324a96a0 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -2724,5 +2724,20 @@
     (should-equal (ring-size ring) 3)
     (should-equal (ring-elements ring) '(5 4 3))))
 
+(ert-deftest save-mark-and-excursion ()
+  (with-temp-buffer
+    (insert "a\nb\nc")
+    (goto-char 1)
+    (set-mark 2)
+    (should-equal (point) 1)
+    (should-equal (mark) 2)
+    (save-mark-and-excursion
+      (goto-char 3)
+      (set-mark 4)
+      (should-equal (point) 3)
+      (should-equal (mark) 4))
+    (should-equal (point) 1)
+    (should-equal (mark) 2)))
+
 (provide 'compat-tests)
 ;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index 4f6a6060cf..90184ef41a 100644
--- a/compat.texi
+++ b/compat.texi
@@ -237,6 +237,13 @@ manage to provide for each Emacs version.
 The following functions and macros implemented in 25.1, and are provided
 by Compat:
 
+@c copied from lispref/positions.texi
+@defmac save-mark-and-excursion body@dots{}
+This macro is like @code{save-excursion}, but also saves and restores
+the mark location and @code{mark-active}.  This macro does what
+@code{save-excursion} did before Emacs 25.1.
+@end defmac
+
 @c copied from lispref/strings.texi
 @defun format-message string &rest objects
 This function acts like @code{format}, except it also converts any grave

Reply via email to