aboutsummaryrefslogtreecommitdiff
path: root/en_US.ISO8859-1/books/fdp-primer/psgml-mode/chapter.xml
blob: 3f2177820fa5baa836fb174f77f98d14c0f7f21f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Copyright (c) 1998, 1999 Nik Clayton, All rights reserved.

     Redistribution and use in source (SGML DocBook) and 'compiled' forms
     (SGML HTML, PDF, PostScript, RTF and so forth) with or without
     modification, are permitted provided that the following conditions
     are met:

      1. Redistributions of source code (SGML DocBook) must retain the above
         copyright notice, this list of conditions and the following
         disclaimer as the first lines of this file unmodified.

      2. Redistributions in compiled form (transformed to other DTDs,
         converted to PDF, PostScript, RTF and other formats) must reproduce
         the above copyright notice, this list of conditions and the
         following disclaimer in the documentation and/or other materials
         provided with the distribution.

     THIS DOCUMENTATION IS PROVIDED BY NIK CLAYTON "AS IS" AND ANY EXPRESS OR
     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     DISCLAIMED. IN NO EVENT SHALL NIK CLAYTON BE LIABLE FOR ANY DIRECT,
     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE
     POSSIBILITY OF SUCH DAMAGE.

-->
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:id="psgml-mode">
  <title>Using <literal>sgml-mode</literal> with
    <application>Emacs</application></title>

  <para>Recent versions of <application>Emacs</application> (available
    from the Ports Collection) contain a very useful package called
    PSGML (can be installed from <package>editors/psgml</package>).
    Automatically invoked when a file with the
    <filename>.xml</filename> extension is loaded, or by typing
    <command>M-x sgml-mode</command>, it is a major mode for dealing
    with SGML files, elements and attributes.</para>

  <para>An understanding of some of the commands provided by this mode
    can make working with SGML documents such as the Handbook much
    easier.</para>

  <variablelist>
    <varlistentry>
      <term><command>C-c C-e</command></term>

      <listitem>
	<para>Runs <function>sgml-insert-element</function>.  You will
	  be prompted for the name of the element to insert at the
	  current point.  You can use the <keycap>Tab</keycap> key to
	  complete the element.  Elements that are not valid at the
	  current point will be disallowed.</para>

	<para>The start and end tags for the element will be inserted.
	  If the element contains other, mandatory, elements then
	  these will be inserted as well.</para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><command>C-c =</command></term>

      <listitem>
	<para>Runs <function>sgml-change-element-name</function>.
	  Place the point within an element and run this command.  You
	  will be prompted for the name of the element to change to.
	  Both the start and end tags of the current element will be
	  changed to the new element.</para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><command>C-c C-r</command></term>

      <listitem>
	<para>Runs <function>sgml-tag-region</function>. Select some
	  text (move to start of text, <command>C-space</command>,
	  move to end of text, <command>C-space</command>) and then
	  run this command.  You will be prompted for the element to
	  use.  This element will then be inserted immediately before
	  and after your marked region.</para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><command>C-c -</command></term>

      <listitem>
	<para>Runs <function>sgml-untag-element</function>.  Place the
	  point within the start or end tag of an element you want to
	  remove, and run this command.  The element's start and end
	  tags will be removed.</para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><command>C-c C-q</command></term>

      <listitem>
	<para>Runs <function>sgml-fill-element</function>.  Will
	  recursively fill (i.e., reformat) content from the current
	  element in.  The filling <emphasis>will</emphasis> affect
	  content in which whitespace is significant, such as within
	  <tag>programlisting</tag> elements, so run this
	  command with care.</para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><command>C-c C-a</command></term>

      <listitem>
	<para>Runs <function>sgml-edit-attributes</function>.  Opens a
	  second buffer containing a list of all the attributes for
	  the closest enclosing element, and their current values.
	  Use <keycap>Tab</keycap> to navigate between attributes,
	  <command>C-k</command> to remove an existing value and
	  replace it with a new one, <command>C-c C-c</command> to
	  close this buffer and return to the main document.</para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><command>C-c C-v</command></term>

      <listitem>
	<para>Runs <function>sgml-validate</function>. Prompts you to
	  save the current document (if necessary) and then runs an
	  SGML validator.  The output from the validator is captured
	  into a new buffer, and you can then navigate from one
	  troublespot to the next, fixing markup errors as you
	  go.</para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><command>C-c /</command></term>

      <listitem>
	<para>Runs <function>sgml-insert-end-tag</function>.  Inserts
	  the end tag for the current open element.</para>
      </listitem>
    </varlistentry>
  </variablelist>

  <para>Doubtless there are other useful functions of this mode, but
    those are the ones I use most often.</para>

  <para>You can also use the following entries in
    <filename>.emacs</filename> to set proper spacing, indentation,
    and column width for working with the Documentation
    Project.</para>

  <programlisting>    (defun local-sgml-mode-hook
      (setq fill-column 70
            indent-tabs-mode nil
            next-line-add-newlines nil
            standard-indent 4
            sgml-indent-data t)
      (auto-fill-mode t)
      (setq sgml-catalog-files '("/usr/local/share/xml/catalog")))
    (add-hook 'psgml-mode-hook
      '(lambda () (local-psgml-mode-hook)))</programlisting>
</chapter>