Alice Liquori <[email protected]> writes:

> Falling back to muscle memory, I evaluated an expression again - which
> contained the function invocation `(org-back-to-heading t)`. This threw
> an error; which should (at least) be specific and indicative of the
> inappropriate buffer type.
>
> For instance, by somehow inserting a check resembling this, or advising
> functions as shown:
>
> #+begin_src elisp
> (when org-src-mode
>   (user-error
>     "Inappropriate invocation at %d in illiterate org-src-mode buffer %s"
>     (point)
>     (current-buffer)))
> #+end_src

I do not think that it is a good idea.
As you might expect, Org mode functions (unless explicitly indicated
otherwise), are expected to be called inside Org buffer. This means that
they have certain expectations about buffer-local variables and the
surrounding text. Checking whether we are really in Org buffer in every
single Org function would make no sense. The same logic applies to any
other major mode, not just org-mode.

> Alternatively, I think that the ideal behavior in this scenario (that is
> - evaluating org-element functions while point is active inside an
> OrgSrc buffer which maps to a location in an existing file and sub-tree)
> would be to evaluate them as if the point was actually at the
> corresponding point in the buffer which the `org-src` buffer point
> refers to. There is a convenient form for this, `org-src-do-at-code-block`.

org-element functions are generally used to check context around
point. If they return some other context unexpectedly, their users will
simply receive inaccurate information, leading to further unexpected
breakage.

There is no bug in what you reported.
Canceled.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
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>

Reply via email to