emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Why is there no inline-src syntax highlighting?
@ 2021-03-14 10:19 Timothy
  2021-03-14 15:00 ` Eric S Fraga
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Timothy @ 2021-03-14 10:19 UTC (permalink / raw)
  To: org-mode-email

Hi all,

It's great how #+begin_src blocks support 'native' syntax highlighting,
but inline src_lang{} blocks don't seem to be formatted/highlighted at
all.

I'm wondering why this is. Might anyone know?

Also, if this is just a case of no-one bothering to provide that
functionality would there be any interest in me submitting
https://tecosaur.github.io/emacs-config/config.html#fontifying-inline-src
as a patch? (see https://0x0.st/-ZRa.png for a preview, this also
includes prettifying {{{results()}}}, which I'm quite a fan of).

--
Timothy.


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-14 10:19 Why is there no inline-src syntax highlighting? Timothy
@ 2021-03-14 15:00 ` Eric S Fraga
  2021-03-14 18:18   ` Colin Baxter
  2021-03-14 18:29   ` Timothy
  2021-03-15  6:07 ` Andreas Leha
  2021-03-29 13:01 ` Timothy
  2 siblings, 2 replies; 11+ messages in thread
From: Eric S Fraga @ 2021-03-14 15:00 UTC (permalink / raw)
  To: Timothy; +Cc: org-mode-email

On Sunday, 14 Mar 2021 at 18:19, Timothy wrote:
> It's great how #+begin_src blocks support 'native' syntax highlighting,
> but inline src_lang{} blocks don't seem to be formatted/highlighted at
> all.
>
> I'm wondering why this is. Might anyone know?

Possibly because nobody had done it before?  Or maybe it slows things
down too much.  I don't know but I would definitely be interested in
having this feature; your screenshot looks good.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4.4-254-g37749c


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-14 15:00 ` Eric S Fraga
@ 2021-03-14 18:18   ` Colin Baxter
  2021-03-14 18:27     ` Timothy
  2021-03-14 18:29   ` Timothy
  1 sibling, 1 reply; 11+ messages in thread
From: Colin Baxter @ 2021-03-14 18:18 UTC (permalink / raw)
  To: Timothy; +Cc: , org-mode-email

>>>>> Eric S Fraga <e.fraga@ucl.ac.uk> writes:

    > On Sunday, 14 Mar 2021 at 18:19, Timothy wrote:
    >> It's great how #+begin_src blocks support 'native' syntax
    >> highlighting, but inline src_lang{} blocks don't seem to be
    >> formatted/highlighted at all.
    >> 
    >> I'm wondering why this is. Might anyone know?

    > Possibly because nobody had done it before?  Or maybe it slows
    > things down too much.  I don't know but I would definitely be
    > interested in having this feature; your screenshot looks good.

    > -- : Eric S Fraga via Emacs 28.0.50, Org release_9.4.4-254-g37749c

There is this: https://stackoverflow.com/questions/20309842/how-to-syntax-highlight-for-org-mode-inline-source-code-src-lang

Best wishes,

Colin Baxter.


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-14 18:18   ` Colin Baxter
@ 2021-03-14 18:27     ` Timothy
  2021-03-14 18:36       ` Colin Baxter
  0 siblings, 1 reply; 11+ messages in thread
From: Timothy @ 2021-03-14 18:27 UTC (permalink / raw)
  To: Colin Baxter; +Cc: emacs-orgmode


Colin Baxter writes:

> There is this: https://stackoverflow.com/questions/20309842/how-to-syntax-highlight-for-org-mode-inline-source-code-src-lang

I take it you didn't look at the pages I linked? I explicitly link that
page myself and complain that it isn't good enough 😂.

Oh, and FWIW in my limited testing using native highlighting hasn't had
any noticeable adverse effect on performance.

--
Timothy


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-14 15:00 ` Eric S Fraga
  2021-03-14 18:18   ` Colin Baxter
@ 2021-03-14 18:29   ` Timothy
  1 sibling, 0 replies; 11+ messages in thread
From: Timothy @ 2021-03-14 18:29 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: org-mode-email


Eric S Fraga <e.fraga@ucl.ac.uk> writes:

>> I'm wondering why this is. Might anyone know?
>
> Possibly because nobody had done it before?  Or maybe it slows things
> down too much.  I don't know but I would definitely be interested in
> having this feature; your screenshot looks good.

I may well submit a patch them :) Org doesn't seem any slower to me, and
it's not really doing much more that we're doing already AFAICT so I
think it would be good to include.

If I submit a patch will we be waiting till Bastien is active on the ML
again? If so I'll likely just PR this to Doom in the meantime and submit
a patch when Bastien is back.

--
Timothy


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-14 18:27     ` Timothy
@ 2021-03-14 18:36       ` Colin Baxter
  0 siblings, 0 replies; 11+ messages in thread
From: Colin Baxter @ 2021-03-14 18:36 UTC (permalink / raw)
  To: Timothy; +Cc: , emacs-orgmode

>>>>> Timothy  <tecosaur@gmail.com> writes:

    > Colin Baxter writes:

    >> There is this:
    >> https://stackoverflow.com/questions/20309842/how-to-syntax-highlight-for-org-mode-inline-source-code-src-lang

    > I take it you didn't look at the pages I linked? I explicitly link
    > that page myself and complain that it isn't good enough 😂.

