Subject: Re: bug#73710: 30.0.91; skeleton-transformation-function sometimes unbound when sgml-xml-mode is t

From: Eli Zaretskii <[email-masked]>
Date: Sun, 13 Oct 2024 15:01:13 +0300

> From: Mike Kupfer <[email-masked]>
> Date: Tue, 08 Oct 2024 11:09:27 -0700
> 
> sgml-mode.el has an autoload for #'skeleton-read, which will pull in
> skeleton.el and define skeleton-transformation-function.  But it looks
> like there are code paths that don't trigger the autoload, so you can
> get "Symbol’s value as variable is void: skeleton-transformation-function".
> 
> Reproducer:
> 
> - save the attached test file to disk
> 
> - emacs -Q
> - M-: (setq sgml-xml-mode t) RET
> - visit the test file
> - move point to the "t" in "<table>"
> - C-c C-a

Thanks.

Does the patch below give good results?

diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index f126df8..ee58589 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -533,6 +533,7 @@ sgml-mode-facemenu-add-face-function
   "Add \"face\" tags with `facemenu-keymap' commands."
   (let ((tag-face (ensure-list (cdr (assq face sgml-face-tag-alist)))))
     (cond (tag-face
+           (require 'skeleton)
 	   (setq tag-face (funcall skeleton-transformation-function tag-face))
            (setq facemenu-end-add-face
                  (mapconcat (lambda (f) (concat "</" f ">")) (reverse tag-face)))
@@ -851,6 +852,7 @@ sgml-attributes
             (setq alist (cons '("class") alist)))
           (unless (assoc-string "id" alist)
             (setq alist (cons '("id") alist))))
+        (require 'skeleton)
 	(if (stringp (car alist))
 	    (progn
 	      (insert (if (eq (preceding-char) ?\s) "" ?\s)