Re: overlap between cite syntax and link activation

2022-04-24 Thread Nicolas Goaziou
Hello,

Ihor Radchenko  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



Re: overlap between cite syntax and link activation

2022-04-24 Thread Ihor Radchenko
Nicolas Goaziou  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

>From 033677f02141f498ca3e1a84e85bb4c9a6d189c9 Mon Sep 17 00:00:00 2001
Message-Id: <033677f02141f498ca3e1a84e85bb4c9a6d189c9.1650784539.git.yanta...@gmail.com>
From: Ihor Radchenko 
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



Re: overlap between cite syntax and link activation

2022-04-22 Thread Nicolas Goaziou
Hello,

"Bruce D'Arcus"  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



Re: overlap between cite syntax and link activation

2022-04-22 Thread Bruce D'Arcus
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  wrote:
>
> On Sun, Apr 3, 2022 at 7:46 PM John Kitchin  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



Re: overlap between cite syntax and link activation

2022-04-03 Thread Bruce D'Arcus
On Sun, Apr 3, 2022 at 7:46 PM John Kitchin  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



overlap between cite syntax and link activation

2022-04-03 Thread John Kitchin
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