Re: Failure to copy attributes when changing element type
Syd Bauman <[email protected]> Sat, 7 Feb 2004 07:30:54 -0500
| Newsgroups | gmane.emacs.psgml.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Peter. I believe I've already submitted this as a bug; maybe not.
In any case, here's our local fix. It is a function intended to be
bound to C-c = instead of the version of sgml-change-element-name
that is part of our psgml:
;; $Id: psgml-edit.el,v 2.65 2002/02/15 15:31:47 lenst Exp $
--------- begin replacement function definition ---------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Bug fix replacement of sgml-change-element-name
;;; by Tom Hinkle 2002-04-16.
;;; 2002-04-19 by Syd Bauman: improved comments and added autoload
;;;
(autoload 'sgml-translate-attribute-specification-list "psgml-edit"
"Translate attribute specification from one element type to another." nil nil)
(defun wwp-change-element-name (gi)
"Replace the name of the current element with a new name.
Eventual attributes of the current element will be translated if
possible."
(interactive
(list (let ((el (sgml-find-element-of (point))))
(goto-char (sgml-element-start el))
(sgml-read-element-name
(format "Change %s to: " (sgml-element-name el))))))
(when (or (null gi) (equal gi ""))
(error "Illegal name"))
(let* ((element (sgml-find-element-of (point)))
(attspec (sgml-element-attribute-specification-list element))
(oldattlist (sgml-element-attlist element))
;; bug fix 2002-04-16 by Tom Hinkle: define tagc here rather than
;; at end of function:
(tagc (if (and sgml-xml-p (sgml-element-empty element))
(sgml-delim "XML-TAGCE")
(sgml-delim "TAGC")))
;; bug fix 2002-04-16 by Tom Hinkle:
(tagc-len (length tagc))) ; length needed to move back into tag
(goto-char (sgml-element-end element))
(unless (sgml-element-empty element)
(delete-char (- (sgml-element-etag-len element))))
(insert (sgml-end-tag-of gi))
(goto-char (sgml-element-start element))
(delete-char (sgml-element-stag-len element))
(insert (sgml-delim "STAGO") ; open delimiter
(sgml-general-insert-case gi) ; GI itself
;; bug fix 2002-04-16 by Tom Hinkle:
tagc) ; end delimiter
(let* ((newel (sgml-find-context-of (point)))
(newattlist (sgml-element-attlist newel))
(newasl (sgml-translate-attribute-specification-list
attspec oldattlist newattlist)))
;; bug fix 2002-04-16 by Tom Hinkle:
;; Go to character before end tag delim before adding attributes
(backward-char tagc-len)
(sgml-insert-attributes newasl newattlist)
;; added 2002-04-16 by Tom Hinkle:
;; End up after the start tag.
(goto-char (sgml-element-stag-end newel)))))
--------- end replacement function definition ---------
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn