28 Jul 2004 11:44
Re: rendering PCDATA in xml documents
Peter Heslin <usenet <at> heslin.eclipse.co.uk>
2004-07-28 09:44:31 GMT
2004-07-28 09:44:31 GMT
On 2004-07-26, James Clark <jjc <at> auth-only.jclark.com> wrote: > If you've got an XML file containing JavaScript, it seems like a very > reasonable to want to be able to use the facilities of javascript mode > to edit the embedded JavaScript, and similarly for other kinds of PCDATA > which have a specialized mode. For want it's worth, I've written a package called nxml-script.el to help with this. It uses narrowing rather than mmm-mode, and it's nothing fancy, but it works for me. You can find it here: http://www.dur.ac.uk/p.j.heslin/emacs/download/nxml-script.el > I haven't yet tried mmm-mode. I found it to be very brittle. I tried to get mmm-mode working with nxml and failed, which led to my writing nxml-script.el. The current Emacs etc/TODO file says this: ** Implement a clean way to use different major modes for different parts of a buffer. This could be useful in editing Bison input files, for instance, or other kinds of text where one language is embedded in another language. This implies to me that the Emacs maintainers do not regard the current implementation of mmm-mode as "clean" and would like to provide something better. I would be wary of having nxml-mode depend on a third-party package that is notoriously fiddly, and that is implicitly deprecated. > > I can see a couple of problems with making a general purpose mode work > for XML: > > a) I want to be able to specify which mode is used for PCDATA at the XML > level rather than in terms of regexes in the buffer. For example, I want > to be able to specify that the content of an element with a specific > namespace URI and local name should use a particular mode. > > b) I don't want to be forced to use CDATA sections. I want Emacs to > understand that the JavaScript code isn't simply a substring of the XML > buffer, but rather a substring of the buffer after substitution of > character/entity references. This seems not so easy. Perhaps you could > have a separate, temporary buffer for each PCDATA fragment, which would > use the appropriate mode for that fragment. You would arrange you could > edit either the XML or the temporary buffer and the temporary buffer > would always be equal to the result of replacing character/entity > references in the corresponding fragment of XML. Then you would have a > command in XML mode to switch to the temporary buffer, and I guess a > minor mode in the temporary buffer to maintain synchronization with the > XML and to provide a command to switch back to the XML. Does mmm-mode > deal with the escaping issue? I very much doubt mmm-mode deals with escaping. Here's an idea suggested by the implementation of nxml-script.el. You have a function that narrows the buffer to the content of the element, unescapes it, and switches to the relevant major mode. Then another function escapes the narrowed text, widens to the whole buffer, and switches back to nxml-mode. It's not ideal, but better than temporary buffers, I think -- no synchronization issues. > > What kind of UI would people like to see for dealing with embedded > PCDATA which has its own Emacs major mode? It may be that, since support for this sort of multiple major-mode functionality is marginal in Emacs, the implementation will be constrained by what is possible to achieve cleanly. Peter ------------------------ Yahoo! Groups Sponsor --------------------~--> Yahoo! Domains - Claim yours for only $14.70 http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/2U_rlB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/emacs-nxml-mode/ <*> To unsubscribe from this group, send an email to: emacs-nxml-mode-unsubscribe <at> yahoogroups.com <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
RSS Feed