From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uJL+BlxHLmGSPgEAgWs5BA (envelope-from ) for ; Tue, 31 Aug 2021 17:14:36 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id WM19AlxHLmEuWgAA1q6Kng (envelope-from ) for ; Tue, 31 Aug 2021 15:14:36 +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 467682297A for ; Tue, 31 Aug 2021 17:14:35 +0200 (CEST) Received: from localhost ([::1]:36214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL5T7-00011o-8k for larch@yhetil.org; Tue, 31 Aug 2021 11:14:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL5Rm-0000yO-Mp for emacs-orgmode@gnu.org; Tue, 31 Aug 2021 11:13:10 -0400 Received: from mout02.posteo.de ([185.67.36.66]:35027) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL5Rj-00033F-P3 for emacs-orgmode@gnu.org; Tue, 31 Aug 2021 11:13:10 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id A3794240108 for ; Tue, 31 Aug 2021 17:13:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.eu; s=2017; t=1630422783; bh=QaqXblTCKNOwSQmHi54CEeWTvgGF2+gh9Z2hJJFzIVI=; h=Subject:To:Cc:From:Date:From; b=ZzltxhWCAUu9Yu7/GYcI+tjlLiK5lGKi1/YZ/1622Ky+wZ/6uUpJxrGAFOIExOiPN fvGcNAAatFxVBwgLgYqV3aiN8zQRX3CL1waoD7+mHMdvpZKNiQTFmFNxuNPUXs+hKC BV2TMnIF9w/wj6Mv5uBictE9IQQzKYXfsvNAHzXVtWMFLnbV90JI4Y8KTHy7YQspye Xb6IH34H9SVv8tGRtea8Zrk+yPjV6173QZdzbJpBMOijePXdw6eXyjtiC7ezCbl/iY RwpRbAJ/YlQ3v7Mj7SmVGb59/Jv/nes26mYRWriIDCuSvfg8EOzhkAsHkGSgpc2Tyi vUkroBXuzSFzg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GzW0G62L9z6tmD; Tue, 31 Aug 2021 17:13:02 +0200 (CEST) Subject: [PATCH] Re: Bug: org-edit-special indents inline latex [9.5 (nil @ /home/david/.emacs.d/.local/straight/build-27.2/org-mode/)] To: Ihor Radchenko , =?UTF-8?Q?D=c3=a1vid_Jakab?= References: <0f961d3b-a4ef-fbbf-ab16-7ff1af8b2070@gmail.com> <87bl5hu31c.fsf@localhost> From: =?UTF-8?Q?S=c3=a9bastien_Miquel?= Message-ID: <3af691d1-cabd-27ce-94cd-89feb5a59665@posteo.eu> Date: Tue, 31 Aug 2021 15:13:02 +0000 MIME-Version: 1.0 In-Reply-To: <87bl5hu31c.fsf@localhost> Content-Type: multipart/mixed; boundary="------------C8602307F3F5BE4DDCE18190" Content-Language: fr Received-SPF: pass client-ip=185.67.36.66; envelope-from=sebastien.miquel@posteo.eu; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, 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: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1630422875; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=LaCYCmuLGwOO3YZIBpOnjQ6moYEd6tQ3QwfxkxRJUDA=; b=HBeUocTXbjBTcl6BR6UebSqnssdzHdX7o2rTH8/fFI4UGHRQK5j1I1lkJvrAStrJiUavuZ MDo8+XWxp1EDCKy0JlK18wRaO33zEIDtB6lrht+JWcBYaRIB0/fkMjhKi9bHH8D3+0HWqq fU2ZVTEbxcEDqVB6FPCQQuOEU5ZmzO15qOg9muDGqqYq0RDoOGZcv+AtZr8V9K+YRn2OeY cSY7Io9mGR2vJLGhaa43eMAGmJKPmlL4lp59/zOkTEn8tB+HtRo+qoF7LOdAh28ViO5YVb cxJIuj/147xJDokTj0fE1y7SMSwXaxEe56YzBQuWIPhTXn1lH1trBjTI87InGg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1630422875; a=rsa-sha256; cv=none; b=RvHhNk4HcqZWEyjOcUCBQr0ChLSPjLFDqSyzLgP4kJZf3v2OuiI0TTUOKmzc+jH/LC1uJi 6/jvXgXDnYQs084hlyKVX44pVNsAMrs+lSu+4dKSlRaAKsT1V0WoIeINpTZhQ3ifq1+dU8 8H7XMXwnCJPnaEUl6Zfstb9+iuViGngNnmRf7m/7gUVvE2YpXCcR7qsnAIS388SyCh6/Nb zhT5vT4ZERK3RDvzwPgtZ++l+7Kqi/aAH2hDKAI+0GnMMItJFXhF/b3UdRi+fR11amVeNw PUSsNP9f6zgorPEodoKqs9KgeTiR2PbgdV6dTv7H75OzocSQyF+Pf312YQzEwQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.eu header.s=2017 header.b=ZzltxhWC; 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-Migadu-Spam-Score: -1.62 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.eu header.s=2017 header.b=ZzltxhWC; 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-Migadu-Queue-Id: 467682297A X-Spam-Score: -1.62 X-Migadu-Scanner: scn0.migadu.com X-TUID: wLzue5CJoto7 This is a multi-part message in MIME format. --------------C8602307F3F5BE4DDCE18190 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, Ihor Radchenko writes: > Dávid Jakab writes: >> When using org-edit-special to edit inline latex, i.e., equations >> between \( and \), in an org-mode buffer, a number of >> spaces may get inserted before \( after the latex editing minibuffer is >> closed. The attached patch fixes this as well as a couple other issues with special editing of latex fragments :  + the coordinates computation was wrong, so point position inside fragment    isn't preserved when calling ~org-edit-special~ from an inline fragment.  + common leading indentation wasn't getting trimmed when editing a multiline    fragment inside an org list such as    $$abc    def$$ Thanks for reporting and confirming. Regards, -- Sébastien Miquel --------------C8602307F3F5BE4DDCE18190 Content-Type: text/x-patch; charset=UTF-8; name="0001-org-src.el-Fix-special-editing-of-LaTeX-fragments.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-org-src.el-Fix-special-editing-of-LaTeX-fragments.patch" >From 5c3254d42e3d359021d41dae9a0549244e6fddff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= Date: Mon, 30 Aug 2021 23:18:41 +0200 Subject: [PATCH] org-src.el: Fix special editing of LaTeX fragments * lisp/org-macs.el (org-do-remove-indentation): Add optional argument to skip the first line. * lisp/org-src.el (org-src--coordinates): Fix coordinates for inline LaTeX fragments. (org-src--contents-for-write-back): Do not indent first line for LaTeX fragments. (org-src--edit-element): Compute block-indentation according to parent for LaTeX fragments. Skip first line when removing common indentation for LaTeX fragments. --- lisp/org-macs.el | 9 ++++++--- lisp/org-src.el | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 77458db96..5c90c92f6 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -326,17 +326,19 @@ it for output." ;;; Indentation -(defun org-do-remove-indentation (&optional n) +(defun org-do-remove-indentation (&optional n skip-fl) "Remove the maximum common indentation from the buffer. When optional argument N is a positive integer, remove exactly -that much characters from indentation, if possible. Return nil -if it fails." +that much characters from indentation, if possible. When +optional argument SKIP-FL is non-nil, skip the first +line. Return nil if it fails." (catch :exit (goto-char (point-min)) ;; Find maximum common indentation, if not specified. (let ((n (or n (let ((min-ind (point-max))) (save-excursion + (when skip-fl (forward-line)) (while (re-search-forward "^[ \t]*\\S-" nil t) (let ((ind (current-indentation))) (if (zerop ind) (throw :exit nil) @@ -344,6 +346,7 @@ if it fails." min-ind)))) (if (zerop n) (throw :exit nil) ;; Remove exactly N indentation, but give up if not possible. + (when skip-fl (forward-line)) (while (not (eobp)) (let ((ind (progn (skip-chars-forward " \t") (current-column)))) (cond ((eolp) (delete-region (line-beginning-position) (point))) diff --git a/lisp/org-src.el b/lisp/org-src.el index 4698c6dd2..2e72b1755 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -324,7 +324,8 @@ a cons cell (LINE . COLUMN) or symbol `end'. See also (if (>= pos end) 'end (org-with-wide-buffer (goto-char (max beg pos)) - (cons (count-lines beg (line-beginning-position)) + (cons (count-lines (save-excursion (goto-char beg) (line-beginning-position)) + (line-beginning-position)) ;; Column is relative to the end of line to avoid problems of ;; comma escaping or colons appended in front of the line. (- (point) (min end (line-end-position))))))) @@ -442,6 +443,7 @@ Assume point is in the corresponding edit buffer." org-src--content-indentation 0)))) (use-tabs? (and (> org-src--tab-width 0) t)) + (preserve-fl (eq org-src--source-type 'latex-fragment)) (source-tab-width org-src--tab-width) (contents (org-with-wide-buffer (buffer-string))) (write-back org-src--allow-write-back)) @@ -456,7 +458,8 @@ Assume point is in the corresponding edit buffer." ;; Add INDENTATION-OFFSET to every line in buffer, ;; unless indentation is meant to be preserved. (when (> indentation-offset 0) - (while (not (eobp)) + (when preserve-fl (forward-line)) + (while (not (eobp)) (skip-chars-forward " \t") (let ((i (current-column))) (delete-region (line-beginning-position) (point)) @@ -504,7 +507,13 @@ Leave point in edit buffer." (source-tab-width (if indent-tabs-mode tab-width 0)) (type (org-element-type datum)) (block-ind (org-with-point-at (org-element-property :begin datum) - (current-indentation))) + (cond + ((save-excursion (skip-chars-backward " \t") (bolp)) + (current-indentation)) + ((org-element-property :parent datum) + (org--get-expected-indentation + (org-element-property :parent datum) nil)) + (t (current-indentation))))) (content-ind org-edit-src-content-indentation) (preserve-ind (and (memq type '(example-block src-block)) @@ -529,7 +538,8 @@ Leave point in edit buffer." (insert contents) (remove-text-properties (point-min) (point-max) '(display nil invisible nil intangible nil)) - (unless preserve-ind (org-do-remove-indentation)) + (let ((lf (eq type 'latex-fragment))) + (unless preserve-ind (org-do-remove-indentation (and lf block-ind) lf))) (set-buffer-modified-p nil) (setq buffer-file-name nil) ;; Initialize buffer. -- 2.33.0 --------------C8602307F3F5BE4DDCE18190--