Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / textmodes / rst.el
index fdd3585..5527fdf 100644 (file)
@@ -1,6 +1,6 @@
 ;;; rst.el --- Mode for viewing and editing reStructuredText-documents.
 
-;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+;; Copyright (C) 2003-2011
 ;;   Free Software Foundation, Inc.
 
 ;; Authors: Martin Blais <blais@furius.ca>,
 ;;; Code:
 
 \f
-(defgroup rst nil "Support for reStructuredText documents"
+(defgroup rst nil "Support for reStructuredText documents."
   :group 'wp
   :version "23.1"
   :link '(url-link "http://docutils.sourceforge.net/rst.html"))
     (define-key map [(control c) (?5)] 'rst-compile-slides-preview)
 
     map)
-  "Keymap for ReStructuredText mode commands.
+  "Keymap for reStructuredText mode commands.
 This inherits from Text mode.")
 
 
 ;; Abbrevs.
 (defvar rst-mode-abbrev-table nil
-  "Abbrev table used while in rst mode.")
+  "Abbrev table used while in Rst mode.")
 (define-abbrev-table 'rst-mode-abbrev-table
-  '(
-    ("contents" ".. contents::\n..\n   " nil 0)
-    ("con" ".. contents::\n..\n   " nil 0)
-    ("cont" "[...]" nil 0)
-    ("skip" "\n\n[...]\n\n  " nil 0)
-    ("seq" "\n\n[...]\n\n  " nil 0)
-    ;; FIXME: Add footnotes, links, and more.
-    ))
+  (mapcar (lambda (x) (append x '(nil 0 system)))
+          '(("contents" ".. contents::\n..\n   ")
+            ("con" ".. contents::\n..\n   ")
+            ("cont" "[...]")
+            ("skip" "\n\n[...]\n\n  ")
+            ("seq" "\n\n[...]\n\n  ")
+            ;; FIXME: Add footnotes, links, and more.
+            )))
 
 
 ;; Syntax table.
