Debian Codegraph @

docs/user/emacs.rst

raw
1 .. -*- coding: utf-8 -*-
2
3 .. include:: ../header.rst
4
5 ========================================
6 Emacs Support for reStructuredText
7 ========================================
8
9 :Authors: Stefan Merten <[email protected]>, Martin Blais
10 <[email protected]>
11 :Version: ``rst.el`` V1.4.1
12 :Abstract:
13
14 High-level description of the existing Emacs_ support for editing
15 reStructuredText_ text documents. Suggested setup code and usage
16 instructions are provided.
17
18 .. contents::
19
20 Introduction
21 ============
22
23 reStructuredText_ is a syntax for simple text files that allows a
24 tool set - docutils_ - to extract generic document structure. For
25 people who use Emacs_, there is a package that adds a major mode that
26 supports editing the syntax of reStructuredText_: ``rst.el``. This
27 document describes the features it provides, and how to setup your
28 Emacs_ to use them and how to invoke them.
29
30 Installation
31 ============
32
33 Emacs_ support for reStructuredText_ is implemented as an Emacs_ major
34 mode (``rst-mode``) provided by the ``rst.el`` Emacs_ package.
35
36 Emacs_ distributions contain ``rst.el`` since version V23.1. However,
37 a significantly updated version of ``rst.el`` is contained in Emacs_
38 V24.3. This document describes the version of ``rst.el`` contained in
39 Emacs_ V24.3 and later versions. This version of ``rst.el`` has the
40 internal version V1.4.1.
41
42 If you have Emacs_ V24.3 or later you do not need to install anything
43 to get reST support. If you have an Emacs_ between V23.1 and V24.2 you
44 may use the version of ``rst.el`` installed with Emacs_ or install a
45 more recent one locally_ (recommended). In other cases you need to
46 install ``rst.el`` locally_ to get reST support.
47
48 Checking situation
49 ------------------
50
51 Here are some steps to check your situation:
52
53 #. In Emacs_ switch to an empty buffer and try ::
54
55 M-x rst-mode
56
57 If this works you have ``rst.el`` installed somewhere. You can see
58 that it works if you find a string ``ReST`` in Emacs' modeline of
59 the current buffer. If this doesn't work you need to install
60 ``rst.el`` yourself locally_.
61
62 #. In the buffer you just switched to ``rst-mode`` try ::
63
64 C-h v rst-version
65
66 If this fails you have a version of ``rst.el`` older than
67 V1.1.0. Either you have an old ``rst.el`` locally or you are using
68 an Emacs_ between V23.1 and V24.2. In this case it is recommended
69 that you install a more recent version of ``rst.el`` locally_.
70
71 You may also try ::
72
73 C-h v emacs-version
74
75 to find out your Emacs_ version.
76
77 #. Check the version of ``rst.el``
78
79 The content of ``rst-version`` gives you the internal version of
80 ``rst.el``. The version contained in Emacs_ V24.3 and described here
81 is V1.4.0. If you have an older version you may or may not install
82 a more recent version of ``rst.el`` locally_.
83
84 .. _locally:
85
86 Local installation
87 ------------------
88
89 If you decided to install locally please follow these steps.
90
91 #. Download ``rst.el``
92
93 Download the most recent published version of ``rst.el`` from
94 https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/tools/editors/emacs/rst.el
95
96 #. Put ``rst.el`` to a directory in ``load-path``
97
98 Use ::
99
100 C-h v load-path
101
102 If in the resulting list you find a directory in your home
103 directory put ``rst.el`` in this directory.
104
105 Make sure the directory is one of the first entries in
106 ``load-path``. Otherwise a version of ``rst.el`` which came with
107 Emacs_ may be found before your local version.
108
109 In Emacs_ see the info node ``Init File Examples`` for more
110 information on how to set up your Emacs_ initialization
111 machinery. Try ::
112
113 C-h i
114 mEmacs<Return>
115 sInit File Examples<Return>
116
117 #. Enable ``rst-mode``
118
119 Add the following to your Emacs_ initialization setup ::
120
121 (require 'rst)
122
123 After you restarted Emacs_ ``rst.el`` is loaded and ready to be
124 used.
125
126 Switching ``rst-mode`` on
127 -------------------------
128
129 By default ``rst-mode`` is switched on for files ending in ``.rst`` or
130 ``.rest``. If in a buffer you want to switch ``rst-mode`` on manually
131 use ::
132
133 M-x rst-mode
134
135 If you want to use ``rst-mode`` in files with other extensions modify
136 ``auto-mode-alist`` to automatically turn it on whenever you visit
137 reStructuredText_ documents::
138
139 (setq auto-mode-alist
140 (append '(("\\.txt\\'" . rst-mode)
141 ("\\.rst\\'" . rst-mode)
142 ("\\.rest\\'" . rst-mode)) auto-mode-alist))
143
144 Put the extensions you want in the correct place in the example
145 above. Add more lines if needed.
146
147 If have local variables enabled (try ``C-h v enable-local-variables``
148 to find out), you can also add the following at the top of your
149 documents to trigger rst-mode::
150
151 .. -*- mode: rst -*-
152
153 Or this at the end of your documents::
154
155 ..
156 Local Variables:
157 mode: rst
158 End:
159
160 Key bindings
161 ============
162
163 ``rst-mode`` automatically binds several keys for invoking special
164 functions for editing reStructuredText_. Since ``rst-mode`` contains a
165 lot of functionality most key bindings consist of three
166 keystrokes.
167
168 Following the Emacs_ conventions for major modes the key bindings of
169 ``rst-mode`` start with ``C-c C-<letter>``. The second key stroke
170 selects a group of key bindings:
171
172 C-c C-a
173 Commands to adjust the section headers and work with the hierarchy
174 they build.
175
176 C-c C-c
177 Commands to compile the current reStructuredText_ document to
178 various output formats.
179
180 C-c C-l
181 Commands to work with lists of various kinds.
182
183 C-c C-r
184 Commands to manipulate the current region.
185
186 C-c C-t
187 Commands to create and manipulate a table of contents.
188
189 At any stage of typing you may use ``C-h`` to get help on the
190 available key bindings. I.e. ``C-c C-h`` gives you help on all key
191 bindings while ``C-c C-r C-h`` gives you help on the commands for
192 regions. This is handy if you forgot a certain key binding.
193
194 Additional key bindings which have a certain meaning in other Emacs_
195 modes are reused in ``rst-mode`` so you don't have to learn a
196 different set of key bindings for editing reStructuredText_.
197
198 In ``rst-mode`` try ::
199
200 C-h m
201
202 to list all mode specific key bindings. Most of the key bindings are
203 described in this tutorial.
204
205 .. note:: The key bindings have been completely revamped in ``rst.el``
206 V1.0.0. This was necessary to make room for new
207 functionality. Some of the old bindings still work but give
208 a warning to use the new binding. In the output of ``C-h m``
209 these bindings show up as ``rst-deprecated-...``. The old
210 bindings will be removed completely in a later version.
211
212 Section Adornments
213 ==================
214
215 ``rst-mode`` recognizes the section adornments building the section
216 hierarchy of the document. Section adornments are the underlines or
217 under- and overlines used to mark a section title. There are a couple
218 of commands to work with section adornments. These commands are bound
219 to key bindings starting with ``C-c C-a``.
220
221 Adjusting a Section Title
222 -------------------------
223
224 There is a function that helps a great deal to maintain these
225 adornments: ``rst-adjust`` (bound to ``C-c C-a C-a``, ``C-c C-=``, and
226 ``C-=``). This function is a Swiss army knife that can be invoked
227 repeatedly and whose behavior depends on context:
228
229 #. If there is an incomplete adornment, e.g. ::
230
231 My Section Title
232 ==
233
234 invocation will complete the adornment. It can also be used to
235 adjust the length of the existing adornment when you need to edit
236 the title.
237
238 #. If there is no section adornment at all, by default an adornment of
239 the same level as the last encountered section level is added. You
240 can simply enter a few characters of the title and invoke the
241 function to create the section adornment.
242
243 The variable ``rst-new-adornment-down`` can be customized to create
244 one level lower adornments than the previous section title instead
245 of keeping the level.
246
247 #. If there is already a section adornment, it is promoted one level
248 up. You can invoke it like this repeatedly to cycle the title
249 through the hierarchy of existing adornments.
250
251 Invoking the function with a negative prefix argument, e.g. ``C--
252 C-=``, will effectively reverse the direction of adornment cycling.
253 To alternate between underline-only and over-and-under styles, you can
254 use a regular prefix argument, e.g. ``C-u C-=``. See the
255 documentation of ``rst-adjust`` for more description of the prefix
256 arguments to alter the behavior of the function.
257
258 Promoting and Demoting Many Sections
259 ------------------------------------
260
261 When you are re-organizing the structure of a document, it can be
262 useful to change the level of a number of section titles. The same
263 key binding can be used to do that: if the region is active when the
264 binding is invoked, all the section titles that are within the region
265 are promoted accordingly (or demoted, with negative prefix argument).
266
267 Redoing All the Adornments to Your Taste
268 ----------------------------------------
269
270 If you open someone else's file and the adornments it contains are
271 unfamiliar, you may want to readjust them to fit your own preferred
272 hierarchy of adornments. This can be difficult to perform by hand.
273 However, you can do this easily by invoking
274 ``rst-straighten-adornments`` (``C-c C-a C-s``), which operates on the
275 entire buffer.
276
277 Customizations for Adornments
278 -----------------------------
279
280 You can customize the variable ``rst-preferred-adornments`` to a list
281 of the adornments that you like to use for documents.
282
283 If you prefer adornments according to
284 http://sphinx-doc.org/rest.html#sections you may customize it to end
285 up with a value like this::
286
287 ((35 over-and-under 0) ; ?#
288 (42 over-and-under 0) ; ?*
289 (61 simple 0) ; ?=
290 (45 simple 0) ; ?-
291 (94 simple 0) ; ?^
292 (34 simple 0)) ; ?"
293
294 This will become the default in a later version of ``rst.el``.
295
296 If you set ``rst-preferred-adornments`` to nil resembling the empty
297 list only the section adornment found in the buffer will be used.
298
299 Viewing the Hierarchy of Section Adornments
300 -------------------------------------------
301
302 You can visualize the hierarchy of the section adornments in the
303 current buffer by invoking ``rst-display-adornments-hierarchy``, bound
304 on ``C-c C-a C-d``. A temporary buffer will appear with fake section
305 titles rendered in the style of the current document. This can be
306 useful when editing other people's documents to find out which section
307 adornments correspond to which levels.
308
309 Movement and Selection
310 ======================
311
312 Movement and Selection for Sections
313 -----------------------------------
314
315 You can move the cursor between the different section titles by using
316 the ``rst-backward-section`` (``C-M-a``) and ``rst-forward-section``
317 (``C-M-e``). To mark the section that cursor lies in, use
318 ``rst-mark-section`` (``C-M-h``).
319
320 The key bindings are modeled after other modes with similar
321 functionality.
322
323 Movements and Selection for Text Blocks
324 ---------------------------------------
325
326 The understanding of reStructuredText_ of ``rst-mode`` is used to set
327 all the variables influencing Emacs' understanding of paragraphs. Thus
328 all operations on paragraphs work as usual. For instance
329 ``forward-paragraph`` (``M-}``) works as usual.
330
331 Indenting and Filling
332 =====================
333
334 Indentation of text plays a major role in the syntax of
335 reStructuredText_. It is tedious to maintain the indentation
336 manually. ``rst-mode`` understands most of the structure of
337 reStructuredText_ allowing for sophisticated indentation and filling
338 support described in this section.
339
340 Indenting Text Blocks
341 ---------------------
342
343 ``rst-mode`` supports indentation of text blocks by the command
344 ``rst-shift-region`` (``C-c C-r TAB``). Mark a region and use ``C-c
345 C-r TAB`` to indent all blocks one tab to the right. Use ``M-- C-c C-r
346 TAB`` to indent the region one tab to the left.
347
348 You may use arbitrary prefix arguments such as ``M-2`` or ``M-- 2`` to
349 determine the number of tabs you want to indent. A prefix of ``M-0``
350 removes all indentation in the active region.
351
352 A tab is an indentation making sense for the block at hand in
353 reStructuredText_ syntax. In some cases the exact indentation depends
354 on personal taste. You may customize a couple of variables ``M-x
355 customize-group<RET> rst-indent<RET>`` to match your taste.
356
357 Indenting Lines While Typing
358 ----------------------------
359
360 In Emacs_ the ``TAB`` key is often used for indenting the current
361 line. ``rst-mode`` implements this for the sophisticated indentation
362 rules of reStructuredText_. Pressing ``TAB`` cycles through the
363 possible tabs for the current line. In the same manner
364 ``newline-and-indent`` (``C-j``) indents the new line properly.
365
366 This is very handy while writing lists. Consider this
367 reStructuredText_ bullet list with the cursor at ``@``::
368
369 * Level 1
370
371 * Level 2@
372
373 Type ``C-j`` twice to get this::
374
375 * Level 1
376
377 * Level 2
378
379 @
380
381 Now you an enter text at this level, or start a new list item by
382 typing another ``*``. Or you may type ``TAB`` to reduce the
383 indentation once::
384
385 * Level 1
386
387 * Level 2
388
389 @
390
391 Typing another ``TAB`` gets you to the first level::
392
393 * Level 1
394
395 * Level 2
396
397 @
398
399 .. note:: Since Emacs_ V24.4 ``electric-indent-mode`` is globally on.
400 This breaks indentation in ``rst-mode`` and renders
401 ``rst-mode`` mostly useless. This is fixed in V1.4.1 of
402 ``rst-mode``.
403
404 A quick fix for older versions of ``rst.el`` is to add the
405 following line at the end of the ``(define-derived-mode
406 rst-mode ...`` block in your copy of ``rst.el``::
407
408 (setq electric-indent-inhibit t)
409
410 You may also install V1.4.1 or newer locally_.
411
412 Filling
413 -------
414
415 ``rst-mode`` understanding the indentation rules of reStructuredText_
416 also supports filling paragraphs. Just use ``fill-paragraph``
417 (``M-q``) as you do in other modes.
418
419 Operating on Lists
420 ==================
421
422 Lists are supported in various flavors in reStructuredText_.
423 ``rst-mode`` understands reStructuredText_ lists and offers some
424 support for operating on lists. Key bindings for commands for
425 operating on lists start with ``C-c C-l``.
426
427 Please note that so far definition lists are not explicitly supported
428 by ``rst-mode``.
429
430 Bulleted and Enumerated Lists
431 -----------------------------
432
433 If you have a couple of plain lines you want to turn into an
434 enumerated list you can invoke ``rst-enumerate-region`` (``C-c C-l
435 C-e``). For example, the following region ::
436
437 Apples
438
439 Oranges
440
441 Bananas
442
443 becomes ::
444
445 1. Apples
446
447 2. Oranges
448
449 3. Bananas
450
451 ``rst-bullet-list-region`` (``C-c C-l C-b``) does the same, but
452 results in a bullet list ::
453
454 * Apples
455
456 * Oranges
457
458 * Bananas
459
460 By default, each paragraph starting on the leftmost line in the
461 highlighted region will be taken to be a single list or enumeration
462 item, for example, enumerating the following::
463
464 An apple a day
465 keeps the doctor away.
466
467 But oranges
468 are tastier than apples.
469
470 If you preferred bananas
471 you may be
472 a monkey.
473
474 Will result in::
475
476 1. An apple a day
477 keeps the doctor away.
478
479 2. But oranges
480 are tastier than apples.
481
482 3. If you preferred bananas
483 you may be
484 a monkey.
485
486 If you would like to enumerate each of the lines, use a prefix
487 argument on the preceding commands, e.g.::
488
489 Apples
490 Oranges
491 Bananas
492
493 becomes::
494
495 * Apples
496 * Oranges
497 * Bananas
498
499 Straightening Existing Bullet List Hierarchies
500 ----------------------------------------------
501
502 If you invoke ``rst-straighten-bullets-region`` (``C-c C-l C-s``), the
503 existing bullets in the active region will be replaced to reflect
504 their respective level. This does not make a difference in the
505 document structure that reStructuredText_ defines, but looks better
506 in, for example, if all of the top-level bullet items use the
507 character ``-``, and all of the 2nd level items use ``*``, etc.
508
509 Inserting a List Item
510 ---------------------
511
512 To start a new list you may invoke ``rst-insert-list`` (``C-c C-l
513 C-i``). You may choose from an item style supported by
514 reStructuredText_.
515
516 You may also invoke ``rst-insert-list`` at the end of a list item. In
517 this case it inserts a new line containing the markup for the a list
518 item on the same level.
519
520 Operating on Other Text Blocks
521 ==============================
522
523 Creating and Removing Line Blocks
524 ---------------------------------
525
526 To create line blocks, first select the region to convert and invoke
527 ``rst-line-block-region`` ``C-c C-r C-l``. For example, the following
528 ::
529
530 Apples
531 Oranges
532 Bananas
533
534 becomes ::
535
536 | Apples
537 | Oranges
538 | Bananas
539
540 This works even if the region is indented. To remove line blocks,
541 select a region and invoke with a prefix argument.
542
543 Commenting a Region of Text
544 ---------------------------
545
546 ``rst-mode`` understands reStructuredText_ comments. Use
547 ``comment-dwim`` (``M-;``) to work on comments as usual::
548
549 Apples
550 Oranges
551 Bananas
552
553 becomes::
554
555 ..
556 Apples
557 Oranges
558 Bananas
559
560 To remove a comment you have to tell this to ``comment-dwim``
561 explicitly by using a prefix argument (``C-u M-;``).
562
563 Please note that only indented comments are supported properly by the
564 parts of ``comment-dwim`` working on regions.
565
566 .. _Conversion:
567
568 Converting Documents from Emacs
569 ===============================
570
571 ``rst-mode`` provides a number of functions for running documents
572 being edited through the docutils tools. The key bindings for these
573 commands start with ``C-c C-c``.
574
575 The main generic function is ``rst-compile`` (``C-c C-c C-c``). It
576 invokes a compilation command with the correct output name for the
577 current buffer and then invokes Emacs' compile function. It also looks
578 for the presence of a ``docutils.conf`` configuration file in the
579 parent directories and adds it to the command line options. There is also
580 ``rst-compile-alt-toolset`` (``C-c C-c C-a``) in case you often need
581 run your document in a second toolset.
582
583 You can customize the commands being used by setting
584 ``rst-compile-primary-toolset`` and ``rst-compile-secondary-toolset``.
585
586 Other commands are available for other formats:
587
588 * ``rst-compile-pseudo-region`` (``C-c C-c C-x``)
589
590 When crafting documents, it is often convenient to view which data
591 structures docutils will parse them into. You can use to run the
592 active region through ``rst2pseudoxml`` and have the output
593 automatically be displayed in a new buffer.
594
595 * ``rst-compile-pdf-preview`` (``C-c C-c C-p``)
596
597 Convert the current document to PDF and launch a viewer on the
598 results.
599
600 * ``rst-compile-slides-preview`` (``C-c C-c C-s``): Convert the
601 current document to S5 slides and view in a web browser.
602
603 Imenu Support
604 =============
605
606 Using Imenu
607 -----------
608
609 Emacs_ has a package called ``imenu``. ``rst-mode`` supports Imenu by
610 adding a function to convert the structure of a reStructuredText_
611 buffer to an Imenu index. Thus you can use invoke ``imenu`` (``M-x
612 imenu``) to navigate through the section index or invoke
613 ``imenu-add-to-menubar`` (``M-x imenu-add-to-menubar``) to add an
614 Imenu menu entry to Emacs' menu bar.
615
616 Using which function
617 --------------------
618
619 As a side effect of Imenu support the ``which-func`` package is also
620 supported. Invoke ``which-function-mode`` (``M-x
621 which-function-mode``) to add the name of the current section to the
622 mode line. This is especially useful if you navigate through documents
623 with long sections which do not fit on a single screen.
624
625 Using the Table of Contents
626 ===========================
627
628 The sections in a reStructuredText_ document can be used to form a
629 table of contents. ``rst-mode`` can work with such a table of contents
630 in various forms. Key bindings for these commands start with ``C-c
631 C-t``.
632
633 Navigating Using the Table of Contents
634 --------------------------------------
635
636 When you are editing long documents, it can be a bit difficult to
637 orient yourself in the structure of your text. To that effect, a
638 function is provided that presents a hierarchically indented table of
639 contents of the document in a temporary buffer, in which you can
640 navigate and press ``Return`` to go to a specific section.
641
642 Invoke ``rst-toc`` (``C-c C-t C-t``). It presents a temporary buffer
643 that looks something like this::
644
645 Table of Contents:
646 Debugging Meta-Techniques
647 Introduction
648 Debugging Solution Patterns
649 Recognize That a Bug Exists
650 Subdivide and Isolate
651 Identify and Verify Assumptions
652 Use a Tool for Introspection
653 Change one thing at a time
654 Learn about the System
655 Understanding a bug
656 The Basic Steps in Debugging
657 Attitude
658 Bad Feelings
659 Good Feelings
660 References
661
662 When you move the cursor to a section title and press ``RET`` or ``f``
663 or click with ``button1`` on a section title, the temporary buffer
664 disappears and you are left with the cursor positioned at the chosen
665 section. Clicking with ``button2`` jumps to the respective section but
666 keeps the toc buffer. You can use this to look at the various section
667 headers quickly. Use ``q`` in this buffer to just quit it without
668 moving the cursor in the original document. Use ``z`` to zap the
669 buffer altogether.
670
671 Inserting a Table of Contents
672 -----------------------------
673
674 Oftentimes in long text documents that are meant to be read directly,
675 a table of contents is inserted at the beginning of the text. In
676 reStructuredText_ documents, since the table of contents is
677 automatically generated by the parser with the ``.. contents::``
678 directive, people generally have not been adding an explicit table of
679 contents to their source documents, and partly because it is too much
680 trouble to edit and maintain.
681
682 The Emacs_ support for reStructuredText_ provides a function to insert
683 such a table of contents in your document. Since it is not meant to
684 be part of the document text, you should place such a table of
685 contents within a comment, so that it is ignored by the parser. This
686 is the favored usage::
687
688 .. contents::
689 ..
690 1 Introduction
691 2 Debugging Solution Patterns
692 2.1 Recognize That a Bug Exists
693 2.2 Subdivide and Isolate
694 2.3 Identify and Verify Assumptions
695 2.4 Use a Tool for Introspection
696 2.5 Change one thing at a time
697 2.6 Learn about the System
698 3 Understanding a bug
699 4 The Basic Steps in Debugging
700 5 Attitude
701 5.1 Bad Feelings
702 5.2 Good Feelings
703 6 References
704
705 Just place the cursor at the top-left corner where you want to insert
706 the TOC and invoke the function ``rst-toc-insert`` with ``C-c C-t
707 C-i``. The table of contents will display all the section titles that
708 are under the location where the insertion occurs. This way you can
709 insert local table of contents by placing them in the appropriate
710 location.
711
712 You can use a numeric prefix argument to limit the depth of rendering
713 of the TOC.
714
715 You can customize the look of the TOC by setting the values of the
716 following variables: ``rst-toc-indent``, ``rst-toc-insert-style``,
717 ``rst-toc-insert-max-level``.
718
719 Maintaining the Table of Contents Up-to-date
720 --------------------------------------------
721
722 One issue is that you will probably want to maintain the inserted
723 table of contents up-to-date. ``rst-toc-update`` (``C-c C-t C-u``)
724 will automatically update an inserted table of contents following a
725 ``.. contents::`` directive laid out like the example above.
726
727 Syntax Highlighting via Font-Lock
728 =================================
729
730 ``rst-mode`` provides syntax highlighting for nearly all to
731 reStructuredText_ constructs.
732
733 Use ``customize-group rst-faces`` to customize the faces used for
734 font-locking.
735
736 Customization
737 =============
738
739 Some aspects of ``rst-mode`` can be configured through the
740 customization feature of Emacs_. Try ::
741
742 M-x customize-group<RETURN>rst
743
744 for all customizations or use the respective menu entry. Those
745 customizations which are useful for many people are described in this
746 section.
747
748 Customizing Section Title Formatting
749 ------------------------------------
750
751 For a couple of things the reStructuredText_ syntax offers a choice of
752 options on how to do things exactly. Some of these choices influence
753 the operation of ``rst.el`` and thus can be configured. The
754 customizations are contained in the ``rst-adjust`` group.
755
756 Among these things is the exact layout of section adornments. In fact
757 reStructuredText_ prescribes only the characters and how these
758 characters must be used but the exact use of concrete adornments may
759 be different in every source file. Using the customization option
760 ``rst-preferred-adornments`` you can tell ``rst-mode`` on the exact
761 sequence of adornments you prefer to markup the different levels of
762 sections headers.
763
764 Finally the title text of over-and-under adornments may be indented in
765 reStructuredText_. ``rst-default-indent`` tells ``rst-mode`` how many
766 positions a over-and-under adornment should be indented when toggling
767 from simple adornment and in case a consistent indentation throughout
768 the whole buffer for such adornment is needed.
769
770 Customizing Indentation
771 -----------------------
772
773 reStructuredText_ uses indentation a lot to signify a certain meaning.
774 In some cases the exact amount of indentation is prescribed by the
775 syntax while in some cases the exact indentation is not fixed. The
776 customization group ``rst-indent`` allows to customize the amount of
777 indentation in these cases.
778
779 In field lists the content of a field needs to be indented relative to
780 the field label. ``rst-indent-field`` tells ``rst-mode`` the amount of
781 indentation to use for field content. A value of zero always indents
782 according to the content after the field label.
783
784 The indentation of literal blocks is controlled by
785 ``rst-indent-literal-normal`` and ``rst-indent-literal-minimized``.
786 The first is used when the leading literal tag (``::``) appears alone
787 on a line. The second is used when the minimized style is used where
788 the literal tag follows some text.
789
790 The indentation of comments is controlled by ``rst-indent-comment``.
791 Of course this makes only sense for the indented comments of
792 reStructuredText_.
793
794 Customization option ``rst-indent-width`` gives the default
795 indentation when there are no other hints on what amount of
796 indentation to use.
797
798 Customizing Faces
799 -----------------
800
801 The faces used for font-locking can be defined in the ``rst-faces``
802 customization group. The customization options ending in ``-face`` are
803 only there for backward compatibility so please leave them as they
804 are.
805
806 reStructuredText_ sets no limit on the nesting of sections. By default
807 there are six levels of fontification defined. Section titles deeper
808 than six level have no special fontification - only the adornments are
809 fontified. The exact mapping from a level to a face is done by by
810 ``rst-adornment-faces-alist``, however. So if you need fontification
811 deeper than six levels you may want to customize this option. You may
812 also want to customize it if you like the general idea of section
813 title fontification in ``rst-mode`` but for instance prefer a reversed
814 order.
815
816 Customizing Conversion
817 ----------------------
818
819 Conversion_ can be customized by the customization options in the
820 customization group ``rst-compile``.
821
822 If some conversion does not work as expected please check
823 the variable ``rst-compile-toolsets`` ::
824
825 M-x customize-option<RETURN>rst-compile-toolsets
826
827 This variable defines the commands and other details used for
828 conversion. In case of problems please check that the commands are
829 either available or customize them to what is available in your
830 environment.
831
832 .. note:: There are some options in V1.4.1 of ``rst.el`` which should
833 be customization options but are not yet. Customization
834 support will be added in a later version.
835
836 .. note:: Please note that there is a package ``rst2pdf`` based on the
837 ReportLab library. Please note that the command of this
838 package requires an additional ``-o`` for naming the output
839 file. This breaks the usual conventions employed by Docutils
840 tools. ``rst-mode`` V1.4.1 does not support this directly.
841
842 Other Customizations
843 --------------------
844
845 ``rst-preferred-bullets`` can be customized to hold your preferred set
846 of bullets to use for bulleted lists.
847
848 ``rst-mode-hook`` is a normal major mode hook which may be customized.
849 It is run if you enter ``rst-mode``.
850
851 Related aspects
852 ===============
853
854 This section covers some general aspects using Emacs_ for editing
855 reStructuredText_ source. They are not directly related to
856 ``rst-mode`` but may enhance your experience.
857
858 ``text-mode`` Settings
859 ----------------------
860
861 Consult the Emacs_ manual for more ``text-mode`` customizations. In
862 particular, you may be interested in setting the following variables,
863 functions and modes that pertain somewhat to ``text-mode``:
864
865 * ``indent-tabs-mode``
866 * ``colon-double-space``
867 * ``sentence-end-double-space``
868 * ``auto-fill-mode``
869 * ``auto-mode-alist``
870
871 Editing Tables: Emacs table mode
872 --------------------------------
873
874 You may want to check out `Emacs table mode`_ to create an edit
875 tables, it allows creating ASCII tables compatible with
876 reStructuredText_.
877
878 .. _Emacs table mode: http://table.sourceforge.net/
879
880 Character Processing
881 --------------------
882
883 Since reStructuredText punts on the issue of character processing,
884 here are some useful resources for Emacs_ users in the Unicode world:
885
886 * `xmlunicode.el and unichars.el from Norman Walsh
887 <http://nwalsh.com/emacs/xmlchars/index.html>`__
888
889 * `An essay by Tim Bray, with example code
890 <http://www.tbray.org/ongoing/When/200x/2003/09/27/UniEmacs>`__
891
892 * For Emacs_ users on Mac OS X, here are some useful useful additions
893 to your .emacs file.
894
895 - To get direct keyboard input of non-ASCII characters (like
896 "option-e e" resulting in "é" [eacute]), first enable the option
897 key by setting the command key as your meta key::
898
899 (setq mac-command-key-is-meta t) ;; nil for option key
900
901 Next, use one of these lines::
902
903 (set-keyboard-coding-system 'mac-roman)
904 (setq mac-keyboard-text-encoding kTextEncodingISOLatin1)
905
906 I prefer the first line, because it enables non-Latin-1 characters
907 as well (em-dash, curly quotes, etc.).
908
909 - To enable the display of all characters in the Mac-Roman charset,
910 first create a fontset listing the fonts to use for each range of
911 characters using charsets that Emacs_ understands::
912
913 (create-fontset-from-fontset-spec
914 "-apple-monaco-medium-r-normal--10-*-*-*-*-*-fontset-monaco,
915 ascii:-apple-monaco-medium-r-normal--10-100-75-75-m-100-mac-roman,
916 latin-iso8859-1:-apple-monaco-medium-r-normal--10-100-75-75-m-100-mac-roman,
917 mule-unicode-0100-24ff:-apple-monaco-medium-r-normal--10-100-75-75-m-100-mac-roman")
918
919 Latin-1 doesn't cover characters like em-dash and curly quotes, so
920 "mule-unicode-0100-24ff" is needed.
921
922 Next, use that fontset::
923
924 (set-frame-font "fontset-monaco")
925
926 - To enable cooperation between the system clipboard and the Emacs_
927 kill ring, add this line::
928
929 (set-clipboard-coding-system 'mac-roman)
930
931 Other useful resources are in `Andrew Choi's Emacs 21 for Mac OS X
932 FAQ <http://members.shaw.ca/akochoi-emacs/stories/faq.html>`__.
933
934 Credits
935 =======
936
937 Part of the original code of ``rst.el`` has been written by Martin
938 Blais and David Goodger and Wei-Wei Guo. The font-locking came from
939 Stefan Merten.
940
941 Most of the code has been modified, enhanced and extended by Stefan
942 Merten who also is the current maintainer of ``rst.el``.
943
944 .. _Emacs: https://www.gnu.org/software/emacs/emacs.html
945 .. _reStructuredText: https://docutils.sourceforge.io/rst.html
946 .. _Docutils: https://docutils.sourceforge.io/
947
948 .. Emacs settings
949
950 LocalWords: reST utf Merten Blais rst el docutils modeline emacs
951 LocalWords: Init mEmacs sInit alist setq txt overlines RET nd py
952 LocalWords: dwim conf toolset pseudoxml pdf Imenu imenu menubar
953 LocalWords: func toc xmlunicode unichars eacute charset fontset
954 LocalWords: kTextEncodingISOLatin charsets monaco ascii latin
955 LocalWords: iso unicode Choi's Goodger Guo
956
957 Local Variables:
958 mode: rst
959 indent-tabs-mode: nil
960 fill-column: 70
961 End: