The documentation for mark-sexp says:

> Set mark ARG sexps from point.
> The place mark goes is the same place C-M-<right> would
> move to with the same argument.

This is correct but misleading. Worse still is the next part:

> Interactively, if this command is repeated
> or (in Transient Mark mode) if the mark is active,
> it marks the next ARG sexps after the ones already marked.

This says it marks sexps *after* the ones already marked. This is incorrect; if point is *after* mark, and mark is active, this function marks sexps *before* the ones already marked.

> In my opinion, the description of that feature should not be part of the
> mark-sexp command documentation, because the feature is actually
> provided by C-x C-x (exchange-point-and-mark).

One way for this situation to occur is by using C-x C-x, yes, but it's not the only way. You can set point, move forward sexps, and then calling mark-sexp will mark sexps backwards.

There is specific code in mark-sexp to check which direction to move; it should be documented as such.

On Tue, Apr 25, 2023 at 6:26 PM Daniel Martín <mardani29@yahoo.es> wrote:
Zachary Kanfer <zkanfer@gmail.com> writes:

>
> Also, whatever the outcome of this patch, I think it would be advisable to
> explain somewhere how mark-sexp extends region by the end of region
> opposite point; this is not in the docstring or any other documentation
> I've seen.
>

In my opinion, the description of that feature should not be part of the
mark-sexp command documentation, because the feature is actually
provided by C-x C-x (exchange-point-and-mark).  The Emacs manual in
section 12.1 Setting the Mark describes this use case well, I think:

‘C-x C-x’ is useful when you are
satisfied with the position of point but want to move the other end of
the region (where the mark is).