Subject: bug#32823: 26.1; nxml-mode: "no matching start-tag" with long entity definition list

From: [email-masked], "Bunkus <moritz"@bunkus.org
Date: Mon, 24 Sep 2018 14:50:29 +0200

Hey,

I'm using Emacs to write DocBook XML documents that will be turned into
man pages later. In said XML documents I often define entities used
later in the file. As soon as the that list gets too long (~5
definitions), nxml-mode fails to parse the following structure properly
and fails to close open start tags with the error message "No matching
start-tag".

Note that nxml-mode always states that the document is valid, even
though it fails to find an open start tag (I'm storing DocBook relaxng
schemas in ~/.xml/schemas/relaxng/docbook/4.5/…, but the same is true
when the schemas from /usr/share/emacs/26.1/etc/schema/… are used).

How to reproduce:

1. Save the XML code below into a file.
2. Start emacs -Q
3. Open the test file.
4. Place the cursor at the end of the line starting with "<refentry…".
5. Try using the "nxml-finish-element" function, e.g. C-c C-f. It will
   show the aforementioned error message instead of inserting "</refentry>".
6. Now shorten the entity definition list, e.g. by removing the whole
   line defining "ent5". Execute "normal-mode" to let nxml-mode parse the
   buffer again. Re-run the test from step 5. It will now insert
   "</refentry>" properly.

---[ test file content start ]-----------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
[
<!ENTITY &product; "myprog">
<!ENTITY ent2 "moretext">
<!ENTITY ent3 "evenmoretext">

<!ENTITY ent4 "<citerefentry><refentrytitle>anotherprogram</refentrytitle><manvolnum>1</manvolnum></citerefentry>">
<!ENTITY ent5 "<citerefentry><refentrytitle>onemoreprogram</refentrytitle><manvolnum>1</manvolnum></citerefentry>">
]

<refentry lang="en">
 <refentryinfo>
  <productname>&product;</productname>
 </refentryinfo>

 <refmeta>
  <refentrytitle>&product;</refentrytitle>
 </refmeta>

 <refnamediv>
  <refname>&product;</refname>
  <refpurpose>doing things</refpurpose>
 </refnamediv>

 <refsect1>
  <title>Test</title>
  <para>here</para>
 </refsect1>
</refentry>
---[ test file content end ]-----------------------------------------------------

Kind regards
mosu

In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
 of 2018-07-05 built on juergen
Windowing system distributor 'The X.Org Foundation', version 11.0.12001000
Recent messages:
Saving file /home/mbunkus/tmp/nxml-test.xml...
Wrote /home/mbunkus/tmp/nxml-test.xml
Using schema ~/.xml/schemas/relaxng/docbook/4.5/docbook.rnc
nxml-finish-element-1: No matching start-tag
Saving file /home/mbunkus/tmp/nxml-test.xml...
Wrote /home/mbunkus/tmp/nxml-test.xml
Using schema ~/.xml/schemas/relaxng/docbook/4.5/docbook.rnc
Undo! [2 times]
Saving file /home/mbunkus/tmp/nxml-test.xml...
Wrote /home/mbunkus/tmp/nxml-test.xml

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-modules 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'