emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ignacio Casso <ignaciocasso@hotmail.com>
To: emacs-orgmode@gnu.org
Subject: [BUG] C-c C-o on headline evaluates source code blocks with links inside [9.5.2 (release_9.5.2-25-gaf6f12 @ /home/ignacio/repos/emacs/lisp/org/)]
Date: Thu, 24 Mar 2022 00:15:35 +0100	[thread overview]
Message-ID: <PAXPR06MB776062284C8525DC3DED853CC6199@PAXPR06MB7760.eurprd06.prod.outlook.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1747 bytes --]

Hello,

The recent threads about timestamps inside property drawers, which
mentioned the issue of timestamps and links being recognized in contexts
where they should not, had me experimenting a bit, and I found the
following bug (point 3) which was probably introduced by some change
regarding those issues:

1) `org-open-at-point' with point in a source code block calls and used
to call `org-babel-open-src-block-result'. This is not documented on the
docstring, but happens at least since Emacs 27' org built-in version,
9.4.4.

2) `org-open-at-point' with point in a link inside a source code block
also calls `org-babel-open-src-block-result' since at least org version
9.4.4. However I think that back when I was using Emacs 26, with
org-builtin version 9.1.9 or so, it opened the link. I think that when
that was fixed, the bug in 3) was introduced.

3) `org-open-at-point' with point in a headline collects all org links
in the body of the entry and offers to select one and open it, or if
there was only one it opens it directly. Links are collected using a
regular expression, so they match links inside a source code block. For
the selected link, `org-open-at-point' moves the point to the link and
calls itself recursively. In old versions of org, that means that it
opened the link. But in new versions, that means it evaluates the source
code block.

To reproduce this behavior, just copy the following entry into an org
buffer and type C-c C-o with point in the heading. It will evaluate the
source code block, instead of just messaging "No Links" as it would do
with a source code block without links.

* Heading
  #+begin_src emacs-lisp
    (message "https://orgmode.org/manual/")
  #+end_src

The following patch should fix it:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 807 bytes --]

From bc5092fdef512280b7d7d3aa04f1ba887360a759 Mon Sep 17 00:00:00 2001
From: Ignacio <ignacio.decasso@imdea.org>
Date: Thu, 24 Mar 2022 01:15:44 +0100
Subject: [PATCH] fixed bug

---
 lisp/org/org.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org/org.el b/lisp/org/org.el
index 67c8f1cedf..0fff28af81 100644
--- a/lisp/org/org.el
+++ b/lisp/org/org.el
@@ -9063,7 +9063,8 @@ org-offer-links-in-entry
 	 (org-back-to-heading t)
 	 (setq end (save-excursion (outline-next-heading) (point)))
 	 (while (re-search-forward org-link-any-re end t)
-	   (push (match-string 0) links))
+           (when (eq (org-element-type (org-element-context)) 'link)
+	     (push (match-string 0) links)))
 	 (setq links (org-uniquify (reverse links))))
        (cond
 	((null links)
-- 
2.25.1


[-- Attachment #3: Type: text/plain, Size: 217 bytes --]



Emacs  : GNU Emacs 29.0.50 (build 15, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0)
 of 2022-03-23
Package: Org mode version 9.5.2 (release_9.5.2-25-gaf6f12 @ /home/ignacio/repos/emacs/lisp/org/)

             reply	other threads:[~2022-03-24  0:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 23:15 Ignacio Casso [this message]
2022-03-26  8:15 ` Ihor Radchenko
     [not found] <878rt019jq.fsf@hotmail.com>
2022-03-24  8:02 ` Ignacio Casso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PAXPR06MB776062284C8525DC3DED853CC6199@PAXPR06MB7760.eurprd06.prod.outlook.com \
    --to=ignaciocasso@hotmail.com \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [BUG] C-c C-o on headline evaluates source code blocks with links inside [9.5.2 (release_9.5.2-25-gaf6f12 @ /home/ignacio/repos/emacs/lisp/org/)]' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).