;;; 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.
(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)
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.
;; 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")
(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)
"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)
(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))))
(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)))
(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* (
(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))
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
"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.
+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)
(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.
;; 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
(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.
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
(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
"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
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
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
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).
(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))
;; Create a list of markers for all the decorations which are found within
;; the region.
(save-excursion
- (let (m 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)
- )))
+ )))
(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)
;; 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
)
"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)
(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]"
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."
(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)))
(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
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)
(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.
(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
(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)
(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))
))
(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))
"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)))
;; 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))
(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)))
)
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
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))
`(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))
(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)
(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")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
: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)
"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
;; 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
;; 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
(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
(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
(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
(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
(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)))
)))
;; 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.
: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. :
(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"
(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)
(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)
;; 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'.
"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