Commits

Anonymous committed d9fe822

Sync with upstream 1.3.1 <1042891591.4895.587.camel@bobcat.ods.org>.

Comments (0)

Files changed (17)

+2003-01-11  Ville Skyttä  <scop@xemacs.org>
+
+	* Sync with upstream 1.3.1, miscellaneous doc fixes.
+
+	* psgml-sysdep.el: New.
+	* ChangeLog.upstream: New.
+	* package-info.in (provides): Add psgml-sysdep.
+	* Makefile (AUTHOR_VERSION): Bump to 1.3.1.
+	(REQUIRES): Add ps-print.
+	(ELCS): Add psgml-sysdep.elc.
+	(EXTRA_SOURCES): Add ChangeLog.upstream.
+
 2003-01-13  Rendhalver [Peter Brown]  <rendhalver@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 1.37 released.

ChangeLog.upstream

+2002-12-13  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.3.1 released
+
+2002-09-19  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-parse-prolog): Check if sgml-dtd-info is
+	nil before trying to use it.
+
+2002-08-13  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-edit-attrib-abort): new command
+	(sgml-edit-attrib-mode-map): abort on key C-c C-k
+	(sgml-attribute-buffer): include abort key in header line and use
+	substitute-command-keys.
+	(sgml-edit-attributes): move setting mode to
+	sgml-attribute-buffer.
+
+	* psgml-parse.el (sgml-open-element): add optional net-enabled
+	parameter.
+	(sgml-do-start-tag): use new parameter on sgml-open-element.
+	Fixes bug with NET (tc17).
+	
+	* psgml-edit.el (sgml-edit-attrib-field-start,
+	sgml-edit-attrib-clear, sgml-attribute-buffer,
+	sgml-edit-attrib-specification-list): change sgml-category to
+	category. Fix bug with edit attributes.
+	(sgml-change-element-name): insert TAGC before finding new element
+	object. Fix bug with change element name not copying attributes.
+
+2002-05-08  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.3.0 released
+	
+	* psgml.el (sgml-default-nonsticky): moved from psgml-other.el
+
+2002-05-07  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-maint.el (psgml-common-files): add psgml-sysdep
+	(psgml-find-source-dir): fix version
+
+2002-04-26  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-mode): make adding to
+	text-property-default-nonsticky conditional on
+	sgml-default-nonsticky to work with Emacs < 21.
+	
+2002-04-25  Lennart Staflin  <lenst@lysator.liu.se>
+
+	fixing merge of Dave Love's patch.
+	
+2002-02-08  Dave Love  <fx@gnu.org>
+	[Merging from 1.2.4 branch /lenst]
+	
+	Changes for various things: Useful DTD-less XML editing; avoiding
+	CL at runtime; some Emacs portability; Mule-related fixes,
+	particularly for non-ASCII names in DTD.
+
+	* psgml-maint.el (psgml-find-source-dir): Fix version number.
+
+	* psgml-info.el (sgml-set-difference, sgml-union): New functions.
+	(sgml-eltype-refrenced-elements): Use them and also use
+	add-to-list instead of pushnew.
+
+	* psgml-dtd.el: Doc and message fixes.
+	(sgml-write-dtd): Use sgml-set-buffer-multibyte and bind
+	coding-system-for-write around write-region.
+	(sgml-merge-attlists): Use copy-sequence, not copy-list.
+
+	* psgml-edit.el: Require cl when compiling.  Don't set
+	byte-compile-warnings.
+	(sgml-quote-attribute-value, sgml-tag-regexp)
+	(sgml-edit-attrib-next): Use documented way of including `-' in
+	regexp range.
+	(sgml-change-start-tag, sgml-insert-attribute)
+	(sgml-make-attrib-menu, sgml-menu-ask): Fix to work without a DTD.
+	(sgml-edit-attrib-next, sgml-tag-regexp): Maybe allow non-ASCII.
+	(sgml--all-possible-elements): Kludge for DTD-less case.
+	(sgml-make-character-reference): Take care over multibyteness.
+	Maybe deal with unicodes.
+	(sgml-edit-attrib-specification-list, sgml-edit-attrib-default)
+	(sgml-edit-attrib-default, sgml-edit-attrib-clear)
+	(sgml-edit-attrib-field-start, sgml-attribute-buffer): Use
+	property name `sgml-category', not `category', which is special in
+	Emacs. [backed out //lenst]
+	(sgml-operate-on-tags): Use sgml-restore-buffer-modified-p.
+
+	* psgml-lucid.el (sgml-insert): Use property name `sgml-category',
+	not `category'. [backed out //lenst]
+	
+	* psgml.el: Require cl only when compiling.  Doc fixes.
+	(sgml-mode): Set text-property-default-nonsticky.  In Emacs, use
+	which-fun-mode hook instead of trying to modify mode-line-format.
+	<paragraph-separate>: Maybe allow non-ASCII.
+	(sgml-mode-map): Define unconditionally. [backed out //lenst]
+	(sgml-running-lucid): Defconst, not defvar.
+	(sgml-have-re-char-clases): New constant.
+	(sgml-markup-faces): Default to font-lock faces if available.
+	(sgml-start-tag-regex, sgml-close-angle): Allow non-ASCII if
+	possible.
+	(sgml-angle-distance, sgml-slash-distance): Defvar, not defconst,
+	since it's a user variable.
+	(sgml-restore-buffer-modified-p): New alias.
+	(sgml-parse-colon-path): Use parse-colon-path, if available.
+	[backed out, parse-colon-path is for directories //lenst]
+	(sgml-command-post, sgml-mode): Assume make-local-hook exists.
+
+	* psgml-parse.el: Doc and message fixes.
+	(sgml-dtd-less): New buffer-local variable.
+	(sgml-eltype-name, sgml-eltype-defined, sgml-eltype-token)
+	(sgml-token-eltype, sgml-eltype-mixed, sgml-check-name)
+	(sgml-element-etag-optional, sgml-element-mixed, sgml-parse-name):
+	Avoid unnecessary compiler macros.
+	(sgml-read-element-type, sgml-read-element-name): DTRT for non-nil
+	sgml-dtd-less.
+	(sgml-push-to-entity): Obey sgml-warn-about-undefined-entities.
+	Don't make the buffer unibyte here.  Ensure an old one is
+	multibyte.
+	(sgml-parse-prolog): Set sgml-dtd-less.
+	(sgml-attdecl-default-value): Avoid caddr.
+	(sgml-entity-marked-undefined-p): Avoid cddddr.  Avoid (CL
+	runtime) setter for nthcdr.
+	(sgml-load-dtd): Avoid mapcan.
+	(sgml-bdtd-load): Set buffer unibyte.
+	(sgml-bdtd-merge): Don't set buffer unibyte here.
+	(sgml-set-active-dtd-indicator): Set which-func-mode.
+	(sgml-merge-eltypes): Use copy-sequence, not copy-list.
+	(sgml-open-element-hook, sgml-close-element-hook)
+	(sgml-map-eltypes): Remove redundant level of lambda.
+	(sgml-entity-case, sgml-general-case): Moved before
+	sgml-entity-case use.
+	(sgml-update-display): Call force-mode-line-update.
+	(sgml-parse-attribute-specification-list): Use sgml-dtd-less.
+	
+	* psgml-other.el (sgml-insert): Use plist-get rather than CL
+	runtime's getf.
+	(sgml-use-text-properties): Default to t.
+	(sgml-with-modification-state): New macro.
+	(sgml-default-nonsticky): New constant.
+	(sgml-set-face-for): Use sgml-with-modification-state,
+	sgml-default-nonsticky.
+	(sgml-clear-faces): Avoid CL runtime.
+	(next-overlay-at): Remove as consequence of above.
+
+	* psgml-fs.el: Require cl and ps-print when compiling.
+	(fs-do-style, fs-do-style, fs-do-style): Use plist-get rather than
+	CL runtime's getf.
+	(fs-element-with-id): Use compare-strings, not equalp.
+
+	* psgml-dtd.el, psgml-charent.el, psgml-api.el, psgml-info.el:
+	Require cl when compiling.
+
+	* psgml-debug.el: Require cl, elp and edebug when compiling.
+
+	
+2002-04-19  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.2.5 released
+
+2002-03-17  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-api.el (sgml-map-content): don't try to map empty
+	elements, no point and the code doesn't work for that case.
+
+2002-02-13  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-auto-insert-required-elements): doc fix.
+	(sgml-balanced-tag-edit): doc fix.
+
+	* psgml-edit.el (sgml-edit-attrib-default): don't make text read-only
+	(sgml-insert-tag): doc fix.
+
+2002-02-09  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el: Explicitly setup prefix keys
+	(sgml-prefix-f-map): new var
+	(sgml-prefix-u-map): new var
+
+2002-02-08  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-set-buffer-multibyte): support setting to
+	default 
+	(sgml-compile-dtd): removed sgml-set-buffer-multibyte, this is
+	done by sgml-write-dtd
+	(sgml-push-to-entity): reset buffer to default multibyte support
+
+	* psgml-dtd.el (sgml-write-dtd): fixes for multibyte handling
+
+2001-12-20  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-xml-validate-command): new option. Default for
+	sgml-validate-command in XML mode.
+	(xml-mode): use sgml-xml-validate-command.
+	(xml-mode): remove conditional. Always set sgml-declaration to
+	sgml-xml-declaration.
+
+2001-12-18  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-attribute-buffer): Don't write-protect the
+	"#DEFAULT" marker.
+	(sgml-extract-attribute-value): strip any remains of "#DEFAULT".
+	(sgml-edit-attrib-next): if point is before the attribute value,
+	move to beginning of line to avoid skipping this attribute.
+
+2001-12-16  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.2.4 released
+
+2001-12-16  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-info.el (sgml-eltype-refrenced-elements): use built-in
+	function copy-sequence
+
+2001-12-14  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-set-buffer-multibyte): Mule/multibyte patch
+	from Yasushi Abe.
+	(sgml-compile-dtd): dito.
+	(sgml-bdtd-merge): dito.
+	(sgml-push-to-entity): dito.
+	(sgml-do-entity-ref): fix sgml-warn-about-undefined-entities behviour.
+
+2001-12-06  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-update-display): take max-pos of top-tree
+	not current-tree as that is not always defined at that point.
+
+2001-11-09  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.2.3 released
+
+	* psgml.el (sgml-running-lucid): make sure it gets defined during
+	compilation.
+
+2001-11-04  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-other.el, psgml-parse.el, psgml-debug.el, psgml-edit.el:
+	Fix the obsolete variable `before-change-function' and
+	`after-change-function', which are no longer used by Emacs.
+
+2001-02-10  Adrian Aichner  <adrian@xemacs.org>
+
+	* psgml-dtd.el: Fix typos.
+	* psgml-edit.el: Ditto.
+	* psgml-fs.el: Ditto.
+	* psgml-info.el: Ditto.
+	* psgml-parse.el: Ditto.
+	* psgml.el: Ditto.
+
+Wed Feb 28 00:02:45 2001  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-fs.el (fs-split-tokens): new helper function for use in
+	style sheets.
+
+2001-02-28  Lennart Staflin  <lennarts@infostream.no>
+
+	* psgml-other.el (sgml-split-long-menus): new
+	(sgml-popup-menu): use above
+	(sgml-popup-multi-menu): use above
+
+Wed Feb 21 23:30:07 2001  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-parse-to): remove debug code
+
+2001-02-20  Lennart Staflin  <lennarts@infostream.no>
+
+	* psgml-dtd.el (sgml-check-content): check case of declared
+	content name.
+	(sgml-parse-exception): fix misspelled function name
+	(sgml-declare-entity): Fix wrong case on symbols
+	(sgml-parse-entity-type): for consistency, don't downcase entity
+	type name
+	(sgml-parse-entity-type): Remove case check and intern for
+	notation name. Notation name will be stored as a string.
+
+	* psgml-parse.el (sgml-push-to-entity): remove debugging code
+	(sgml-set-initial-state): Change to use change hooks
+
+Fri Feb  9 01:06:27 2001  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.2.2 released
+
+	* psgml.el (sgml-mode-map): Bind (meta control h) instead of ESC
+	C-h, avoids redefining M-BS
+
+Thu Feb  8 20:08:47 2001  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-info.el: Add provide psgml-info
+
+Sun Oct 22 17:29:53 2000  Marc-Antoine Parent
+
+	* patch from Marc-Antoine Parent
+
+	* psgml-edit.el (sgml-read-attribute-value): include the element name, thus:
+	Value for {attribute name} in {element name} ({type} {Default}):
+
+
+2000-10-11  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-edit.el (sgml-indent-line): new strategy for identifying
+	elements
+
+2000-09-06  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-api.el (sgml-map-content): Use sgml-with-parser-syntax-ro
+
+	* psgml-parse.el (sgml-find-start-point): renamed to
+	sgml-goto-start-point, to indicate that this actually changes the
+	point and buffer. And should always be called inside
+	sgml-with-parser-syntax.
+	(sgml-with-parser-syntax-ro): As sgml-with-parser-syntax also
+	handle restoring buffer modification state.
+	(sgml-last-buffer): New state variable
+	(sgml-with-parser-syntax): set sgml-last-buffer
+	(sgml-mainbuf-point): new function
+	(sgml-max-pos-in-tree): new function
+	(sgml-update-display): don't call sgml-find-start-point, use
+	sgml-max-pos-in-tree to figure out if there is much to parse.
+	(sgml-parse-to): calls sgml-parser-loop directly no
+	sgml-parse-continue.
+	(sgml-parse-continue): use sgml-with-parser-syntax-ro and
+	set-buffer to sgml-last-buffer.
+
+2000-08-24  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml.el (sgml-insert-defaulted-attributes): new option
+	* psgml-edit.el (sgml-insert-attributes): check new option
+
+	* psgml-fs.el (style-format): set ps-left-header to include a
+	style-sheet specified title and the filename. (for ps-print-buffer)
+	(fs-special-styles): New special style 'title' for setting title.
+	(fs-do-style): handle title style
+	(fs-element-content): make element argument optional, defaults to
+	current element.
+
+2000-08-08  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-edit.el (sgml-insert-element): Fix bug with empty element.
+
+Thu Aug  3 07:52:46 2000  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-insert-element): Fix bug when inserting
+	element at end of buffer.
+
+2000-08-03  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-edit.el (sgml-attribute-buffer): Fix missing space for
+	unspecified required attributes.
+
+2000-06-05  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-dtd.el (sgml-parse-parameter-literal): use
+	buffer-substring-no-properties .
+
+2000-05-31  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-api.el (sgml-parse-data): Don't call sgml-parse-loop
+	directly, use sgml-parse-continue.
+
+Sat May 27 00:04:31 2000  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-attr-clean-and-insert): new command. Used to
+	automatically remove #DEFAULT when a character is typed.
+	(sgml-attr-default-keymap): keymap used as only for #DEFAULT in
+	attribute editing.
+
+Mon Apr 24 09:55:14 2000  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-complete): Transform case on inserted names
+	using sgml-general-insert-case or sgml-entity-insert-case.
+
+Sun Apr 16 16:07:55 2000  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-indent-line): compute indentation from
+ 	context, not element under point. Did this change once before but
+ 	had to back it out. This time take care of omitted end-tags by
+ 	choosing parent element as context, if point is at the very end of
+ 	the element. Don't do special attribute indenting for elements
+ 	that occur in data context.
+	(sgml-fill-region): Fix giving up to early.
+	(sgml-do-fill): indent tags of subelements in element context
+
+	* psgml-info.el (sgml-describe-element-type): Use sgml-princ-names
+	for occurs in section.
+
+2000-03-22  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-edit.el (sgml-change-element-name): Add end-tag event if
+	original element is empty. (hmm this isn't quite right). Also use
+	sgml-find-context-of to find element, because -element-of gives
+	the element of the following char.
+
+Tue Jan  4 19:51:03 2000  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-with-parser-syntax): Restore current buffer
+	before restoring syntax table.
+
+Tue Dec 21 20:50:31 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-other.el (sgml-set-face-for): set rear-nonsticky for face
+	when sgml-use-text-properties is true. (Suggested by Dirk Frömbgen)
+
+Sat Dec 18 18:55:02 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-charent.el (sgml-charent-to-display-char): use
+	buffer-substring-no-properties to allow for using text properties
+	for fontification.
+
+1999-11-02  Tim Bradshaw  <tfb@tfeb.org>
+
+ 	* psgml-edit.el (sgml-doctype-insert): made it not loop when it
+ 	gets a bogus nil
+
+1999-12-16  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-parse.el (sgml-parse-prolog): restore buffer modified
+	after parsing. To allow using text properties for fontification.
+	(sgml-parse-continue): dito.
+	(sgml-parse-to): call sgml-parse-continue instead of calling
+	sgml-parser-loop directly.
+
+1999-12-15  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml.el: autoload for sgml-do-set-option
+
+1999-12-03  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml.el (sgml-mode-syntax-table): new variable
+	(sgml-mode): use sgml-mode-syntax-table
+
+1999-11-29  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-validate-error-regexps): Also recognize warnings
+	(:W:) in output from nsgmls.
+
+1999-11-11  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-parse.el (sgml-parse-to): Let sgml-with-parser-syntax wrap
+	a bigger chunk of the code to make sure the syntax table is set up
+	before any buffer changes.
+
+Tue Nov  9 16:25:53 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-modify-dtd): use sgml-general-case on names
+	from modifier.
+
+Mon Nov  8 22:13:12 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-info.el (sgml-eltype-refrenced-elements): Copy sequence
+	before sorting destructively.
+	(sgml-describe-element-type): Include exceptions in info display.
+
+Thu Nov  4 19:07:09 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-note-change-at): If in XML mode and
+ 	previous char is /, back up one char. This allows for the />
+ 	delimiter to be recognized even if the start tag has been
+ 	previously parsed as an improperly ended tag.
+
+	* psgml-edit.el (sgml-last-element): don't use sgml-last-element
+	for XML (there is not omitted tags to account for).
+
+1999-10-21  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-parse.el (sgml-push-to-entity): restore the (erase-buffer)
+	that had been commented out. This is needed for the case when
+	sgml-try-merge-compiled-dtd fails and leaves junk in the buffer.
+
+1999-10-19  Lennart Staflin  <lennarts@infotek.no>
+
+	* Version 1.2.1 released
+
+1999-10-14  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-parse.el (sgml-log-entity-stack): don't use
+	sgml-pop-entity, just loop thru the entity stack and print out the
+	files.
+	(sgml-load-ecat): bind sgml-xml-p while parsing catalog
+
+1999-10-13  Lennart Staflin  <lennarts@infotek.no>
+
+	* psgml-parse.el (sgml-current-file): New variable, holds the name
+	of file name (if any) of the entity beeing parsed in the buffer.
+	(sgml-parse-warning): New func. Log a parser warning, a warning
+	including information about where the error occured. Mostly for
+	DTD parsing.
+	(sgml-log-entity-stack): new factored function.
+	(*) Replaces some sgml-parse-error and sgml-log-warning with
+	sgml-parse-warning.
+	(sgml-parse-catalog-buffer): bind sgml-xml-p while parsing catalog
+
+Sun Oct 10 15:53:12 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.2 released
+
+Wed Oct  6 00:43:37 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.1.7 released
+
+	* psgml-parse.el (sgml-push-to-entity): carry XML-ness to parsed
+	text entities.
+
+	* psgml-charent.el (sgml-display-char-list-filename): new default
+	is "iso8859.map" in the same directory where psgml is installed.
+
+Wed Sep 22 19:34:08 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el: Apply sgml-general-case to attribute name for
+ 	interactive sgml-insert-attribute. Don't test for non empty asl in
+ 	sgml-edit-attrib. A lot of changes in handling text attributes
+ 	when in attribute edit mode.
+
+Sat Aug 14 22:34:59 1999  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-tag-regexp): Recognize XMLs empty tags.
+
+1998-11-16  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-set-local-variable): insert "mode: xml" for
+	xml-mode and "mode: sgml" otherwise
+
+	* psgml-edit.el (sgml-add-element-to-element): add end-tag to
+	empty xml-elements before inserting an element
+
+1998-11-15  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.1.6 released
+
+	* psgml-parse.el (sgml-char-int): from XEmacs
+	(sgml-read-octet): modified for XEmacs
+	(sgml-read-peek): dito.
+	(sgml-read-number): dito.
+
+	* psgml.el (sgml-option-value-indicator): moved here.
+	(sgml-mode): activate-menubar-hook can't be local in XEmacs and
+	sgml-build-custom-menus need to be after the easy-menu-adds.
+
+1998-11-14  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el, psgml-edit.el: Fix from David Megginson to some
+	regexps for _: in names.
+	(sgml-build-custom-menus): Do not call easy-menu-change with empty
+	menu.
+
+	* psgml-edit.el (sgml-do-set-option): Don't modify the *Help*
+	buffer directly, call sgml-append-to-help-buffer. Fixes problem
+	with read-only buffer.
+	(sgml-append-to-help-buffer): new func.
+
+	* psgml.el (sgml-main-menu):  Options handling changed after
+	suggestion and code from Matthias Clasen
+	(sgml-update-all-options-menus): new func. called by
+	activate-menubar-hook
+
+Thu Nov  5 20:59:08 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-parse-processing-instruction): removed let
+	of sgml-markup-start. Was probably wrong solution to problem with
+	sgml-markup-start beeing nil. Added in-declaration parameter. If
+	in a declaration, no fontification should be done.
+	(sgml-parse-prolog): do not call sgml-skip-ds, rather call
+	parse-s, parse-pi as this is what "other prolog" contains.
+
+1998-10-31  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.1.5 released
+
+	* psgml-parse.el (sgml-declared-value-notation): change 'notation
+	to 'NOTATION
+
+Sat Oct 31 20:00:22 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-cache-catalog): Use file-truename for
+	file-attributes, to get modification time from real file and not
+	from symlink.
+
+	* psgml.el (xml-mode): Do not build a syntax table
+	(sgml-dtd-menu): moved Custom DTD's to submenu
+	(sgml-markup-menu): moved Custom Markup to submenu
+	(sgml-build-custom-menus): Make submenus for Custom DTD and Markup
+
+	* psgml-parse.el (xml-parser-syntax): build special syntax table
+	for XML.
+	(sgml-with-parser-syntax): Use sgml-parser-syntax or
+	xml-parser-syntax depending on sgml-xml-p
+
+Wed Oct 28 23:15:38 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-read-element-type): use
+	let (completion-ignore-case sgml-namecase-general)
+
+Sat Oct 24 13:13:48 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-build-custom-menus): Construct sub-menus for
+	custom DTD and custom Markup insert, only if
+	easy-menu-filter-return is not defined otherwise use the :filter
+	facility to build menu when needed.
+
+	* psgml-edit.el (sgml-what-element): Guard call to
+	sgml-deref-shortmap
+
+1998-10-20  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-edit-external-entity): fix from Matthias Clasen
+
+	* psgml.el (sgml-validate-error-regexps): modify regexp to work in
+	Emacs 20.3
+
+1998-09-30  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.1.4 release
+
+Mon Aug 31 21:53:45 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-bdtd-load): Increase version number
+	(sgml-read-dtd): Increase version number
+
+	* psgml-dtd.el (sgml-write-dtd): Increase version number
+
+Sat Aug 15 18:58:25 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-complete): add completion of #-reserved words
+
+Fri Jul  3 18:14:21 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.1.3
+
+	* Makefile.in: Call install with only one source file.
+
+Fri Jul  3 17:54:06 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-complete): ignore case
+
+	* psgml-parse.el (sgml-push-to-entity): use setf to set
+	sgml-entity-marked-undefined-p.
+	(setf sgml-entity-marked-undefined-p): define setf method
+
+Tue Jun 30 22:06:20 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-do-set-option): Added file-list and
+	file-or-nil types contributed by Matthias Clasen
+	<mclasen@sun2.mathematik.uni-freiburg.de>
+
+Tue Jun 30 21:48:39 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-mode-map): C-c C-i calls sgml-add-element-to-element
+
+	* psgml-edit.el (sgml-add-element-to-element): New command.
+
+Wed Jun 24 23:23:38 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-attribute-buffer): Fixed another victim of
+	the case change.
+	(sgml-change-element-name): fix bug with empty XML element
+
+Mon Jun 22 19:58:43 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (psgml-version): Version 1.1.2
+
+	* Installed patch from Matthias Clasen
+	<clasen@pong.mathematik.uni-freiburg.de>.
+	Adding notation to entities and a sgml-notation-handlers variable
+	used by sgml-edit-external-entity.
+
+	* psgml-edit.el (sgml-indent-line): Previous change of
+	sgml-indent-line did not work well with OMITTAG. Restore old
+	functionallity.
+
+Fri Jun 19 18:54:27 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-attribute-buffer):
+	changed case of default value type, here and in many other functions.
+	(sgml-translate-attribute-specification-list): changed case for
+	declared value
+
+	* psgml-parse.el (sgml-parse-attribute-specification-list):
+	changed case of default value type
+
+1998-06-16  Dave Love  <d.love@dl.ac.uk>
+
+	* psgml-edit.el (sgml-read-element-name,
+	sgml-read-attribute-value, sgml-insert-attribute,
+	sgml-custom-markup): Use sgml-namecase-general to set
+	completion-ignore-case.
+
+1998-06-16  Dave Love  <d.love@dl.ac.uk>
+
+	* psgml-parse.el (sgml-push-to-entity): Don't use save-excursion
+	around insert-file-contents -- may break in Emacs 20.3.
+
+Fri Jun 19 10:40:53 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-dtd.el (sgml-check-declared-value): upcase NOTATION
+
+	* psgml-parse.el (sgml-read-element-name): bind
+	completion-ignore-case as suggested by Mark Eichin. Also present
+	element names in the insert case.
+
+Tue Jun 16 00:31:03 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-command-post): added ignore-errors
+
+	* psgml-parse.el (sgml-get-delim-string): new func.
+	(sgml-delim): changed to macro.
+	(sgml-do-usemap): upcase #EMPTY
+	(sgml-parse-xml-comment): set markup type
+
+	* psgml-dtd.el (sgml-validate-default-value-rn): upcase keywords
+	(sgml-declare-entity): remove case fiddling
+
+	* psgml-parse.el (sgml-check-case): remove case fiddling -- retain
+	check.
+
+	* psgml-dtd.el (sgml-validate-declared-value): upcase attribute types
+	(sgml-check-default-value): remove case fiddling -- reserved names
+	should be in upper case.
+
+	* psgml-parse.el (sgml-push-to-entity): use syntax table from
+	current buffer in entity buffer and not the sgml-parser-syntax as
+	XML will use another syntax table.
+
+Wed Jun 10 23:28:42 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-catalog-lookup): Take additional catalogs
+	in right order.
+
+Thu May 14 20:02:42 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* Version 1.1.1
+
+	* psgml.el (psgml-version): new version 1.1.1
+
+	* psgml-dtd.el (sgml-parse-character-reference): upcase funchar
+	names.
+
+	* psgml-edit.el (sgml-indent-line): compute indentation from
+	context, not element under point. Removed special handling of
+	start-tag and document context. Extra indentation if in markup.
+
+	* psgml-parse.el (sgml-parse-external): use upper case keywords.
+	(sgml-check-case): use upper case instead of lower case.
+
+Wed May 13 06:13:05 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-do-marked-section): Change keyword strings
+	to upper case.
+	(sgml-general-case): Use Upcase instead of Downcase.
+	(sgml-parse-markup-declaration): upcase keywords.
+
+Sat Mar 14 21:31:09 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-do-processing-instruction): Added
+	recognition of PSGML NOFILL.
+	(sgml-parse-catalog-buffer): add catalog as a noname entry
+	(sgml-catalog-lookup): handle catalog entries
+
+Thu Mar 12 00:04:52 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-current-element-name): make buffer local
+
+Wed Mar 11 22:11:01 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-insert-start-tag): extended meaning of NET
+	paramenter to insert XML-TAGCE if XML.
+	(sgml-change-start-tag): keep XML-TAGCE
+
+	* psgml-parse.el (sgml-read-element-name): use completing read on
+	all defined element types if in an ANY context.
+	(sgml-check-tag-close): removed check for XML-TAGCE
+	(sgml-do-start-tag): added check for XML-TAGCE
+	(sgml-element-empty): In XML no special handling of elements with
+	declared content of EMPTY, but use conref to signal empty element tag.
+
+	* psgml-dtd.el (sgml-merge-attlists): reverse the list
+
+Tue Mar 10 20:13:11 1998  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el: Merged David Megginson's latest xml modifications.
+
+Sat Nov 15 20:50:35 1997  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-parse-attribute-value-specification): New func.
+	(sgml-parse-attribute-specification-list): use new func. This
+	changes an error to a warning to make better error recovery when
+	illegal characters occurs in starttag.
+
+Sun Aug 17 20:22:28 1997  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-cache-catalog): remove file-truename. This
+	made relative filenames refer to the wrong directory if the
+	catalog file was a symlink.
+
+Thu Jul 24 22:36:15 1997  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-modify-dtd): fixed bug in handling
+	sgml-parent-document.
+
+Mon May 19 18:43:32 1997  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-edit.el (sgml-expand-entity-reference): changed to allow
+	point to be within entity referens, not only at start of ref. As
+	suggested by Matthias Clasen.
+	(sgml-edit-external-entity): new command contributed by Matthias
+	Clasen <clasen@netzservice.de>
+
+	* psgml-charent.el (sgml-charent-to-display-char): fix bug in regexp.
+
+Sat Mar 15 19:20:57 1997  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml-parse.el (sgml-check-tag-close): change sgml-error to
+ 	sgml-log-warning
+
+Sun Jan 12 19:15:32 1997  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (psgml-version): bump version
+
+Fri Nov 22 20:29:44 1996  Lennart Staflin  <lenst@lysator.liu.se>
+
+	* psgml.el (sgml-parse-colon-path): use path-separator if
+	available.
 # Boston, MA 02111-1307, USA.
 
 VERSION = 1.37
