]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/rst.el
* textmodes/rst.el (rst-define-level-faces): Do not define face
[gnu-emacs] / lisp / textmodes / rst.el
index 7d0006a8ee5631b79080d3ba50c3a1bebf0d0352..9ed5309bb5311cc502392c74ee1f81199e3fba04 100644 (file)
@@ -1,7 +1,6 @@
 ;;; rst.el --- Mode for viewing and editing reStructuredText-documents.
 
-;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 2003-2011  Free Software Foundation, Inc.
 
 ;; Authors: Martin Blais <blais@furius.ca>,
 ;;          Stefan Merten <smerten@oekonux.de>,
     (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.")
 
 
@@ -310,14 +309,14 @@ This inherits from Text mode.")
 (defvar rst-mode-abbrev-table nil
   "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,8 +343,8 @@ 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))
 
@@ -363,22 +362,23 @@ The value of this variable is used when Rst mode is turned on."
 
 ;; 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"
   "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}
 
-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
@@ -697,11 +697,9 @@ 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))
@@ -788,7 +786,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
@@ -869,7 +867,7 @@ A 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)
@@ -878,10 +876,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.
@@ -909,15 +907,11 @@ 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)
@@ -1040,7 +1034,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
@@ -1369,9 +1363,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))
@@ -1394,31 +1388,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)
-    )))
+      )))
 
 
 
@@ -1461,10 +1452,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)
@@ -1496,7 +1487,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
        )
@@ -1507,7 +1499,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)
@@ -1627,13 +1619,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)))
@@ -1643,10 +1635,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
@@ -1782,7 +1774,7 @@ 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)
@@ -2018,7 +2010,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))
     ))
 
 
@@ -2051,11 +2044,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)))
@@ -2133,13 +2126,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))
 
@@ -2299,8 +2293,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)))
         )
@@ -2379,8 +2373,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
@@ -2414,8 +2408,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))
@@ -2453,8 +2446,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))
@@ -2531,9 +2523,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)
@@ -2578,62 +2568,132 @@ With prefix argument set the empty lines too."
   :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")
 
-(defcustom rst-external-face 'font-lock-type-face
+(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 '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")
 
-(defcustom rst-comment-face 'font-lock-comment-face
+(defface rst-comment '((t :inherit font-lock-comment-face))
+  "Face used for comments."
+  :version "24.1"
+  :group 'rst-faces)
+
+(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")
+
+(defface rst-emphasis1 '((t :inherit italic))
+  "Face used for simple emphasis."
+  :version "24.1"
+  :group 'rst-faces)
 
-(defcustom rst-emphasis1-face
-  ;; XEmacs compatibility
-  (if (facep 'italic)
-      ''italic
-    'italic)
+(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")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -2740,11 +2800,12 @@ details check the Rst Faces Defaults group."
                         rst-level-face-base-color
                         (+ (* (1- i) rst-level-face-step-light)
                            rst-level-face-base-light))))
-       (make-empty-face sym)
-       (set-face-doc-string sym doc)
-       (set-face-background sym col)
-       (set sym sym)
-       (setq i (1+ i))))))
+        (unless (boundp sym)
+          (make-empty-face sym)
+          (set-face-doc-string sym doc)
+          (set-face-background sym col)
+          (set sym sym))
+        (setq i (1+ i))))))
 
 (rst-define-level-faces)
 
@@ -2782,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
@@ -2811,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
 
@@ -2907,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
@@ -2927,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
@@ -2935,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
@@ -2948,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
@@ -2962,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)))
     )))
 
 
@@ -3194,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. :
@@ -3291,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"
@@ -3300,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)
@@ -3315,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)
@@ -3366,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'.
 
@@ -3414,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