Thanks, Arash. Agreed, on all counts. Revised patch attached. Best, David. On Thu, 16 May 2024 at 08:54, Arash Esbati wrote: > > David Fussner writes: > > > +(defun tex-expl-buffer-parse () > > + "Identify buffers where expl3 syntax is always active." > > + (save-excursion > > + (goto-char (point-min)) > > + (when (tex-search-noncomment > > + (re-search-forward > > + "\\(?:\\\\\\(?:ExplFile\\|ProvidesExpl\\|__xparse_file\\)\\)" > > Is the outer grouping necessary? Why not just: > > "\\\\\\(?:ExplFile\\|ProvidesExpl\\|__xparse_file\\)" > > > + nil t)) > > + (setq tex-expl-buffer-p t)))) > > + > > +(defun tex-expl-region-set (_beg _end) > > + "Create a list of regions where expl3 syntax is active. > > +This function updates the list whenever `syntax-propertize' runs, and > > +stores it in the buffer-local variable `tex-expl-region-list'. The > > +list will always be nil when the buffer visits an expl3 file, e.g., an > > +expl3 class or package, where expl3 syntax is always active." > > + (unless syntax-ppss--updated-cache;; Stop forward search running twice. > > + (setq tex-expl-region-list nil) > > + ;; Leaving this test here allows users to set `tex-expl-buffer-p' > > + ;; independently of the mode's automatic detection of an expl3 file. > > + (unless tex-expl-buffer-p > > + (goto-char (point-min)) > > + (while (tex-search-noncomment > > + (re-search-forward "\\ExplSyntaxOn" nil t)) > > This looks wrong, I think you want `search-forward'. > > > + (let ((new-beg (point)) > > + (new-end (or (tex-search-noncomment > > + (re-search-forward "\\ExplSyntaxOff" nil t)) > > Same here. > > > + (point-max)))) > > + (push (cons new-beg new-end) tex-expl-region-list)))))) > > Best, Arash