emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* inconsistency links and code line labels
@ 2023-07-06 12:49 Dan Drake
  2023-07-07  5:57 ` gerard.vermeulen
  2023-07-07  9:48 ` Ihor Radchenko
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Drake @ 2023-07-06 12:49 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello -- I'm wondering about my question from here:

https://emacs.stackexchange.com/questions/77768/why-the-inconsistency-with-org-mode-code-line-labels-and-links

Copying my question: in a source code special block, I can add code line
labels, which have ref: in the label -- but when I make a link there, I
have to omit the ref:. For example:

#+begin_src csharp
1044 string foo = someFunction(1234);
1045 if (foo == "1")
1046 {
1047     bar = 5; //  (ref:my-code-line-label)
1048 }
// etc etc
#+end_src

There's a bug [[(my-code-line-label)][right here]].

This seems inconsistent. Why do I have to omit the ref: bit? This always
confuses me; it seems like it would be simpler to just make the label and
the links to that line of code be exactly the same. I don't see any
particular reference to this in the org manual (
https://orgmode.org/manual/Internal-Links.html). Any insights?

My idea would be to get rid of the special behavior for code line labels
and just make this work with dedicated targets: in regular parts of my org
file, I use <<link-target>> and can make links to that. It would be simple
and consistent to make that also work the same when <<link-target>> is
inside a code block.

Thanks!

-- 
Ceci n'est pas une .signature.

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

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

* Re: inconsistency links and code line labels
  2023-07-06 12:49 inconsistency links and code line labels Dan Drake
@ 2023-07-07  5:57 ` gerard.vermeulen
  2023-07-07  9:48 ` Ihor Radchenko
  1 sibling, 0 replies; 4+ messages in thread
From: gerard.vermeulen @ 2023-07-07  5:57 UTC (permalink / raw)
  To: Dan Drake
  Cc: emacs-orgmode, emacs-orgmode-bounces+gerard.vermeulen=posteo.net



On 06.07.2023 14:49, Dan Drake wrote:
> 
> There's a bug [[(my-code-line-label)][right here]].
> 
> This seems inconsistent. Why do I have to omit the ref: bit? This
> always confuses me; it seems like it would be simpler to just make the
> label and the links to that line of code be exactly the same. I don't
> see any particular reference to this in the org manual
> (https://orgmode.org/manual/Internal-Links.html [2]). Any insights?
> 
> My idea would be to get rid of the special behavior for code line
> labels and just make this work with dedicated targets: in regular
> parts of my org file, I use <<link-target>> and can make links to
> that. It would be simple and consistent to make that also work the
> same when <<link-target>> is inside a code block.
> 
Such link targets would conflict with <<code-block-id>> references
See: https://orgmode.org/manual/Noweb-Reference-Syntax.html

Therefore something like the behavior described in
https://orgmode.org/manual/Literal-Examples.html
must have been invented (look at the description of the -n, -r, and
-l switches).

Regards -- Gerard


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

* Re: inconsistency links and code line labels
  2023-07-06 12:49 inconsistency links and code line labels Dan Drake
  2023-07-07  5:57 ` gerard.vermeulen
@ 2023-07-07  9:48 ` Ihor Radchenko
  2023-07-08 22:24   ` Dan Drake
  1 sibling, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2023-07-07  9:48 UTC (permalink / raw)
  To: Dan Drake; +Cc: emacs-orgmode

Dan Drake <dan.drake@gmail.com> writes:

> Hello -- I'm wondering about my question from here:
>
> https://emacs.stackexchange.com/questions/77768/why-the-inconsistency-with-org-mode-code-line-labels-and-links
>
> Copying my question: in a source code special block, I can add code line
> labels, which have ref: in the label -- but when I make a link there, I
> have to omit the ref:. For example:
> ...
> 1047     bar = 5; //  (ref:my-code-line-label)
> ...
> There's a bug [[(my-code-line-label)][right here]].
>
> This seems inconsistent. Why do I have to omit the ref: bit? This always
> confuses me; it seems like it would be simpler to just make the label and
> the links to that line of code be exactly the same. I don't see any
> particular reference to this in the org manual (
> https://orgmode.org/manual/Internal-Links.html). Any insights?

The way coderefs appear in the code are completely configurable using
org-coderef-label-format ("(ref:%s)" by default) and using -l src code
switch.

> My idea would be to get rid of the special behavior for code line labels
> and just make this work with dedicated targets: in regular parts of my org
> file, I use <<link-target>> and can make links to that. It would be simple
> and consistent to make that also work the same when <<link-target>> is
> inside a code block.

If you examine 12.6 Literal Examples section of Org manual, you will see
that coderef links are exported specially:

       In literal examples, Org interprets strings like ‘(ref:name)’ as
    labels, and use them as targets for special hyperlinks like
    ‘[[(name)]]’—i.e., the reference name enclosed in single parenthesis.
    In HTML, hovering the mouse over such a link remote-highlights the
    corresponding code line, which is kind of cool.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: inconsistency links and code line labels
  2023-07-07  9:48 ` Ihor Radchenko
@ 2023-07-08 22:24   ` Dan Drake
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Drake @ 2023-07-08 22:24 UTC (permalink / raw)
  To: emacs-orgmode

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

I should have mentioned that I'm not exporting any of this. I only use org
by itself; I never export things to other formats. So the link behavior
that I need is for making and following links inside org/emacs; noweb and
other things aren't important.

The (ahem) link to the org-coderef-label-format is what I was looking for:
I set that to just (%s) and now something like the above example works
without adding the "ref:" bit. I'll update the emacs.sx post.

Thanks!



On Fri, Jul 7, 2023 at 4:48 AM Ihor Radchenko <yantar92@posteo.net> wrote:

> Dan Drake <dan.drake@gmail.com> writes:
>
> > Hello -- I'm wondering about my question from here:
> >
> >
> https://emacs.stackexchange.com/questions/77768/why-the-inconsistency-with-org-mode-code-line-labels-and-links
> >
> > Copying my question: in a source code special block, I can add code line
> > labels, which have ref: in the label -- but when I make a link there, I
> > have to omit the ref:. For example:
> > ...
> > 1047     bar = 5; //  (ref:my-code-line-label)
> > ...
> > There's a bug [[(my-code-line-label)][right here]].
> >
> > This seems inconsistent. Why do I have to omit the ref: bit? This always
> > confuses me; it seems like it would be simpler to just make the label and
> > the links to that line of code be exactly the same. I don't see any
> > particular reference to this in the org manual (
> > https://orgmode.org/manual/Internal-Links.html). Any insights?
>
> The way coderefs appear in the code are completely configurable using
> org-coderef-label-format ("(ref:%s)" by default) and using -l src code
> switch.
>
> > My idea would be to get rid of the special behavior for code line labels
> > and just make this work with dedicated targets: in regular parts of my
> org
> > file, I use <<link-target>> and can make links to that. It would be
> simple
> > and consistent to make that also work the same when <<link-target>> is
> > inside a code block.
>
> If you examine 12.6 Literal Examples section of Org manual, you will see
> that coderef links are exported specially:
>
>        In literal examples, Org interprets strings like ‘(ref:name)’ as
>     labels, and use them as targets for special hyperlinks like
>     ‘[[(name)]]’—i.e., the reference name enclosed in single parenthesis.
>     In HTML, hovering the mouse over such a link remote-highlights the
>     corresponding code line, which is kind of cool.
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
>


-- 
Ceci n'est pas une .signature.

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

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

end of thread, other threads:[~2023-07-08 22:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 12:49 inconsistency links and code line labels Dan Drake
2023-07-07  5:57 ` gerard.vermeulen
2023-07-07  9:48 ` Ihor Radchenko
2023-07-08 22:24   ` Dan Drake

Code repositories for project(s) associated with this public 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).