aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Colascione2015-05-04 11:46:12 -0700
committerDaniel Colascione2015-05-04 11:46:12 -0700
commit255a011f0ecf004b31c59945b10154b10fac3af1 (patch)
treeef4c1809537fd50c98cd137dbb70a8d48c015616
parentfe4e258b17feb529ac364daee67a5f0441f851f4 (diff)
downloademacs-255a011f0ecf004b31c59945b10154b10fac3af1.tar.gz
emacs-255a011f0ecf004b31c59945b10154b10fac3af1.zip
Add `save-mark-and-excursion', which has the old `save-excursion' behavior
* doc/lispref/positions.texi (Excursions): Document `save-mark-and-excursion'. * lisp/font-lock.el (font-lock-fontify-block): Use `save-mark-and-excursion' instead of `save-excursion', restoring Emacs 24 behavior. * lisp/simple.el (save-mark-and-excursion--save) (save-mark-and-excursion--restore): New functions. (save-mark-and-excursion): New user macro. * src/editfns.c (Fsave_excursion): Mention `save-mark-and-excursion' in `save-excursion' documentation.
-rw-r--r--doc/lispref/positions.texi8
-rw-r--r--lisp/font-lock.el2
-rw-r--r--lisp/simple.el38
-rw-r--r--src/editfns.c4
4 files changed, 51 insertions, 1 deletions
diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi
index fc47f1c7a78..e7c79d58241 100644
--- a/doc/lispref/positions.texi
+++ b/doc/lispref/positions.texi
@@ -888,6 +888,14 @@ type @code{nil}. @xref{Marker Insertion Types}. Therefore, when the
888saved point value is restored, it normally comes before the inserted 888saved point value is restored, it normally comes before the inserted
889text. 889text.
890 890
891@defmac save-mark-and-excursion body@dots{}
892@cindex mark excursion
893@cindex point excursion
894This macro is like @code{save-excursion}, but also saves and restores
895the mark location and @code{mark-active}. This macro does what
896@code{save-excursion} did before Emacs 25.1.
897@end defmac
898
891@node Narrowing 899@node Narrowing
892@section Narrowing 900@section Narrowing
893@cindex narrowing 901@cindex narrowing
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 96b290e34f4..b1455131114 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -1350,7 +1350,7 @@ delimit the region to fontify."
1350 deactivate-mark) 1350 deactivate-mark)
1351 ;; Make sure we have the right `font-lock-keywords' etc. 1351 ;; Make sure we have the right `font-lock-keywords' etc.
1352 (if (not font-lock-mode) (font-lock-set-defaults)) 1352 (if (not font-lock-mode) (font-lock-set-defaults))
1353 (save-excursion 1353 (save-mark-and-excursion
1354 (save-match-data 1354 (save-match-data
1355 (condition-case error-data 1355 (condition-case error-data
1356 (if (or arg (not font-lock-mark-block-function)) 1356 (if (or arg (not font-lock-mark-block-function))
diff --git a/lisp/simple.el b/lisp/simple.el
index 31efe3896d4..9f42f00b149 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -4870,6 +4870,44 @@ store it in a Lisp variable. Example:
4870 (setq mark-active nil) 4870 (setq mark-active nil)
4871 (set-marker (mark-marker) nil))) 4871 (set-marker (mark-marker) nil)))
4872 4872
4873(defun save-mark-and-excursion--save ()
4874 (cons
4875 (let ((mark (mark-marker)))
4876 (and mark (marker-position mark) (copy-marker mark)))
4877 mark-active))
4878
4879(defun save-mark-and-excursion--restore (saved-mark-info)
4880 (let ((saved-mark (car saved-mark-info))
4881 (omark (marker-position (mark-marker)))
4882 (nmark nil)
4883 (saved-mark-active (cdr saved-mark-info)))
4884 ;; Mark marker
4885 (if (null saved-mark)
4886 (set-marker (mark-marker nil))
4887 (setf nmark (marker-position saved-mark))
4888 (set-marker (mark-marker) nmark)
4889 (set-marker saved-mark nil))
4890 ;; Mark active
4891 (let ((cur-mark-active mark-active))
4892 (setf mark-active saved-mark-active)
4893 ;; If mark is active now, and either was not active or was at a
4894 ;; different place, run the activate hook.
4895 (if saved-mark-active
4896 (unless (eq omark nmark)
4897 (run-hooks 'activate-mark-hook))
4898 ;; If mark has ceased to be active, run deactivate hook.
4899 (when cur-mark-active
4900 (run-hooks 'deactivate-mark-hook))))))
4901
4902(defmacro save-mark-and-excursion (&rest body)
4903 "Like `save-excursion', but also save and restore the mark state.
4904This macro does what `save-excursion' did before Emacs 25.1."
4905 (let ((saved-marker-sym (make-symbol "saved-marker")))
4906 `(let ((,saved-marker-sym (save-mark-and-excursion--save)))
4907 (unwind-protect
4908 (save-excursion ,@body)
4909 (save-mark-and-excursion--restore ,saved-marker-sym)))))
4910
4873(defcustom use-empty-active-region nil 4911(defcustom use-empty-active-region nil
4874 "Whether \"region-aware\" commands should act on empty regions. 4912 "Whether \"region-aware\" commands should act on empty regions.
4875If nil, region-aware commands treat empty regions as inactive. 4913If nil, region-aware commands treat empty regions as inactive.
diff --git a/src/editfns.c b/src/editfns.c
index dead48c1a62..1686fbf668b 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -908,6 +908,10 @@ even in case of abnormal exit (throw or error).
908If you only want to save the current buffer but not point, 908If you only want to save the current buffer but not point,
909then just use `save-current-buffer', or even `with-current-buffer'. 909then just use `save-current-buffer', or even `with-current-buffer'.
910 910
911Before Emacs 25.1, `save-excursion' used to save the mark state.
912To save the marker state as well as the point and buffer, use
913`save-mark-and-excursion'.
914
911usage: (save-excursion &rest BODY) */) 915usage: (save-excursion &rest BODY) */)
912 (Lisp_Object args) 916 (Lisp_Object args)
913{ 917{