emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* overlap between cite syntax and link activation
@ 2022-04-03 23:44 John Kitchin
  2022-04-04  0:55 ` Bruce D'Arcus
  0 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2022-04-03 23:44 UTC (permalink / raw)
  To: org-mode-email

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

I think there is some overlap between the org-cite syntax and org-link
activation.

Consider this org-cite:

[cite/noauthor/bare:@key]

Now define this link:

#+BEGIN_SRC emacs-lisp
(org-link-set-parameters "bare"
:help-echo "BARE LINK"
:activate-func (lambda (start end path _bracketp)
 (message-box "%S activating bare" (list start end path))
 (put-text-property start
    end
    'face '(:foreground "OrangeRed1"))))

#+END_SRC

When I put my cursor on the org-cite line and press spc, I see a message
box pop up, and the @key has a tooltip of "BARE LINK".

I guess this means the activate-func is being used too aggressively. It
looks like it is called after (re-search-forward org-link-any-re limit t).
This does seem to match the cite syntax above.

Does anyone else see this?

John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

[-- Attachment #2: Type: text/html, Size: 1631 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overlap between cite syntax and link activation
  2022-04-03 23:44 overlap between cite syntax and link activation John Kitchin
@ 2022-04-04  0:55 ` Bruce D'Arcus
  2022-04-22 12:47   ` Bruce D'Arcus
  0 siblings, 1 reply; 6+ messages in thread
From: Bruce D'Arcus @ 2022-04-04  0:55 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode-email

On Sun, Apr 3, 2022 at 7:46 PM John Kitchin <jkitchin@andrew.cmu.edu> wrote:
...

> When I put my cursor on the org-cite line and press spc, I see a message box pop up, and the @key has a tooltip of "BARE LINK".

....

> Does anyone else see this?

Yes; I see the same thing with your example.

Bruce


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overlap between cite syntax and link activation
  2022-04-04  0:55 ` Bruce D'Arcus
@ 2022-04-22 12:47   ` Bruce D'Arcus
  2022-04-22 17:10     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Bruce D'Arcus @ 2022-04-22 12:47 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode-email

Nicolas (or Ihor?) - can you take a look at this too?

It's the second of the two stoppers that John identified.

He seems to have reported a related issue last August, but it slipped
through the cracks.

https://lists.gnu.org/archive/html/emacs-orgmode/2021-08/msg00303.html


On Sun, Apr 3, 2022 at 8:55 PM Bruce D'Arcus <bdarcus@gmail.com> wrote:
>
> On Sun, Apr 3, 2022 at 7:46 PM John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> ...
>
> > When I put my cursor on the org-cite line and press spc, I see a message box pop up, and the @key has a tooltip of "BARE LINK".
>
> ....
>
> > Does anyone else see this?
>
> Yes; I see the same thing with your example.
>
> Bruce


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overlap between cite syntax and link activation
  2022-04-22 12:47   ` Bruce D'Arcus
@ 2022-04-22 17:10     ` Nicolas Goaziou
  2022-04-24  7:19       ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2022-04-22 17:10 UTC (permalink / raw)
  To: Bruce D'Arcus; +Cc: org-mode-email, John Kitchin

Hello,

"Bruce D'Arcus" <bdarcus@gmail.com> writes:

> Nicolas (or Ihor?) - can you take a look at this too?
>
> It's the second of the two stoppers that John identified.
>
> He seems to have reported a related issue last August, but it slipped
> through the cracks.
>
> https://lists.gnu.org/archive/html/emacs-orgmode/2021-08/msg00303.html

One short-term solution would be to use the same function to fontify
links and cites. I.e., "org.el" could define
`org-activate-cites-and-links', which in turn, would dispatch work to
either `org-activate-links' or `org-cite-activate'.

A long-term solution would be to apply fontification on top of parsed
data exclusively. IIRC, I think Ihor started to work on something like
this, but I don't know about the current state of that project.

Regards,
-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overlap between cite syntax and link activation
  2022-04-22 17:10     ` Nicolas Goaziou
@ 2022-04-24  7:19       ` Ihor Radchenko
  2022-04-24  9:03         ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2022-04-24  7:19 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode-email, Bruce D'Arcus, John Kitchin

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

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

>> It's the second of the two stoppers that John identified.
>>
>> He seems to have reported a related issue last August, but it slipped
>> through the cracks.
>>
>> https://lists.gnu.org/archive/html/emacs-orgmode/2021-08/msg00303.html

> A long-term solution would be to apply fontification on top of parsed
> data exclusively. IIRC, I think Ihor started to work on something like
> this, but I don't know about the current state of that project.

Yeah, but I afraid that I will have to implement object-level caching to
get sustainable performance. Currently, I got something semi-working in
https://github.com/yantar92/org/tree/feature/org-font-lock-element, but
it still chocks on large paragraphs with a lot of emphasis objects.

> One short-term solution would be to use the same function to fontify
> links and cites. I.e., "org.el" could define
> `org-activate-cites-and-links', which in turn, would dispatch work to
> either `org-activate-links' or `org-cite-activate'.

A quick temporary fix could be like the attached. Or checking
(org-element-context) instead of direct call to citation parser.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-cite-activate-Temporary-fix-to-not-fontify-links.patch --]
[-- Type: text/x-patch, Size: 1201 bytes --]

From 033677f02141f498ca3e1a84e85bb4c9a6d189c9 Mon Sep 17 00:00:00 2001
Message-Id: <033677f02141f498ca3e1a84e85bb4c9a6d189c9.1650784539.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sun, 24 Apr 2022 15:14:26 +0800
Subject: [PATCH] org-cite-activate: Temporary fix to not fontify links as
 citations

* lisp/oc.el (org-cite-activate): Use heuristics to check previous
char to determine if current match is not citation, but link.
---
 lisp/oc.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/oc.el b/lisp/oc.el
index 360f1fadc..147bda368 100644
--- a/lisp/oc.el
+++ b/lisp/oc.el
@@ -1214,7 +1214,9 @@ (defun org-cite-activate (limit)
               #'org-cite-fontify-default)))
     (when (re-search-forward org-element-citation-prefix-re limit t)
       (let ((cite (org-with-point-at (match-beginning 0)
-                    (org-element-citation-parser))))
+                    (and (or (bolp)
+                             (not (eq ?\[ (char-before))))
+                         (org-element-citation-parser)))))
         (when cite
           (funcall activate cite)
           ;; Move after cite object and make sure to return
-- 
2.35.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overlap between cite syntax and link activation
  2022-04-24  7:19       ` Ihor Radchenko
@ 2022-04-24  9:03         ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2022-04-24  9:03 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Bruce D'Arcus, org-mode-email, John Kitchin

Hello,

Ihor Radchenko <yantar92@gmail.com> writes:

> A quick temporary fix could be like the attached.

I don't think this is sufficient. As demonstrated by John Kitchin in its
message from April 4, plain link with type "bare"

  bare:@key

matches

  [cite/noauthor/bare:@key]

> Or checking (org-element-context) instead of direct call to citation
> parser.

This is morally equivalent to use the parser for fontification, which is
the long-term solution exposed before.

Regards,
-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-24  9:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 23:44 overlap between cite syntax and link activation John Kitchin
2022-04-04  0:55 ` Bruce D'Arcus
2022-04-22 12:47   ` Bruce D'Arcus
2022-04-22 17:10     ` Nicolas Goaziou
2022-04-24  7:19       ` Ihor Radchenko
2022-04-24  9:03         ` Nicolas Goaziou

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).