From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id Ey5EHhs6el9gFQAA0tVLHw (envelope-from ) for ; Sun, 04 Oct 2020 21:09:47 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id SLTBGRs6el8WSQAA1q6Kng (envelope-from ) for ; Sun, 04 Oct 2020 21:09:47 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A06459400D3 for ; Sun, 4 Oct 2020 21:09:46 +0000 (UTC) Received: from localhost ([::1]:39912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPBGK-0000mF-Et for larch@yhetil.org; Sun, 04 Oct 2020 17:09:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPBFZ-0000lR-GO for emacs-orgmode@gnu.org; Sun, 04 Oct 2020 17:08:58 -0400 Received: from mout01.posteo.de ([185.67.36.65]:36755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPBFW-0002hr-3o for emacs-orgmode@gnu.org; Sun, 04 Oct 2020 17:08:57 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id D7A7D16005F for ; Sun, 4 Oct 2020 23:08:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.eu; s=2017; t=1601845728; bh=D2mlF2dv8g2luwizGblpjpKyaY1VXg4+blI6XAe5R/A=; h=Subject:To:Cc:From:Date:From; b=THVNTdNQOiouJOKpesaFs2K+UlgsEWPrbsCq8jTt5ZwGDFmp0x5wrd1bQMETjvE3k +iyNZ5M1+18HNS1ElRK2Y0wcl6xBPxPHWWVZ1EaOp0WEqs6MqyBLX6zGFpClywIcpD kakZt+hCSKYPeAcds1xlWtIWoqwmpo6zfSfedvKlgYVkbsG0l3E1A6FL5d3KkSK+DD LAOly7zHn6PzrNOp8FeeB5ExI2K+lpS8nprHSHkL5LbH8k16xpxGJm2p+thoSYUo1i 0T+nqZa/JyxoPClL5F77stXXmAaIaJRyAmL3eo9CqZpF4x8cbg52wJaDz+gAhxUFjc p9pyYg5hEB3UQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4C4GYX1j04z9rxX; Sun, 4 Oct 2020 23:08:47 +0200 (CEST) Subject: Re: [Patch] Bug: org-indent-region doesn't restore cursor position when org-src-tab-acts-natively is t [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.3/lisp/org/)] To: emacs-orgmode@gnu.org References: <603f9c4e-c621-7592-5b20-a7354c11d5d2@posteo.eu> <87zhdz1par.fsf@gnu.org> <878slijpzg.fsf@gnu.org> <4545c239-c8bf-fa16-2591-b0ee541ea732@posteo.eu> <87d0andkmi.fsf@gnu.org> <0b735431-d1e3-090d-da9f-904bd538b57f@posteo.eu> <875z8tomtx.fsf@gnu.org> From: =?UTF-8?Q?S=c3=a9bastien_Miquel?= Message-ID: <5afb1142-5167-fc44-783d-937ad2bd5584@posteo.eu> Date: Sun, 4 Oct 2020 23:08:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <875z8tomtx.fsf@gnu.org> Content-Type: multipart/mixed; boundary="------------5A07D6224CD2520E6DED699E" Content-Language: fr Received-SPF: pass client-ip=185.67.36.65; envelope-from=sebastien.miquel@posteo.eu; helo=mout01.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/04 17:08:49 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sebastien.miquel@posteo.eu Cc: Bastien Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.eu header.s=2017 header.b=THVNTdNQ; dmarc=pass (policy=none) header.from=posteo.eu; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.71 X-TUID: 8c1ji6XPGgv6 This is a multi-part message in MIME format. --------------5A07D6224CD2520E6DED699E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, The attached patch fixes this issue for emacs >= 26.1. It also fixes a similar issue where comment-line moves the cursor to the beginning of the block aswell. Can this patch be applied ? Regards, Sébastien Miquel --------------5A07D6224CD2520E6DED699E Content-Type: text/x-patch; charset=UTF-8; name="0001-org-edit-src-Use-replace-buffer-contents.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-org-edit-src-Use-replace-buffer-contents.patch" >From 36f01b8e9d8dc335564f8dc932caf21c43c374eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= Date: Sun, 4 Oct 2020 21:33:30 +0200 Subject: [PATCH] org-edit-src: Use replace-buffer-contents * lisp/org-src.el (org-src--contents-for-write-back): Use a write back buffer * lisp/org-src.el (org-edit-src-exit): Use replace-buffer-contents * lisp/org-src.el (org-edit-src-save): Use replace-buffer-contents --- lisp/org-src.el | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 28733d011..4f0044394 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -432,8 +432,8 @@ spaces after it as being outside." (line-end-position) (point)))))) -(defun org-src--contents-for-write-back () - "Return buffer contents in a format appropriate for write back. +(defun org-src--contents-for-write-back (write-back-buf) + "Populate write-back-buf with contents in a format appropriate for write back. Assume point is in the corresponding edit buffer." (let ((indentation-offset (if org-src--preserve-indentation 0 @@ -445,7 +445,7 @@ Assume point is in the corresponding edit buffer." (source-tab-width org-src--tab-width) (contents (org-with-wide-buffer (buffer-string))) (write-back org-src--allow-write-back)) - (with-temp-buffer + (with-current-buffer write-back-buf ;; Reproduce indentation parameters from source buffer. (setq indent-tabs-mode use-tabs?) (when (> source-tab-width 0) (setq tab-width source-tab-width)) @@ -462,8 +462,7 @@ Assume point is in the corresponding edit buffer." (let ((i (current-column))) (delete-region (line-beginning-position) (point)) (indent-to (+ i indentation-offset)))) - (forward-line))) - (buffer-string)))) + (forward-line)))))) (defun org-src--edit-element (datum name &optional initialize write-back contents remote) @@ -1189,20 +1188,27 @@ Throw an error if there is no such buffer." (interactive) (unless (org-src-edit-buffer-p) (user-error "Not in a sub-editing buffer")) (set-buffer-modified-p nil) - (let ((edited-code (org-src--contents-for-write-back)) + (let ((write-back-buf (generate-new-buffer "*org-src-write-back*")) (beg org-src--beg-marker) (end org-src--end-marker) (overlay org-src--overlay)) + (org-src--contents-for-write-back write-back-buf) (with-current-buffer (org-src-source-buffer) (undo-boundary) (goto-char beg) ;; Temporarily disable read-only features of OVERLAY in order to ;; insert new contents. (delete-overlay overlay) - (delete-region beg end) (let ((expecting-bol (bolp))) - (insert edited-code) + (if (version< emacs-version "26.1") + (progn (delete-region beg end) + (insert (with-current-buffer write-back-buf (buffer-string)))) + (save-restriction + (narrow-to-region beg end) + (replace-buffer-contents write-back-buf) + (goto-char (point-max)))) (when (and expecting-bol (not (bolp))) (insert "\n"))) + (kill-buffer write-back-buf) (save-buffer) (move-overlay overlay beg (point)))) ;; `write-contents-functions' requires the function to return @@ -1219,7 +1225,8 @@ Throw an error if there is no such buffer." (remote org-src--remote) (coordinates (and (not remote) (org-src--coordinates (point) 1 (point-max)))) - (code (and write-back (org-src--contents-for-write-back)))) + (write-back-buf (and write-back (generate-new-buffer "*org-src-write-back*")))) + (when write-back (org-src--contents-for-write-back write-back-buf)) (set-buffer-modified-p nil) ;; Switch to source buffer. Kill sub-editing buffer. (let ((edit-buffer (current-buffer)) @@ -1229,13 +1236,20 @@ Throw an error if there is no such buffer." (kill-buffer edit-buffer)) ;; Insert modified code. Ensure it ends with a newline character. (org-with-wide-buffer - (when (and write-back (not (equal (buffer-substring beg end) code))) + (when (and write-back (not (equal (buffer-substring beg end) + (with-current-buffer write-back-buf (buffer-string))))) (undo-boundary) (goto-char beg) - (delete-region beg end) (let ((expecting-bol (bolp))) - (insert code) - (when (and expecting-bol (not (bolp))) (insert "\n"))))) + (if (version< emacs-version "26.1") + (progn (delete-region beg end) + (insert (with-current-buffer write-back-buf (buffer-string)))) + (save-restriction + (narrow-to-region beg end) + (replace-buffer-contents write-back-buf) + (goto-char (point-max)))) + (when (and expecting-bol (not (bolp))) (insert "\n"))) + (kill-buffer write-back-buf))) ;; If we are to return to source buffer, put point at an ;; appropriate location. In particular, if block is hidden, move ;; to the beginning of the block opening line. -- 2.28.0 --------------5A07D6224CD2520E6DED699E--