-AUTHOR_VERSION = 1.2.2
+AUTHOR_VERSION = 1.3.1
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = psgml
 PKG_TYPE = regular
-REQUIRES = xemacs-base edit-utils edebug xemacs-devel mail-lib fsf-compat eterm sh-script
+REQUIRES = xemacs-base edit-utils edebug xemacs-devel mail-lib fsf-compat \
+	eterm sh-script ps-print
 CATEGORY = standard
 
 ELCS = iso-sgml.elc psgml-api.elc psgml-charent.elc psgml-debug.elc \
 	psgml-dtd.elc psgml-edit.elc psgml-fs.elc psgml-html.elc \
-	psgml-info.elc psgml-parse.elc psgml-xemacs.elc psgml.elc
+	psgml-info.elc psgml-parse.elc psgml-xemacs.elc psgml.elc \
+	psgml-sysdep.elc
 
 INFO_FILES = $(PACKAGE).info* $(PACKAGE)-api.info
 HTML_FILES = $(PACKAGE)*.html $(PACKAGE)-api*.html
 DATA_FILES = iso88591.map
 DATA_DEST = $(PACKAGE)
 
+EXTRA_SOURCES = ChangeLog.upstream
+
 # We need to set this to an existing directory when building the package.
 PRELOADS = -eval "(setq sgml-data-directory (expand-file-name \".\"))"
 
