help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: [External] : forward-sexp


From: Drew Adams
Subject: RE: [External] : forward-sexp
Date: Fri, 11 Aug 2023 20:01:06 +0000

> > The syntactic definition of "sexp" depends on the context, e.g., the
> > current major mode. Without knowing how a "sexp" is defined in your
> > context, we can't help much. That said, trying it in a Lisp mode tells
> > me that an error is raised when I try it at the beginning of the
> > second line, because: Debugger entered--Lisp error: (scan-error
> > "Unbalanced parentheses" 450 459) scan-sexps(450 1) forward-sexp(1)
> > funcall-interactively(forward-sexp 1) call-interactively(forward-sexp
> > nil nil) command-execute(forward-sexp) IOW, the `(' char isn't
> > balanced with a `)' char, so parsing to the end of the `[' sexp isn't
> > possible.
> 
> let assume fundamental mode, cursor at opening bracket: what puzzles me,
> 
> with [ asdf ] it recognizes the opening bracket.
> 
> In such a case, it should not look inside, just travel onto the closing one.
> 
> But with [(&asdf] it fails.

As I said, it all depends on how `forward-sexp' is defined in the current mode, 
which essentially means it depends on what constitutes a sexp.

With point before the second [ or after the first ], `forward-sexp' raises the 
error (user-error "No next sexp"):

Debugger entered--Lisp error: (user-error "No next sexp")
  user-error("No next sexp")
  forward-sexp(1 10)
  funcall-interactively(forward-sexp 1 10)
  command-execute(forward-sexp)

The code defining `forward-sexp' has this, for interactive use:

(condition-case _
    (forward-sexp arg nil)
  (scan-error (user-error (if (> arg 0)
                              "No next sexp"
                            "No previous sexp"))))

The Elisp manual, node `Motion Via Parsing', says this about `scan-error':

 If the scan reaches the beginning or end of the accessible part of
 the buffer before it has scanned over COUNT parenthetical
 groupings, the return value is ‘nil’ if the depth at that point is
 zero; if the depth is non-zero, a ‘scan-error’ error is signaled.

So it seems that the `(' starts a "parenthetical grouping", which has no end.

IOW, even `fundamental-mode' recognizes parentheses as paired delimiters.

reply via email to

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