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 wStdH3nVRl8YZgAA0tVLHw (envelope-from ) for ; Wed, 26 Aug 2020 21:34:49 +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 CLShGnnVRl/RawAA1q6Kng (envelope-from ) for ; Wed, 26 Aug 2020 21:34:49 +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 88B19940365 for ; Wed, 26 Aug 2020 21:34:48 +0000 (UTC) Received: from localhost ([::1]:51622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kB341-0003Y7-BX for larch@yhetil.org; Wed, 26 Aug 2020 17:34:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kB33R-0003Ty-EK for emacs-orgmode@gnu.org; Wed, 26 Aug 2020 17:34:01 -0400 Received: from mout01.posteo.de ([185.67.36.65]:42305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kB33P-0004l4-56 for emacs-orgmode@gnu.org; Wed, 26 Aug 2020 17:34:01 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id AD6F716005F for ; Wed, 26 Aug 2020 23:33:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1598477633; bh=LUeDyn56lJVWP+8GV8byx3bs/MI3Wdemxdva7VgxW+Q=; h=From:Subject:To:Cc:Date:From; b=OwDhsC6jToc+smxqZwKf0FAhZ+KtRkyHrGK1cT52EDcoEAK5pp1ORPI1nwC0kDNTd uZH/bhweU2hE9k8uCSzA4eA4xhDFCtLLEiqPieKU208QNHojh5b4Gp+h1Q3zmWBy9Y hez/2SAO1E830LXJ3h20bd4VQZ0EKIJsQqe89qGINnTOeUfd/7/zDltiLhfBaDq7SF n/4XFASpWtD2a9aFt3Y9V9c3P0T5OoCPMRxQdO+gSt970x6KL/YYyELJNfj/MyFDwS fpJFWOT/uyQtZ+CRd2HHX+QP9h74ZLDOxAfCBsKeDKRsegDjxyBqtWvm0LSAb4Pz3q rkeP5LZMJhUTw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4BcJyS6p5Yz6tmK; Wed, 26 Aug 2020 23:33:52 +0200 (CEST) From: D Subject: [PATCH] Re: org-forward-heading-same-level and the invisible-ok argument To: Ihor Radchenko References: <87a6yi42ie.fsf@localhost> Message-ID: <61342cad-ed4c-59ef-d2fe-685de58df5de@posteo.net> Date: Wed, 26 Aug 2020 23:33:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <87a6yi42ie.fsf@localhost> Content-Type: multipart/mixed; boundary="------------A99BA10D2E94FEC95644C063" Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=d.williams@posteo.net; helo=mout01.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/26 17:33:54 X-ACL-Warn: Detected OS = Linux 3.11 and newer 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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: , 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=posteo.net header.s=2017 header.b=OwDhsC6j; dmarc=pass (policy=none) header.from=posteo.net; 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: eSpELgdFTQX7 This is a multi-part message in MIME format. --------------A99BA10D2E94FEC95644C063 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit > 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. --------------A99BA10D2E94FEC95644C063 Content-Type: text/x-patch; charset=UTF-8; name="org.el.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="org.el.diff" 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)) --------------A99BA10D2E94FEC95644C063 Content-Type: text/x-patch; charset=UTF-8; name="alternative_org.el.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="alternative_org.el.diff" 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)) --------------A99BA10D2E94FEC95644C063--