From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id oN6wEdJ1M2YkUwEAe85BDQ:P1 (envelope-from ) for ; Thu, 02 May 2024 13:15:30 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id oN6wEdJ1M2YkUwEAe85BDQ (envelope-from ) for ; Thu, 02 May 2024 13:15:30 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="mB6R/EQb"; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1714648530; 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=n9QdlG2IlKjtW5X22xdhceoZLRf2RU97oI6E9uFCjzQ=; b=GGoANqwEQRFBJ8DYAsKXYnM+qGpNNkzX35q+zzb54G0slSlnj5Nx46OiV7O9OpzxH87PoW f0WMInArT3Z4uqVfdebc6reu5t682i6IJYw72DEl8NDt7hCEEH2DhQzSOoAwiTx081xnJv kX6Ed2FoK0YiqmcldhojX3cyWdrKdxNXhIVH4GGEg6l0l8HkOaAYo+o1b1WXqYSzLeczSX kKDdcdSRXVKo6I+sNUtp6SlYd31oszvxg2EtfnHxIavaU+Gk9ZewU7uGMepgA/tdglKSvE vrSb5VeY/q+9DnAIWNTefXTrb+MJI504B/TNybyTkRjOh6WvXLAC/RnLXlfITw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="mB6R/EQb"; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1714648530; a=rsa-sha256; cv=none; b=bOF7T8fcG9F4jHU80qQepLph4M0i58MatM2F0bZRJ8yXgZKzrsYL9xP3ia04WDCoCmCNew jun+uV8QKzvQEN5mTU5FU8J8EUAOwJ5xfAJOZaq0w03MsioSgoqeLjsAcYT6T2nuEDd1p0 M7iLY1RhfedO3BQZQ489SuTlob6/Lw3tOdB7EviSDpXY7MB1HvYPFBgKjkkCL9XDmLyllz yr2C8pzfxHpav/7hzZ/TJEIJDGFjLq8tRKkIgfSbZFhNHeF+gF0evvfueJ6RnBDRxZ9RUe IkoWsSRdWlqjN3bS6oWV+UQRrrZpgIh8kA62GKJmY6VPWt7YRGcvZXnXVePcLQ== 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 00AFA39241 for ; Thu, 2 May 2024 13:15:30 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s2UOZ-00031i-Fa; Thu, 02 May 2024 07:14:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s2UOX-0002te-3d for emacs-orgmode@gnu.org; Thu, 02 May 2024 07:14:33 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s2UOR-0005xg-Pa for emacs-orgmode@gnu.org; Thu, 02 May 2024 07:14:32 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 45021240101 for ; Thu, 2 May 2024 13:14:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1714648465; bh=FdFxjI6FOXEUWWCTpGoI6r+WuC5/lGr2ynJYeMH4uRo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=mB6R/EQbjghGgrjAxxebLQ4jd7AVdESajKGJQz7kxsh/qGf2bBBWTJwuWsCIf4QHS 5sRM5OUWpIoZdR3B30u3OZTfhamgn4EmK+1xFRiO0isBzdzNrxQSBeGK28JbKT1DZD bpm/64yUVTlIeiGxhqrCEUvhs37nfixcN+TKMJvyqC33EXzWlGVdI2Hzlt9EesbSsd GuVnGvf/X4c/enYYdjfTtPNAQKNU0XChML2a3wazZBbGmDgmmRC2UqTsxaZP4Uu1/y WiR3tlg5/TOYnor/0XUpailX5HIo+FL0BZMK89bM1qk3zSjOMS4nosay1yO0rDJneP zVbUMhIL2eesA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VVWXw11lVz6txr; Thu, 2 May 2024 13:14:23 +0200 (CEST) From: Ihor Radchenko To: Max Nikulin Cc: Alexandros Prekates , "emacs-orgmode@gnu.org" Subject: Re: link can not be created in a line with another link. In-Reply-To: References: <20240428093320.120843ae@enoush2o> <87cyq9k6cz.fsf@localhost> <20240429154540.3917dd8c@enoush2o> Date: Thu, 02 May 2024 11:15:35 +0000 Message-ID: <87bk5obh2g.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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.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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.60 X-Spam-Score: -9.60 X-Migadu-Queue-Id: 00AFA39241 X-Migadu-Scanner: mx13.migadu.com X-TUID: 53PxtLkUml1Y --=-=-= Content-Type: text/plain Max Nikulin writes: > I have a more weird example. Consider you are going to get > > - [[#foo]] and [[#bar]] > > starting from > > - [[#bar]] > > There is no problem till > > - [[#foo[[#bar]] > > However in response to "]" point is moved after "[" > > - [[#foo][[#bar]] > > that is displayed as > > - [#bar > > I do not see other ways than undo, SPC, and moving back. It would be > great to keep point between brackets "][" this case. I have no > idea if it is feasible to postpone hiding link target when such pattern > is typed. May you try the attached patch (on top of the latest main)? Does it feel better? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Honor-org-fold-catch-invisible-edits-when-editing-li.patch >From fce16d736a97943f2f2cde521806dd78ed97a9bc Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Thu, 2 May 2024 11:49:00 +0300 Subject: [PATCH] Honor `org-fold-catch-invisible-edits' when editing links * lisp/org.el (org-activate-links): Mark links with 'org-link text property. * lisp/org-fold.el (org-fold-show-set-visibility): Reveal links at point for 'local detail. (org-fold-check-before-invisible-edit): When editing after links, do not warn about inserting after invisible. * testing/lisp/test-org-fold.el (test-org-fold/org-catch-invisible-edits): Update tests. * lisp/org-fold-core.el (org-fold-core-region): Do not re-fontify unnecessarily. --- lisp/org-fold-core.el | 6 ++++-- lisp/org-fold.el | 37 +++++++++++++++++++-------------- lisp/org.el | 1 + testing/lisp/test-org-fold.el | 39 +++++++++++++++++++++-------------- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/lisp/org-fold-core.el b/lisp/org-fold-core.el index 41b16851f..1b2e41cf5 100644 --- a/lisp/org-fold-core.el +++ b/lisp/org-fold-core.el @@ -1047,9 +1047,11 @@ (defun org-fold-core-region (from to flag &optional spec-or-alias) ;; past the ellipsis. See bug#65896. The face properties are ;; assigned via `org-activate-folds'. (when (or (not spec) (org-fold-core-get-folding-spec-property spec :font-lock)) - (when (equal ?\n (char-after from)) + (when (and (equal ?\n (char-after from)) + (or flag (org-fold-folded-p from))) (font-lock-flush from (1+ from))) - (when (equal ?\n (char-after to)) + (when (and (equal ?\n (char-after to)) + (or flag (org-fold-folded-p to))) (font-lock-flush to (1+ to))) (dolist (region (org-fold-core-get-regions :from from :to to :specs spec)) (when (equal ?\n (char-after (cadr region))) diff --git a/lisp/org-fold.el b/lisp/org-fold.el index 1b62168c4..2c11383ba 100644 --- a/lisp/org-fold.el +++ b/lisp/org-fold.el @@ -658,8 +658,6 @@ (defun org-fold-show-set-visibility (detail) (org-fold-show-entry) ;; If point is hidden make sure to expose it. (when (org-invisible-p) - ;; FIXME: No clue why, but otherwise the following might not work. - (redisplay) ;; Reveal emphasis markers. (when (eq detail 'local) (let (org-hide-emphasis-markers @@ -668,6 +666,7 @@ (defun org-fold-show-set-visibility (detail) (org-hide-macro-markers nil) (region (or (org-find-text-property-region (point) 'org-emphasis) (org-find-text-property-region (point) 'org-macro) + (org-find-text-property-region (point) 'org-link) (org-find-text-property-region (point) 'invisible)))) ;; Silence byte-compiler. (ignore org-hide-macro-markers) @@ -882,30 +881,34 @@ (defun org-fold-check-before-invisible-edit (kind) "Check if editing KIND is dangerous with invisible text around. The detailed reaction depends on the user option `org-fold-catch-invisible-edits'." + ;; When cursor is at a link that was revealed during previous edit, + ;; re-fold it, so that we refresh the fontification. + (font-lock-ensure (max (point-min) (1- (point))) (point)) ;; First, try to get out of here as quickly as possible, to reduce overhead (when (and org-fold-catch-invisible-edits (or (not (boundp 'visible-mode)) (not visible-mode)) (or (org-invisible-p) (org-invisible-p (max (point-min) (1- (point)))))) - ;; OK, we need to take a closer look. Only consider invisibility - ;; caused by folding of headlines, drawers, and blocks. Edits - ;; inside links will be handled by font-lock. - (let* ((invisible-at-point (org-fold-folded-p (point) '(headline drawer block))) + ;; OK, we need to take a closer look. + (let* ((invisible-at-point (org-invisible-p (point))) (invisible-before-point - (and (not (bobp)) - (org-fold-folded-p (1- (point)) '(headline drawer block)))) + (and (not (bobp)) (org-invisible-p (1- (point))))) + (folded-before-point + (and (not (bobp)) (org-fold-folded-p (1- (point))))) (border-and-ok-direction (or ;; Check if we are acting predictably before invisible ;; text. (and invisible-at-point (not invisible-before-point) (memq kind '(insert delete-backward))) - ;; Check if we are acting predictably after invisible text - ;; This works not well, and I have turned it off. It seems - ;; better to always show and stop after invisible text. - ;; (and (not invisible-at-point) invisible-before-point - ;; (memq kind '(insert delete))) - ))) + ;; Check if we are acting predictably after invisible + ;; text. After the folds (which are usually multi-line, + ;; always raise a warning; after inline invisible text + ;; (links or hidden markup markers), allow editing + ;; forward. + (and (not invisible-at-point) invisible-before-point + (not folded-before-point) + (memq kind '(insert delete)))))) (when (or invisible-at-point invisible-before-point) (when (eq org-fold-catch-invisible-edits 'error) (user-error "Editing in invisible areas is prohibited, make them visible first")) @@ -922,10 +925,12 @@ (defun org-fold-check-before-invisible-edit (kind) ;; That's it, we do the edit after showing (message "Unfolding invisible region around point before editing") - (sit-for 1)) + (sit-for 0.2)) ((and (eq org-fold-catch-invisible-edits 'smart) border-and-ok-direction) - (message "Unfolding invisible region around point before editing")) + (message "Unfolding invisible region around point before editing") + ;; Flash links before they get hidden back due to fontification after edit. + (sit-for 0.2)) (t ;; Don't do the edit, make the user repeat it in full visibility (user-error "Edit in invisible region aborted, repeat to confirm with text visible")))))))) diff --git a/lisp/org.el b/lisp/org.el index ad4d1b9d3..809fd8ba3 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5351,6 +5351,7 @@ (defun org-activate-links (limit) :htmlize-link) ((and (pred functionp) f) (funcall f)) (_ `(:uri ,link))) + 'org-link t 'font-lock-multiline t))) (org-remove-flyspell-overlays-in start end) (org-rear-nonsticky-at end) diff --git a/testing/lisp/test-org-fold.el b/testing/lisp/test-org-fold.el index f58642be6..904bc6578 100644 --- a/testing/lisp/test-org-fold.el +++ b/testing/lisp/test-org-fold.el @@ -616,7 +616,8 @@ (ert-deftest test-org-fold/org-catch-invisible-edits () (test-org-fold-with-default-template (dolist (txt '("Folded Paragraph inside heading" "Folded Paragraph inside drawer" - "Folded block")) + "Folded block" + "hiddenlink")) (search-forward txt) (message "Inside invisible %S" txt) (pcase org-fold-catch-invisible-edits @@ -631,16 +632,13 @@ (ert-deftest test-org-fold/org-catch-invisible-edits () (should-not (org-invisible-p))) (`error (should-error (org-fold-check-before-invisible-edit kind)) - (should (org-invisible-p))))) - (search-forward "hiddenlink") - (message "Inside hidden link") - (org-fold-check-before-invisible-edit kind) - (should (org-invisible-p))) + (should (org-invisible-p)))))) ;; Edits at the left border. (test-org-fold-with-default-template (dolist (txt '("Folded heading" ":FOLDED-DRAWER:" - "#+begin_src emacs-lisp")) + "#+begin_src emacs-lisp" + "[link")) (search-forward txt) (message "Left of folded %S" txt) (pcase org-fold-catch-invisible-edits @@ -660,12 +658,7 @@ (ert-deftest test-org-fold/org-catch-invisible-edits () (should-not (org-invisible-p (1+ (point))))) (`error (should-error (org-fold-check-before-invisible-edit kind)) - (should (org-invisible-p (1+ (point))))))) - (search-forward "hiddenlink") - (search-forward "lin") - (message "Left border of ]] in link") - (org-fold-check-before-invisible-edit kind) - (should (org-invisible-p (1+ (point))))) + (should (org-invisible-p (1+ (point)))))))) ;; Edits at the right border. (test-org-fold-with-default-template (dolist (txt '("Folded Paragraph inside heading." @@ -689,8 +682,24 @@ (ert-deftest test-org-fold/org-catch-invisible-edits () (search-forward "hiddenlink") (search-forward "link]]") (message "Right border of ]] in link") - (org-fold-check-before-invisible-edit kind) - (should (org-invisible-p (1- (point)))))))))) + (pcase org-fold-catch-invisible-edits + (`nil + (org-fold-check-before-invisible-edit kind) + (should (org-invisible-p (1- (point))))) + (`show + (org-fold-check-before-invisible-edit kind) + (should-not (org-invisible-p (1- (point))))) + (`smart + (if (memq kind '(insert delete)) + (org-fold-check-before-invisible-edit kind) + (should-error (org-fold-check-before-invisible-edit kind))) + (should-not (org-invisible-p (1- (point))))) + (`show-and-error + (should-error (org-fold-check-before-invisible-edit kind)) + (should-not (org-invisible-p (1- (point))))) + (`error + (should-error (org-fold-check-before-invisible-edit kind)) + (should (org-invisible-p (1- (point)))))))))))) (ert-deftest test-org-fold/org-fold-display-inline-images () "Test inline images displaying when cycling." -- 2.44.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--