Patch: sgml-tag-region indenting fix

"John D. Mitchell" <[email protected]>
Newsgroups gmane.emacs.psgml.user
Message-ID <[email protected]>
I'm using psgml-version 1.2.4 on GNU Emacs v20.7.1 and the sgml-tag-region
function has doesn't deal with the end tag very well.  It always inserts an
end tag even for empty elements and it doesn't indent the end tag
(correctly).

So, here's my fix for that stuff.

Along the way, I also updated sgml-end-tag-of to mirror sgml-start-tag-of
-- it now only returns a non-nil value iff the element isn't supposed to be
empty.  It returns nil rather than e.g. and empty string since that seemed
to be a clearer statement of intent.  Note clearly that I just stole the
conditional code from sgml-start-tag so if there's something tricky about
that checking that wasn't obvious then I apologize in advance.

Hope this helps,
		John
	

--- psgml-edit.el.orig	Wed Mar 13 18:29:39 2002
+++ psgml-edit.el	Wed Mar 13 18:42:02 2002
@@ -725,7 +725,8 @@
 	 (sgml-read-attribute-value attdecl (sgml-element-name element) nil))))
 
 (defun sgml-tag-region (element start end)
-  "Reads element name from minibuffer and inserts start and end tags."
+  "Reads element name from minibuffer and inserts start and end tags.
+The end tag is only inserted for non-empty elements."
   (interactive
    (list
     (save-excursion (goto-char (region-beginning))
@@ -734,10 +735,23 @@
     (region-end)))
   (save-excursion
     (when (and element (not (equal element "")))
-      (goto-char end)
-      (insert (sgml-end-tag-of element))
-      (goto-char start)
-      (sgml-insert-tag (sgml-start-tag-of element)))))
+      (let ((new-end (+ end (sgml-insert-and-indent-tag start element))))
+	(sgml-insert-and-indent-tag new-end element t)))))
+
+(defun sgml-insert-and-indent-tag (location element &optional end-tagp)
+  "Inserts a tag for the given element at the given location."
+  (interactive)
+  (let ((tag (if end-tagp
+		 (sgml-end-tag-of element)
+	       (sgml-start-tag-of element))))
+    (goto-char location)
+    (when tag
+      (let ((loc-BOL (bolp)))
+	(insert tag)
+	(when loc-BOL
+	  (sgml-indent-line)
+	  (insert "\n"))
+	(- (point) location)))))
 
 (defun sgml-insert-attributes (avl attlist)
   "Insert the attributes with values AVL and declarations ATTLIST.


--- psgml-parse.el.orig	Wed Mar 13 18:30:16 2002
+++ psgml-parse.el	Wed Mar 13 18:37:47 2002
@@ -4455,8 +4455,9 @@
     (format "<%s>" (sgml-general-insert-case (sgml-cohere-name element)))))
 
 (defun sgml-end-tag-of (element)
-  "Return the end-tag for ELEMENT (token or element)."
-  (format "</%s>" (sgml-general-insert-case (sgml-cohere-name element))))
+  "Return the end-tag for ELEMENT (token or element) or nil if there is no end tag for ELEMENT."
+  (if (and sgml-xml-p (not (sgml-check-empty (sgml-cohere-name element))))
+    (format "</%s>" (sgml-general-insert-case (sgml-cohere-name element)))))
 
 (defun sgml-top-element ()
   "Return the document element."

_______________________________________________
Psgml-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/psgml-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.