% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ts-tree-format.R
\name{ts_tree_format}
\alias{ts_tree_format}
\title{Format the selected elements of a tree sitter tree for printing}
\usage{
ts_tree_format(tree, options, ...)
}
\arguments{
\item{tree}{A \code{ts_tree} object.}

\item{options}{A list of options for the formatting.

See details in the manual of the specific parser.}

\item{...}{Extra arguments for methods.}
}
\value{
A \code{ts_tree} object representing the reformatted document.
}
\description{
(Re)format the selected elements of the document represented by a
tree-sitter tree, if the tree-sitter parser supports formatting.
}
\details{
If \code{tree} does not have a selection, then the whole document is
formatted.

If \code{tree} has an empty selection, then it is returned unchanged.

Some parsers support options to customize the formatting.
See details in the manual of the specific parser.
}
\examples{
\dontshow{if (requireNamespace("tsjsonc", quietly = TRUE)) withAutoprint(\{ # examplesIf}
# Create a parse tree with tsjsonc -------------------------------------
tree <- tsjsonc::ts_parse_jsonc('{ "a":true, "b": [1,2,3] }')
tree

# Format whole document
ts_tree_format(tree)

# Format each top element under the document node in one line
ts_tree_format(
  ts_tree_select(ts_tree_format(tree), TRUE),
  options = list(format = "oneline")
)

\dontshow{\}) # examplesIf}
\dontshow{if (requireNamespace("tstoml", quietly = TRUE)) withAutoprint(\{ # examplesIf}
# Create a parse tree with tstoml --------------------------------------
tree <- tstoml::ts_parse_toml(r"(
  [servers]
  alpha = { ip = "127.0.0.1", dc = "eqdc10" }
  beta = { ip = "127.0.0.2", dc = "eqdc20" }
)")

tree

ts_tree_format(tree)
\dontshow{\}) # examplesIf}
}
\seealso{
Other ts_tree generics:
\code{\link[=[[.ts_tree]{[[.ts_tree()}},
\code{\link[=[[<-.ts_tree]{[[<-.ts_tree()}},
\code{\link[=format.ts_tree]{format.ts_tree()}},
\code{\link[=print.ts_tree]{print.ts_tree()}},
\code{\link{select-set}},
\code{\link[=ts_tree_ast]{ts_tree_ast()}},
\code{\link[=ts_tree_delete]{ts_tree_delete()}},
\code{\link[=ts_tree_dom]{ts_tree_dom()}},
\code{\link[=ts_tree_insert]{ts_tree_insert()}},
\code{\link[=ts_tree_new]{ts_tree_new()}},
\code{\link[=ts_tree_query]{ts_tree_query()}},
\code{\link[=ts_tree_select]{ts_tree_select()}},
\code{\link[=ts_tree_sexpr]{ts_tree_sexpr()}},
\code{\link[=ts_tree_unserialize]{ts_tree_unserialize()}},
\code{\link[=ts_tree_update]{ts_tree_update()}},
\code{\link[=ts_tree_write]{ts_tree_write()}}
}
\concept{ts_tree generics}
