From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id GMJ+JKxd1WLAZAEAbAwnHQ (envelope-from ) for ; Mon, 18 Jul 2022 15:18:36 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 0FZ9JKxd1WIXGgAAauVa8A (envelope-from ) for ; Mon, 18 Jul 2022 15:18:36 +0200 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 10C9AFCB9 for ; Mon, 18 Jul 2022 15:18:36 +0200 (CEST) Received: from localhost ([::1]:58848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDQdu-0007xr-VA for larch@yhetil.org; Mon, 18 Jul 2022 09:18:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDQWh-000414-Vd for emacs-orgmode@gnu.org; Mon, 18 Jul 2022 09:11:08 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:46864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDQWf-000381-Ts; Mon, 18 Jul 2022 09:11:07 -0400 Received: by mail-pg1-x52c.google.com with SMTP id s27so10491020pga.13; Mon, 18 Jul 2022 06:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=Th4A+aIorZmWgzCrTg5QCzal7ECWBU5GxDH6I0Rkr60=; b=CtUtaBKDTLOcEpwOHQldh2YI3cLy+b0bo2tfgcEqIg9DfaAXhDVmjdzXjo6zJ6R5lZ W82Ok2BVZH/4mAs9JwglAGmo+qOtrhELkmLKpO53uaxLx7O7diISOu4kW+t7FaFyfjto D/P8FhaObFpjW7XvAFB7xzni3JGWQ7N4ZRDnRO/VDzE3csQ9vcepTH8Lzed3vMBEeIvp DRRRtH3RZnoNHBjFr8OkKFbYuC2rPHrigdCX70mgqyD4jy/8sCo9TTAyqRdSmrqm67sp q1PCuQ/7onTdJCpqUS1OdSc0AX1TPIaz7mi7oHmXTQL07nTjTQzzS5bwjMUqVpSHhSD1 KyDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Th4A+aIorZmWgzCrTg5QCzal7ECWBU5GxDH6I0Rkr60=; b=YLwFsmSypX9CN2Twir5PD3mtbbHQt6Ego1cDB63mEaAJvB/EKVZhC/Hja1yXIh7+Kv zcgVOb3JQARzYbfJOYxeO0U17C0+R4MriHES+jibtN4H/eu9AmaEVkse3mTS6dFsya8e ZnFu5bg6X85Oa7MlDuVVlEq9Ibvh2qDYvQcdKB89I1VXF1SiGXKEjvVOtv/Rk2cUppt8 bwsWK69OPGqHVehlTLMO15TX75vWCUgqURUQg77ksTfTVRMaqdH65RrvOeW1mlLW7MV/ q/ekQWIzNn462rhB1yqcmgPsKHdQDo5/rmlDfdWELjC1Iog98Wv9l0joHmgMXSmC7InN sP2w== X-Gm-Message-State: AJIora+WhUEj+QaMB405ZidWJ0vi35pQHBZMbQ1m6euqrc4B8RsLyz9s gcNoTHFhJU6YYk1oWo5VFCwNjgYv8HxYcYrB X-Google-Smtp-Source: AGRyM1toKkLpb03lTna/0J3qP9z12dCyriBRoE8Lsopma+rVbQOJ+rQapkL/GnY1zcdIQ6WhzMtXyQ== X-Received: by 2002:a62:4e04:0:b0:52b:30f5:59b8 with SMTP id c4-20020a624e04000000b0052b30f559b8mr19742639pfb.37.1658149846009; Mon, 18 Jul 2022 06:10:46 -0700 (PDT) Received: from localhost ([2409:8a70:2bd:4d0:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id g26-20020aa796ba000000b0052ab5a740aesm9207008pfk.162.2022.07.18.06.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 06:10:45 -0700 (PDT) From: Ihor Radchenko To: Valentin Lab , Bastien Cc: emacs-orgmode@gnu.org Subject: [PATCH] Fix bug in org-indent-region when org-adapt-indentation is set to headline-data (was: [feature] Consistent fixed indentation of headline data) In-Reply-To: References: <2fcae365-97cf-ccc4-23f0-2fc5c110dd69@kalysto.org> <87v8s9urvg.fsf@localhost> Date: Mon, 18 Jul 2022 21:11:49 +0800 Message-ID: <87fsiyh8fe.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=yantar92@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1658150316; h=from:from:sender:sender: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=Th4A+aIorZmWgzCrTg5QCzal7ECWBU5GxDH6I0Rkr60=; b=iVUMpR7xCaRd4U9ez5T70/5/PebuyRN67K2O1TUq3Wb1nPlp7wXKiPzu33K91NZi1+ijxt HinnVmoCmyGBfIZPjusWPzFS+DB6Qyia+GQO5wEj9xOsxMQafeCL+7JhbOOUlRvCEyhis7 vi6ZR7SGOLc/1U00NSlsGp58SW5a8rWTCdmbDoJGbvvf1jY2nznZa3mmItwS9xzypBifYI ITVfLPGtXyg0lJwv7gogkX0GqzGpjtMy5peKqNFd6ikHLxe6RLREvCOJ2MvVICTYbBXJKd ziE1WBfRwX5IroQdcKnN86CmWXMcWN8Icn7olw8Yle1uJTi15iGEE4I2iPH5HQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1658150316; a=rsa-sha256; cv=none; b=YUpHAwb7B9XDgkv09fjbB+pPe1qXHY64XJE0ccukDB+0ONtLHnlHdZ/WKjge8xTxslpZOD jkasQ4NvPgUEQvN+F8iecSLV2QGJR6FNiVr6pbm6oimTaFIYS0rKgBliYGm4mm7OJmZTxe YOAvXj5Yne4yXWoiFdEiBEc549Q1ipX3vibyq3Ky2hHr5IkHykMLCcJtb9hjGfFC24rMJ5 Mw028HYdeRe39tIms1gzo7wp6cQTBisXfHBIdhF8jqXx0q9fDw/aDntxzcDuS6F+UCY7Bg t9GfzgcqK8GV9gmAOGduIuMJvZbGSIs5BlYDNk7MWPDYyElNWc2ctZF4maq90Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=CtUtaBKD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -8.73 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=CtUtaBKD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 10C9AFCB9 X-Spam-Score: -8.73 X-Migadu-Scanner: scn0.migadu.com X-TUID: 2nNZCfst1kr2 --=-=-= Content-Type: text/plain Valentin Lab writes: >>> @@ -1216,6 +1259,13 @@ >>> (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:" >>> (org-indent-region (point-min) (point-max)) >>> (buffer-string))))) >>> + ;; ;; Indent property drawers according to `org-adapt-indentation'. >>> + ;; (let ((org-adapt-indentation 'headline-data)) >>> + ;; (should >>> + ;; (equal "* H\n :PROPERTIES:\n :key:\n :END:\n\ncontent2" >>> + ;; (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:\n\ncontent" >>> + ;; (org-indent-region (point-min) (point-max)) >>> + ;; (buffer-string))))) >> >> This test is commented. Is it intentional? > > My bad ! and an interesting talking point. I'm removing these commented > line in the upcoming patch. They were here (and inadvertently committed) > because while trying to test that my addition would not indent beyond > the headline data, I noticed that actually `org-adapt-indentation' set > to `headline-data' was actually indenting beyond headline data ! As I > don't want to break anything, I was left quite puzzled with what to do: > - I can fix this, but fixing this is for me subject to another > submission, and will touch behaviors that might be wanted, > - Not fixing this make me submitting a feature that carries what I see > like a "bug". > > But, is that a bug ? Here is the case: > > --8<---------------cut here---------------start------------->8--- > * H > :PROPERTIES: > :key: > :END: > > content > --8<---------------cut here---------------start------------->8--- > > Using `org-indent-region' on all the content, with > `org-adapt-indentation' set to `headline-data', will result to: > > --8<---------------cut here---------------start------------->8--- > * H > :PROPERTIES: > :key: > :END: > > content > --8<---------------cut here---------------start------------->8--- > > My issue is with the treatment of the 'content' line that is not > headline-data for me, and should not have been indented. Am I right in > my expectation ? Yes are right and we got a bug here. I am attaching the tentative fix. Bastien, I feel that the current implementation of `org--get-expected-indentation' is wrong since we introduced `org-adapt-indentation' 'headline-data value. AFAIU, it was done by you in e3b79ad2b. See the commit message in the patch below for the explanation why I think that something is going wrong. Am I missing something? Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-indent-region-Fix-when-org-adapt-indentation-is-.patch >From 9917d69543226c68ca9e749e4f53e5f3e8ec8e79 Mon Sep 17 00:00:00 2001 Message-Id: <9917d69543226c68ca9e749e4f53e5f3e8ec8e79.1658149652.git.yantar92@gmail.com> From: Ihor Radchenko Date: Mon, 18 Jul 2022 21:00:13 +0800 Subject: [PATCH] org-indent-region: Fix when `org-adapt-indentation' is 'headline-data * lisp/org.el (org--get-expected-indentation): Remove the extra condition added in e3b79ad2b in the cond branch for first line in an element. Checking `org-adapt-indentation' t value here trigger the last default cond branch that assumes that we are _not_ at the first line. The new logic explicitly avoids inheriting indentation from previous sibling when `org-adapt-indentation' is set to 'headline-data and the previous sibling is satisfying "headline data" condition as in `org-indent-line'. The case when `org-adapt-indentation' is set to t is already handled correctly when calculating the CONTENTSP indentation for parent headline. Fixes https://orgmode.org/list/c13cab60-bbc9-e69e-6d0d-7fe75c5908d6@kalysto.org --- lisp/org.el | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 99e5d0dc7..64b148d9c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -18455,9 +18455,9 @@ (defun org--get-expected-indentation (element contentsp) (org-element-property :parent element) t)) ;; At first line: indent according to previous sibling, if any, ;; ignoring footnote definitions and inline tasks, or parent's - ;; contents. - ((and ( = (line-beginning-position) start) - (eq org-adapt-indentation t)) + ;; contents. If `org-adapt-indentation' is `headline-data', ignore + ;; previous headline data siblings. + ((= (line-beginning-position) start) (catch 'exit (while t (if (= (point-min) start) (throw 'exit 0) @@ -18474,6 +18474,21 @@ (defun org--get-expected-indentation (element contentsp) ((memq (org-element-type previous) '(footnote-definition inlinetask)) (setq start (org-element-property :begin previous))) + ;; Do not indent like previous when the previous + ;; element is headline data and `org-adapt-indentation' + ;; is set to `headline-data'. + ((save-excursion + (goto-char start) + (and + (eq org-adapt-indentation 'headline-data) + (not (or (org-at-clock-log-p) + (org-at-planning-p))) + (progn + (beginning-of-line 1) + (skip-chars-backward "\n") + (or (org-at-heading-p) + (looking-back ":END:.*" (point-at-bol)))))) + (throw 'exit 0)) (t (goto-char (org-element-property :begin previous)) (throw 'exit (if (bolp) (current-indentation) -- 2.35.1 --=-=-=--