@@ -344,44 +344,45 @@ This inherits from Text mode.")
 
 
 (defcustom rst-mode-hook nil
-  "Hook run when Rst Mode is turned on.
-The hook for Text Mode is run before this one."
+  "Hook run when Rst mode is turned on.
+The hook for Text mode is run before this one."
   :group 'rst
   :type '(hook))
 
 
 (defcustom rst-mode-lazy t
-  "*If non-nil Rst Mode tries to font-lock multi-line elements correctly.
+  "If non-nil Rst mode tries to font-lock multi-line elements correctly.
 Because this is really slow it should be set to nil if neither `jit-lock-mode'
 not `lazy-lock-mode' and activated.
 
 If nil, comments and literal blocks are font-locked only on the line they start.
 
-The value of this variable is used when Rst Mode is turned on."
+The value of this variable is used when Rst mode is turned on."
   :group 'rst
   :type '(boolean))
 
 ;; Use rst-mode for *.rst and *.rest files.  Many ReStructured-Text files
 ;; use *.txt, but this is too generic to be set as a default.
-;;;###autoload (add-to-list 'auto-mode-alist '("\\.re?st\\'" . rst-mode))
+;;;###autoload (add-to-list 'auto-mode-alist (purecopy '("\\.re?st\\'" . rst-mode)))
 ;;;###autoload
 (define-derived-mode rst-mode text-mode "ReST"
-  :abbrev-table rst-mode-abbrev-table
-  :syntax-table rst-mode-syntax-table
-  :group 'rst
   "Major mode for editing reStructuredText documents.
-
+\\<rst-mode-map>
 There are a number of convenient keybindings provided by
-rst-mode. The main one is \[rst-adjust\], it updates or rotates
+Rst mode.  The main one is \\[rst-adjust], it updates or rotates
 the section title around point or promotes/demotes the
-decorations within the region (see full details below). Use
-negative prefix arg to rotate in the other direction.
-\\{rst-mode-map}
+decorations within the region (see full details below).
+Use negative prefix arg to rotate in the other direction.
+
+Turning on `rst-mode' calls the normal hooks `text-mode-hook'
+and `rst-mode-hook'.  This mode also supports font-lock
+highlighting.  You may customize `rst-mode-lazy' to toggle
+font-locking of blocks.
 
-Turning on `rst-mode' calls the normal hooks `text-mode-hook' and
-`rst-mode-hook'. This mode also supports font-lock highlighting.
-You may customize `rst-mode-lazy' to toggle font-locking of
-blocks."
+\\{rst-mode-map}"
+  :abbrev-table rst-mode-abbrev-table
+  :syntax-table rst-mode-syntax-table
+  :group 'rst
 
   (set (make-local-variable 'paragraph-separate) paragraph-start)
   (set (make-local-variable 'indent-line-function) 'indent-relative-maybe)
@@ -448,10 +449,9 @@ With no argument, this command toggles the mode.
 Non-null prefix argument turns on the mode.
 Null prefix argument turns off the mode.
 
-When ReST minor mode is enabled, the ReST mode
-keybindings are installed on top of the major
-mode bindings. Use this for modes derived from
-text-mode, like mail-mode.."
+When ReST minor mode is enabled, the ReST mode keybindings
+are installed on top of the major mode bindings.  Use this
+for modes derived from Text mode, like Mail mode."
  ;; The initial value.
  nil
  ;; The indicator for the mode line.
@@ -555,8 +555,7 @@ text-mode, like mail-mode.."
 ;; that has been found previously).
 
 (defgroup rst-adjust nil
-  "Settings for adjustment and cycling of section title
-decorations."
+  "Settings for adjustment and cycling of section title decorations."
   :group 'rst
   :version "21.1")
 
@@ -580,7 +579,7 @@ title in the file."
 (defcustom rst-default-indent 1
   "Number of characters to indent the section title.
 
-THis is used for when toggling decoration styles, when switching
+This is used for when toggling decoration styles, when switching
 from a simple decoration style to a over-and-under decoration
 style."
   :group 'rst-adjust)
@@ -594,13 +593,13 @@ style."
   "Return true if the line is homogeneous.
 
 Predicate that returns the unique char if the current line is
-composed only of a single repeated non-whitespace character.  This
-returns the char even if there is whitespace at the beginning of
-the line.
+composed only of a single repeated non-whitespace character.
+This returns the char even if there is whitespace at the
+beginning of the line.
 
 If ACCEPT-SPECIAL is specified we do not ignore special sequences
 which normally we would ignore when doing a search on many lines.
-For example, normally we have cases to ignore commonly occuring
+For example, normally we have cases to ignore commonly occurring
 patterns, such as :: or ...; with the flag do not ignore them."
   (save-excursion
     (back-to-indentation)
@@ -632,9 +631,9 @@ See `rst-line-homogeneous-p' about ACCEPT-SPECIAL."
 
 (defun rst-compare-decorations (deco1 deco2)
   "Compare decorations.
-Returns true if both DECO1 and DECO2 decorations are equal,
+Return true if both DECO1 and DECO2 decorations are equal,
 according to restructured text semantics (only the character and
-the style are compared, the indentation does not matter."
+the style are compared, the indentation does not matter)."
   (and (eq (car deco1) (car deco2))
        (eq (cadr deco1) (cadr deco2))))
 
@@ -642,7 +641,7 @@ the style are compared, the indentation does not matter."
 (defun rst-get-decoration-match (hier deco)
   "Return the index (level) in hierarchy HIER of decoration DECO.
 This basically just searches for the item using the appropriate
-comparison and returns the index.  We return nil if the item is
+comparison and returns the index.  Return nil if the item is
 not found."
   (let ((cur hier))
     (while (and cur (not (rst-compare-decorations (car cur) deco)))
@@ -653,9 +652,9 @@ not found."
 (defun rst-suggest-new-decoration (alldecos &optional prev)
   "Suggest a new, different decoration from all that have been seen.
 
-ALLDECOS is the set of all decorations, including the line
-numbers.  PREV is the optional previous decoration, in order to
-suggest a better match."
+ALLDECOS is the set of all decorations, including the line numbers.
+PREV is the optional previous decoration, in order to suggest a
+better match."
 
   ;; For all the preferred decorations...
   (let* (
@@ -689,21 +688,19 @@ suggest a better match."
 (defun rst-update-section (char style &optional indent)
   "Unconditionally update the style of a section decoration.
 
-Do this using the given character CHAR, with STYLE 'simple or
-'over-and-under, and with indent INDENT.  If the STYLE is
-'simple, whitespace before the title is removed (indent is always
-assume to be 0).
+Do this using the given character CHAR, with STYLE 'simple
+or 'over-and-under, and with indent INDENT.  If the STYLE
+is 'simple, whitespace before the title is removed (indent
+is always assumed to be 0).
 
 If there are existing overline and/or underline from the
 existing decoration, they are removed before adding the
 requested decoration."
 
   (interactive)
-  (let (marker
-        len)
-
       (end-of-line)
-      (setq marker (point-marker))
+  (let ((marker (point-marker))
+        len)
 
       ;; Fixup whitespace at the beginning and end of the line
       (if (or (null indent) (eq style 'simple))
@@ -790,7 +787,7 @@ This function does not detect the hierarchy of decorations, it
 just finds all of them in a file.  You can then invoke another
 function to remove redundancies and inconsistencies."
 
-  (let (positions
+  (let ((positions ())
         (curline 1))
     ;; Iterate over all the section titles/decorations in the file.
     (save-excursion
@@ -859,19 +856,19 @@ is one) is not taken into account when building the hierarchy."
   "Get the decoration at POINT.
 
 Looks around point and finds the characteristics of the
-decoration that is found there.  We assume that the cursor is
+decoration that is found there.  Assumes that the cursor is
 already placed on the title line (and not on the overline or
 underline).
 
 This function returns a (char, style, indent) triple.  If the
-characters of overline and underline are different, we return
-the underline character.  The indent is always calculated.  A
-decoration can be said to exist if the style is not nil.
+characters of overline and underline are different, return
+the underline character.  The indent is always calculated.
+decoration can be said to exist if the style is not nil.
 
 A point can be specified to go to the given location before
 extracting the decoration."
 
-  (let (char style indent)
+  (let (char style)
     (save-excursion
       (if point (goto-char point))
       (beginning-of-line)
@@ -880,10 +877,10 @@ extracting the decoration."
                          (forward-line -1)
                          (rst-line-homogeneous-nodent-p)))
 
-                (under (save-excursion
-                         (forward-line +1)
-                         (rst-line-homogeneous-nodent-p)))
-                )
+                 (under (save-excursion
+                          (forward-line +1)
+                          (rst-line-homogeneous-nodent-p)))
+                 )
 
             ;; Check that the line above the overline is not part of a title
             ;; above it.
@@ -911,23 +908,19 @@ extracting the decoration."
              ;; Both overline and underline.
              (t
               (setq char under
-                    style 'over-and-under))
-             )
-            )
-        )
-      ;; Find indentation.
-      (setq indent (save-excursion (back-to-indentation) (current-column)))
-      )
-    ;; Return values.
-    (list char style indent)))
+                    style 'over-and-under)))))
+      ;; Return values.
+      (list char style
+            ;; Find indentation.
+            (save-excursion (back-to-indentation) (current-column))))))
 
 
 (defun rst-get-decorations-around (&optional alldecos)
   "Return the decorations around point.
 
-Given the list of all decorations ALLDECOS (with positions), find
-the decorations before and after the given point.  A list of the
-previous and next decorations is returned."
+Given the list of all decorations ALLDECOS (with positions),
+find the decorations before and after the given point.
+A list of the previous and next decorations is returned."
   (let* ((all (or alldecos (rst-find-all-decorations)))
          (curline (line-number-at-pos))
          prev next
@@ -947,7 +940,7 @@ previous and next decorations is returned."
 
 
 (defun rst-decoration-complete-p (deco)
-  "Return true if the decoration DECO around POINT is complete."
+  "Return true if the decoration DECO around point is complete."
   ;; Note: we assume that the detection of the overline as being the underline
   ;; of a preceding title has already been detected, and has been eliminated
   ;; from the decoration that is given to us.
@@ -1014,9 +1007,9 @@ REVERSE-DIRECTION is used to reverse the cycling order."
 Adjust/rotate the section decoration for the section title
 around point or promote/demote the decorations inside the region,
 depending on if the region is active.  This function is meant to
-be invoked possibly multiple times, and can vary its behaviour
+be invoked possibly multiple times, and can vary its behavior
 with a positive prefix argument (toggle style), or with a
-negative prefix argument (alternate behaviour).
+negative prefix argument (alternate behavior).
 
 This function is the main focus of this module and is a bit of a
 swiss knife.  It is meant as the single most essential function
@@ -1042,7 +1035,7 @@ b. a negative numerical argument, which generally inverts the
   (interactive)
 
   (let* (;; Save our original position on the current line.
-        (origpt (set-marker (make-marker) (point)))
+        (origpt (point-marker))
 
         ;; Parse the positive and negative prefix arguments.
          (reverse-direction
@@ -1079,11 +1072,11 @@ decoration.")
 "Adjust/rotate the section decoration for the section title around point.
 
 This function is meant to be invoked possibly multiple times, and
-can vary its behaviour with a true TOGGLE-STYLE argument, or with
+can vary its behavior with a true TOGGLE-STYLE argument, or with
 a REVERSE-DIRECTION argument.
 
-General Behaviour
-=================
+General Behavior
+================
 
 The next action it takes depends on context around the point, and
 it is meant to be invoked possibly more than once to rotate among
@@ -1121,8 +1114,8 @@ The decorations consist in
 See source code for mode details.
 
 
-Detailed Behaviour Description
-==============================
+Detailed Behavior Description
+=============================
 
 Here are the gory details of the algorithm (it seems quite
 complicated, but really, it does the most obvious thing in all
@@ -1183,7 +1176,7 @@ of those decoration that has not been seen in the file yet (and
 not including the decoration around point), and the next
 invocation rolls over to the other end of the hierarchy (i.e. it
 cycles).  This allows you to avoid having to set which character
-to use by always using the
+to use.
 
 If REVERSE-DIRECTION is true, the effect is to change the
 direction of rotation in the hierarchy of decorations, thus
@@ -1212,7 +1205,7 @@ Indented section titles such as ::
    My Title
    --------
 
-are illegal in restructuredtext and thus not recognized by the
+are invalid in restructuredtext and thus not recognized by the
 parser.  This code will thus not work in a way that would support
 indented sections (it would be ambiguous anyway).
 
@@ -1371,9 +1364,9 @@ of the right hand fingers and the binding is unused in `text-mode'."
 (defun rst-promote-region (&optional demote)
   "Promote the section titles within the region.
 
-With argument DEMOTE or a prefix argument, demote the
-section titles instead.  The algorithm used at the boundaries of
-the hierarchy is similar to that used by `rst-adjust-decoration'."
+With argument DEMOTE or a prefix argument, demote the section
+titles instead.  The algorithm used at the boundaries of the
+hierarchy is similar to that used by `rst-adjust-decoration'."
   (interactive)
 
   (let* ((demote (or current-prefix-arg demote))
@@ -1396,31 +1389,28 @@ the hierarchy is similar to that used by `rst-adjust-decoration'."
     ;; Create a list of markers for all the decorations which are found within
     ;; the region.
     (save-excursion
-      (let (line)
+      (let (line)
         (while (and cur (< (setq line (caar cur)) region-end-line))
-          (setq m (make-marker))
-          (goto-line line)
-          (push (list (set-marker m (point)) (cdar cur)) marker-list)
+          (goto-char (point-min))
+          (forward-line (1- line))
+          (push (list (point-marker) (cdar cur)) marker-list)
           (setq cur (cdr cur)) ))
 
       ;; Apply modifications.
-      (let (nextdeco)
-        (dolist (p marker-list)
-          ;; Go to the decoration to promote.
-          (goto-char (car p))
-
-          ;; Rotate the next decoration.
-          (setq nextdeco (rst-get-next-decoration
-                          (cadr p) hier suggestion demote))
-
-          ;; Update the decoration.
-          (apply 'rst-update-section nextdeco)
-
-          ;; Clear marker to avoid slowing down the editing after we're done.
-          (set-marker (car p) nil)
-          ))
+      (dolist (p marker-list)
+        ;; Go to the decoration to promote.
+        (goto-char (car p))
+
+        ;; Update the decoration.
+        (apply 'rst-update-section
+               ;; Rotate the next decoration.
+               (rst-get-next-decoration
+                (cadr p) hier suggestion demote))
+
+        ;; Clear marker to avoid slowing down the editing after we're done.
+        (set-marker (car p) nil))
       (setq deactivate-mark nil)
-    )))
+      )))
 
 
 
@@ -1463,10 +1453,10 @@ in order to adapt it to our preferred style."
           (levels-and-markers (mapcar
                                (lambda (deco)
                                  (cons (rst-position (cdr deco) hier)
-                                       (let ((m (make-marker)))
-                                         (goto-line (car deco))
-                                         (set-marker m (point))
-                                         m)))
+                                       (progn
+                                         (goto-char (point-min))
+                                         (forward-line (1- (car deco)))
+                                          (point-marker))))
                                alldecos))
           )
       (dolist (lm levels-and-markers)
@@ -1498,7 +1488,8 @@ section levels."
       ;; adjust for the changes in the document.
       (dolist (deco (nreverse alldecos))
        ;; Go to the appropriate position.
-       (goto-line (car deco))
+       (goto-char (point-min))
+       (forward-line (1- (car deco)))
        (insert "@\n")
 ;; FIXME: todo, we
        )
@@ -1509,7 +1500,7 @@ section levels."
   "Find all the positions of prefixes in region between BEG and END.
 This is used to find bullets and enumerated list items.  PFX-RE
 is a regular expression for matching the lines with items."
-  (let (pfx)
+  (let ((pfx ()))
     (save-excursion
       (goto-char beg)
       (while (< (point) end)
@@ -1533,9 +1524,9 @@ is a regular expression for matching the lines with items."
   (format "\\([%s][ \t]\\)[^ \t]" (regexp-quote (concat rst-bullets)))
   "Regexp for finding bullets.")
 
-(defvar rst-re-enumerations
-  "\\(\\(#\\|[0-9]+\\)\\.[ \t]\\)[^ \t]"
-  "Regexp for finding bullets.")
+;; (defvar rst-re-enumerations
+;;   "\\(\\(#\\|[0-9]+\\)\\.[ \t]\\)[^ \t]"
+;;   "Regexp for finding bullets.")
 
 (defvar rst-re-items
   (format "\\(%s\\|%s\\)[^ \t]"
@@ -1610,7 +1601,7 @@ string and a marker to the section in the original text document.
 If there are missing section levels, the section titles are
 inserted automatically, and the title string is set to nil, and
 the marker set to the first non-nil child of itself.
-Conceptually, the nil nodes--i.e.  those which have no title--are
+Conceptually, the nil nodes--i.e. those which have no title--are
 to be considered as being the same line as their first non-nil
 child.  This has advantages later in processing the graph."
 
@@ -1629,13 +1620,13 @@ child.  This has advantages later in processing the graph."
     (save-excursion
       (setq lines
             (mapcar (lambda (deco)
-                      (goto-line (car deco))
+                      (goto-char (point-min))
+                      (forward-line (1- (car deco)))
                       (list (gethash (cons (cadr deco) (caddr deco)) levels)
                             (rst-get-stripped-line)
-                            (let ((m (make-marker)))
+                            (progn
                               (beginning-of-line 1)
-                              (set-marker m (point)))
-                            ))
+                              (point-marker))))
                     alldecos)))
 
     (let ((lcontnr (cons nil lines)))
@@ -1645,10 +1636,10 @@ child.  This has advantages later in processing the graph."
 (defun rst-section-tree-rec (decos lev)
   "Recursive guts of the section tree construction.
 DECOS is a cons cell whose cdr is the remaining list of
-decorations, and we change it as we consume them.  LEV is the
-current level of that node.  This function returns a pair of the
-subtree that was built.  This treats the decos list
-destructively."
+decorations, and we change it as we consume them.  LEV is
+the current level of that node.  This function returns a
+pair of the subtree that was built.  This treats the DECOS
+list destructively."
 
   (let ((ndeco (cadr decos))
         node
@@ -1684,9 +1675,9 @@ POINT (default being the current point in the current buffer),
 find and return the node within the sectree where the cursor
 lives.
 
-Return values: a pair of (parent path, container subtree).  The
-parent path is simply a list of the nodes above the container
-subtree node that we're returning."
+Return values: a pair of (parent path, container subtree).
+The parent path is simply a list of the nodes above the
+container subtree node that we're returning."
 
   (let (path outtree)
 
@@ -1784,16 +1775,16 @@ The TOC is inserted indented at the current column."
       (delete-region init-point (+ init-point (length initial-indent)))
 
       ;; Delete the last newline added.
-      (delete-backward-char 1)
+      (delete-char -1)
     )))
 
 (defun rst-toc-insert-node (node level indent pfx)
   "Insert tree node NODE in table-of-contents.
-Recursive function that does printing of the inserted toc.  LEVEL
-is the depth level of the sections in the tree.  INDENT bis the
-indentation string.  PFX is the prefix numbering, that includes
-the alignment necessary for all the children of level to
-align."
+Recursive function that does printing of the inserted toc.
+LEVEL is the depth level of the sections in the tree.
+INDENT is the indentation string.  PFX is the prefix numbering,
+that includes the alignment necessary for all the children of
+level to align."
 
   ;; Note: we do child numbering from the parent, so we start number the
   ;; children one level before we print them.
@@ -1864,7 +1855,7 @@ align."
 
 
 (defun rst-toc-insert-find-delete-contents ()
-  "Find and deletes an existing comment after the first contents directive.
+  "Find and delete an existing comment after the first contents directive.
 Delete that region.  Return t if found and the cursor is left after the comment."
   (goto-char (point-min))
   ;; We look for the following and the following only (in other words, if your
@@ -1955,8 +1946,8 @@ file-write hook to always make it up-to-date automatically."
 (defun rst-toc-count-lines (node target-node)
   "Count the number of lines from NODE to the TARGET-NODE node.
 This recursive function returns a cons of the number of
-additional lines that have been counted for its node and children
-and 't if the node has been found."
+additional lines that have been counted for its node and
+children, and t if the node has been found."
 
   (let ((count 1)
        found)
@@ -2020,7 +2011,8 @@ brings the cursor in that section."
     (set (make-local-variable 'rst-toc-return-buffer) curbuf)
 
     ;; Move the cursor near the right section in the TOC.
-    (goto-line line)
+    (goto-char (point-min))
+    (forward-line (1- line))
     ))
 
 
@@ -2045,7 +2037,7 @@ brings the cursor in that section."
     (recenter 5)))
 
 (defun rst-toc-mode-goto-section ()
-  "Go to the section the current line describes and kill the toc buffer."
+  "Go to the section the current line describes and kill the TOC buffer."
   (interactive)
   (rst-goto-section t))
 
@@ -2053,11 +2045,11 @@ brings the cursor in that section."
   "In `rst-toc' mode, go to the occurrence whose line you click on.
 EVENT is the input event."
   (interactive "e")
-  (let (pos)
+  (let ((pos
     (with-current-buffer (window-buffer (posn-window (event-end event)))
       (save-excursion
         (goto-char (posn-point (event-end event)))
-        (setq pos (rst-toc-mode-find-section))))
+             (rst-toc-mode-find-section)))))
     (pop-to-buffer (marker-buffer pos))
     (goto-char pos)
     (recenter 5)))
@@ -2135,13 +2127,14 @@ backwards in the file (default is to use 1)."
     ;; If the index is positive, goto the line, otherwise go to the buffer
     ;; boundaries.
     (if (and cur (>= idx 0))
-        (goto-line (car cur))
+        (progn
+          (goto-char (point-min))
+          (forward-line (1- (car cur))))
       (if (> offset 0) (goto-char (point-max)) (goto-char (point-min))))
     ))
 
 (defun rst-backward-section ()
-  "Like `rst-forward-section', except move back one title.
-With a prefix argument, move backward by a page."
+  "Like `rst-forward-section', except move back one title."
   (interactive)
   (rst-forward-section -1))
 
@@ -2301,8 +2294,8 @@ of (COLUMN-NUMBER . LINE) pairs."
 
 (defun rst-shift-region-guts (find-next-fun offset-fun)
   "(See `rst-shift-region-right' for a description)."
-  (let* ((mbeg (set-marker (make-marker) (region-beginning)))
-        (mend (set-marker (make-marker) (region-end)))
+  (let* ((mbeg (copy-marker (region-beginning)))
+        (mend (copy-marker (region-end)))
         (tabs (rst-compute-bullet-tabs mbeg))
         (leftmostcol (rst-find-leftmost-column (region-beginning) (region-end)))
         )
@@ -2381,8 +2374,8 @@ Also, if invoked with a negative prefix arg, the entire
 indentation is removed, up to the leftmost character in the
 region, and automatic filling is disabled."
   (interactive "P")
-  (let ((mbeg (set-marker (make-marker) (region-beginning)))
-       (mend (set-marker (make-marker) (region-end)))
+  (let ((mbeg (copy-marker (region-beginning)))
+       (mend (copy-marker (region-end)))
        (leftmostcol (rst-find-leftmost-column
                      (region-beginning) (region-end)))
        (rst-shift-fill-region
@@ -2416,8 +2409,7 @@ Set FIRST-ONLY to true if you want to callback on the first line
 of each paragraph only."
   `(save-excursion
     (let ((leftcol (rst-find-leftmost-column ,beg ,end))
-         (endm (set-marker (make-marker) ,end))
-         )
+         (endm (copy-marker ,end)))
 
       (do* (;; Iterate lines
            (l (progn (goto-char ,beg) (back-to-indentation))
@@ -2455,8 +2447,7 @@ first of a paragraph."
 
   `(save-excursion
      (let ((,leftmost (rst-find-leftmost-column ,beg ,end))
-          (endm (set-marker (make-marker) ,end))
-          )
+          (endm (copy-marker ,end)))
 
       (do* (;; Iterate lines
            (l (progn (goto-char ,beg) (back-to-indentation))
@@ -2533,9 +2524,7 @@ region to enumerated lists, renumbering as necessary."
   (let* (;; Find items and convert the positions to markers.
         (items (mapcar
                 (lambda (x)
-                  (cons (let ((m (make-marker)))
-                          (set-marker m (car x))
-                          m)
+                  (cons (copy-marker (car x))
                         (cdr x)))
                 (rst-find-pfx-in-region beg end rst-re-items)))
         (count 1)
@@ -2575,67 +2564,137 @@ With prefix argument set the empty lines too."
 
 (require 'font-lock)
 
-(defgroup rst-faces nil "Faces used in Rst Mode"
+(defgroup rst-faces nil "Faces used in Rst Mode."
   :group 'rst
   :group 'faces
   :version "21.1")
 
-(defcustom rst-block-face 'font-lock-keyword-face
+(defface rst-block '((t :inherit font-lock-keyword-face))
+  "Face used for all syntax marking up a special block."
+  :version "24.1"
+  :group 'rst-faces)
+
+(defcustom rst-block-face 'rst-block
   "All syntax marking up a special block."
+  :version "24.1"
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-block-face
+                        "customize the face `rst-block' instead."
+                        "24.1")
+
+(defface rst-external '((t :inherit font-lock-type-face))
+  "Face used for field names and interpreted text."
+  :version "24.1"
+  :group 'rst-faces)
 
-(defcustom rst-external-face 'font-lock-type-face
+(defcustom rst-external-face 'rst-external
   "Field names and interpreted text."
+  :version "24.1"
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-external-face
+                        "customize the face `rst-external' instead."
+                        "24.1")
+
+(defface rst-definition '((t :inherit font-lock-function-name-face))
+  "Face used for all other defining constructs."
+  :version "24.1"
+  :group 'rst-faces)
 
-(defcustom rst-definition-face 'font-lock-function-name-face
+(defcustom rst-definition-face 'rst-definition
   "All other defining constructs."
+  :version "24.1"
   :group 'rst-faces
   :type '(face))
-
-(defcustom rst-directive-face
-  ;; XEmacs compatibility
-  (if (boundp 'font-lock-builtin-face)
-      'font-lock-builtin-face
-    'font-lock-preprocessor-face)
+(make-obsolete-variable 'rst-definition-face
+                        "customize the face `rst-definition' instead."
+                        "24.1")
+
+;; XEmacs compatibility (?).
+(defface rst-directive (if (boundp 'font-lock-builtin-face)
+                           '((t :inherit font-lock-builtin-face))
+                         '((t :inherit font-lock-preprocessor-face)))
+  "Face used for directives and roles."
+  :version "24.1"
+  :group 'rst-faces)
+
+(defcustom rst-directive-face 'rst-directive
   "Directives and roles."
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-directive-face
+                        "customize the face `rst-directive' instead."
+                        "24.1")
+
+(defface rst-comment '((t :inherit font-lock-comment-face))
+  "Face used for comments."
+  :version "24.1"
+  :group 'rst-faces)
 
-(defcustom rst-comment-face 'font-lock-comment-face
+(defcustom rst-comment-face 'rst-comment
   "Comments."
+  :version "24.1"
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-comment-face
+                        "customize the face `rst-comment' instead."
+                        "24.1")
 
-(defcustom rst-emphasis1-face
-  ;; XEmacs compatibility
-  (if (facep 'italic)
-      ''italic
-    'italic)
+(defface rst-emphasis1 '((t :inherit italic))
+  "Face used for simple emphasis."
+  :version "24.1"
+  :group 'rst-faces)
+
+(defcustom rst-emphasis1-face 'rst-emphasis1
   "Simple emphasis."
+  :version "24.1"
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-emphasis1-face
+                        "customize the face `rst-emphasis1' instead."
+                        "24.1")
+
+(defface rst-emphasis2 '((t :inherit bold))
+  "Face used for double emphasis."
+  :version "24.1"
+  :group 'rst-faces)
 
-(defcustom rst-emphasis2-face
-  ;; XEmacs compatibility
-  (if (facep 'bold)
-      ''bold
-    'bold)
+(defcustom rst-emphasis2-face 'rst-emphasis2
   "Double emphasis."
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-emphasis2-face
+                        "customize the face `rst-emphasis2' instead."
+                        "24.1")
 
-(defcustom rst-literal-face 'font-lock-string-face
+(defface rst-literal '((t :inherit font-lock-string-face))
+  "Face used for literal text."
+  :version "24.1"
+  :group 'rst-faces)
+
+(defcustom rst-literal-face 'rst-literal
   "Literal text."
+  :version "24.1"
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-literal-face
+                        "customize the face `rst-literal' instead."
+                        "24.1")
+
+(defface rst-reference '((t :inherit font-lock-variable-name-face))
+  "Face used for references to a definition."
+  :version "24.1"
+  :group 'rst-faces)
 
-(defcustom rst-reference-face 'font-lock-variable-name-face
+(defcustom rst-reference-face 'rst-reference
   "References to a definition."
+  :version "24.1"
   :group 'rst-faces
   :type '(face))
+(make-obsolete-variable 'rst-reference-face
+                        "customize the face `rst-reference' instead."
+                        "24.1")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -2668,7 +2727,7 @@ general but you do not like the details."
   :set 'rst-set-level-default)
 (defcustom rst-level-face-base-color "grey"
   "The base name of the color to be used for creating background colors in
-ection title faces for all levels."
+section title faces for all levels."
   :group 'rst-faces-defaults
   :type '(string)
   :set 'rst-set-level-default)
@@ -2759,7 +2818,7 @@ details check the Rst Faces Defaults group."
   "Non-nil if we can use the character classes in our regexps.")
 
 (defun rst-font-lock-keywords-function ()
-  "Return keywords to highlight in rst mode according to current settings."
+  "Return keywords to highlight in Rst mode according to current settings."
   ;; The reST-links in the comments below all relate to sections in
   ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
   (let* ( ;; This gets big - so let's define some abbreviations
@@ -2784,10 +2843,7 @@ details check the Rst Faces Defaults group."
 
         ;; There seems to be a bug leading to error "Stack overflow in regexp
         ;; matcher" when "|" or "\\*" are the characters searched for
-        (re-imendbeg
-         (if (< emacs-major-version 21)
-             "]"
-           "\\]\\|\\\\."))
+        (re-imendbeg "\\]\\|\\\\.")
         ;; inline markup content end
         (re-imend (concat re-imendbeg "\\)*[^\t \\\\]\\)"))
         ;; inline markup content without asterisk
@@ -2813,94 +2869,76 @@ details check the Rst Faces Defaults group."
 
      ;; Simple `Body Elements`_
      ;; `Bullet Lists`_
-     (list
-      (concat re-bol "\\([-*+]" re-blksep1 "\\)")
-      1 rst-block-face)
+     `(,(concat re-bol "\\([-*+]" re-blksep1 "\\)")
+       1 rst-block-face)
      ;; `Enumerated Lists`_
-     (list
-      (concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]"
-             re-blksep1 "\\)")
-      1 rst-block-face)
+     `(,(concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]"
+                re-blksep1 "\\)")
+       1 rst-block-face)
      ;; `Definition Lists`_ FIXME: missing
      ;; `Field Lists`_
-     (list
-      (concat re-bol "\\(:[^:\n]+:\\)" re-blksep1)
-      1 rst-external-face)
+     `(,(concat re-bol "\\(:[^:\n]+:\\)" re-blksep1)
+       1 rst-external-face)
      ;; `Option Lists`_
-     (list
-      (concat re-bol "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*"
-             "\\([ =]\\S +\\)?\\)\\(,[\t ]\\)?\\)+\\)\\($\\|[\t ]\\{2\\}\\)")
-      1 rst-block-face)
+     `(,(concat re-bol "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*"
+               "\\([ =]\\S +\\)?\\)\\(,[\t ]\\)?\\)+\\)\\($\\|[\t ]\\{2\\}\\)")
+       1 rst-block-face)
 
      ;; `Tables`_ FIXME: missing
 
      ;; All the `Explicit Markup Blocks`_
      ;; `Footnotes`_ / `Citations`_
-     (list
-      (concat re-bol "\\(" re-ems "\\[[^[\n]+\\]\\)" re-blksep1)
+     `(,(concat re-bol "\\(" re-ems "\\[[^[\n]+\\]\\)" re-blksep1)
       1 rst-definition-face)
      ;; `Directives`_ / `Substitution Definitions`_
-     (list
-      (concat re-bol "\\(" re-ems "\\)\\(\\(|[^|\n]+|[\t ]+\\)?\\)\\("
-             re-sym1 "+::\\)" re-blksep1)
-      (list 1 rst-directive-face)
-      (list 2 rst-definition-face)
-      (list 4 rst-directive-face))
+     `(,(concat re-bol "\\(" re-ems "\\)\\(\\(|[^|\n]+|[\t ]+\\)?\\)\\("
+                re-sym1 "+::\\)" re-blksep1)
+       (1 rst-directive-face)
+       (2 rst-definition-face)
+       (4 rst-directive-face))
      ;; `Hyperlink Targets`_
-     (list
-      (concat re-bol "\\(" re-ems "_\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+:\\)"
-             re-blksep1)
-      1 rst-definition-face)
-     (list
-      (concat re-bol "\\(__\\)" re-blksep1)
-      1 rst-definition-face)
+     `(,(concat re-bol "\\(" re-ems "_\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+:\\)"
+                re-blksep1)
+       1 rst-definition-face)
+     `(,(concat re-bol "\\(__\\)" re-blksep1)
+       1 rst-definition-face)
 
      ;; All `Inline Markup`_
      ;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented
      ;; `Strong Emphasis`_
-     (list
-      (concat re-imp1 "\\(\\*\\*" re-ima2 "\\*\\*\\)" re-ims1)
-      2 rst-emphasis2-face)
+     `(,(concat re-imp1 "\\(\\*\\*" re-ima2 "\\*\\*\\)" re-ims1)
+       2 rst-emphasis2-face)
      ;; `Emphasis`_
-     (list
-      (concat re-imp1 "\\(\\*" re-ima2 "\\*\\)" re-ims1)
-      2 rst-emphasis1-face)
+     `(,(concat re-imp1 "\\(\\*" re-ima2 "\\*\\)" re-ims1)
+       2 rst-emphasis1-face)
      ;; `Inline Literals`_
-     (list
-      (concat re-imp1 "\\(``" re-imb2 "``\\)" re-ims1)
-      2 rst-literal-face)
+     `(,(concat re-imp1 "\\(``" re-imb2 "``\\)" re-ims1)
+       2 rst-literal-face)
      ;; `Inline Internal Targets`_
-     (list
-      (concat re-imp1 "\\(_`" re-imb2 "`\\)" re-ims1)
-      2 rst-definition-face)
+     `(,(concat re-imp1 "\\(_`" re-imb2 "`\\)" re-ims1)
+       2 rst-definition-face)
      ;; `Hyperlink References`_
      ;; FIXME: `Embedded URIs`_ not considered
-     (list
-      (concat re-imp1 "\\(\\(`" re-imb2 "`\\|\\(\\sw\\(\\sw\\|-\\)+\\sw\\)\\)__?\\)" re-ims1)
+     `(,(concat re-imp1 "\\(\\(`" re-imb2 "`\\|\\(\\sw\\(\\sw\\|-\\)+\\sw\\)\\)__?\\)" re-ims1)
       2 rst-reference-face)
      ;; `Interpreted Text`_
-     (list
-      (concat re-imp1 "\\(\\(:" re-sym1 "+:\\)?\\)\\(`" re-imb2 "`\\)\\(\\(:"
-             re-sym1 "+:\\)?\\)" re-ims1)
-      (list 2 rst-directive-face)
-      (list 5 rst-external-face)
-      (list 8 rst-directive-face))
+     `(,(concat re-imp1 "\\(\\(:" re-sym1 "+:\\)?\\)\\(`" re-imb2 "`\\)\\(\\(:"
+                re-sym1 "+:\\)?\\)" re-ims1)
+       (2 rst-directive-face)
+       (5 rst-external-face)
+       (8 rst-directive-face))
      ;; `Footnote References`_ / `Citation References`_
-     (list
-      (concat re-imp1 "\\(\\[[^]]+\\]_\\)" re-ims1)
-      2 rst-reference-face)
+     `(,(concat re-imp1 "\\(\\[[^]]+\\]_\\)" re-ims1)
+       2 rst-reference-face)
      ;; `Substitution References`_
-     (list
-      (concat re-imp1 "\\(|" re-imv2 "|\\)" re-ims1)
-      2 rst-reference-face)
+     `(,(concat re-imp1 "\\(|" re-imv2 "|\\)" re-ims1)
+       2 rst-reference-face)
      ;; `Standalone Hyperlinks`_
-     (list
-      ;; FIXME: This takes it easy by using a whitespace as delimiter
-      (concat re-imp1 "\\(" re-uris1 ":\\S +\\)" re-ims1)
-      2 rst-definition-face)
-     (list
-      (concat re-imp1 "\\(" re-sym1 "+@" re-sym1 "+\\)" re-ims1)
-      2 rst-definition-face)
+     `(;; FIXME: This takes it easy by using a whitespace as delimiter
+       ,(concat re-imp1 "\\(" re-uris1 ":\\S +\\)" re-ims1)
+       2 rst-definition-face)
+     `(,(concat re-imp1 "\\(" re-sym1 "+@" re-sym1 "+\\)" re-ims1)
+       2 rst-definition-face)
 
      ;; Do all block fontification as late as possible so 'append works
 
@@ -2909,7 +2947,7 @@ details check the Rst Faces Defaults group."
       (list
        re-ado2)
       (if (not rst-mode-lazy)
-         (list 1 rst-block-face)
+         '(1 rst-block-face)
        (list
         (list 'rst-font-lock-handle-adornment
               '(progn
@@ -2929,7 +2967,7 @@ details check the Rst Faces Defaults group."
       (list
        (concat re-bol "\\(" re-ems "\\)\[^[|_]\\([^:\n]\\|:\\([^:\n]\\|$\\)\\)*$")
 
-       (list 1 rst-comment-face))
+       '(1 rst-comment-face))
       (if rst-mode-lazy
          (list
           (list 'rst-font-lock-find-unindented-line
@@ -2937,12 +2975,12 @@ details check the Rst Faces Defaults group."
                    (setq rst-font-lock-indentation-point (match-end 1))
                    (point-max))
                 nil
-                (list 0 rst-comment-face 'append)))))
+                '(0 rst-comment-face append)))))
      (append
       (list
        (concat re-bol "\\(" re-emt "\\)\\(\\s *\\)$")
-       (list 1 rst-comment-face)
-       (list 2 rst-comment-face))
+       '(1 rst-comment-face)
+       '(2 rst-comment-face))
       (if rst-mode-lazy
          (list
           (list 'rst-font-lock-find-unindented-line
@@ -2950,13 +2988,13 @@ details check the Rst Faces Defaults group."
                    (setq rst-font-lock-indentation-point 'next)
                    (point-max))
                 nil
-                (list 0 rst-comment-face 'append)))))
+                '(0 rst-comment-face append)))))
 
      ;; `Literal Blocks`_
      (append
       (list
        (concat re-bol "\\(\\([^.\n]\\|\\.[^.\n]\\).*\\)?\\(::\\)$")
-       (list 3 rst-block-face))
+       '(3 rst-block-face))
       (if rst-mode-lazy
          (list
           (list 'rst-font-lock-find-unindented-line
@@ -2964,14 +3002,14 @@ details check the Rst Faces Defaults group."
                    (setq rst-font-lock-indentation-point t)
                    (point-max))
                 nil
-                (list 0 rst-literal-face 'append)))))
+                '(0 rst-literal-face append)))))
 
     ;; `Doctest Blocks`_
     (append
      (list
       (concat re-bol "\\(>>>\\|\\.\\.\\.\\)\\(.+\\)")
-      (list 1 rst-block-face)
-      (list 2 rst-literal-face)))
+      '(1 rst-block-face)
+      '(2 rst-literal-face)))
     )))
 
 
@@ -3057,8 +3095,8 @@ point is not moved."
 ;; Adornments
 
 (defvar rst-font-lock-adornment-point nil
-  "Stores the point where the current adornment ends.  Also used as a trigger
-for `rst-font-lock-handle-adornment'.")
+  "Stores the point where the current adornment ends.
+Also used as a trigger for `rst-font-lock-handle-adornment'.")
 
 ;; Here `rst-font-lock-handle-adornment' stores the section level of the
 ;; current adornment or t for a transition.
@@ -3196,16 +3234,37 @@ document with \\[rst-compile]."
   :group 'rst
   :version "21.1")
 
-(defvar rst-compile-toolsets
-  '((html . ("rst2html.py" ".html" nil))
-    (latex . ("rst2latex.py" ".tex" nil))
-    (newlatex . ("rst2newlatex.py" ".tex" nil))
-    (pseudoxml . ("rst2pseudoxml.py" ".xml" nil))
-    (xml . ("rst2xml.py" ".xml" nil)))
+(defcustom rst-compile-toolsets
+  `((html ,(if (executable-find "rst2html.py") "rst2html.py" "rst2html")
+          ".html" nil)
+    (latex ,(if (executable-find "rst2latex.py") "rst2latex.py" "rst2latex")
+           ".tex" nil)
+    (newlatex ,(if (executable-find "rst2newlatex.py") "rst2newlatex.py"
+                 "rst2newlatex")
+              ".tex" nil)
+    (pseudoxml ,(if (executable-find "rst2pseudoxml.py") "rst2pseudoxml.py"
+                  "rst2pseudoxml")
+               ".xml" nil)
+    (xml ,(if (executable-find "rst2xml.py") "rst2xml.py" "rst2xml")
+         ".xml" nil)
+    (pdf ,(if (executable-find "rst2pdf.py") "rst2pdf.py" "rst2pdf")
+         ".pdf" nil)
+    (s5 ,(if (executable-find "rst2s5.py") "rst2s5.py" "rst2s5")
+        ".html" nil))
   "Table describing the command to use for each toolset.
 An association list of the toolset to a list of the (command to use,
 extension of produced filename, options to the tool (nil or a
-string)) to be used for converting the document.")
+string)) to be used for converting the document."
+  :type '(alist :options (html latex newlatex pseudoxml xml pdf s5)
+                :key-type symbol
+                :value-type (list :tag "Specification"
+                             (file :tag "Command")
+                             (string :tag "File extension")
+                             (choice :tag "Command options"
+                                     (const :tag "No options" nil)
+                                     (string :tag "Options"))))
+  :group 'rst
+  :version "24.1")
 
 ;; Note for Python programmers not familiar with association lists: you can set
 ;; values in an alists like this, e.g. :
@@ -3293,7 +3352,7 @@ or of the entire buffer, if the region is not selected."
     (shell-command-on-region
      (if mark-active (region-beginning) (point-min))
      (if mark-active (region-end) (point-max))
-     "rst2pseudoxml.py"
+     (cadr (assq 'pseudoxml rst-compile-toolsets))
      standard-output)))
 
 (defvar rst-pdf-program "xpdf"
@@ -3302,8 +3361,9 @@ or of the entire buffer, if the region is not selected."
 (defun rst-compile-pdf-preview ()
   "Convert the document to a PDF file and launch a preview program."
   (interactive)
-  (let* ((tmp-filename "/tmp/out.pdf")
-        (command (format "rst2pdf.py %s %s && %s %s"
+  (let* ((tmp-filename (make-temp-file "rst-out" nil ".pdf"))
+        (command (format "%s %s %s && %s %s"
+                         (cadr (assq 'pdf rst-compile-toolsets))
                          buffer-file-name tmp-filename
                          rst-pdf-program tmp-filename)))
     (start-process-shell-command "rst-pdf-preview" nil command)
@@ -3317,8 +3377,9 @@ or of the entire buffer, if the region is not selected."
 (defun rst-compile-slides-preview ()
   "Convert the document to an S5 slide presentation and launch a preview program."
   (interactive)
-  (let* ((tmp-filename "/tmp/slides.html")
-        (command (format "rst2s5.py %s %s && %s %s"
+  (let* ((tmp-filename (make-temp-file "rst-slides" nil ".html"))
+        (command (format "%s %s %s && %s %s"
+                         (cadr (assq 's5 rst-compile-toolsets))
                          buffer-file-name tmp-filename
                          rst-slides-program tmp-filename)))
     (start-process-shell-command "rst-slides-preview" nil command)
@@ -3368,7 +3429,7 @@ This is useful for filling list item paragraphs."
 ;; For sections, better to use the specialized function above, but this can
 ;; be useful for creating separators.
 (defun rst-repeat-last-character (&optional tofill)
-  "Fills the current line up to the length of the preceding line (if not
+  "Fill the current line up to the length of the preceding line (if not
 empty), using the last character on the current line.  If the preceding line is
 empty, we use the `fill-column'.
 
@@ -3416,11 +3477,10 @@ column is used (fill-column vs. end of previous/next line)."
   "A portable function that returns non-nil if the mark is active."
   (cond
    ((fboundp 'region-active-p) (region-active-p))
-   ((boundp 'transient-mark-mode) transient-mark-mode mark-active)))
-
+   ((boundp 'transient-mark-mode) (and transient-mark-mode mark-active))
+   (t mark-active)))
 
 \f
 (provide 'rst)
 
-;; arch-tag: 255ac0a3-a689-44cb-8643-04ca55ae490d
 ;;; rst.el ends here