Bastien <[email protected]> writes:
> Hi Aaron and Tod,
>
> Aaron Ecay <[email protected]> writes:
>
>> This seems like an excellent use case for the parser: basically a bunch
>> of uses of org-*-regexp and org-re-property need to be augmented with
>> a check like:
>> (not (memq (org-element-type (org-element-at-point)) '(src-block
>> example-block ...)))
>>
>> A better alternative might be to use the parser to find the property
>> drawer in the first place (instead of a regex). Either way, it seems
>> like the best strategy might be to fix all uses of these problem
>> variables at once, which is a big undertaking.
>
> Also don't forget the cost in terms of speed. It's fine to fix the
> behavior of Org for such cases, but those cases are rare, and could
> be explicitely prevented. If the general fix does not slow down the
> parsing too much, then I'm all for it. Nicolas might have better
> insight here than me.
With newly introduced parser cache, the cost is amortized when using
`org-element-at-point' and `org-element-context'. With a little care,
the overhead is negligible. Therefore, these functions should be used
whenever possible.
I'm slowly working on introducing these functions in basic parts of Org
(e.g. fontification, indentation). Then I will target other functions
not using them yet. There's a lot to do. Help is welcome. IMO, at the
bare minimum, new or rewritten functions should use them.
For example, a way to correctly find the property drawer associated to
the current section is to use something like the following:
(save-excursion
(outline-previous-heading)
(unless (bobp)
(let ((limit (save-excursion (outline-next-heading) (point))))
(catch 'exit
(while (re-search-forward org-property-start-re limit t)
(let ((drawer (org-element-at-point)))
(when (eq (org-element-type drawer) 'property-drawer)
...
(throw 'exit ...))))))))
Regards,
--
Nicolas Goaziou