Function: neocaml--forward-sexp-hybrid

neocaml--forward-sexp-hybrid is a natively compiled function defined in neocaml.el.

Signature

(neocaml--forward-sexp-hybrid ARG)

Documentation

Hybrid forward-sexp-function combining tree-sitter and syntax table.

When point is on a delimiter character (paren, bracket, brace), fall back to syntax-table-based matching so that commands like delete-pair find the correct matching delimiter. Otherwise, use tree-sitter sexp navigation.

Used on every Emacs version: treesit-forward-sexp lacks the scan-sexps fallback and treesit-forward-sexp-list ignores the sexp thing, so neither built-in does both.

ARG is as in forward-sexp-function.

Source Code

;; Defined in /nix/store/ahssdx4rwzyxhyhavpn0bkznk13xrggi-emacs-packages-deps/share/emacs/site-lisp/elpa/neocaml-20260907.2015/neocaml.el
         (memq (syntax-class syntax) '(4 5)))))  ; 4=open, 5=close

(defun neocaml--forward-sexp-hybrid (arg)
  "Hybrid `forward-sexp-function' combining tree-sitter and syntax table.
When point is on a delimiter character (paren, bracket, brace),
fall back to syntax-table-based matching so that commands like
`delete-pair' find the correct matching delimiter.  Otherwise,
use tree-sitter sexp navigation.

Used on every Emacs version: `treesit-forward-sexp' lacks the
`scan-sexps' fallback and `treesit-forward-sexp-list' ignores the
`sexp' thing, so neither built-in does both.

ARG is as in `forward-sexp-function'."
  (let ((arg (or arg 1)))
    (if (or (neocaml--delimiter-p)
            ;; Moving backward: check if the character before point
            ;; (skipping whitespace) is a closing delimiter.
            (and (< arg 0)
                 (save-excursion
                   (skip-chars-backward " \t")
                   (not (bobp))
                   (let ((syntax (syntax-after (1- (point)))))
                     (and syntax (eq (syntax-class syntax) 5))))))
        ;; On a delimiter: use syntax-table paren matching.
        ;; `forward-sexp-default-function' wraps `scan-sexps' but is
        ;; only available from Emacs 30; fall back to raw `scan-sexps'
        ;; on Emacs 29.
        (if (fboundp 'forward-sexp-default-function)
            (forward-sexp-default-function arg)
          (goto-char (or (scan-sexps (point) arg) (buffer-end arg))))
      ;; Not on a delimiter: use tree-sitter node navigation.
      ;; `treesit-forward-sexp' is available from Emacs 30; on Emacs 29
      ;; fall back to the simpler `neocaml-forward-sexp'.
      (if (fboundp 'treesit-forward-sexp)
          (treesit-forward-sexp arg)
        (neocaml-forward-sexp arg)))))