You're right, I didn't.


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-14 10:19 Why is there no inline-src syntax highlighting? Timothy
  2021-03-14 15:00 ` Eric S Fraga
@ 2021-03-15  6:07 ` Andreas Leha
  2021-03-29 13:01 ` Timothy
  2 siblings, 0 replies; 11+ messages in thread
From: Andreas Leha @ 2021-03-15  6:07 UTC (permalink / raw)
  To: emacs-orgmode

Timothy <tecosaur@gmail.com> writes:

> Hi all,
>
> It's great how #+begin_src blocks support 'native' syntax highlighting,
> but inline src_lang{} blocks don't seem to be formatted/highlighted at
> all.
>
> I'm wondering why this is. Might anyone know?
>
> Also, if this is just a case of no-one bothering to provide that
> functionality would there be any interest in me submitting
> https://tecosaur.github.io/emacs-config/config.html#fontifying-inline-src
> as a patch? (see https://0x0.st/-ZRa.png for a preview, this also
> includes prettifying {{{results()}}}, which I'm quite a fan of).


It seems to work great here.

Best,
Andreas



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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-14 10:19 Why is there no inline-src syntax highlighting? Timothy
  2021-03-14 15:00 ` Eric S Fraga
  2021-03-15  6:07 ` Andreas Leha
@ 2021-03-29 13:01 ` Timothy
  2021-03-29 13:58   ` Sébastien Miquel
  2021-03-29 13:59   ` Ihor Radchenko
  2 siblings, 2 replies; 11+ messages in thread
From: Timothy @ 2021-03-29 13:01 UTC (permalink / raw)
  To: org-mode-email


Update: I've been using
https://tecosaur.github.io/emacs-config/config.html#fontifying-inline-src
for a while now and it seems to work out, there's just one thing I
haven't been able to work out --- how to have font-lock apply to
*multiple* inline src blocks on one line.

If anyone has any ideas, please let me know. Once I've got this sorted
I'll probably make a patch.

--
Timothy


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-29 13:01 ` Timothy
@ 2021-03-29 13:58   ` Sébastien Miquel
  2021-03-29 14:53     ` Timothy
  2021-03-29 13:59   ` Ihor Radchenko
  1 sibling, 1 reply; 11+ messages in thread
From: Sébastien Miquel @ 2021-03-29 13:58 UTC (permalink / raw)
  To: Timothy; +Cc: emacs-orgmode

Hi,

I don't use inline src blocks, but your work makes me want to start !

Timothy writes:
> there's just one thing I
> haven't been able to work out --- how to have font-lock apply to
> *multiple*  inline src blocks on one line.

With multiple inline src blocks that each have a result part,
fontification appears to work.

I think there are these two issues with the code :
  - When an inline src blocks has no matching result part,
    `org-fontify-inline-src-blocks-1` returns nil. It should return t
    instead, then it will be called again, to fontify the next block.
  - If an inline src block without results is followed by a src block
    with results, your function skips over the second src block.
    Perhaps you should assume that only whitespace separates a src
    block and its results (this is already assumed for subsequent
    evaluations of the block  to replace the results).

Regards,

-- 
Sébastien Miquel



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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-29 13:01 ` Timothy
  2021-03-29 13:58   ` Sébastien Miquel
@ 2021-03-29 13:59   ` Ihor Radchenko
  1 sibling, 0 replies; 11+ messages in thread
From: Ihor Radchenko @ 2021-03-29 13:59 UTC (permalink / raw)
  To: Timothy, org-mode-email

Timothy <tecosaur@gmail.com> writes:

> Update: I've been using
> https://tecosaur.github.io/emacs-config/config.html#fontifying-inline-src
> for a while now and it seems to work out, there's just one thing I
> haven't been able to work out --- how to have font-lock apply to
> *multiple* inline src blocks on one line.
>
> If anyone has any ideas, please let me know. Once I've got this sorted
> I'll probably make a patch.

I think you just need to replace `when' with `while' in the following line:

(when (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t)

Best,
Ihor


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

* Re: Why is there no inline-src syntax highlighting?
  2021-03-29 13:58   ` Sébastien Miquel
@ 2021-03-29 14:53     ` Timothy
  0 siblings, 0 replies; 11+ messages in thread
From: Timothy @ 2021-03-29 14:53 UTC (permalink / raw)
  To: sebastien.miquel; +Cc: emacs-orgmode


Thanks Sébastien and Ihor :) I've combined a bit of both of your
suggestions. See
https://github.com/tecosaur/emacs-config/commit/1afd9eaca.

Sébastien Miquel <sebastien.miquel@posteo.eu> writes:

> I think there are these two issues with the code :
>  - When an inline src blocks has no matching result part,
>    `org-fontify-inline-src-blocks-1` returns nil. It should return t
>    instead, then it will be called again, to fontify the next block.

TBH I'm not quite sure what should be done here the way I've structured
things, but following Ihor's suggestion and changing `when' to `while'
worked. I checked with highlight-refontification and it seems like this
doesn't result in spurious fortification (I guess "limit" is set well).

>  - If an inline src block without results is followed by a src block
>    with results, your function skips over the second src block.
>    Perhaps you should assume that only whitespace separates a src
>    block and its results (this is already assumed for subsequent
>    evaluations of the block  to replace the results).

Nice catch, thanks! I think I've got this handled much better now :)

If you have any further advice, please don't hesitate to share.

--
Timothy.


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

end of thread, other threads:[~2021-03-29 14:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-14 10:19 Why is there no inline-src syntax highlighting? Timothy
2021-03-14 15:00 ` Eric S Fraga
2021-03-14 18:18   ` Colin Baxter
2021-03-14 18:27     ` Timothy
2021-03-14 18:36       ` Colin Baxter
2021-03-14 18:29   ` Timothy
2021-03-15  6:07 ` Andreas Leha
2021-03-29 13:01 ` Timothy
2021-03-29 13:58   ` Sébastien Miquel
2021-03-29 14:53     ` Timothy
2021-03-29 13:59   ` Ihor Radchenko

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