From: Noam Postavsky Date: Mon, 11 Jul 2016 01:52:23 +0000 (-0400) Subject: Document buffer-swap-text+save-excursion interaction X-Git-Tag: emacs-25.1-rc1~19 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9ba51ed;p=emacs.git Document buffer-swap-text+save-excursion interaction * doc/lispref/buffers.texi (Swapping Text): * src/buffer.c (Fbuffer_swap_text): Add warning about interaction of `buffer-swap-text' and `save-excursion' (Bug #4655). --- diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index 1f7f263fb21..740d7cfd8a1 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi @@ -1211,6 +1211,12 @@ swapped as well: the positions of point and mark, all the markers, the overlays, the text properties, the undo list, the value of the @code{enable-multibyte-characters} flag (@pxref{Text Representations, enable-multibyte-characters}), etc. + +@strong{Warning:} If this function is called from within a +@code{save-excursion} form, the current buffer will be set to +@var{buffer} upon leaving the form, since the marker used by +@code{save-excursion} to save the position and buffer will be swapped +as well. @end defun If you use @code{buffer-swap-text} on a file-visiting buffer, you diff --git a/src/buffer.c b/src/buffer.c index e4269c0046a..89f4479740a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2231,7 +2231,9 @@ advance_to_char_boundary (ptrdiff_t byte_pos) DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, 1, 1, 0, - doc: /* Swap the text between current buffer and BUFFER. */) + doc: /* Swap the text between current buffer and BUFFER. +Using this function from `save-excursion' might produce surprising +results, see Info node `(elisp)Swapping Text'. */) (Lisp_Object buffer) { struct buffer *other_buffer;