diff options
| author | Stefan Monnier | 2015-03-25 09:47:12 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-03-25 09:47:12 -0400 |
| commit | 599ca626d760215b090012c69c749d391cfd6fbe (patch) | |
| tree | 6cc2d4c57d53e317d33bfc7fb2012908c14316c2 /src | |
| parent | 76040ddd8a4142e2933f1c24940d9e20c206ee6f (diff) | |
| download | emacs-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/ChangeLog | 6 | ||||
| -rw-r--r-- | src/editfns.c | 54 |
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 @@ | |||
| 1 | 2015-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 | |||
| 1 | 2015-03-24 Paul Eggert <eggert@cs.ucla.edu> | 7 | 2015-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) | |||
| 864 | void | 861 | void |
| 865 | save_excursion_restore (Lisp_Object info) | 862 | save_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 | ||
| 934 | DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0, | 902 | DEFUN ("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. |
| 936 | Executes BODY just like `progn'. | 904 | Executes BODY just like `progn'. |
| 937 | The values of point, mark and the current buffer are restored | 905 | The values of point and the current buffer are restored |
| 938 | even in case of abnormal exit (throw or error). | 906 | even in case of abnormal exit (throw or error). |
| 939 | The state of activation of the mark is also restored. | ||
| 940 | |||
| 941 | This construct does not save `deactivate-mark', and therefore | ||
| 942 | functions that change the buffer will still cause deactivation | ||
| 943 | of the mark at the end of the command. To prevent that, bind | ||
| 944 | `deactivate-mark' with `let'. | ||
| 945 | 907 | ||
| 946 | If you only want to save the current buffer but not point nor mark, | 908 | If you only want to save the current buffer but not point, |
| 947 | then just use `save-current-buffer', or even `with-current-buffer'. | 909 | then just use `save-current-buffer', or even `with-current-buffer'. |
| 948 | 910 | ||
| 949 | usage: (save-excursion &rest BODY) */) | 911 | usage: (save-excursion &rest BODY) */) |