help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SGML/XML major mode in files that do not declare a DOCTYPE


From: Xah
Subject: Re: SGML/XML major mode in files that do not declare a DOCTYPE
Date: Sun, 13 Jul 2008 04:21:52 -0700 (PDT)
User-agent: G2/1.0

> What's the best way to get the XML or the SGML major mode working when
> editing chapter1.xml? I haven't had much luck Googling this.

assuming that what you wanted is to get emacs to load the proper mode
when you open your xml file.

The file suffix “.xml” should work though.

also, you might try nxml-mode and nxhtml-mode based on it. This is the
replacement for the emacs aged html/xml modes based on its sgml mode.

here's more detail:
--------------------

Emacs determines what mode to use primarily by 2 mechanisms, in order:
(1) Check the first line in the file, using “magic-mode-alist”. (2)
Check the file name's suffix, using “auto-mode-alist”.

The “magic-mode-alist” is a list that emacs use to match the first
line of a file with a mode. For example, if you want files that begin
with the line “<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...” to
always use nxml-mode, then add the following to your “.emacs”:

(add-to-list
 'magic-mode-alist
 '("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0" . nxml-mode))

The magic-mode-alist is a list. In the above example, the string with
the “DOCTYPE” is a regex, used to match the first line of a file.

If emacs goes thru magic-mode-alist and didn't find any match, then
it'll use auto-mode-alist to check on file name suffix. The “auto-mode-
alist” associates a file name suffix with a mode. For example, if you
want files ending in “.js” to always open with js2-mode, then do:

(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))

Note: The double backslash in the string “\\.js\\'” is used to escape
the backslash. So, the regex engine just got “\.js\'”. The “\.” is to
match a period. The “\'” is one of emacs special regex syntax, to
match end of a string. (See also: Text Pattern Matching in Emacs)

the above is from
How To Install Emacs Packages
 http://xahlee.org/emacs/emacs_installing_packages.html

  Xah
∑ http://xahlee.org/

☄

On Jul 12, 7:26 pm, Sam <s...@email-scan.com> wrote:
> I split up large XML documents by placing large chunks into separate files,
> then declare them as entities:
>
> <!ENTITY chapter1 SYSTEM "chapter1.xml">
>
> My understanding is that chapter1.xml should not declare its own DOCTYPE. I
> have a single DOCTYPE in the main XML document, which includes all these
> entity definitions. However, when editing chapter1.xml, the XML and the SGML
> major modes do not work, since the file lacks its own DOCTYPE declaration.
>
> What's the best way to get the XML or the SGML major mode working when
> editing chapter1.xml? I haven't had much luck Googling this.
>
>  application_pgp-signature_part
> 1KDownload



reply via email to

[Prev in Thread] Current Thread [Next in Thread]