From cc33c6cf3a4868ab8cd3cc52679985026a42d176 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 22 Aug 2022 12:48:37 +0200 Subject: [PATCH] Make start/end in libxml-parse-html-region optional * doc/lispref/text.texi (Parsing HTML/XML): Adjust. * src/xml.c (parse_region): Default start/end to point-min/point-max. (Flibxml_parse_html_region, Flibxml_parse_xml_region): Make start/end optional. --- doc/lispref/text.texi | 7 +++++-- src/xml.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index c2161b9341d..8b859042ad0 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -5473,12 +5473,15 @@ available in this Emacs session. When libxml2 support is available, the following functions can be used to parse HTML or XML text into Lisp object trees. -@defun libxml-parse-html-region start end &optional base-url discard-comments +@defun libxml-parse-html-region &optional start end base-url discard-comments This function parses the text between @var{start} and @var{end} as HTML, and returns a list representing the HTML @dfn{parse tree}. It attempts to handle real-world HTML by robustly coping with syntax mistakes. +If @var{start} or @var{end} are @code{nil}, they default to the values +from @code{point-min} and @code{point-max}, respectively. + The optional argument @var{base-url}, if non-@code{nil}, should be a string specifying the base URL for relative URLs occurring in links. @@ -5524,7 +5527,7 @@ buffer. The argument @var{dom} should be a list as generated by @end defun @cindex parsing xml -@defun libxml-parse-xml-region start end &optional base-url discard-comments +@defun libxml-parse-xml-region &optional start end base-url discard-comments This function is the same as @code{libxml-parse-html-region}, except that it parses the text as XML rather than HTML (so it is stricter about syntax). diff --git a/src/xml.c b/src/xml.c index 522efd224c6..2cccff12331 100644 --- a/src/xml.c +++ b/src/xml.c @@ -186,6 +186,12 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, xmlCheckVersion (LIBXML_VERSION); + if (NILP (start)) + start = Fpoint_min (); + + if (NILP (end)) + end = Fpoint_max (); + validate_region (&start, &end); istart = XFIXNUM (start); @@ -269,8 +275,11 @@ xml_cleanup_parser (void) DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region, Slibxml_parse_html_region, - 2, 4, 0, + 0, 4, 0, doc: /* Parse the region as an HTML document and return the parse tree. +If START is nil, it defaults to `point-min'. If END is nil, it +defaults to `point-max'. + If BASE-URL is non-nil, it is used to expand relative URLs. If you want comments to be stripped, use the `xml-remove-comments' @@ -284,8 +293,11 @@ function to strip comments before calling this function. */) DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region, Slibxml_parse_xml_region, - 2, 4, 0, + 0, 4, 0, doc: /* Parse the region as an XML document and return the parse tree. +If START is nil, it defaults to `point-min'. If END is nil, it +defaults to `point-max'. + If BASE-URL is non-nil, it is used to expand relative URLs. If you want comments to be stripped, use the `xml-remove-comments' -- 2.39.2