% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ts-tree-delete.R
\name{ts_tree_delete}
\alias{ts_tree_delete}
\title{Delete selected elements from a tree-sitter tree}
\usage{
ts_tree_delete(tree, ...)
}
\arguments{
\item{tree}{A \code{ts_tree} object.}

\item{...}{Extra arguments for methods.}
}
\value{
The modified \code{ts_tree} object with the selected elements removed.
}
\description{
Use \code{\link[tsitter:ts_tree_select]{ts_tree_select()}} to select the
elements to be deleted, and then call \code{ts_tree_delete()} to remove them
from the tree.
}
\details{
The formatting of the rest of the document is left as is.

If the tree does not have a selection, the tree corresponding to the
empty document is returned, i.e. the whole content is deleted.

If the tree has a selection, but it is the empty selection, then
the tree is returned unchanged.

For parsers that support comments, deleting elements that include
comments typically delete the comments as well. Other comments are
kept as is. 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\": //comment\ntrue, \"b\": [1, 2, 3] }"
)

tree

ts_tree_select(tree, "a")

ts_tree_delete(ts_tree_select(tree, "a"))
\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_select(tree, "servers", TRUE, "dc")
ts_tree_delete(ts_tree_select(tree, "servers", TRUE, "dc"))
\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_dom]{ts_tree_dom()}},
\code{\link[=ts_tree_format]{ts_tree_format()}},
\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}