-This is the READ ME file for psgml.el version 1.2.2.       -*- text -*-
+This is the READ ME file for psgml.el version 1.3.1.       -*- text -*-
 
-This is a BETA release of PSGML. Release 1.2.2 fixes a number of bugs
-in 1.2.1.
-
-
-PSGML is a major mode for editing SGML and XML documents.  It works with
-GNU Emacs 19.34, 20.3 and later or with XEmacs 19.9 and later.  PSGML
-contains a simple SGML parser and can work with any DTD.  Functions
-provided includes menus and commands for inserting tags with only the
-contextually valid tags, identification of structural errors, editing of
-attribute values in a separate window with information about types and
-defaults, and structure based editing.
-
-To install PSGML you first need to uncompress and unpack the source
-archive.  This is done with the `gunzip' and `tar' commands.
-
-     gunzip psgml-1.2.2.tar.gz; tar xf psgml-1.2.2.tar
-
-This should create a subdirectory to the current directory with the
-source code. This directory contains a `configure' command (see the file
-INSTALL for more information about configure).  You can use the
-`configure' command to configure the package or you can load the file
-`psgml-maint' and execute the `psgml-compile-files' command.
-
-Place the `*.el' and the `*.elc' files in a directory where Emacs can
-find it (i.e. one of the directories in the `load-path' variable, you
-can add a directory to this variable in your `.emacs'.)
-
-If you use the `configure' approach, compile psgml with `make' and the
-you can run `make install' to install it in the system library
-`site-lisp'.  The files are installed in a subdirectory named `psgml'.
-The location of `site-lisp' is figured out by `configure', but you can
-change it in the `Makefile'.  You need to make sure that this
-subdirectory is in Emacs `load-path'.
-
-Put the following line in your .emacs:
-
-     (autoload 'sgml-mode "psgml" "Major mode to edit SGML files." t)
-     (autoload 'xml-mode "psgml" "Major mode to edit XML files." t)
-
-You may also want to set up search paths for external entities,
-See the section Entity manager in the psgml.info manual.
-
-The `psgml.info' is the documentation for PSGML in the info format.  You
-can read this with the Emacs command `C-u C-h i'.  You can also install
-the file in your systems info directory and edit the `dir' file to
-include `psgml.info' in the menu.
-
-The info file `psgml.info' is created from the texinfo file
-`psgml.texi'.  The texinfo file can also be used to create a hard copy
-of the documentation.  To do this you need the TeX program and a copy of
-`texinfo.tex'.
-
+This is an ALPHA release. 
    filename FILENAME
    md5sum MD5SUM
    size SIZE
-   provides (iso-sgml psgml-api psgml-charent psgml-debug psgml-dtd psgml-edit psgml-fs psgml-html psgml-info psgml-parse psgml-xemacs psgml sgml-mode)
+   provides (iso-sgml psgml-api psgml-charent psgml-debug psgml-dtd psgml-edit psgml-fs psgml-html psgml-info psgml-parse psgml-sysdep psgml-xemacs psgml sgml-mode)
    requires (REQUIRES)
    type regular
 ))
 (provide 'psgml-api)
 (require 'psgml)
 (require 'psgml-parse)
-
+(eval-when-compile (require 'cl))
 
 ;;;; Mapping: map and modify
 
   (sgml-pop-all-entities)
   (sgml-need-dtd)
   (sgml-element-end element)		; Make sure all content is parsed
-  (let ((main-buffer-max (point-max)))
-    (save-excursion
-      (sgml-with-parser-syntax-ro
-       (sgml-set-parse-state element 'start)
-       (when (eobp) (sgml-pop-entity))
-       (when (eolp) (forward-char 1))
-       (sgml-parse-data main-buffer-max data-fun pi-fun entity-fun)
-       (let ((c (sgml-tree-content element)))
-         (while c
-           (sgml-pop-all-entities)
-           (funcall element-fun c)
-           (sgml-set-parse-state c 'after)
-           (sgml-parse-data main-buffer-max data-fun pi-fun entity-fun)
-           (setq c (sgml-tree-next c))))))
-    )
-  (sgml-pop-all-entities))
+  (unless (sgml-element-empty element)
+    (let ((main-buffer-max (point-max)))
+      (save-excursion
+        (sgml-with-parser-syntax-ro
+         (sgml-set-parse-state element 'start)
+         (when (eobp) (sgml-pop-entity))
+         (when (eolp) (forward-char 1))
+         (sgml-parse-data main-buffer-max data-fun pi-fun entity-fun)
+         (let ((c (sgml-tree-content element)))
+           (while c
+             (sgml-pop-all-entities)
+             (funcall element-fun c)
+             (sgml-set-parse-state c 'after)
+             (sgml-parse-data main-buffer-max data-fun pi-fun entity-fun)
+             (setq c (sgml-tree-next c)))))))))
 
 (defun sgml-parse-data (sgml-goal sgml-data-function sgml-pi-function
 				  sgml-entity-function)
 \input texinfo   @c -*-texinfo-*-
 @c %**start of header
+@c XEmacs change
 @setfilename ../info/psgml-api.info
+@c @setfilename psgml-api.info
 @settitle psgml-api
 @c @setchapternewpage odd
 @c %**end of header
 ;;  Functions to convert character entities into displayable characters
 ;;  and displayable characters back into character entities.
 
+;; This should either use iso-cvt or do better with a multilingual set of entities 
+
 
 ;;;; Code:
 
 (provide 'psgml-charent)
 (require 'psgml-parse)
+(eval-when-compile (require 'cl))
 
 
 ;;;; Variable declarations
 
 (defvar sgml-display-char-list-filename
   (expand-file-name "iso88591.map"
+                    ;; XEmacs change: use data-directory, try "sgml" too.
                     (file-name-directory
                      (or (locate-data-directory "psgml")
                          (locate-data-directory "sgml"))))
   "*Name of file holding relations between character codes and character
-names of displayable characters")
+names of displayable characters.")
 
 (defvar sgml-display-char-alist-cache nil)
 
   (let (key disp-char alist)
     (while (re-search-forward "^\\([0-9]+\\)[ \t]+\\(.+\\)$" nil t)
       (setq key (buffer-substring (match-beginning 2) (match-end 2)))
-      (setq disp-char
-	    (char-to-string
-	     (string-to-number
-	      (buffer-substring (match-beginning 1) (match-end 1)))))
+      (setq disp-char (string-to-number (buffer-substring (match-beginning 1)
+							  (match-end 1))))
+      (if (fboundp 'unibyte-char-to-multibyte)
+	  (setq disp-char (unibyte-char-to-multibyte disp-char)))
+      (setq disp-char (char-to-string disp-char))
       (push (cons key disp-char)
 	    alist))
     alist))
       (goto-char (point-min))
       (sgml-with-parser-syntax
        (while (re-search-forward "&\\(\\w\\(\\w\\|\\s_\\)*\\);?" nil t)
-	 (setq charent (buffer-substring
+	 (setq charent (buffer-substring-no-properties
                         (match-beginning 1) (match-end 1)))
 	 (if (setq replacement (cdr (assoc charent charent-to-char)))
 	     (replace-match replacement t t)))))))
 ;;;;\filename psgml-debug.el
-;;;\Last edited: 2000-06-07 07:29:59 lenst
+;;;\Last edited: 2001-03-10 00:32:00 lenst
 ;;;\RCS $Id$
 ;;;\author {Lennart Staflin}
 ;;;\maketitle
 (require 'psgml-edit)
 (require 'psgml-dtd)
 (autoload 'sgml-translate-model "psgml-dtd" "" nil)
-
-;; XEmacs change
 (eval-when-compile
-  (require 'edebug)
   (require 'cl)
-  (require 'elp))
+  (require 'elp)
+  (require 'edebug))
 
 ;;;; Debugging
 
   (interactive)
   (setq sgml-dtd-info (sgml-pstate-dtd sgml-buffer-parse-state)
 	sgml-top-tree (sgml-pstate-top-tree sgml-buffer-parse-state))
-  (sgml-find-start-point (point))
+  (sgml-goto-start-point (point))
   (message "%s" (sgml-dump-node sgml-current-tree)))
 
 (defun sgml-dump-tree (arg)
   (beginning-of-line)
   (let ((pos-pair (assoc (point) show-structure-positions)))
     (when pos-pair
-      (switch-to-buffer show-structure-source-buffer)
+      (select-window
+       (display-buffer show-structure-source-buffer))
       (goto-char (cdr pos-pair)))))
 
 
 ;; Candidate for C-c C-t
 
 (autoload 'sgml-princ-names "psgml-info")
+(autoload 'sgml-eltype-refrenced-elements "psgml-info")
 
 (define-key sgml-mode-map "\C-c\C-t" 'sgml-show-current-element-type)
 
 	       (overlay-put old-overlay 'sgml-type type)
 	       (overlay-put old-overlay 'face face))))))))
 
-;¤¤\end{codeseg}
+;;;; New Right Button Menu
+
+;; XEmacs change
+(if running-xemacs
+    (define-key sgml-mode-map [(shift button3)] 'sgml-right-menu)
+  (define-key sgml-mode-map [S-mouse-3] 'sgml-right-menu))
+
+(defun sgml-right-menu (event)
+  "Pop up a menu with valid tags and insert the choosen tag.
+If the variable `sgml-balanced-tag-edit' is t, also inserts the
+corresponding end tag. If `sgml-leave-point-after-insert' is t, the point
+is left after the inserted tag(s), unless the element has som required
+content.  If `sgml-leave-point-after-insert' is nil the point is left
+after the first tag inserted."
+  (interactive "*e")
+  (let ((end (sgml-mouse-region)))
+    (sgml-parse-to-here)
+    (cond
+     ((eq sgml-markup-type 'start-tag)
+      (sgml-right-stag-menu event))
+     (t
+      (let ((what
+	     (sgml-menu-ask event (if (or end sgml-balanced-tag-edit)
+                                      'element 'tags))))
+	(cond
+	 ((null what))
+	 (end
+	  (sgml-tag-region what (point) end))
+	 (sgml-balanced-tag-edit
+	  (sgml-insert-element what))
+	 (t
+	  (sgml-insert-tag what))))))))
+
+
+(defun sgml-right-stag-menu (event)
+  (let* ((el (sgml-find-attribute-element))
+         (attrib-menu (ignore-errors (sgml-make-attrib-menu el))))
+
+    (let* ((alt-gi (mapcar (function sgml-eltype-name)
+                           (progn
+                             (sgml-find-context-of (sgml-element-start el))
+                             (sgml-current-list-of-valid-eltypes))))
+           (change-menu
+            (cons "Change To"
+                  (loop for gi in alt-gi
+                        collect `(,gi (sgml-change-element-name ,gi))))))
+      (sgml-popup-multi-menu
+       event "Start Tag"
+       (list* change-menu
+             `("Misc"
+               ("Edit attributes" (sgml-edit-attributes))
+               ("Normalize" (sgml-normalize-element))
+               ("Fill" (sgml-fill-element
+                        (sgml-find-context-of (point))))
+               ("Splice" (sgml-untag-element))
+               ("Fold"   (sgml-fold-element)))
+             `("--" "--")
+             attrib-menu)))))
+
+
+
+
+(defun sgml--empty-is-nil (s)
+  (if (equal s "")
+      nil
+    s))
+
+(defun sgml-dl-to-table (border table-width first-col-width)
+  (interactive "sBorder: \nsTab Width: \nsFirst Col Width: \n")
+  (setq border (sgml--empty-is-nil border))
+  (setq table-width (sgml--empty-is-nil table-width))
+  (setq first-col-width (sgml--empty-is-nil first-col-width))
+  (let ((el (sgml-find-element-of (point))))
+    (goto-char (sgml-element-etag-start el))
+    (let ((end (point-marker)))
+      (goto-char (sgml-element-start el))
+      (sgml-change-element-name "TABLE")
+      (sgml-insert-attribute "BORDER" border)
+      (sgml-insert-attribute "WIDTH" table-width)
+      (while (search-forward "<" end t)
+        (cond
+         ((looking-at "dt")
+          (backward-char 1)
+          (insert "<tr>")
+          (sgml-change-element-name "TD")
+          (sgml-insert-attribute "WIDTH" first-col-width))
+         ((looking-at "tr>\\s-*<td")
+          (sgml-down-element)
+          (sgml-insert-attribute "WIDTH" first-col-width))
+         ((looking-at "dd")
+          (sgml-change-element-name "TD")
+          (sgml-up-element)
+          (insert "</tr>")))))))
+
+
+;\end{codeseg}
 (provide 'psgml-dtd)
 (require 'psgml)
 (require 'psgml-parse)
-
+(eval-when-compile (require 'cl))
 
 ;;;; Variables
 
 ;; Variables used during doctype parsing and loading
 (defvar sgml-used-pcdata nil
-  "True if model group built is mixed")
+  "True if model group built is mixed.")
 
 
 ;;;; Constructing basic
 ;;;; Optimization for the dfa building
 
 (defsubst sgml-empty-state-p (s)
-  ;; True if S has no outgoing moves.
+  "True if S has no outgoing moves."
   (and (sgml-normal-state-p s)
        (null (sgml-state-reqs s))
        (null (sgml-state-opts s)))  )
 	      (t
 	       (setq value
 		     (concat value
-			     (buffer-substring
+			     (buffer-substring-no-properties
 			      (point)
 			      (progn (forward-char 1)
 				     (if lita
 	 (sgml-check-content-model))
 	(t
 	 ;; ANY, CDATA, RCDATA or EMPTY
-	 (let ((dc (intern (sgml-check-name)))) 
+	 (let ((dc (intern (sgml-check-case (sgml-check-name)))))
 	   (cond ((eq dc 'ANY)
 		  (setq sgml-used-pcdata t))
 		 ((eq dc 'CDATA)
   (let ((type (sgml-parse-name))
 	(notation nil))
     (when type
-      (setq type (intern (downcase (sgml-check-case type))))
-      (when (and sgml-xml-p (memq type '(subdoc cdata sdata)))
-	(sgml-error "XML forbids %s entities."
+      (setq type (intern (sgml-check-case type)))
+      (when (and sgml-xml-p (memq type '(SUBDOC CDATA SDATA)))
+	(sgml-error "XML forbids %s entities"
 		    (upcase (symbol-name type))))
-      (cond ((eq type 'subdoc))
-	    ((memq type '(cdata ndata sdata))
+      (cond ((eq type 'SUBDOC))
+	    ((memq type '(CDATA NDATA SDATA))
 	     (sgml-skip-ps)
 	     (setq notation (sgml-parse-name))
-	     (when notation
-	       (setq notation (intern (downcase (sgml-check-case notation)))))
 	     ;;149.2+ data attribute specification
 	     ;;                      = 65 ps+, DSO,
 	     ;;                        31 attribute specification list,
 		   attlist))))))
 
 (defun sgml-merge-attlists (old new)
-  (setq old (nreverse (copy-list old)))
+  (setq old (nreverse (copy-sequence old)))
   (loop for att in new do
 	(unless (assoc (car att) old)
 	  (setq old (cons att old))))
 (defun sgml-write-dtd (dtd file)
   "Save the parsed DTD in FILE.
 Construct the binary coded DTD (bdtd) in the current buffer."
-  (when (fboundp 'set-buffer-multibyte)
-    (setq buffer-file-coding-system 'no-conversion)
-    (set-buffer-multibyte nil))
+  (sgml-set-buffer-multibyte nil)
   (insert
-   ";;; This file was created by psgml on " (current-time-string) "\n"
+   ";;; This file was created by psgml on " (current-time-string)
+   " -*-coding:binary-*-\n"
    "(sgml-saved-dtd-version 7)\n")
-  (sgml-code-dtd dtd)
+  (let ((print-escape-multibyte t))
+    (sgml-code-dtd dtd))
   (set 'file-type 1)
-  (write-region (point-min) (point-max) file))
+  (let ((coding-system-for-write 'no-conversion))
+    (write-region (point-min) (point-max) file)))
 
 
 ;;; psgml-dtd.el ends here
 (provide 'psgml-edit)
 (require 'psgml)
 (require 'psgml-parse)
-(require 'tempo)
+(require 'tempo) ;; XEmacs change
+(eval-when-compile (require 'cl))
 
-(eval-when-compile
-  (setq byte-compile-warnings '(free-vars unresolved callargs redefine)))
+;; (eval-when-compile
+;;   (setq byte-compile-warnings '(free-vars unresolved callargs redefine)))
 
 
 ;;;; Variables
     (error "Illegal name"))
   (let* ((element (sgml-find-element-of (point)))
 	 (attspec (sgml-element-attribute-specification-list element))
-	 (oldattlist (sgml-element-attlist element)))
+	 (oldattlist (sgml-element-attlist element))
+         (tagc (if (and sgml-xml-p (sgml-element-empty element))
+                   (sgml-delim "XML-TAGCE")
+                 (sgml-delim "TAGC")))
+         (tagc-len (length tagc)))
     (goto-char (sgml-element-end element))
     (unless (sgml-element-empty element)
-      (delete-char (- (sgml-element-etag-len element)))
-      (tempo-process-and-insert-string (sgml-end-tag-of gi)))
+      (delete-char (- (sgml-element-etag-len element))))
+    ;; XEmacs change: use tempo
+    (tempo-process-and-insert-string (sgml-end-tag-of gi))
     (goto-char (sgml-element-start element))
     (delete-char (sgml-element-stag-len element))
+    ;; XEmacs change: use tempo
     (tempo-process-and-insert-string (concat (sgml-delim "STAGO")
-					     (sgml-general-insert-case gi)))
+					     (sgml-general-insert-case gi)
+					     tagc))
     (let* ((newel (sgml-find-context-of (point)))
 	   (newattlist (sgml-element-attlist newel))
 	   (newasl (sgml-translate-attribute-specification-list
 		    attspec oldattlist newattlist)))
-      (sgml-insert-attributes newasl newattlist))
-    (tempo-process-and-insert-string
-     (if (and sgml-xml-p (sgml-element-empty element))
-	 (sgml-delim "XML-TAGCE")
-       (sgml-delim "TAGC")))))
+      (backward-char tagc-len)
+      (sgml-insert-attributes newasl newattlist)
+      (forward-char tagc-len))))
 
 
 (defun sgml-translate-attribute-specification-list (values from to)
 If called from a program first two arguments are start and end of
 region. And optional third argument true unhides."
   (interactive "r\nP")
+  (setq selective-display t)
   (let ((mp (buffer-modified-p))
-	(inhibit-read-only t)		;
-	(buffer-read-only nil)		; should not need this, but
-					; perhaps some old version of
-					; emacs does not understand
-					; inhibit-read-only
-	(before-change-function nil)
-	(after-change-function nil))
-    (setq selective-display t)
+	(inhibit-read-only t)
+	(before-change-functions nil)
+	(after-change-functions nil))
     (unwind-protect
-	(subst-char-in-region beg end
-			      (if unhide ?\r ?\n)
-			      (if unhide ?\n ?\r)
-			      'noundo)
+        (subst-char-in-region beg end
+                              (if unhide ?\r ?\n)
+                              (if unhide ?\n ?\r)
+                              'noundo)
       (when sgml-buggy-subst-char-in-region
-	(set-buffer-modified-p mp)))))
+        (set-buffer-modified-p mp)))))
 
 (defun sgml-fold-element ()
   "Fold the lines comprising the current element, leaving the first line visible.
 is given.  If COL is given it should be the column to indent to.  If
 ELEMENT is given it should be a parse tree node, from which the level
 is determined."
+  (sgml-debug "-> sgml-indent-line %s %s"
+	      col (if element (sgml-element-gi element)))
   (when sgml-indent-step
-    (let ((here (point-marker)))
+    (let ((here (point-marker))
+	  ;; Where the indentation goes, i.e., will this be data
+	  element-insert                
+	  ;; Where we compute indentation, where the thing we indent is.
+	  ;; Can be different from above if end-tag is omitted.
+	  element-level)
       (back-to-indentation)
-      (unless (or col element)
+      (unless col
 	;; Determine element
-	(setq element
+	(setq element-insert
 	      (let ((sgml-throw-on-error 'parse-error))
 		(catch sgml-throw-on-error
-		  (if (eobp)
-		      (sgml-find-context-of (point))
-		    (sgml-find-element-of (point)))))))
-      (when (eq element sgml-top-tree)	; not in a element at all
-	(setq element nil)		; forget element
-	(goto-char here))		; insert normal tab instead)
-      (when element
-	(sgml-with-parser-syntax
-	 (let ((stag (sgml-is-start-tag))
-	       (etag (sgml-is-end-tag)))
-           (cond ((and (> (point) (sgml-element-start element))
-                       (< (point) (sgml-element-stag-end element)))
-                  (setq col
-                        (+ (save-excursion
-                             (goto-char (sgml-element-start element))
-                             (current-column))
-                           (length (sgml-element-gi element))
-                           2)))
-                 ((and
-		   ;; Wing change, adapted by James
-		   (not (member* (sgml-element-gi
-				  (if (or stag etag)
-				      (sgml-element-parent element)
-				    element))
-				 sgml-inhibit-indent-tags :test #'equalp))
-		   (or sgml-indent-data
-		       (not (sgml-element-data-p
-			     (if stag
-				 (sgml-element-parent element)
-			       element))))
-		   (setq col
-			 (* sgml-indent-step
-			    (+ (if (or stag etag) -1 0)
-			       (sgml-element-level element))))))))))
+		  ;; This used to be (sgml-find-element-of (point))
+		  ;; Why? Possibly to handle omitted end-tags
+		  (sgml-debug "-- sgml-indent-line find context")
+		  (sgml-find-context-of (point)))))
+	(setq element-level element-insert)
+	(when (and (not (eobp)) element-level)
+	  (setq element-level (sgml-find-element-of (point)))
+	  ;; It would be good if sgml-find-element-of would also tell
+	  ;; us if the character is in the start-tag/end-tag or
+	  ;; content
+	  (when (or (= (point) (sgml-element-start element-level))
+		    (sgml-with-parser-syntax (sgml-is-end-tag)))
+	    (setq element-level (sgml-element-parent element-level)))))
+      (when (eq element-level sgml-top-tree)	; not in a element at all
+	(setq element-level nil)		; forget element
+	(goto-char here))			; insert normal tab instead
+      (when element-level
+	(cond ((and (> (point) (sgml-element-start element-insert))
+		    (< (point) (sgml-element-stag-end element-insert))
+		    (not (sgml-element-data-p
+			  (sgml-element-parent element-insert))))
+	       (setq col
+		     (funcall sgml-attribute-indent-function element-insert)))
+	      ((and
+		;; Wing change, adapted by James
+		(not (member* (sgml-element-gi
+			       (if (or (sgml-is-start-tag) (sgml-is-end-tag))
+				   (sgml-element-parent element-level)
+				 element-level))
+			      sgml-inhibit-indent-tags :test #'equalp))
+		(or sgml-indent-data
+		    (not (sgml-element-data-p element-insert))))
+	       (setq col
+		     (funcall sgml-content-indent-function element-level)))))
       (when (and col (/= col (current-column)))
 	(beginning-of-line 1)    
 	(delete-horizontal-space)
 
 (defun sgml-insert-tag (tag &optional silent no-nl-after)
   "Insert a tag, reading tag name in minibuffer with completion.
-If the variable sgml-balanced-tag-edit is t, also inserts the
-corresponding end tag. If sgml-leave-point-after-insert is t, the point
+If the variable `sgml-balanced-tag-edit' is t, also inserts the
+corresponding end tag.  If `sgml-leave-point-after-insert' is t, the point
 is left after the inserted tag(s), unless the element has some required
-content.  If sgml-leave-point-after-insert is nil the point is left
+content.  If `sgml-leave-point-after-insert' is nil, the point is left
 after the first tag inserted."
   (interactive 
    (list
 	       (fixup-whitespace)))
 	  (t
 	   (insert "\n"))))
+  ;; XEmacs change: use tempo
   (tempo-process-and-insert-string tag)
   (sgml-indent-line)  
   (unless no-nl-after
   (save-excursion
     (when (and element (not (equal element "")))
       (goto-char end)
+      ;; XEmacs change: use tempo
       (tempo-process-and-insert-string (sgml-end-tag-of element))
       (goto-char start)
       (sgml-insert-tag (sgml-start-tag-of element)))))
 	   ((and sgml-minimize-attributes sgml-shorttag
 		 (member (sgml-general-case val)
 			 (sgml-declared-value-token-group dcl)))
+	    ;; XEmacs change: use tempo
 	    (tempo-process-and-insert-string (concat " " val)))
 	   (t
+	    ;; XEmacs change: use tempo
 	    (tempo-process-and-insert-string (concat " " name "="))
 	    (insert (sgml-quote-attribute-value val)))))
     (when auto-fill-function
   (let ((quote ""))
 	(cond ((and (not sgml-always-quote-attributes)
 		    sgml-shorttag
-		    (string-match "\\`[.A-Za-z0-9---]+\\'" value))
+		    (string-match "\\`[-.A-Za-z0-9]+\\'" value))
 	       ) ; no need to quote
 	      ((not (string-match "\"" value)) ; can use "" quotes
 	       (setq quote "\""))
       (unless (bolp)
 	(insert "\n")))
     (when (prog1 (bolp)
+	    ;; XEmacs change: use tempo
 	    (tempo-process-and-insert-string
 	      (if (eq t (sgml-element-net-enabled sgml-current-tree))
 		  "/"
   ;; Insert a start-tag with attributes
   ;; if NET is true end with NESTC unless XML then end with NESTC NET
   ;; (aka XML-TAGCE).
+  ;; XEmacs change: use tempo
   (tempo-process-and-insert-string (concat (sgml-delim "STAGO")
 					   (sgml-general-insert-case name)))
   (sgml-insert-attributes asl attlist)
   ;; In XML, force net if element is always empty
   (when (and sgml-xml-p (sgml-check-empty name))
     (setq net t))
+  ;; XEmacs change: use tempo
   (tempo-process-and-insert-string
    (if net (if sgml-xml-p
 	       (sgml-delim "XML-TAGCE")
 (defun sgml-change-start-tag (element asl)
   (let ((name (sgml-element-gi element))
 	(attlist (sgml-element-attlist element)))
+    ;; Concoct an attribute specification list using the names of the
+    ;; existing attributes and those ot be changed.
+    (when (and (not attlist) sgml-dtd-less)
+      (dolist (elt (mapcar 'car asl))
+	(unless (assoc elt attlist)	; avoid duplicates
+	  (push (sgml-make-attdecl elt 'CDATA 'REQUIRED) attlist)))
+      (setq attlist (nreverse attlist)))
     (assert (sgml-bpos-p (sgml-element-stag-epos element)))
     (goto-char (sgml-element-start element))
     (delete-char (sgml-element-stag-len element))
             (let ((completion-ignore-case sgml-namecase-general))
               (completing-read
                "Attribute name: "
-               (mapcar (function (lambda (a) (list (sgml-attdecl-name a))))
-                       (sgml-non-fixed-attributes (sgml-element-attlist el)))
-               nil t)))))
+               (mapcar
+		(function (lambda (a) (list (sgml-attdecl-name a))))
+		(if sgml-dtd-less
+		    (sgml-tree-asl el)
+		  (sgml-non-fixed-attributes (sgml-element-attlist el))))
+               nil (not sgml-dtd-less))))))
      (list name
 	   (sgml-read-attribute-value
-	    (sgml-lookup-attdecl name (sgml-element-attlist el))
-			(sgml-element-name el)
+	    (if sgml-dtd-less
+		(list name)
+	      (sgml-lookup-attdecl name (sgml-element-attlist el)))
+	    (sgml-element-name el)
 	    (sgml-element-attval el name)))))
   ;; Body
   (assert (stringp name))
 	      (nconc tab
 		     (mapcar (function sgml-start-tag-of)
 			     (sgml-current-list-of-valid-eltypes)))))))
+    (if sgml-dtd-less
+	;; The best we can do is assemble a list of elements we've
+	;; seen so far.
+	(dolist (n (append (sgml-dtd-eltypes sgml-dtd-info) '())
+		   ;; Space avoids possible clash with valid element.
+		   (setq tab (cons "Any " (cons "--" tab))))
+	  (when (and (symbolp n) (not (memq n tab)))
+	    (push (symbol-name n) tab))))
     (or tab
 	(error "No valid %s at this point" type))
-    (or
-     (sgml-popup-menu event
-		      title
-		      (mapcar (function (lambda (x) (cons x x)))
-			      tab))
-     (message nil))))
+    (let ((elt (sgml-popup-menu event
+				title
+				(mapcar (function (lambda (x) (cons x x)))
+					tab))))
+      (if (equal elt "Any ")
+	  (setq elt (sgml-read-element-name "Element: ")))
+      (or elt (message nil)))))
 
 (defun sgml-entities-menu (event)
   (interactive "*e")
 
 (defun sgml-make-attrib-menu (el)
   (let ((attlist (sgml-non-fixed-attributes (sgml-element-attlist el))))
+    (if (and (not attlist) sgml-dtd-less)
+      (let ((name
+	     (sgml-general-case
+	      (let ((completion-ignore-case sgml-namecase-general))
+		(completing-read
+		 "Attribute name: "
+		 (mapcar
+		  (lambda (a) (list (sgml-attdecl-name a)))
+		  (if sgml-dtd-less
+		      (sgml-tree-asl el)
+		    (sgml-non-fixed-attributes (sgml-element-attlist el))))
+		 nil (not sgml-dtd-less))))))
+	(if name
+	    (setq attlist (list (sgml-make-attdecl name 'CDATA nil))))))
     (or attlist
 	(error "No non-fixed attributes for element"))
     (loop for attdecl in attlist
 	   (xml-p sgml-xml-p))
       (switch-to-buffer-other-window
        (sgml-attribute-buffer element asl))
-      (sgml-edit-attrib-mode)
       (make-local-variable 'sgml-start-attributes)
       (setq sgml-start-attributes start)
       (make-local-variable 'sgml-always-quote-attributes)
       (setq buf (get-buffer-create bname))
       (set-buffer buf)
       (erase-buffer)
+      (sgml-edit-attrib-mode)
       (make-local-variable 'sgml-attlist)
       (setq sgml-attlist (sgml-effective-attlist
                           (sgml-element-eltype element)))
       (sgml-insert '(read-only t)
-		   "<%s  -- Edit values and finish with C-c C-c --\n"
-		   (sgml-element-name element))
+                   (substitute-command-keys
+                    "<%s  -- Edit values and finish with \
+\\[sgml-edit-attrib-finish], abort with \\[sgml-edit-attrib-abort] --\n")
+                   (sgml-element-name element))
       (loop
        for attr in sgml-attlist do
        ;; Produce text like
 	  ((and (null cur-value)
 		(or (memq def-value '(IMPLIED CONREF CURRENT))
 		    (sgml-default-value-attval def-value)))
-           (sgml-insert '(read-only t category sgml-form) " ")
-	   (sgml-insert '(category sgml-default rear-nonsticky (category)
-                                   read-only sgml-default)
+	   (sgml-insert '(read-only t category sgml-form
+				    rear-nonsticky (read-only category))
+			" ")
+	   (sgml-insert '(category sgml-default rear-nonsticky (category))
 			"#DEFAULT"))
 	  (t
            (sgml-insert '(read-only t category sgml-form
 
 (define-key sgml-edit-attrib-mode-map "\C-c\C-c" 'sgml-edit-attrib-finish)
 (define-key sgml-edit-attrib-mode-map "\C-c\C-d" 'sgml-edit-attrib-default)
-(define-key sgml-edit-attrib-mode-map "\C-c\C-k" 'sgml-edit-attrib-clear)
+(define-key sgml-edit-attrib-mode-map "\C-c\C-k" 'sgml-edit-attrib-abort)
 
 (define-key sgml-edit-attrib-mode-map "\C-a"  'sgml-edit-attrib-field-start)
 (define-key sgml-edit-attrib-mode-map "\C-e"  'sgml-edit-attrib-field-end)
   (use-local-map sgml-edit-attrib-mode-map)
   (run-hooks 'text-mode-hook 'sgml-edit-attrib-mode-hook))
 
+(defun sgml-edit-attrib-abort ()
+  "Abort the attribute editor, removing the window."
+  (interactive)
+  (let ((cb (current-buffer))
+	(start sgml-start-attributes))
+    (delete-windows-on cb)
+    (kill-buffer cb)
+    (when (markerp start)
+      (switch-to-buffer (marker-buffer start))
+      (goto-char start))))
 
 (defun sgml-edit-attrib-finish ()
   "Finish editing and insert attribute values in original buffer."
       (narrow-to-region (point)
 			(progn (sgml-edit-attrib-field-end)
 			       (point)))
+      (goto-char (point-min))
+      (while (not (eobp))
+        (if (eq 'sgml-default (get-text-property (point) 'category))
+            (delete-char 1)
+          (forward-char 1)))
       (unless (eq type 'CDATA)
 	(subst-char-in-region (point-min) (point-max) ?\n ? )
 	(goto-char (point-min))
   (interactive)
   (sgml-edit-attrib-clear)
   (save-excursion
-    (sgml-insert '(category sgml-default read-only sgml-default)
-		 "#DEFAULT"))
-  (let ((inhibit-read-only t))
-    (put-text-property (1- (point)) (point)
-                       'rear-nonsticky '(category))))
+    (sgml-insert '(category sgml-default rear-nonsticky (category))
+                 "#DEFAULT")))
 
 (defun sgml-edit-attrib-clear ()
   "Kill the value of current attribute."
 (defun sgml-edit-attrib-next ()
   "Move to next attribute value."
   (interactive)
-  (or (search-forward-regexp "^ *[_.:A-Za-z0-9---]+ *= ?" nil t)
+  (if (eq t (get-text-property (point) 'read-only))
+      (beginning-of-line 1))
+  (or (search-forward-regexp (if sgml-have-re-char-clases
+				 "^ *[-_.:[:alnum:]]+ *= ?"
+			       "^ *[-_.:A-Za-z0-9]+ *= ?") nil t)
       (goto-char (point-min))))
 
 
 ;;;; SGML mode: Hiding tags/attributes
 
 (defconst sgml-tag-regexp
-  "\\(</?>\\|</?[_A-Za-z][---_:A-Za-z0-9.]*\\(\\([^'\"></]\\|'[^']*'\\|\"[^\"]*\"\\)*\\)/?>?\\)")
+  (if sgml-have-re-char-clases
+      "\\(</?>\\|</?[_[:alpha:]][-_:[:alnum:].]*\\(\\([^'\"></]\\|'[^']*'\\|\"[^\"]*\"\\)*\\)/?>?\\)"
+    "\\(</?>\\|</?[_A-Za-z][-_:A-Za-z0-9.]*\\(\\([^'\"></]\\|'[^']*'\\|\"[^\"]*\"\\)*\\)/?>?\\)"))
 
 (defun sgml-operate-on-tags (action &optional attr-p)
   (let ((buffer-modified-p (buffer-modified-p))
 				      '(invisible nil)))
 	     (t (error "Invalid action: %s" action)))
 	    (incf tagcount)))
-      (set-buffer-modified-p buffer-modified-p))))
+      (sgml-restore-buffer-modified-p buffer-modified-p))))
 
 (defun sgml-hide-tags ()
   "Hide all tags in buffer."
 	       sgml-normalize-trims)
 	  (skip-chars-backward " \t\n\r"))
       (delete-char (sgml-tree-etag-len element))
+      ;; XEmacs change: use tempo
       (save-excursion (tempo-process-and-insert-string (sgml-end-tag-of element))))))
 
 
   "Convert character after point into a character reference.
 If called with a numeric argument, convert a character reference back
 to a normal character.  If called from a program, set optional
-argument INVERT to non-nil."
+argument INVERT to non-nil.  If the function `decode-char' is defined,
+convert to and from Unicode.  Otherwise will only work for ASCII or 8-bit
+characters in the current coding system."
   (interactive "*P")
   (cond
    (invert
 					      (match-end 1)))))
       (delete-region (match-beginning 0)
 		     (match-end 0))
+      (if (fboundp 'decode-char)	; Emacs 21, Mule-UCS
+	  (setq c (decode-char 'ucs c))
+	;; Else have to assume 8-bit character.
+	(if (fboundp 'unibyte-char-to-multibyte) ; Emacs 20
+	    (setq c (unibyte-char-to-multibyte c))))
       (insert c)))
    ;; Convert character to &#nn;
    (t
     (let ((c (following-char)))
       (delete-char 1)
+      (if (fboundp 'encode-char)
+	  (setq c (encode-char c 'ucs))
+	(if (fboundp 'multibyte-char-to-unibyte)
+	    (setq c (multibyte-char-to-unibyte c))))
       (insert (format "&#%d;" c))))))
 
 (defun sgml-expand-entity-reference ()
         (s (sgml-element-model el))
         (found nil))
     (loop do
-          (dolist (tok (nconc (sgml-optional-tokens s)
-                              (sgml-required-tokens s)))
-            (unless (memq tok found)
-              ;; tok is optional here and not already found -- check that
-              ;; it would not make the content invalid
-              (when (sgml--add-before-p tok s c)
-                  (push tok found))))
+	  ;; Fixme: this test avoids an error when DTD-less, but it's
+	  ;; probably an inappropriate kludge.  -- fx
+          (when (not (eq s 'ANY))
+	    (dolist (tok (nconc (sgml-optional-tokens s)
+				(sgml-required-tokens s)))
+	      (unless (memq tok found)
+		;; tok is optional here and not already found -- check that
+		;; it would not make the content invalid
+		(when (sgml--add-before-p tok s c)
+                  (push tok found)))))
           while c do
           (setq s (sgml-element-pstate c))
           (setq c (sgml-element-next c)))
 otherwise it will be added at the first legal position."
   (interactive
    (let ((tab
-          (mapcar (function (lambda (et) (cons (sgml-eltype-name et) nil)))
+          (mapcar (lambda (et) (cons (sgml-eltype-name et) nil))
                   (sgml--all-possible-elements
                    (sgml-find-context-of (point))))))
      (cond ((null tab)
 
 
 ;;; Code:
-(provide 'psgml-fs)
+(provide 'psgml-fs) ;; XEmacs change
 (require 'psgml-api)
+(eval-when-compile (require 'cl)
+		   (require 'ps-print))
 
 ;;;; Formatting parameters
 
   (sgml-pop-entity)
   (sit-for 0))
 
-(defun fs-element-content (&optional e)
-  (unless e (setq e (fs-element)))
-  (let ((fs-para-acc "") fs-first-indent fs-left-indent)
-    (sgml-map-content e
-		      (function fs-paraform-phrase)
-		      (function fs-paraform-data)
-		      nil
-		      (function fs-paraform-entity))
-    fs-para-acc))
-
 (defun fs-paraform-phrase (e)
   (sgml-map-content e
 		    (function fs-paraform-phrase)
 			(assq t fs-style)))))
 
 (defun fs-do-style (fs-current-element style)
-  (let ((hang-from (eval (getf style 'hang-from))))
+  (let ((hang-from (eval (plist-get style 'hang-from))))
     (when hang-from
       (setq fs-hang-from
 	    (format "%s%s "
 			collect (cons (car st)
 				      (eval (cadr st))))
 		  fs-char)))
-    (when (getf style 'block)
+    (when (plist-get style 'block)
       (fs-para)
-      (fs-addvspace (or (getf style 'top)
+      (fs-addvspace (or (plist-get style 'top)
 			(fs-char 'default-top))))
-    (let ((before (getf style 'before)))
+    (let ((before (plist-get style 'before)))
       (when before
 	(fs-do-style e before)))
-    (cond ((getf style 'text)
-	   (let ((text (eval (getf style 'text))))
-	     (when (stringp text)
-	       (fs-paraform-data text))))
-	  (t
-           (let ((fs-style
-                  (append (getf style 'sub-style)
-                          fs-style)))
+    (let ((fs-style
+           (append (plist-get style 'sub-style)
+                   fs-style)))
+      (cond ((plist-get style 'text)
+             (let ((text (eval (plist-get style 'text))))
+               (when (stringp text)
+                 (fs-paraform-data text))))
+            (t
              (sgml-map-content e
                                (function fs-engine)
                                (function fs-paraform-data)
                                nil
                                (function fs-paraform-entity)))))
-    (let ((title (getf style 'title)))
+    (let ((title (plist-get style 'title)))
       (when title
         (setq title (eval title))
         (save-excursion
           (set-buffer fs-buffer)
           (setq fs-title title))))
-    (let ((after (getf style 'after)))
+    (let ((after (plist-get style 'after)))
       (when after
 	(fs-do-style e after)))
-    (when (getf style 'block)
+    (when (plist-get style 'block)
       (fs-para)
-      (fs-addvspace (or (getf style 'bottom)
+      (fs-addvspace (or (plist-get style 'bottom)
 			(fs-char 'default-bottom))))))
 
+
+(defun fs-clear ()
+  (setq fs-para-acc ""
+        fs-hang-from nil
+        fs-first-indent nil
+        fs-left-indent nil
+        fs-vspace 0)  )
+
+
+(defun fs-setup-buffer ()
+  (save-excursion
+    (let ((orig-filename (buffer-file-name (current-buffer))))
+      (set-buffer fs-buffer)
+      (erase-buffer)
+      (setq ps-left-header
+            '(fs-title fs-filename))
+      (make-local-variable 'fs-filename)
+      (setq fs-filename (file-name-nondirectory orig-filename))
+      (make-local-variable 'fs-title)
+      (setq fs-title ""))))
+
+(defun fs-wrapper (buffer-name thunk)
+  (fs-clear)
+  (let ((fs-style (fs-get-style fs-style))
+        (fs-buffer (get-buffer-create buffer-name)))
+    (fs-setup-buffer)
+    (funcall thunk)
+    (fs-para)
+    (save-excursion
+      (set-buffer fs-buffer)
+      (goto-char (point-min)))
+    fs-buffer))
+
+
 ;;;###autoload
 (defun style-format ()
   (interactive)
-  (setq fs-para-acc ""
-        fs-hang-from nil
-        fs-first-indent nil
-        fs-left-indent nil
-        fs-vspace 0)
-  (let ((fs-style (fs-get-style fs-style))
-        (fs-buffer (get-buffer-create "*Formatted*")))
-    (save-excursion
-      (let ((orig-filename (buffer-file-name (current-buffer))))
-        (set-buffer fs-buffer)
-        (erase-buffer)
-        (setq ps-left-header
-              '(fs-title fs-filename))
-        (make-local-variable 'fs-filename)
-        (setq fs-filename (file-name-nondirectory orig-filename))
-        (make-local-variable 'fs-title)
-        (setq fs-title "")))
-    (display-buffer fs-buffer)
-    (fs-engine (sgml-top-element))
-    (fs-para)
-    (save-excursion
-      (set-buffer fs-buffer)
-      (goto-char (point-min)))))
+  (fs-wrapper  "*Formatted*"
+               (lambda ()
+                 (display-buffer fs-buffer)
+                 (fs-engine (sgml-top-element)))))
 
 
 ;;;; Helper functions for use in style sheet
         (child  (setq element (sgml-element-content element)))))
     element))
 
+(defun fs-element-content (&optional e)
+  (unless e (setq e (fs-element)))
+  (let ((fs-para-acc "") fs-first-indent fs-left-indent)
+    (sgml-map-content e
+		      (function fs-paraform-phrase)
+		      (function fs-paraform-data)
+		      nil
+		      (function fs-paraform-entity))
+    fs-para-acc))
 
 (defun fs-attval (name &optional element)
   (sgml-element-attval (if element element (fs-element))
         (let ((attlist (sgml-element-attlist element)))
           (loop for attdecl in attlist
                 if (eq 'ID (sgml-attdecl-declared-value attdecl))
-                do (if (equalp id (sgml-element-attval element
-                                                       (sgml-attdecl-name attdecl)))
+                ;; XEmacs change: use equalp if compare-strings not avaialable.
+                do (if (or (and (fboundp 'compare-strings)
+                                (compare-strings id nil nil
+                                                 (sgml-element-attval
+                                                  element
+                                                  (sgml-attdecl-name attdecl))
+                                                 nil nil))
+                           (equalp id (sgml-element-attval
+                                       element (sgml-attdecl-name attdecl))))
                        (return-from func element))))
         ;; Next element
         (if (sgml-element-content element)
           (setq element (sgml-element-next element)))))
     nil))
 
+
+(defun fs-split-tokens (s)
+  "Split a string S into a list of tokens."
+  (let ((result nil))
+    (sgml-push-to-string s)
+    (while (not (eobp))
+      (skip-syntax-forward "-")
+      (let ((start (point)))
+        (skip-syntax-forward "^-")
+        (when (/= start (point))
+          (push (buffer-substring-no-properties start (point))
+                result))))
+    (sgml-pop-entity)
+    (nreverse result)))
+
 
 ;;; fs.el ends here
 
 (defconst sgml-attr-col 18)
 
+(eval-when-compile (require 'cl))
 
 ;;;; Utility functions
 
 		    (sgml-pstate-dtd sgml-buffer-parse-state)
 		    t))
 
+
+(defun sgml-set-difference (l1 l2)
+  (if (or (null l1) (null l2))
+      l1
+    (let ((res nil))
+      (while l1
+	(or (member (car l1)
+		   l2)
+	    (push (car l1) res))
+	(pop l1))
+      res)))
+
+(defun sgml-union (l1 l2)
+  (cond ((null l1) l2) ((null l2) l1)
+	((equal l1 l2) l1)
+	(t
+	 (or (>= (length l1) (length l2))
+	     (setq l1 (prog1 l2 (setq l2 l1))))
+	 (while l2
+	   (or (member (car l2) l1)
+	       (push (car l2) l1))
+	   (pop l2))
+	 l1)))
+
 (defun sgml-eltype-refrenced-elements (eltype)
   "List of element types referenced in the model of ELTYPE."
   ;; Now with cache. Uses appdata prop re-cache.
 	   (loop for dfa in (sgml-and-node-dfas (car agenda)) do
 		 (sgml-add-last-unique dfa states))))
 	 (setq agenda (cdr agenda)))
-       (setq res (sort (copy-seq (set-difference
-                                  (union res (sgml-eltype-includes eltype))
-                                  (sgml-eltype-excludes eltype)))
-		       (function string-lessp)))
+       (setq res
+             (sort (copy-sequence (sgml-set-difference
+                                   (sgml-union res (sgml-eltype-includes eltype))
+                                   (sgml-eltype-excludes eltype)))
+                   (function string-lessp)))
        (setf (sgml-eltype-appdata eltype 're-cache) res)
        res)))))
 
 ;;;; Code:
 
 (require 'psgml)
+(require 'psgml-sysdep)
 
 ;;; Interface to psgml-dtd
 (eval-and-compile
   (autoload 'sgml-write-dtd	     "psgml-dtd")
   (autoload 'sgml-check-dtd-subset   "psgml-dtd") )
 
+(eval-when-compile (require 'cl))
+
 
 ;;;; Advise to do-auto-fill
 
 This is nil if no previous node.")
 
 (defvar sgml-last-buffer nil
-  "Buffer where last parse was ended. Used for restarting parser at the
-point where it left off.")
+  "Buffer where last parse was ended.
+Used for restarting parser at the point where it left off.")
 
 (defvar sgml-markup-type nil
 "Contains the type of markup parsed last.
 (defvar sgml-current-element-name nil
   "Name of current element for mode line display.")
 (make-variable-buffer-local 'sgml-current-element-name)
+
+(defvar sgml-dtd-less nil
+  "Non-nil means the document doesn't have a DTD.
+Applicable to XML.")
+(make-variable-buffer-local 'sgml-dtd-less)
 
 ;;;; Build parser syntax table
 
          (setq sgml-last-buffer (current-buffer))
          (set-buffer cb)
 	 (set-syntax-table normal-syntax-table)
-         (set-buffer-modified-p buffer-modified)
+         (sgml-restore-buffer-modified-p buffer-modified)
          (sgml-debug "Restoring buffer mod: %s" buffer-modified)))))
 
+(defun sgml-set-buffer-multibyte (flag)
+  (cond (running-xemacs
+         flag)
+        ((and (boundp 'emacs-major-version) (>= emacs-major-version 20))
+         (set-buffer-multibyte
+          (if (eq flag 'default)
+              default-enable-multibyte-characters
+            flag)))
+	((boundp 'MULE)
+         (set 'mc-flag flag))
+        (t
+         flag)))
+;; Probably better.  -- fx
+;; (eval-and-compile
+;;   (if (fboundp 'set-buffer-multibyte)
+;;       (defalias 'sgml-set-buffer-multibyte
+;; 	(if (fboundp 'set-buffer-multibyte)
+;; 	    'set-buffer-multibyte
+;; 	  'identity))))
+
 
 ;;;; State machine
 
 The default value is either a symbol (REQUIRED | IMPLIED | CURRENT |
 CONREF) or a list with first element nil or symbol `FIXED' and second
 element the value."
-  (caddr attdecl))
+  (car (cddr attdecl)))
 
 
 ;;; attlist representation = (attspec*)
 
 ;;; Element type objects
 
-(defun sgml-eltype-name (et)
+(defsubst sgml-eltype-name (et)
   (symbol-name et))
 
-(define-compiler-macro sgml-eltype-name (et)
-  (`(symbol-name (, et))))
-
-(defun sgml-eltype-defined (et)
+(defsubst sgml-eltype-defined (et)
   (fboundp et))
 
-(defun sgml-eltype-token (et)
-  "Return a token for the element type"
+(defsubst sgml-eltype-token (et)
+  "Return a token for the element type."
   et)
 
-(define-compiler-macro sgml-eltype-token (et)
-  et)
-
-(defun sgml-token-eltype (token)
+(defsubst sgml-token-eltype (token)
   "Return the element type corresponding to TOKEN."
   token)
 
-(define-compiler-macro sgml-token-eltype (token)
-  token)
-
 (defmacro sgml-prop-fields (&rest names)
   (cons
    'progn
 
 
 (defun sgml-eltype-stag-optional (et)
-  (oddp (sgml-eltype-flags et)))