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