unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: turning on SGML mode
Date: Fri, 13 Mar 2020 09:38:04 +0100	[thread overview]
Message-ID: <20200313083804.GA12641@tuxteam.de> (raw)
In-Reply-To: <a09a1fd5-8190-6dd6-2205-4e59264b03de@uni-koeln.de>

[-- Attachment #1: Type: text/plain, Size: 2744 bytes --]

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">
> <article>
> …
> 
> 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 [1].

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
on that.

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.

Cheers
[1] https://www.gnu.org/software/emacs/manual/html_node/emacs/Choosing-Modes.html#Choosing-Modes
-- tomás

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

      parent reply	other threads:[~2020-03-13  8:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 21:01 turning on SGML mode Ulrich Deiters
2020-03-12 22:12 ` Stefan Monnier
2020-03-13  0:12   ` Ulrich Deiters
2020-03-13  0:26 ` Perry Smith
2020-03-13 16:06   ` Ulrich Deiters
2020-03-13  8:38 ` tomas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200313083804.GA12641@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).