From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id wKtjFzaeR1+LBAAA0tVLHw (envelope-from ) for ; Thu, 27 Aug 2020 11:51:18 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 5IVWEzaeR1/CUAAAB5/wlQ (envelope-from ) for ; Thu, 27 Aug 2020 11:51:18 +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 9C5B39404E1 for ; Thu, 27 Aug 2020 11:51:17 +0000 (UTC) Received: from localhost ([::1]:55720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBGR1-0004KF-KA for larch@yhetil.org; Thu, 27 Aug 2020 07:51:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBGQd-0004J3-VG for emacs-orgmode@gnu.org; Thu, 27 Aug 2020 07:50:51 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:38803) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kBGQb-0007aw-VY for emacs-orgmode@gnu.org; Thu, 27 Aug 2020 07:50:51 -0400 Received: by mail-pg1-x542.google.com with SMTP id l191so3182153pgd.5 for ; Thu, 27 Aug 2020 04:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=FJqQs3xqUkHE8wymP+9zpOds8oZfrX/yQDK3/U1Cjfs=; b=klSU3RtX9t5cNMukcrUZObQzKpuB1O0v6wR/pilMVTdEi6vuKXLifMs7xo7udlZSSh nACLZCM88ZHOhxTWbs2P3RnL9rDOuaVUg6dV80QUvPdfikObRiJ2AH7F9jJJloL/Lmy6 FJ+I9AIj7/sC7VTSYLwsGArEe2moXASNP8E0vdXz7qUzlS9gPDkbcQ6Rr2GXlYVedQNU e6mnKJtZHVlTlJz+29OLxdMX/IyVfsI+5gWXHfYUfds1BEKkDMcREQrBhg96FEPTFx90 3Jdvq9Upgk++dQgeldWYJZB260QhZyYApA3MsuNVFnMfvn+4Ea8VTNWv28D+U+9LOul7 OnUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=FJqQs3xqUkHE8wymP+9zpOds8oZfrX/yQDK3/U1Cjfs=; b=FKQhdK78+oQkQyJ2hzVKOQqtUXqGWeeoMX7DYY6zokVVV/EJygZ9RNfpuOJxp4ZK/a 0Xrl2DkxlPjRTcOBe9EmEREBcOMLghTBUMCRS/t5oVyzekHDv1V64B3m6soaKI3QWz/X Aqru7IiiXGqT2nPzjJWPWkoHS0/E5Z0kRaDrzGUoN7SPsVS7NCMglVW/AgQ3W/wrHn+A dwmcFlfw5AILENJ19UTU4BJ3ooeIirUN6bdo4WQKER+XaOt9APZ2nZvIGYWqCUcanArY kcyhVZNvJIjKsKbAKc1zRVD/Hl64eH8kOjzsWlYonRO9By97Tk59Dqwp8e8rBolpoUXF IgPQ== X-Gm-Message-State: AOAM5337pTBd8VQO3Uife2lEe7w76iIAaiCWGkayLGtUlFTiLfchXT3e //fEiI58JAehcf4sl4PlxDo= X-Google-Smtp-Source: ABdhPJzipp/Z2cHVFGEt4srHeyPOesUtfVsdTbRRwy6QmN/D3Uq21KpXdHlVL/zawfFtMl/xhpJCHw== X-Received: by 2002:a63:1323:: with SMTP id i35mr3932316pgl.41.1598529048288; Thu, 27 Aug 2020 04:50:48 -0700 (PDT) Received: from localhost ([104.250.131.79]) by smtp.gmail.com with ESMTPSA id h64sm2524864pfe.201.2020.08.27.04.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 04:50:47 -0700 (PDT) From: Ihor Radchenko To: D Subject: Re: [PATCH] Re: org-forward-heading-same-level and the invisible-ok argument In-Reply-To: <61342cad-ed4c-59ef-d2fe-685de58df5de@posteo.net> References: <87a6yi42ie.fsf@localhost> <61342cad-ed4c-59ef-d2fe-685de58df5de@posteo.net> Date: Thu, 27 Aug 2020 19:49:52 +0800 Message-ID: <87tuwo2tr3.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::542; envelope-from=yantar92@gmail.com; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, 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 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: , Cc: emacs-orgmode@gnu.org 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=gmail.com header.s=20161025 header.b=klSU3RtX; dmarc=pass (policy=none) header.from=gmail.com; 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.21 X-TUID: l0OclWQ5EZ69 > What I am wondering is whether it would make more sense as an argument > for org-forward-heading-same-level and similar commands, or as a > (potentially buffer-local) org variable to tweak the behavior, given > it's most likely going to affect these functions as interactive commands > (see alternative_org.el.diff). This version has the advantage of > allowing minor modes to easily mess with Org's behavior buffer-locally. I do not think that setting visibility the leading stars is a correct approach to control the movement commands. After second though about the issue you raised in the first email, I think that it would make more sense for org-forward-heading-same-level to check if any part of the heading line is visible to decide if we need to skip it (instead of current approach checking only the point at the beginning of the headline). Any mode aiming to make org-forward-heading-same-level skip a heading will then just need to make the whole heading invisible. Skipping partially visible headlines would be a violation of the docstring. Best, Ihor D writes: >> I guess it is simply because nobody though that the leading stars can be >> hidden via fontification. >> >> I think the whole issue can be fixed by changing the call to >> org-invisible-p inside org-forward-heading-same-level. org-invisible-p >> has an optional third argument to ignore text hidden via fontification. >> You can try to make a patch for org-forward-heading-same-level and >> similar commands adding that third argument. > > I looked into the git repository and noticed that org-invisible-p > already, thanks to a patch from Nicolas Goaziou (b1822760f4). > What I am wondering is whether it would make more sense as an argument > for org-forward-heading-same-level and similar commands, or as a > (potentially buffer-local) org variable to tweak the behavior, given > it's most likely going to affect these functions as interactive commands > (see alternative_org.el.diff). This version has the advantage of > allowing minor modes to easily mess with Org's behavior buffer-locally. > > I considered how adding a third argument to > org-forward-heading-same-level, but realized that adding another > invisibility argument would kinda leak a little complexity, as we'd wind > up with TWO invisibility-related arguments (which only differ in subtle > ways) and their interactions. So instead I'd recommend to instead allow > a distinct, non-nil option for invisible-ok, for example `t', `nil' and > `except-folding' (see org.el.diff). This version would be more > transparent, as it would not change the behavior of ALL calls in the > buffer, but comes at the cost of minor modes needing to overshadow > bindings to accomplish the same. > > I whipped up a quick diff for both versions, and will gladly make a > patch once we settled on one, but I wanted to discuss which is > preferable before making an uninformed decision on my own. > diff --git a/lisp/org.el b/lisp/org.el > index 71dbc611e..b8e6d47c2 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -20482,7 +20482,12 @@ entry." > "Move forward to the ARG'th subheading at same level as this one. > Stop at the first and last subheadings of a superior heading. > Normally this only looks at visible headings, but when INVISIBLE-OK is > -non-nil it will also look at invisible ones." > +non-nil it will also look at invisible ones. > + > +If INVISIBLE-OK is set to the symbol `except-folding', continue > +ignoring all parts that are invisible due to folding of a > +headline, a block or a drawer, i.e., not because of > +fontification." > (interactive "p") > (let ((backward? (and arg (< arg 0)))) > (if (org-before-first-heading-p) > @@ -20495,12 +20500,14 @@ non-nil it will also look at invisible ones." > (result (point))) > (while (and (> count 0) > (funcall f org-outline-regexp-bol nil 'move)) > - (let ((l (- (match-end 0) (match-beginning 0) 1))) > + (let ((l (- (match-end 0) (match-beginning 0) 1)) > + (folding-only (eq 'except-folding invisible-ok))) > (cond ((< l level) (setq count 0)) > ((and (= l level) > - (or invisible-ok > + (or (and invisible-ok (not folding-only)) > (not (org-invisible-p > - (line-beginning-position))))) > + (line-beginning-position) > + folding-only)))) > (cl-decf count) > (when (= l level) (setq result (point))))))) > (goto-char result)) > diff --git a/lisp/org.el b/lisp/org.el > index 71dbc611e..8e0040814 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -20478,6 +20478,18 @@ entry." > ((looking-at-p re) (forward-line)) > (t (throw 'exit t)))))))) > > + > +(defcustom org-navigate-invisible-headings nil > + "If non-nil, navigate through (unfolded) invisible headings normally. > +Commands such as `org-forward-heading-same-level' and > +`org-forward-heading-same-level' will consider all invisible > +headings except for those that are invisible due to folding of a > +headline, a block or a drawer." > + :group 'org > + :type '(choice > + (const :tag "Don't navigate invisible headings" nil) > + (const :tag "Navigate invisible (unfolded) headings" t))) > + > (defun org-forward-heading-same-level (arg &optional invisible-ok) > "Move forward to the ARG'th subheading at same level as this one. > Stop at the first and last subheadings of a superior heading. > @@ -20498,9 +20510,11 @@ non-nil it will also look at invisible ones." > (let ((l (- (match-end 0) (match-beginning 0) 1))) > (cond ((< l level) (setq count 0)) > ((and (= l level) > - (or invisible-ok > + (or (and invisible-ok > + (not org-navigate-invisible-headings)) > (not (org-invisible-p > - (line-beginning-position))))) > + (line-beginning-position) > + org-navigate-invisible-headings)))) > (cl-decf count) > (when (= l level) (setq result (point))))))) > (goto-char result))