[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: turning on SGML mode
Re: turning on SGML mode
Fri, 13 Mar 2020 09:38:04 +0100
On Thu, Mar 12, 2020 at 10:01:14PM +0100, Ulrich Deiters wrote:
> Dear all,
> I abuse Emacs for my typesetting, i.e., I use Emacs with the psgml
> extension to edit XML documents (where Emacs gives me context-dependent
> menus and automatic syntax checks), translate the XML file to LaTeX,
> and convert the outcome to PDF.
> My XML file starts with
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE book SYSTEM "$ATXHOME/xml/book.dtd">
> and I invoke Emacs by
> emacs -l $ATXHOME/interface/cfg_emacs.el -geometry +0+0
> where cfg_emacs.el contains definitions of menu points etc.
> My problem: Whenever I start Emacs, I need to enter
> ESC x sgml-mode
> manually. I tried to add
> (setq-default major-mode 'sgml-mode)
Since Emacs is made to edit many different kinds of files, there's
no "one major mode" to be in. But there's a way to decide which
major mode to set depending on a multitude of factors.
See the chapter "Choosing File Modes" in your Emacs manual for
all the gory details, which you can find online around here .
In a nutshell, Emacs looks at the content of the file's first
line(s) for a hint on what this file is; failing that it looks
then at the file name.
You have a few choices here: the "first line tag", i.e. sneaking
"-*- mode: psgml -*-" whithin the first line seems out (or at
least somewhat ugly) because the first line is already taken up
by the XML "cookie".
Secondly, you might want to customize your variable "magic-mode-alist",
which is a list of pairs associating a regular expression (to
match the file's beginning) to a major mode. This looks like a
good candidate, since your second line "...<DOCTYPE book-..."
seems pretty distinctive. Just ask here if you need more support
Thirdly, you can match the file name (not just the "ending", or
"suffix") to a pattern and decide on that (cf. "auto-mode-alist".
Personally I don't very much care for this way of doing things,
which is a relict from Good Old DOS (TM): not every file called
"foo.xml" on your system will want the same treatment. But this
(anti-) pattern is widespread enough that people expect it to
work. I feel strongly about this, but hey, that's just me :-)
The first choice mentioned above has a very powerful sister,
which is the "file variables" thing: you can hide, at the
end of the file, a whole parameter block which not only
specifies which mode to use -- but other stuff (like how
to call your SGML processor or what not). Somewhat advanced,
but incredibly powerful. Just ask.
Description: Digital signature