emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fontification for inline src blocks


From: Timothy
Subject: Re: [PATCH] Fontification for inline src blocks
Date: Mon, 22 Nov 2021 21:43:23 +0800
User-agent: mu4e 1.6.9; emacs 28.0.50

Hi Ihor,

> I have some comments. See below.

Thanks for going through this, and for all your help previously.
I appreciate it :)

>> (org-inline-src-fontify-max-length): Create a variable to limit the
>> maximum length of an inline-src block fontified, to protect from lag
>> spikes (e.g. when typing out src_lang{ and half of the buffer is
>> fontified).
>
> I do not like this. Even with this variable, some part of buffer may be
> spuriously fontified. Maybe you just verify that you are at actual
> inline-src block by examining org-element-context?

The description may need updating, as that’s a tad inaccurate. That value
actually limits how far forwards a paired paren is searched for. There’s no
spurious fontification.

>> +(defun org-fontify-inline-src-blocks (limit)
>> +  “Try to apply `org-fontify-inline-src-blocks-1’.”
>> +  (condition-case nil
>> +      (progn
>> +        (org-fontify-inline-src-blocks-1 limit)
>> +        (org-fontify-inline-src-results limit))
>
> org-fontify-inline-src-results is not defined in this patch.

Ah. Thanks for catching this!

>> +        (font-lock-append-text-property lang-beg lang-end ’face 
>> ’org-meta-line)
>> +        (font-lock-append-text-property beg lang-beg ’face ’shadow)
>> +        (font-lock-append-text-property beg lang-end ’face 
>> ’org-inline-src-block)
>
> Is there some special reason why you apply both ’shadow and
> ’org-inline-src-block? What about ’org-meta-line face? Maybe
> ’org-meta-line should not be hard-coded?

I think there’s an argument for more faces that can be made because of element
like this, but it comes down to the idea that in a `src_lang[options]{content}'
construct `src_' is effectively visual noise, particularly once fortification
occurs and it’s obvious that it’s inline code even without it. So, I find it
nicest if it’s faded, which `shadow' does. Also applying `org-inline-src-block'
allows for a consistent background colour across the whole construct.

>> +        (setq pt (goto-char lang-end))
>> +        ;; `org-element–parse-paired-brackets’ doesn’t take a limit, so to
>> +        ;; prevent it searching the entire rest of the buffer we temporarily
>> +        ;; narrow the active region.
>> +        (save-restriction
>> +          (narrow-to-region beg (min (point-max)
>> +                                     limit
>> +                                     (+ lang-end 
>> org-inline-src-fontify-max-length)))
>> +          (when (ignore-errors (org-element–parse-paired-brackets ?\[))
>> +            (font-lock-append-text-property pt (point) ’face 
>> ’org-inline-src-block)
>> +            (setq pt (point)))
>> +          (when (ignore-errors (org-element–parse-paired-brackets ?\{))
>
> It looks like you are repeating the job of org-element-context here. Why
> don’t you just get the proper object?

IIRC `org-element-context' doesn’t separate out the `src_', `lang', 
`[options]', and
`{content}' of an inline source code block (which we want).

>> +            (remove-text-properties pt (point) ’(face nil))
>> +            (font-lock-append-text-property pt (1+ pt) ’face ’(org-block 
>> shadow))
>
> Do you really intend to use ’org-block and ’shadow faces here? Not
> ’org-inline-src-block?

Ah, that was an oversight. Thanks for catching that, changed to
`(org-inline-src-block shadow)'.

>> +(defcustom org-inline-src-prettify-results t
>
> Looks like a stray defcustom. At least, it is not mentioned in the
> commit message and not used within the patch.

Removed.

> Best,
> Ihor

Thanks again! See an updated patch attached.

All the best,
Timothy

Attachment: 0001-org-src-Implement-native-inline-src-fontification.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]