From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: point moved despite save-excursion, after deleting/reinserting region Date: Thu, 18 Oct 2018 16:16:42 +0300 Message-ID: <83sh13qts5.fsf@gnu.org> References: <87r2gpic0b.fsf@portable.galex-713.eu> <835zy0sgbr.fsf@gnu.org> <87lg6w72mv.fsf@portable.galex-713.eu> <83tvlkq8rz.fsf@gnu.org> <87efcnziq7.fsf@portable.galex-713.eu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1539868540 6429 195.159.176.226 (18 Oct 2018 13:15:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 18 Oct 2018 13:15:40 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Oct 18 15:15:36 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gD89E-0001Wy-J1 for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Oct 2018 15:15:32 +0200 Original-Received: from localhost ([::1]:42380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD8BK-0005Au-IT for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Oct 2018 09:17:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD8Ap-0005Am-7P for help-gnu-emacs@gnu.org; Thu, 18 Oct 2018 09:17:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD8Ak-0006rT-Ai for help-gnu-emacs@gnu.org; Thu, 18 Oct 2018 09:17:11 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:60364) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD8Ak-0006qf-6O for help-gnu-emacs@gnu.org; Thu, 18 Oct 2018 09:17:06 -0400 Original-Received: from [176.228.60.248] (port=3916 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gD8Aj-0000y3-Mv for help-gnu-emacs@gnu.org; Thu, 18 Oct 2018 09:17:06 -0400 In-reply-to: <87efcnziq7.fsf@portable.galex-713.eu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118325 Archived-At: > From: "Garreau\, Alexandre" > Cc: help-gnu-emacs@gnu.org > Date: Thu, 18 Oct 2018 11:50:40 +0200 > > > When you delete text, markers pointing into that text cannot follow, > > they get relocated to the beginning/end of the deletion/insertion. > > What else can Emacs do, given that it doesn't know your future > > intentions? > > I thought something such as `save-excursion' would do that, or that it > would be saved with the string, or something alike. What save-excursion does in this case is documented in the ELisp manual: *Warning:* Ordinary insertion of text adjacent to the saved point value relocates the saved value, just as it relocates all markers. More precisely, the saved value is a marker with insertion type ‘nil’. *Note Marker Insertion Types::. Therefore, when the saved point value is restored, it normally comes before the inserted text. > > If that's what you want, why not record the position of point before > > the delete/insert operation and restore it afterwards? > > So is that the canonical way of doing? It's the most direct method, AFAIK. > that feels like defeating the purpose of `save-excursion' a little > bit As you can see above, it does not. save-excursion's main use case is that you don't edit text around point. Maybe you should try using replace-buffer-contents instead (you'll have to copy text to a temporary buffer and edit it there). > (I only wanted to produce a result for this src-block), and as this > is more complex behavior than just “undoing backward” or anything > part of core elisp, I feared side-effects I wouldn’t be aware of: > for instance tho, it means my function will have the side-effects of > moving all the markers (and maybe other similar things) that were > inside that portion of text: it feels somewhat hardly like > “restoring as before”. You should be aware of the fact that point is also a marker, or at least behaves like one.