aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2015-03-25 09:47:12 -0400
committerStefan Monnier2015-03-25 09:47:12 -0400
commit599ca626d760215b090012c69c749d391cfd6fbe (patch)
tree6cc2d4c57d53e317d33bfc7fb2012908c14316c2 /src
parent76040ddd8a4142e2933f1c24940d9e20c206ee6f (diff)
downloademacs-599ca626d760215b090012c69c749d391cfd6fbe.tar.gz
emacs-599ca626d760215b090012c69c749d391cfd6fbe.zip
`save-excursion' does not save&restore the mark any more
* src/editfns.c (save_excursion_save): Don't save the mark. (save_excursion_restore): Don't restore the mark. (Fsave_excursion): Fix docstring accordingly. * doc/lispintro/emacs-lisp-intro.texi: * doc/lispref/positions.texi (Excursions, Narrowing): `save-excursion' does not save&restore the mark any more.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/editfns.c54
2 files changed, 14 insertions, 46 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 23f125c567d..632b798ce08 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12015-03-25 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * editfns.c (save_excursion_save): Don't save the mark.
4 (save_excursion_restore): Don't restore the mark.
5 (Fsave_excursion): Fix docstring accordingly.
6
12015-03-24 Paul Eggert <eggert@cs.ucla.edu> 72015-03-24 Paul Eggert <eggert@cs.ucla.edu>
2 8
3 Fix minor ldexp issues 9 Fix minor ldexp issues
diff --git a/src/editfns.c b/src/editfns.c
index 7c146f13e14..f463890a98d 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -849,14 +849,11 @@ save_excursion_save (void)
849{ 849{
850 return make_save_obj_obj_obj_obj 850 return make_save_obj_obj_obj_obj
851 (Fpoint_marker (), 851 (Fpoint_marker (),
852 /* Do not copy the mark if it points to nowhere. */ 852 Qnil,
853 (XMARKER (BVAR (current_buffer, mark))->buffer
854 ? Fcopy_marker (BVAR (current_buffer, mark), Qnil)
855 : Qnil),
856 /* Selected window if current buffer is shown in it, nil otherwise. */ 853 /* Selected window if current buffer is shown in it, nil otherwise. */
857 (EQ (XWINDOW (selected_window)->contents, Fcurrent_buffer ()) 854 (EQ (XWINDOW (selected_window)->contents, Fcurrent_buffer ())
858 ? selected_window : Qnil), 855 ? selected_window : Qnil),
859 BVAR (current_buffer, mark_active)); 856 Qnil);
860} 857}
861 858
862/* Restore saved buffer before leaving `save-excursion' special form. */ 859/* Restore saved buffer before leaving `save-excursion' special form. */
@@ -864,8 +861,8 @@ save_excursion_save (void)
864void 861void
865save_excursion_restore (Lisp_Object info) 862save_excursion_restore (Lisp_Object info)
866{ 863{
867 Lisp_Object tem, tem1, omark, nmark; 864 Lisp_Object tem, tem1;
868 struct gcpro gcpro1, gcpro2, gcpro3; 865 struct gcpro gcpro1;
869 866
870 tem = Fmarker_buffer (XSAVE_OBJECT (info, 0)); 867 tem = Fmarker_buffer (XSAVE_OBJECT (info, 0));
871 /* If we're unwinding to top level, saved buffer may be deleted. This 868 /* If we're unwinding to top level, saved buffer may be deleted. This
@@ -873,8 +870,7 @@ save_excursion_restore (Lisp_Object info)
873 if (NILP (tem)) 870 if (NILP (tem))
874 goto out; 871 goto out;
875 872
876 omark = nmark = Qnil; 873 GCPRO1 (info);
877 GCPRO3 (info, omark, nmark);
878 874
879 Fset_buffer (tem); 875 Fset_buffer (tem);
880 876
@@ -883,34 +879,6 @@ save_excursion_restore (Lisp_Object info)
883 Fgoto_char (tem); 879 Fgoto_char (tem);
884 unchain_marker (XMARKER (tem)); 880 unchain_marker (XMARKER (tem));
885 881
886 /* Mark marker. */
887 tem = XSAVE_OBJECT (info, 1);
888 omark = Fmarker_position (BVAR (current_buffer, mark));
889 if (NILP (tem))
890 unchain_marker (XMARKER (BVAR (current_buffer, mark)));
891 else
892 {
893 Fset_marker (BVAR (current_buffer, mark), tem, Fcurrent_buffer ());
894 nmark = Fmarker_position (tem);
895 unchain_marker (XMARKER (tem));
896 }
897
898 /* Mark active. */
899 tem = XSAVE_OBJECT (info, 3);
900 tem1 = BVAR (current_buffer, mark_active);
901 bset_mark_active (current_buffer, tem);
902
903 /* If mark is active now, and either was not active
904 or was at a different place, run the activate hook. */
905 if (! NILP (tem))
906 {
907 if (! EQ (omark, nmark))
908 run_hook (intern ("activate-mark-hook"));
909 }
910 /* If mark has ceased to be active, run deactivate hook. */
911 else if (! NILP (tem1))
912 run_hook (intern ("deactivate-mark-hook"));
913
914 /* If buffer was visible in a window, and a different window was 882 /* If buffer was visible in a window, and a different window was
915 selected, and the old selected window is still showing this 883 selected, and the old selected window is still showing this
916 buffer, restore point in that window. */ 884 buffer, restore point in that window. */
@@ -932,18 +900,12 @@ save_excursion_restore (Lisp_Object info)
932} 900}
933 901
934DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0, 902DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0,
935 doc: /* Save point, mark, and current buffer; execute BODY; restore those things. 903 doc: /* Save point, and current buffer; execute BODY; restore those things.
936Executes BODY just like `progn'. 904Executes BODY just like `progn'.
937The values of point, mark and the current buffer are restored 905The values of point and the current buffer are restored
938even in case of abnormal exit (throw or error). 906even in case of abnormal exit (throw or error).
939The state of activation of the mark is also restored.
940
941This construct does not save `deactivate-mark', and therefore
942functions that change the buffer will still cause deactivation
943of the mark at the end of the command. To prevent that, bind
944`deactivate-mark' with `let'.
945 907
946If you only want to save the current buffer but not point nor mark, 908If you only want to save the current buffer but not point,
947then just use `save-current-buffer', or even `with-current-buffer'. 909then just use `save-current-buffer', or even `with-current-buffer'.
948 910
949usage: (save-excursion &rest BODY) */) 911usage: (save-excursion &rest BODY) */)