aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-06-20 17:53:42 +0000
committerStefan Monnier2008-06-20 17:53:42 +0000
commitb47475199b9ed0efd78df87736e2991b5738b636 (patch)
treebd404073f05840d2330aa99178dad101cad5b636
parent469ca4030a351d865a4412a284ace9d2e11cf9e7 (diff)
downloademacs-b47475199b9ed0efd78df87736e2991b5738b636.tar.gz
emacs-b47475199b9ed0efd78df87736e2991b5738b636.zip
Fix up docstring conventions.
Move vars to before their first use. (rst-mode): Don't mess with font-lock-support-mode. (rst-suggest-new-decoration, rst-adjust-decoration): Avoid CL's copy-list. (rst-delete-entire-line): Use line-beginning-position. (rst-position): New fun. (rst-straighten-decorations): Use it instead of CL's position. (rst-straighten-bullets-region): Avoid CL's mapcar*. (rst-toc-mode): Use define-derived-mode. (rst-iterate-leftmost-paragraphs, rst-iterate-leftmost-paragraphs-2): Remove unused var `in-par'. Use `point' rather than `point-marker'. (rst-line-block-region): Reduce redundancy. Use the `pfxarg' arg. (rst-replace-lines): Simplify.
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/textmodes/rst.el537
2 files changed, 276 insertions, 276 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6ecf3dd3fc5..ae154fced75 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,20 @@
12008-06-20 Stefan Monnier <monnier@iro.umontreal.ca> 12008-06-20 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * textmodes/rst.el: Fix up docstring conventions.
4 Move vars to before their first use.
5 (rst-mode): Don't mess with font-lock-support-mode.
6 (rst-suggest-new-decoration, rst-adjust-decoration):
7 Avoid CL's copy-list.
8 (rst-delete-entire-line): Use line-beginning-position.
9 (rst-position): New fun.
10 (rst-straighten-decorations): Use it instead of CL's position.
11 (rst-straighten-bullets-region): Avoid CL's mapcar*.
12 (rst-toc-mode): Use define-derived-mode.
13 (rst-iterate-leftmost-paragraphs, rst-iterate-leftmost-paragraphs-2):
14 Remove unused var `in-par'. Use `point' rather than `point-marker'.
15 (rst-line-block-region): Reduce redundancy. Use the `pfxarg' arg.
16 (rst-replace-lines): Simplify.
17
3 * simple.el (special-mode-map): New var. 18 * simple.el (special-mode-map): New var.
4 (special-mode): New major mode. 19 (special-mode): New major mode.
5 20
diff --git a/lisp/textmodes/rst.el b/lisp/textmodes/rst.el
index e7b5c9b2d33..b73b334b509 100644
--- a/lisp/textmodes/rst.el
+++ b/lisp/textmodes/rst.el
@@ -25,10 +25,10 @@
25;;; Commentary: 25;;; Commentary:
26 26
27;; This package provides major mode rst-mode, which supports documents marked up 27;; This package provides major mode rst-mode, which supports documents marked up
28;; using the reStructuredText format. Support includes font locking as well as 28;; using the reStructuredText format. Support includes font locking as well as
29;; some convenience functions for editing. It does this by defining a Emacs 29;; some convenience functions for editing. It does this by defining a Emacs
30;; major mode: rst-mode (ReST). This mode is derived from text-mode (and 30;; major mode: rst-mode (ReST). This mode is derived from text-mode (and
31;; inherits much of it). This package also contains: 31;; inherits much of it). This package also contains:
32;; 32;;
33;; - Functions to automatically adjust and cycle the section underline 33;; - Functions to automatically adjust and cycle the section underline
34;; decorations; 34;; decorations;
@@ -49,17 +49,17 @@
49;; http://docutils.sourceforge.net/docs/user/emacs.html 49;; http://docutils.sourceforge.net/docs/user/emacs.html
50;; 50;;
51;; 51;;
52;; There are a number of convenient keybindings provided by rst-mode. The main 52;; There are a number of convenient keybindings provided by rst-mode.
53;; one is 53;; The main one is
54;; 54;;
55;; C-c C-a (also C-=): rst-adjust 55;; C-c C-a (also C-=): rst-adjust
56;; 56;;
57;; Updates or rotates the section title around point or promotes/demotes the 57;; Updates or rotates the section title around point or promotes/demotes the
58;; decorations within the region (see full details below). Note that C-= is a 58;; decorations within the region (see full details below). Note that C-= is a
59;; good binding, since it allows you to specify a negative arg easily with C-- 59;; good binding, since it allows you to specify a negative arg easily with C--
60;; C-= (easy to type), as well as ordinary prefix arg with C-u C-=. 60;; C-= (easy to type), as well as ordinary prefix arg with C-u C-=.
61;; 61;;
62;; For more on bindings, see rst-mode-map below. There are also many variables 62;; For more on bindings, see rst-mode-map below. There are also many variables
63;; that can be customized, look for defcustom and defvar in this file. 63;; that can be customized, look for defcustom and defvar in this file.
64;; 64;;
65;; If you use the table-of-contents feature, you may want to add a hook to 65;; If you use the table-of-contents feature, you may want to add a hook to
@@ -67,8 +67,8 @@
67;; 67;;
68;; (add-hook 'rst-adjust-hook 'rst-toc-update) 68;; (add-hook 'rst-adjust-hook 'rst-toc-update)
69;; 69;;
70;; Syntax highlighting: font-lock is enabled by default. If you want to turn off 70;; Syntax highlighting: font-lock is enabled by default. If you want to turn
71;; syntax highlighting to rst-mode, you can use the following:: 71;; off syntax highlighting to rst-mode, you can use the following::
72;; 72;;
73;; (setq font-lock-global-modes '(not rst-mode ...)) 73;; (setq font-lock-global-modes '(not rst-mode ...))
74;; 74;;
@@ -84,7 +84,7 @@
84;; 84;;
85;; rst-faces 85;; rst-faces
86;; --------- 86;; ---------
87;; This group contains all necessary for customizing fonts. The default 87;; This group contains all necessary for customizing fonts. The default
88;; settings use standard font-lock-*-face's so if you set these to your 88;; settings use standard font-lock-*-face's so if you set these to your
89;; liking they are probably good in rst-mode also. 89;; liking they are probably good in rst-mode also.
90;; 90;;
@@ -96,21 +96,21 @@
96;; section title faces. 96;; section title faces.
97;; 97;;
98;; The general idea for section title faces is to have a non-default background 98;; The general idea for section title faces is to have a non-default background
99;; but do not change the background. The section level is shown by the 99;; but do not change the background. The section level is shown by the
100;; lightness of the background color. If you like this general idea of 100;; lightness of the background color. If you like this general idea of
101;; generating faces for section titles but do not like the details this group 101;; generating faces for section titles but do not like the details this group
102;; is the point where you can customize the details. If you do not like the 102;; is the point where you can customize the details. If you do not like the
103;; general idea, however, you should customize the faces used in 103;; general idea, however, you should customize the faces used in
104;; rst-adornment-faces-alist. 104;; rst-adornment-faces-alist.
105;; 105;;
106;; Note: If you are using a dark background please make sure the variable 106;; Note: If you are using a dark background please make sure the variable
107;; frame-background-mode is set to the symbol dark. This triggers 107;; frame-background-mode is set to the symbol dark. This triggers
108;; some default values which are probably right for you. 108;; some default values which are probably right for you.
109;; 109;;
110;; The group is contained in the rst-faces group. 110;; The group is contained in the rst-faces group.
111;; 111;;
112;; All customizable features have a comment explaining their meaning. Refer to 112;; All customizable features have a comment explaining their meaning.
113;; the customization of your Emacs (try ``M-x customize``). 113;; Refer to the customization of your Emacs (try ``M-x customize``).
114 114
115 115
116;;; DOWNLOAD 116;;; DOWNLOAD
@@ -128,12 +128,12 @@
128;; If you are using `.txt' as a standard extension for reST files as 128;; If you are using `.txt' as a standard extension for reST files as
129;; http://docutils.sourceforge.net/FAQ.html#what-s-the-standard-filename-extension-for-a-restructuredtext-file 129;; http://docutils.sourceforge.net/FAQ.html#what-s-the-standard-filename-extension-for-a-restructuredtext-file
130;; suggests you may use one of the `Local Variables in Files' mechanism Emacs 130;; suggests you may use one of the `Local Variables in Files' mechanism Emacs
131;; provides to set the major mode automatically. For instance you may use:: 131;; provides to set the major mode automatically. For instance you may use::
132;; 132;;
133;; .. -*- mode: rst -*- 133;; .. -*- mode: rst -*-
134;; 134;;
135;; in the very first line of your file. The following code is useful if you want 135;; in the very first line of your file. The following code is useful if you
136;; to automatically enter rst-mode from any file with compatible extensions: 136;; want automatically enter rst-mode from any file with compatible extensions:
137;; 137;;
138;; (setq auto-mode-alist 138;; (setq auto-mode-alist
139;; (append '(("\\.txt$" . rst-mode) 139;; (append '(("\\.txt$" . rst-mode)
@@ -196,7 +196,7 @@
196;;; HISTORY 196;;; HISTORY
197;; 197;;
198 198
199;;; CODE 199;;; Code:
200 200
201 201
202(defgroup rst nil "Support for reStructuredText documents" 202(defgroup rst nil "Support for reStructuredText documents"
@@ -302,7 +302,8 @@
302 (define-key map [(control c) (?5)] 'rst-compile-slides-preview) 302 (define-key map [(control c) (?5)] 'rst-compile-slides-preview)
303 303
304 map) 304 map)
305 "Keymap for ReStructuredText mode commands. This inherits from Text mode.") 305 "Keymap for ReStructuredText mode commands.
306This inherits from Text mode.")
306 307
307 308
308;; Abbrevs. 309;; Abbrevs.
@@ -343,18 +344,18 @@
343 344
344 345
345(defcustom rst-mode-hook nil 346(defcustom rst-mode-hook nil
346 "Hook run when Rst Mode is turned on. The hook for Text Mode is run before 347 "Hook run when Rst Mode is turned on.
347 this one." 348The hook for Text Mode is run before this one."
348 :group 'rst 349 :group 'rst
349 :type '(hook)) 350 :type '(hook))
350 351
351 352
352(defcustom rst-mode-lazy t 353(defcustom rst-mode-lazy t
353 "*If non-nil Rst Mode font-locks comment, literal blocks, and section titles 354 "*If non-nil Rst Mode tries to font-lock multi-line elements correctly.
354correctly. Because this is really slow it switches on Lazy Lock Mode 355Because this is really slow it should be set to nil if neither `jit-lock-mode'
355automatically. You may increase Lazy Lock Defer Time for reasonable results. 356not `lazy-lock-mode' and activated.
356 357
357If nil comments and literal blocks are font-locked only on the line they start. 358If nil, comments and literal blocks are font-locked only on the line they start.
358 359
359The value of this variable is used when Rst Mode is turned on." 360The value of this variable is used when Rst Mode is turned on."
360 :group 'rst 361 :group 'rst
@@ -405,33 +406,35 @@ blocks."
405 t nil nil nil 406 t nil nil nil
406 (font-lock-multiline . t) 407 (font-lock-multiline . t)
407 (font-lock-mark-block-function . mark-paragraph))) 408 (font-lock-mark-block-function . mark-paragraph)))
408 (when (boundp 'font-lock-support-mode) 409 ;; `jit-lock-mode' has been the default since Emacs-21.1, so there's no
409 ;; rst-mode has its own mind about font-lock-support-mode 410 ;; point messing around with font-lock-support-mode any more.
410 (make-local-variable 'font-lock-support-mode) 411 ;; (when (boundp 'font-lock-support-mode)
411 ;; jit-lock-mode replaced lazy-lock-mode in GNU Emacs 22 412 ;; ;; rst-mode has its own mind about font-lock-support-mode
412 (let ((jit-or-lazy-lock-mode 413 ;; (make-local-variable 'font-lock-support-mode)
413 (cond 414 ;; ;; jit-lock-mode replaced lazy-lock-mode in GNU Emacs 21.
414 ((fboundp 'lazy-lock-mode) 'lazy-lock-mode) 415 ;; (let ((jit-or-lazy-lock-mode
415 ((fboundp 'jit-lock-mode) 'jit-lock-mode) 416 ;; (cond
416 ;; if neither lazy-lock nor jit-lock is supported, 417 ;; ((fboundp 'lazy-lock-mode) 'lazy-lock-mode)
417 ;; tell user and disable rst-mode-lazy 418 ;; ((fboundp 'jit-lock-mode) 'jit-lock-mode)
418 (t (when rst-mode-lazy 419 ;; ;; if neither lazy-lock nor jit-lock is supported,
419 (message "Disabled lazy fontification, because no known support mode found.") 420 ;; ;; tell user and disable rst-mode-lazy
420 (setq rst-mode-lazy nil)))))) 421 ;; (t (when rst-mode-lazy
421 (cond 422 ;; (message "Disabled lazy fontification, because no known support mode found.")
422 ((and (not rst-mode-lazy) (not font-lock-support-mode))) 423 ;; (setq rst-mode-lazy nil))))))
423 ;; No support mode set and none required - leave it alone 424 ;; (cond
424 ((or (not font-lock-support-mode) ;; No support mode set (but required) 425 ;; ((and (not rst-mode-lazy) (not font-lock-support-mode)))
425 (symbolp font-lock-support-mode)) ;; or a fixed mode for all 426 ;; ;; No support mode set and none required - leave it alone
426 (setq font-lock-support-mode 427 ;; ((or (not font-lock-support-mode) ;; No support mode set (but required)
427 (list (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode)) 428 ;; (symbolp font-lock-support-mode)) ;; or a fixed mode for all
428 (cons t font-lock-support-mode)))) 429 ;; (setq font-lock-support-mode
429 ((and (listp font-lock-support-mode) 430 ;; (list (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode))
430 (not (assoc 'rst-mode font-lock-support-mode))) 431 ;; (cons t font-lock-support-mode))))
431 ;; A list of modes missing rst-mode 432 ;; ((and (listp font-lock-support-mode)
432 (setq font-lock-support-mode 433 ;; (not (assoc 'rst-mode font-lock-support-mode)))
433 (cons (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode)) 434 ;; ;; A list of modes missing rst-mode
434 font-lock-support-mode)))))) 435 ;; (setq font-lock-support-mode
436 ;; (cons (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode))
437 ;; font-lock-support-mode))))))
435 438
436 ) 439 )
437 440
@@ -675,12 +678,12 @@ suggest a better match."
675 678
676 (setq curpotential (cdr curpotential))) 679 (setq curpotential (cdr curpotential)))
677 680
678 (copy-list (car curpotential)) )) 681 (copy-sequence (car curpotential))))
679 682
680(defun rst-delete-entire-line () 683(defun rst-delete-entire-line ()
681 "Delete the entire current line without using the `kill-ring'." 684 "Delete the entire current line without using the `kill-ring'."
682 (delete-region (line-beginning-position) (min (+ 1 (line-end-position)) 685 (delete-region (line-beginning-position)
683 (point-max)))) 686 (line-beginning-position 2)))
684 687
685(defun rst-update-section (char style &optional indent) 688(defun rst-update-section (char style &optional indent)
686 "Unconditionally update the style of a section decoration. 689 "Unconditionally update the style of a section decoration.
@@ -1065,10 +1068,11 @@ b. a negative numerical argument, which generally inverts the
1065 "Hooks to be run after running `rst-adjust'.") 1068 "Hooks to be run after running `rst-adjust'.")
1066 1069
1067(defvar rst-new-decoration-down nil 1070(defvar rst-new-decoration-down nil
1068 "If true, a new decoration being added will be initialized to 1071 "Non-nil if new decoration is added deeper.
1069 be one level down from the previous decoration. If nil, a new 1072If non-nil, a new decoration being added will be initialized to
1070 decoration will be equal to the level of the previous 1073be one level down from the previous decoration. If nil, a new
1071 decoration.") 1074decoration will be equal to the level of the previous
1075decoration.")
1072 1076
1073(defun rst-adjust-decoration (&optional toggle-style reverse-direction) 1077(defun rst-adjust-decoration (&optional toggle-style reverse-direction)
1074"Adjust/rotate the section decoration for the section title around point. 1078"Adjust/rotate the section decoration for the section title around point.
@@ -1284,8 +1288,7 @@ of the right hand fingers and the binding is unused in `text-mode'."
1284 (rst-get-decoration-match hier prev)) 1288 (rst-get-decoration-match hier prev))
1285 (rst-suggest-new-decoration hier prev)) 1289 (rst-suggest-new-decoration hier prev))
1286 prev) 1290 prev)
1287 (copy-list (car rst-preferred-decorations)) 1291 (copy-sequence (car rst-preferred-decorations))))
1288 ))
1289 1292
1290 ;; Invert the style if requested. 1293 ;; Invert the style if requested.
1291 (if toggle-style 1294 (if toggle-style
@@ -1440,6 +1443,11 @@ DECORATIONS."
1440 )) 1443 ))
1441 ))) 1444 )))
1442 1445
1446(defun rst-position (elem list)
1447 "Return position of ELEM in LIST or nil."
1448 (let ((tail (member elem list)))
1449 (if tail (- (length list) (length tail)))))
1450
1443(defun rst-straighten-decorations () 1451(defun rst-straighten-decorations ()
1444 "Redo all the decorations in the current buffer. 1452 "Redo all the decorations in the current buffer.
1445This is done using our preferred set of decorations. This can be 1453This is done using our preferred set of decorations. This can be
@@ -1453,7 +1461,7 @@ in order to adapt it to our preferred style."
1453 ;; Get a list of pairs of (level . marker) 1461 ;; Get a list of pairs of (level . marker)
1454 (levels-and-markers (mapcar 1462 (levels-and-markers (mapcar
1455 (lambda (deco) 1463 (lambda (deco)
1456 (cons (position (cdr deco) hier :test 'equal) 1464 (cons (rst-position (cdr deco) hier)
1457 (let ((m (make-marker))) 1465 (let ((m (make-marker)))
1458 (goto-line (car deco)) 1466 (goto-line (car deco))
1459 (set-marker m (point)) 1467 (set-marker m (point))
@@ -1515,8 +1523,8 @@ is a regular expression for matching the lines with items."
1515 (> (current-column) pfx-col) 1523 (> (current-column) pfx-col)
1516 (and (= (current-column) pfx-col) 1524 (and (= (current-column) pfx-col)
1517 (looking-at pfx-re)))))) 1525 (looking-at pfx-re))))))
1518 (setq pfx (cons (cons (point) (current-column)) 1526 (push (cons (point) (current-column))
1519 pfx))) 1527 pfx))
1520 (forward-line 1)) ) 1528 (forward-line 1)) )
1521 (nreverse pfx))) 1529 (nreverse pfx)))
1522 1530
@@ -1562,23 +1570,18 @@ adjust. If bullets are found on levels beyond the
1562 levtable))) 1570 levtable)))
1563 1571
1564 ;; Sort this map and create a new map of prefix char and list of positions. 1572 ;; Sort this map and create a new map of prefix char and list of positions.
1565 (let (poslist) 1573 (let ((poslist ())) ; List of (indent . positions).
1566 (maphash (lambda (x y) (setq poslist (cons (cons x y) poslist))) levtable) 1574 (maphash (lambda (x y) (push (cons x y) poslist)) levtable)
1567 1575
1568 (mapcar* (lambda (x char) 1576 (let ((bullets rst-preferred-bullets))
1569 ;; Apply the characters. 1577 (dolist (x (sort poslist 'car-less-than-car))
1570 (dolist (pos (cdr x)) 1578 (when bullets
1571 (goto-char pos) 1579 ;; Apply the characters.
1572 (delete-char 1) 1580 (dolist (pos (cdr x))
1573 (insert (char-to-string char)))) 1581 (goto-char pos)
1574 1582 (delete-char 1)
1575 ;; Sorted list of indent . positions 1583 (insert (string (car bullets))))
1576 (sort poslist (lambda (x y) (<= (car x) (car y)))) 1584 (setq bullets (cdr bullets))))))))
1577
1578 ;; List of preferred bullets.
1579 rst-preferred-bullets)
1580
1581 )))
1582 1585
1583(defun rst-rstrip (str) 1586(defun rst-rstrip (str)
1584 "Strips the whitespace at the end of string STR." 1587 "Strips the whitespace at the end of string STR."
@@ -1711,6 +1714,42 @@ subtree node that we're returning."
1711 )) 1714 ))
1712 1715
1713 1716
1717(defgroup rst-toc nil
1718 "Settings for reStructuredText table of contents."
1719 :group 'rst
1720 :version "21.1")
1721
1722(defcustom rst-toc-indent 2
1723 "Indentation for table-of-contents display.
1724Also used for formatting insertion, when numbering is disabled."
1725 :group 'rst-toc)
1726
1727(defcustom rst-toc-insert-style 'fixed
1728 "Insertion style for table-of-contents.
1729Set this to one of the following values to determine numbering and
1730indentation style:
1731- plain: no numbering (fixed indentation)
1732- fixed: numbering, but fixed indentation
1733- aligned: numbering, titles aligned under each other
1734- listed: numbering, with dashes like list items (EXPERIMENTAL)"
1735 :group 'rst-toc)
1736
1737(defcustom rst-toc-insert-number-separator " "
1738 "Separator that goes between the TOC number and the title."
1739 :group 'rst-toc)
1740
1741;; This is used to avoid having to change the user's mode.
1742(defvar rst-toc-insert-click-keymap
1743 (let ((map (make-sparse-keymap)))
1744 (define-key map [mouse-1] 'rst-toc-mode-mouse-goto)
1745 map)
1746 "(Internal) What happens when you click on propertized text in the TOC.")
1747
1748(defcustom rst-toc-insert-max-level nil
1749 "If non-nil, maximum depth of the inserted TOC."
1750 :group 'rst-toc)
1751
1752
1714(defun rst-toc-insert (&optional pfxarg) 1753(defun rst-toc-insert (&optional pfxarg)
1715 "Insert a simple text rendering of the table of contents. 1754 "Insert a simple text rendering of the table of contents.
1716By default the top level is ignored if there is only one, because 1755By default the top level is ignored if there is only one, because
@@ -1747,42 +1786,6 @@ The TOC is inserted indented at the current column."
1747 (delete-backward-char 1) 1786 (delete-backward-char 1)
1748 ))) 1787 )))
1749 1788
1750
1751(defgroup rst-toc nil
1752 "Settings for reStructuredText table of contents."
1753 :group 'rst
1754 :version "21.1")
1755
1756(defcustom rst-toc-indent 2
1757 "Indentation for table-of-contents display.
1758Also used for formatting insertion, when numbering is disabled."
1759 :group 'rst-toc)
1760
1761(defcustom rst-toc-insert-style 'fixed
1762 "Insertion style for table-of-contents.
1763Set this to one of the following values to determine numbering and
1764indentation style:
1765- plain: no numbering (fixed indentation)
1766- fixed: numbering, but fixed indentation
1767- aligned: numbering, titles aligned under each other
1768- listed: numbering, with dashes like list items (EXPERIMENTAL)"
1769 :group 'rst-toc)
1770
1771(defcustom rst-toc-insert-number-separator " "
1772 "Separator that goes between the TOC number and the title."
1773 :group 'rst-toc)
1774
1775;; This is used to avoid having to change the user's mode.
1776(defvar rst-toc-insert-click-keymap
1777 (let ((map (make-sparse-keymap)))
1778 (define-key map [mouse-1] 'rst-toc-mode-mouse-goto)
1779 map)
1780 "(Internal) What happens when you click on propertized text in the TOC.")
1781
1782(defcustom rst-toc-insert-max-level nil
1783 "If non-nil, maximum depth of the inserted TOC."
1784 :group 'rst-toc)
1785
1786(defun rst-toc-insert-node (node level indent pfx) 1789(defun rst-toc-insert-node (node level indent pfx)
1787 "Insert tree node NODE in table-of-contents. 1790 "Insert tree node NODE in table-of-contents.
1788Recursive function that does printing of the inserted toc. LEVEL 1791Recursive function that does printing of the inserted toc. LEVEL
@@ -1966,6 +1969,12 @@ and 't if the node has been found."
1966 child (cdr child)))))) 1969 child (cdr child))))))
1967 (cons count found))) 1970 (cons count found)))
1968 1971
1972(defvar rst-toc-buffer-name "*Table of Contents*"
1973 "Name of the Table of Contents buffer.")
1974
1975(defvar rst-toc-return-buffer nil
1976 "Buffer to which to return when leaving the TOC.")
1977
1969 1978
1970(defun rst-toc () 1979(defun rst-toc ()
1971 "Display a table-of-contents. 1980 "Display a table-of-contents.
@@ -2023,9 +2032,6 @@ brings the cursor in that section."
2023 (error "Buffer for this section was killed")) 2032 (error "Buffer for this section was killed"))
2024 pos)) 2033 pos))
2025 2034
2026(defvar rst-toc-buffer-name "*Table of Contents*"
2027 "Name of the Table of Contents buffer.")
2028
2029(defun rst-goto-section (&optional kill) 2035(defun rst-goto-section (&optional kill)
2030 "Go to the section the current line describes." 2036 "Go to the section the current line describes."
2031 (interactive) 2037 (interactive)
@@ -2047,8 +2053,7 @@ brings the cursor in that section."
2047EVENT is the input event." 2053EVENT is the input event."
2048 (interactive "e") 2054 (interactive "e")
2049 (let (pos) 2055 (let (pos)
2050 (save-excursion 2056 (with-current-buffer (window-buffer (posn-window (event-end event)))
2051 (set-buffer (window-buffer (posn-window (event-end event))))
2052 (save-excursion 2057 (save-excursion
2053 (goto-char (posn-point (event-end event))) 2058 (goto-char (posn-point (event-end event)))
2054 (setq pos (rst-toc-mode-find-section)))) 2059 (setq pos (rst-toc-mode-find-section))))
@@ -2057,15 +2062,13 @@ EVENT is the input event."
2057 (recenter 5))) 2062 (recenter 5)))
2058 2063
2059(defun rst-toc-mode-mouse-goto-kill (event) 2064(defun rst-toc-mode-mouse-goto-kill (event)
2065 "Same as `rst-toc-mode-mouse-goto', but kill TOC buffer as well."
2060 (interactive "e") 2066 (interactive "e")
2061 (call-interactively 'rst-toc-mode-mouse-goto event) 2067 (call-interactively 'rst-toc-mode-mouse-goto event)
2062 (kill-buffer (get-buffer rst-toc-buffer-name))) 2068 (kill-buffer (get-buffer rst-toc-buffer-name)))
2063 2069
2064(defvar rst-toc-return-buffer nil
2065 "Buffer local variable that is used to return to the original
2066 buffer from the TOC.")
2067
2068(defun rst-toc-quit-window () 2070(defun rst-toc-quit-window ()
2071 "Leave the current TOC buffer."
2069 (interactive) 2072 (interactive)
2070 (quit-window) 2073 (quit-window)
2071 (pop-to-buffer rst-toc-return-buffer)) 2074 (pop-to-buffer rst-toc-return-buffer))
@@ -2083,15 +2086,10 @@ EVENT is the input event."
2083 2086
2084(put 'rst-toc-mode 'mode-class 'special) 2087(put 'rst-toc-mode 'mode-class 'special)
2085 2088
2086(defun rst-toc-mode () 2089;; Could inherit from the new `special-mode'.
2090(define-derived-mode rst-toc-mode nil "ReST-TOC"
2087 "Major mode for output from \\[rst-toc], the table-of-contents for the document." 2091 "Major mode for output from \\[rst-toc], the table-of-contents for the document."
2088 (interactive) 2092 (setq buffer-read-only t))
2089 (kill-all-local-variables)
2090 (use-local-map rst-toc-mode-map)
2091 (setq major-mode 'rst-toc-mode)
2092 (setq mode-name "ReST-TOC")
2093 (setq buffer-read-only t)
2094 )
2095 2093
2096;; Note: use occur-mode (replace.el) as a good example to complete missing 2094;; Note: use occur-mode (replace.el) as a good example to complete missing
2097;; features. 2095;; features.
@@ -2104,8 +2102,8 @@ EVENT is the input event."
2104 2102
2105(defun rst-forward-section (&optional offset) 2103(defun rst-forward-section (&optional offset)
2106 "Skip to the next restructured text section title. 2104 "Skip to the next restructured text section title.
2107 OFFSET specifies how many titles to skip. Use a negative OFFSET to move 2105OFFSET specifies how many titles to skip. Use a negative OFFSET to move
2108 backwards in the file (default is to use 1)." 2106backwards in the file (default is to use 1)."
2109 (interactive) 2107 (interactive)
2110 (let* (;; Default value for offset. 2108 (let* (;; Default value for offset.
2111 (offset (or offset 1)) 2109 (offset (or offset 1))
@@ -2141,7 +2139,7 @@ EVENT is the input event."
2141 )) 2139 ))
2142 2140
2143(defun rst-backward-section () 2141(defun rst-backward-section ()
2144 "Like rst-forward-section, except move back one title. 2142 "Like `rst-forward-section', except move back one title.
2145With a prefix argument, move backward by a page." 2143With a prefix argument, move backward by a page."
2146 (interactive) 2144 (interactive)
2147 (rst-forward-section -1)) 2145 (rst-forward-section -1))
@@ -2177,11 +2175,10 @@ With a prefix argument, move backward by a page."
2177 2175
2178;; (FIXME: there is currently a bug that makes the region go away when we do that.) 2176;; (FIXME: there is currently a bug that makes the region go away when we do that.)
2179(defvar rst-shift-fill-region nil 2177(defvar rst-shift-fill-region nil
2180 "Set to true if you want to automatically re-fill the region that is being 2178 "If non-nil, automatically re-fill the region that is being shifted.")
2181shifted.")
2182 2179
2183(defun rst-find-leftmost-column (beg end) 2180(defun rst-find-leftmost-column (beg end)
2184 "Finds the leftmost column in the region." 2181 "Find the leftmost column in the region."
2185 (let ((mincol 1000)) 2182 (let ((mincol 1000))
2186 (save-excursion 2183 (save-excursion
2187 (goto-char beg) 2184 (goto-char beg)
@@ -2213,11 +2210,12 @@ shifted.")
2213;; positions, in case the line matches the bullet pattern, and then sort. 2210;; positions, in case the line matches the bullet pattern, and then sort.
2214 2211
2215(defun rst-compute-bullet-tabs (&optional pt) 2212(defun rst-compute-bullet-tabs (&optional pt)
2216 "Search backwards from point (or point PT if specified) to 2213 "Build the list of possible horizontal alignment points.
2214Search backwards from point (or point PT if specified) to
2217build the list of possible horizontal alignment points that 2215build the list of possible horizontal alignment points that
2218includes the beginning and contents of a restructuredtext 2216includes the beginning and contents of a restructuredtext
2219bulleted or enumerated list item. Return a sorted list 2217bulleted or enumerated list item. Return a sorted list
2220of (column-number . line) pairs." 2218of (COLUMN-NUMBER . LINE) pairs."
2221 (save-excursion 2219 (save-excursion
2222 (when pt (goto-char pt)) 2220 (when pt (goto-char pt))
2223 2221
@@ -2245,7 +2243,7 @@ of (column-number . line) pairs."
2245 2243
2246 ;; Add the beginning of the line as a tabbing point. 2244 ;; Add the beginning of the line as a tabbing point.
2247 (unless (memq col (mapcar 'car tablist)) 2245 (unless (memq col (mapcar 'car tablist))
2248 (setq tablist (cons (cons col (point)) tablist))) 2246 (push (cons col (point)) tablist))
2249 2247
2250 ;; Look at the line to figure out if it is a bulleted or enumerate 2248 ;; Look at the line to figure out if it is a bulleted or enumerate
2251 ;; list item. 2249 ;; list item.
@@ -2264,9 +2262,8 @@ of (column-number . line) pairs."
2264 (newcol (+ col matchlen))) 2262 (newcol (+ col matchlen)))
2265 (unless (or (>= newcol leftcol) 2263 (unless (or (>= newcol leftcol)
2266 (memq (+ col matchlen) (mapcar 'car tablist))) 2264 (memq (+ col matchlen) (mapcar 'car tablist)))
2267 (setq tablist (cons 2265 (push (cons (+ col matchlen) (+ (point) matchlen))
2268 (cons (+ col matchlen) (+ (point) matchlen)) 2266 tablist)))
2269 tablist))))
2270 ) 2267 )
2271 2268
2272 (setq leftcol col) 2269 (setq leftcol col)
@@ -2279,8 +2276,7 @@ of (column-number . line) pairs."
2279 ))) 2276 )))
2280 2277
2281(defun rst-debug-print-tabs (tablist) 2278(defun rst-debug-print-tabs (tablist)
2282 "A routine that inserts a line and places special characters at 2279 "Insert a line and place special characters at the tab points in TABLIST."
2283the tab points in the given tablist."
2284 (beginning-of-line) 2280 (beginning-of-line)
2285 (insert (concat "\n" (make-string 1000 ? ) "\n")) 2281 (insert (concat "\n" (make-string 1000 ? ) "\n"))
2286 (beginning-of-line 0) 2282 (beginning-of-line 0)
@@ -2292,8 +2288,7 @@ the tab points in the given tablist."
2292 )) 2288 ))
2293 2289
2294(defun rst-debug-mark-found (tablist) 2290(defun rst-debug-mark-found (tablist)
2295 "A routine that inserts a line and places special characters at 2291 "Insert a line and place special characters at the tab points in TABLIST."
2296the tab points in the given tablist."
2297 (dolist (col tablist) 2292 (dolist (col tablist)
2298 (when (cdr col) 2293 (when (cdr col)
2299 (goto-char (cdr col)) 2294 (goto-char (cdr col))
@@ -2304,7 +2299,7 @@ the tab points in the given tablist."
2304 "Basic horizontal shift distance when there is no preceding alignment tabs.") 2299 "Basic horizontal shift distance when there is no preceding alignment tabs.")
2305 2300
2306(defun rst-shift-region-guts (find-next-fun offset-fun) 2301(defun rst-shift-region-guts (find-next-fun offset-fun)
2307 "(See rst-shift-region-right for a description.)" 2302 "(See `rst-shift-region-right' for a description)."
2308 (let* ((mbeg (set-marker (make-marker) (region-beginning))) 2303 (let* ((mbeg (set-marker (make-marker) (region-beginning)))
2309 (mend (set-marker (make-marker) (region-end))) 2304 (mend (set-marker (make-marker) (region-end)))
2310 (tabs (rst-compute-bullet-tabs mbeg)) 2305 (tabs (rst-compute-bullet-tabs mbeg))
@@ -2361,12 +2356,12 @@ the tab points in the given tablist."
2361 )) 2356 ))
2362 2357
2363(defun rst-shift-region-right (pfxarg) 2358(defun rst-shift-region-right (pfxarg)
2364 "Indent region ridigly, by a few characters to the right. This 2359 "Indent region ridigly, by a few characters to the right.
2365function first computes all possible alignment columns by 2360This function first computes all possible alignment columns by
2366inspecting the lines preceding the region for bulleted or 2361inspecting the lines preceding the region for bulleted or
2367enumerated list items. If the leftmost column is beyond the 2362enumerated list items. If the leftmost column is beyond the
2368preceding lines, the region is moved to the right by 2363preceding lines, the region is moved to the right by
2369rst-shift-basic-offset. With a prefix argument, do not 2364`rst-shift-basic-offset'. With a prefix argument, do not
2370automatically fill the region." 2365automatically fill the region."
2371 (interactive "P") 2366 (interactive "P")
2372 (let ((rst-shift-fill-region 2367 (let ((rst-shift-fill-region
@@ -2380,7 +2375,7 @@ automatically fill the region."
2380 ))) 2375 )))
2381 2376
2382(defun rst-shift-region-left (pfxarg) 2377(defun rst-shift-region-left (pfxarg)
2383 "Like rst-shift-region-right, except we move to the left. 2378 "Like `rst-shift-region-right', except we move to the left.
2384Also, if invoked with a negative prefix arg, the entire 2379Also, if invoked with a negative prefix arg, the entire
2385indentation is removed, up to the leftmost character in the 2380indentation is removed, up to the leftmost character in the
2386region, and automatic filling is disabled." 2381region, and automatic filling is disabled."
@@ -2408,41 +2403,6 @@ region, and automatic filling is disabled."
2408 )) 2403 ))
2409 ))) 2404 )))
2410 2405
2411
2412;;------------------------------------------------------------------------------
2413
2414;; FIXME: these next functions should become part of a larger effort to redo the
2415;; bullets in bulletted lists. The enumerate would just be one of the possible
2416;; outputs.
2417;;
2418;; FIXME: TODO we need to do the enumeration removal as well.
2419
2420(defun rst-enumerate-region (beg end)
2421 "Add enumeration to all the leftmost paragraphs in the given region.
2422The region is specified between BEG and END. With prefix argument,
2423do all lines instead of just paragraphs."
2424 (interactive "r")
2425 (let ((count 0)
2426 (last-insert-len nil))
2427 (rst-iterate-leftmost-paragraphs
2428 beg end (not current-prefix-arg)
2429 (let ((ins-string (format "%d. " (incf count))))
2430 (setq last-insert-len (length ins-string))
2431 (insert ins-string))
2432 (insert (make-string last-insert-len ?\ ))
2433 )))
2434
2435(defun rst-bullet-list-region (beg end)
2436 "Add bullets to all the leftmost paragraphs in the given region.
2437The region is specified between BEG and END. With prefix argument,
2438do all lines instead of just paragraphs."
2439 (interactive "r")
2440 (rst-iterate-leftmost-paragraphs
2441 beg end (not current-prefix-arg)
2442 (insert "- ")
2443 (insert " ")
2444 ))
2445
2446(defmacro rst-iterate-leftmost-paragraphs 2406(defmacro rst-iterate-leftmost-paragraphs
2447 (beg end first-only body-consequent body-alternative) 2407 (beg end first-only body-consequent body-alternative)
2448 "FIXME This definition is old and deprecated / we need to move 2408 "FIXME This definition is old and deprecated / we need to move
@@ -2456,7 +2416,6 @@ of each paragraph only."
2456 `(save-excursion 2416 `(save-excursion
2457 (let ((leftcol (rst-find-leftmost-column ,beg ,end)) 2417 (let ((leftcol (rst-find-leftmost-column ,beg ,end))
2458 (endm (set-marker (make-marker) ,end)) 2418 (endm (set-marker (make-marker) ,end))
2459 ,(when first-only '(in-par nil))
2460 ) 2419 )
2461 2420
2462 (do* (;; Iterate lines 2421 (do* (;; Iterate lines
@@ -2473,7 +2432,7 @@ of each paragraph only."
2473 (and (= curcol leftcol) 2432 (and (= curcol leftcol)
2474 (not (looking-at "[ \t]*$")))) 2433 (not (looking-at "[ \t]*$"))))
2475 ) 2434 )
2476 ((>= (point-marker) endm)) 2435 ((>= (point) endm))
2477 2436
2478 (if (if ,first-only 2437 (if (if ,first-only
2479 (and valid (not previous)) 2438 (and valid (not previous))
@@ -2487,15 +2446,15 @@ of each paragraph only."
2487(defmacro rst-iterate-leftmost-paragraphs-2 (spec &rest body) 2446(defmacro rst-iterate-leftmost-paragraphs-2 (spec &rest body)
2488 "Evaluate BODY for each line in region defined by BEG END. 2447 "Evaluate BODY for each line in region defined by BEG END.
2489LEFTMOST is set to true if the line is one of the leftmost of the 2448LEFTMOST is set to true if the line is one of the leftmost of the
2490entire paragraph. PARABEGIN is set to true if the line is the 2449entire paragraph. PARABEGIN is set to true if the line is the
2491first of a paragraph." 2450first of a paragraph."
2451 (declare (indent 1) (debug (sexp body)))
2492 (destructuring-bind 2452 (destructuring-bind
2493 (beg end parabegin leftmost isleftmost isempty) spec 2453 (beg end parabegin leftmost isleftmost isempty) spec
2494 2454
2495 `(save-excursion 2455 `(save-excursion
2496 (let ((,leftmost (rst-find-leftmost-column ,beg ,end)) 2456 (let ((,leftmost (rst-find-leftmost-column ,beg ,end))
2497 (endm (set-marker (make-marker) ,end)) 2457 (endm (set-marker (make-marker) ,end))
2498 (in-par nil)
2499 ) 2458 )
2500 2459
2501 (do* (;; Iterate lines 2460 (do* (;; Iterate lines
@@ -2516,13 +2475,48 @@ first of a paragraph."
2516 (and (not ,isempty) 2475 (and (not ,isempty)
2517 (= (current-column) ,leftmost))) 2476 (= (current-column) ,leftmost)))
2518 ) 2477 )
2519 ((>= (point-marker) endm)) 2478 ((>= (point) endm))
2520 2479
2521 (progn ,@body) 2480 (progn ,@body)
2522 2481
2523 ))))) 2482 )))))
2524 2483
2525 2484
2485;;------------------------------------------------------------------------------
2486
2487;; FIXME: these next functions should become part of a larger effort to redo the
2488;; bullets in bulletted lists. The enumerate would just be one of the possible
2489;; outputs.
2490;;
2491;; FIXME: TODO we need to do the enumeration removal as well.
2492
2493(defun rst-enumerate-region (beg end)
2494 "Add enumeration to all the leftmost paragraphs in the given region.
2495The region is specified between BEG and END. With prefix argument,
2496do all lines instead of just paragraphs."
2497 (interactive "r")
2498 (let ((count 0)
2499 (last-insert-len nil))
2500 (rst-iterate-leftmost-paragraphs
2501 beg end (not current-prefix-arg)
2502 (let ((ins-string (format "%d. " (incf count))))
2503 (setq last-insert-len (length ins-string))
2504 (insert ins-string))
2505 (insert (make-string last-insert-len ?\ ))
2506 )))
2507
2508(defun rst-bullet-list-region (beg end)
2509 "Add bullets to all the leftmost paragraphs in the given region.
2510The region is specified between BEG and END. With prefix argument,
2511do all lines instead of just paragraphs."
2512 (interactive "r")
2513 (rst-iterate-leftmost-paragraphs
2514 beg end (not current-prefix-arg)
2515 (insert "- ")
2516 (insert " ")
2517 ))
2518
2519
2526;; FIXME: there are some problems left with the following function 2520;; FIXME: there are some problems left with the following function
2527;; implementation: 2521;; implementation:
2528;; 2522;;
@@ -2533,7 +2527,7 @@ first of a paragraph."
2533 2527
2534(defun rst-convert-bullets-to-enumeration (beg end) 2528(defun rst-convert-bullets-to-enumeration (beg end)
2535 "Convert all the bulleted items and enumerated items in the 2529 "Convert all the bulleted items and enumerated items in the
2536 region to enumerated lists, renumbering as necessary." 2530region to enumerated lists, renumbering as necessary."
2537 (interactive "r") 2531 (interactive "r")
2538 (let* (;; Find items and convert the positions to markers. 2532 (let* (;; Find items and convert the positions to markers.
2539 (items (mapcar 2533 (items (mapcar
@@ -2559,26 +2553,20 @@ first of a paragraph."
2559;;------------------------------------------------------------------------------ 2553;;------------------------------------------------------------------------------
2560 2554
2561(defun rst-line-block-region (rbeg rend &optional pfxarg) 2555(defun rst-line-block-region (rbeg rend &optional pfxarg)
2562 "Toggle line block prefixes for a region. With prefix argument 2556 "Toggle line block prefixes for a region.
2563set the empty lines too." 2557With prefix argument set the empty lines too."
2564 (interactive "r\nP") 2558 (interactive "r\nP")
2565 (let ((comment-start "| ") 2559 (let ((comment-start "| ")
2566 (comment-end "") 2560 (comment-end "")
2567 (comment-start-skip "| ") 2561 (comment-start-skip "| ")
2568 (comment-style 'indent) 2562 (comment-style 'indent)
2569 (force current-prefix-arg)) 2563 (force (not (not pfxarg))))
2570 (rst-iterate-leftmost-paragraphs-2 2564 (rst-iterate-leftmost-paragraphs-2
2571 (rbeg rend parbegin leftmost isleft isempty) 2565 (rbeg rend parbegin leftmost isleft isempty)
2572 (if force 2566 (when (or force (not isempty))
2573 (progn 2567 (move-to-column leftmost force)
2574 (move-to-column leftmost t) 2568 (delete-region (point) (+ (point) (- (current-indentation) leftmost)))
2575 (delete-region (point) (+ (point) (- (current-indentation) leftmost))) 2569 (insert "| ")))))
2576 (insert "| "))
2577 (when (not isempty)
2578 (move-to-column leftmost)
2579 (delete-region (point) (+ (point) (- (current-indentation) leftmost)))
2580 (insert "| ")))
2581 )))
2582 2570
2583 2571
2584 2572
@@ -2592,17 +2580,17 @@ set the empty lines too."
2592 :version "21.1") 2580 :version "21.1")
2593 2581
2594(defcustom rst-block-face 'font-lock-keyword-face 2582(defcustom rst-block-face 'font-lock-keyword-face
2595 "All syntax marking up a special block" 2583 "All syntax marking up a special block."
2596 :group 'rst-faces 2584 :group 'rst-faces
2597 :type '(face)) 2585 :type '(face))
2598 2586
2599(defcustom rst-external-face 'font-lock-type-face 2587(defcustom rst-external-face 'font-lock-type-face
2600 "Field names and interpreted text" 2588 "Field names and interpreted text."
2601 :group 'rst-faces 2589 :group 'rst-faces
2602 :type '(face)) 2590 :type '(face))
2603 2591
2604(defcustom rst-definition-face 'font-lock-function-name-face 2592(defcustom rst-definition-face 'font-lock-function-name-face
2605 "All other defining constructs" 2593 "All other defining constructs."
2606 :group 'rst-faces 2594 :group 'rst-faces
2607 :type '(face)) 2595 :type '(face))
2608 2596
@@ -2611,12 +2599,12 @@ set the empty lines too."
2611 (if (boundp 'font-lock-builtin-face) 2599 (if (boundp 'font-lock-builtin-face)
2612 'font-lock-builtin-face 2600 'font-lock-builtin-face
2613 'font-lock-preprocessor-face) 2601 'font-lock-preprocessor-face)
2614 "Directives and roles" 2602 "Directives and roles."
2615 :group 'rst-faces 2603 :group 'rst-faces
2616 :type '(face)) 2604 :type '(face))
2617 2605
2618(defcustom rst-comment-face 'font-lock-comment-face 2606(defcustom rst-comment-face 'font-lock-comment-face
2619 "Comments" 2607 "Comments."
2620 :group 'rst-faces 2608 :group 'rst-faces
2621 :type '(face)) 2609 :type '(face))
2622 2610
@@ -2625,7 +2613,7 @@ set the empty lines too."
2625 (if (facep 'italic) 2613 (if (facep 'italic)
2626 ''italic 2614 ''italic
2627 'italic) 2615 'italic)
2628 "Simple emphasis" 2616 "Simple emphasis."
2629 :group 'rst-faces 2617 :group 'rst-faces
2630 :type '(face)) 2618 :type '(face))
2631 2619
@@ -2634,17 +2622,17 @@ set the empty lines too."
2634 (if (facep 'bold) 2622 (if (facep 'bold)
2635 ''bold 2623 ''bold
2636 'bold) 2624 'bold)
2637 "Double emphasis" 2625 "Double emphasis."
2638 :group 'rst-faces 2626 :group 'rst-faces
2639 :type '(face)) 2627 :type '(face))
2640 2628
2641(defcustom rst-literal-face 'font-lock-string-face 2629(defcustom rst-literal-face 'font-lock-string-face
2642 "Literal text" 2630 "Literal text."
2643 :group 'rst-faces 2631 :group 'rst-faces
2644 :type '(face)) 2632 :type '(face))
2645 2633
2646(defcustom rst-reference-face 'font-lock-variable-name-face 2634(defcustom rst-reference-face 'font-lock-variable-name-face
2647 "References to a definition" 2635 "References to a definition."
2648 :group 'rst-faces 2636 :group 'rst-faces
2649 :type '(face)) 2637 :type '(face))
2650 2638
@@ -2657,26 +2645,8 @@ general but you do not like the details."
2657 :group 'rst-faces 2645 :group 'rst-faces
2658 :version "21.1") 2646 :version "21.1")
2659 2647
2660(defun rst-define-level-faces ()
2661 "Define the faces for the section title text faces from the values."
2662 ;; All variables used here must be checked in `rst-set-level-default'
2663 (let ((i 1))
2664 (while (<= i rst-level-face-max)
2665 (let ((sym (intern (format "rst-level-%d-face" i)))
2666 (doc (format "Face for showing section title text at level %d" i))
2667 (col (format (concat "%s" rst-level-face-format-light)
2668 rst-level-face-base-color
2669 (+ (* (1- i) rst-level-face-step-light)
2670 rst-level-face-base-light))))
2671 (make-empty-face sym)
2672 (set-face-doc-string sym doc)
2673 (set-face-background sym col)
2674 (set sym sym)
2675 (setq i (1+ i))))))
2676
2677(defun rst-set-level-default (sym val) 2648(defun rst-set-level-default (sym val)
2678 "Set a customized value affecting section title text face and recompute the 2649 "Set custom var SYM affecting section title text face and recompute the faces."
2679faces."
2680 (custom-set-default sym val) 2650 (custom-set-default sym val)
2681 ;; Also defines the faces initially when all values are available 2651 ;; Also defines the faces initially when all values are available
2682 (and (boundp 'rst-level-face-max) 2652 (and (boundp 'rst-level-face-max)
@@ -2684,6 +2654,7 @@ faces."
2684 (boundp 'rst-level-face-base-color) 2654 (boundp 'rst-level-face-base-color)
2685 (boundp 'rst-level-face-step-light) 2655 (boundp 'rst-level-face-step-light)
2686 (boundp 'rst-level-face-base-light) 2656 (boundp 'rst-level-face-base-light)
2657 (fboundp 'rst-define-level-faces)
2687 (rst-define-level-faces))) 2658 (rst-define-level-faces)))
2688 2659
2689;; Faces for displaying items on several levels; these definitions define 2660;; Faces for displaying items on several levels; these definitions define
@@ -2704,9 +2675,9 @@ ection title faces for all levels."
2704 (if (eq frame-background-mode 'dark) 2675 (if (eq frame-background-mode 'dark)
2705 15 2676 15
2706 85) 2677 85)
2707 "The lightness factor for the base color. This value is used for level 1. The 2678 "The lightness factor for the base color. This value is used for level 1.
2708default depends on whether the value of `frame-background-mode' is `dark' or 2679The default depends on whether the value of `frame-background-mode' is
2709not." 2680`dark' or not."
2710 :group 'rst-faces-defaults 2681 :group 'rst-faces-defaults
2711 :type '(integer) 2682 :type '(integer)
2712 :set 'rst-set-level-default) 2683 :set 'rst-set-level-default)
@@ -2720,7 +2691,8 @@ This value is expanded by `format' with an integer."
2720 (if (eq frame-background-mode 'dark) 2691 (if (eq frame-background-mode 'dark)
2721 7 2692 7
2722 -7) 2693 -7)
2723 "The step width to use for the next color. The formula 2694 "The step width to use for the next color.
2695The formula
2724 2696
2725 `rst-level-face-base-light' 2697 `rst-level-face-base-light'
2726 + (`rst-level-face-max' - 1) * `rst-level-face-step-light' 2698 + (`rst-level-face-max' - 1) * `rst-level-face-step-light'
@@ -2741,10 +2713,11 @@ This color is used as background for section title text on level
2741 (nconc alist (list (cons i (intern (format "rst-level-%d-face" i))))) 2713 (nconc alist (list (cons i (intern (format "rst-level-%d-face" i)))))
2742 (setq i (1+ i))) 2714 (setq i (1+ i)))
2743 alist) 2715 alist)
2744 "Provides faces for the various adornment types. Key is a number (for the 2716 "Faces for the various adornment types.
2745section title text of that level), t (for transitions) or nil (for section 2717Key is a number (for the section title text of that level),
2746title adornment). If you generally do not like how section title text faces are 2718t (for transitions) or nil (for section title adornment).
2747set up tweak here. If the general idea is ok for you but you do not like the 2719If you generally do not like how section title text faces are
2720set up tweak here. If the general idea is ok for you but you do not like the
2748details check the Rst Faces Defaults group." 2721details check the Rst Faces Defaults group."
2749 :group 'rst-faces 2722 :group 'rst-faces
2750 :type '(alist 2723 :type '(alist
@@ -2757,6 +2730,23 @@ details check the Rst Faces Defaults group."
2757 :value-type (face)) 2730 :value-type (face))
2758 :set-after '(rst-level-face-max)) 2731 :set-after '(rst-level-face-max))
2759 2732
2733(defun rst-define-level-faces ()
2734 "Define the faces for the section title text faces from the values."
2735 ;; All variables used here must be checked in `rst-set-level-default'
2736 (let ((i 1))
2737 (while (<= i rst-level-face-max)
2738 (let ((sym (intern (format "rst-level-%d-face" i)))
2739 (doc (format "Face for showing section title text at level %d" i))
2740 (col (format (concat "%s" rst-level-face-format-light)
2741 rst-level-face-base-color
2742 (+ (* (1- i) rst-level-face-step-light)
2743 rst-level-face-base-light))))
2744 (make-empty-face sym)
2745 (set-face-doc-string sym doc)
2746 (set-face-background sym col)
2747 (set sym sym)
2748 (setq i (1+ i))))))
2749
2760 2750
2761 2751
2762;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2752;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2767,7 +2757,7 @@ details check the Rst Faces Defaults group."
2767 "Non-nil if we can use the character classes in our regexps.") 2757 "Non-nil if we can use the character classes in our regexps.")
2768 2758
2769(defun rst-font-lock-keywords-function () 2759(defun rst-font-lock-keywords-function ()
2770 "Returns keywords to highlight in rst mode according to current settings." 2760 "Return keywords to highlight in rst mode according to current settings."
2771 ;; The reST-links in the comments below all relate to sections in 2761 ;; The reST-links in the comments below all relate to sections in
2772 ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html 2762 ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
2773 (let* ( ;; This gets big - so let's define some abbreviations 2763 (let* ( ;; This gets big - so let's define some abbreviations
@@ -2990,8 +2980,8 @@ details check the Rst Faces Defaults group."
2990(defun rst-forward-indented-block (&optional column limit) 2980(defun rst-forward-indented-block (&optional column limit)
2991 "Move forward across one indented block. 2981 "Move forward across one indented block.
2992Find the next non-empty line which is not indented at least to COLUMN (defaults 2982Find the next non-empty line which is not indented at least to COLUMN (defaults
2993to the column of the point). Moves point to first character of this line or the 2983to the column of the point). Moves point to first character of this line or the
2994first empty line immediately before it and returns that position. If there is 2984first empty line immediately before it and returns that position. If there is
2995no such line before LIMIT (defaults to the end of the buffer) returns nil and 2985no such line before LIMIT (defaults to the end of the buffer) returns nil and
2996point is not moved." 2986point is not moved."
2997 (interactive) 2987 (interactive)
@@ -3077,9 +3067,9 @@ point is not moved."
3077;; on this information 3067;; on this information
3078(defvar rst-adornment-level-alist nil 3068(defvar rst-adornment-level-alist nil
3079 "Associates adornments with section levels. 3069 "Associates adornments with section levels.
3080The key is a two character string. The first character is the adornment 3070The key is a two character string. The first character is the adornment
3081character. The second character distinguishes underline section titles (`u') 3071character. The second character distinguishes underline section titles (`u')
3082from overline/underline section titles (`o'). The value is the section level. 3072from overline/underline section titles (`o'). The value is the section level.
3083 3073
3084This is made buffer local on start and adornments found during font lock are 3074This is made buffer local on start and adornments found during font lock are
3085entered.") 3075entered.")
@@ -3203,7 +3193,8 @@ document with \\[rst-compile]."
3203 (newlatex . ("rst2newlatex.py" ".tex" nil)) 3193 (newlatex . ("rst2newlatex.py" ".tex" nil))
3204 (pseudoxml . ("rst2pseudoxml.py" ".xml" nil)) 3194 (pseudoxml . ("rst2pseudoxml.py" ".xml" nil))
3205 (xml . ("rst2xml.py" ".xml" nil))) 3195 (xml . ("rst2xml.py" ".xml" nil)))
3206 "An association list of the toolset to a list of the (command to use, 3196 "Table describing the command to use for each toolset.
3197An association list of the toolset to a list of the (command to use,
3207extension of produced filename, options to the tool (nil or a 3198extension of produced filename, options to the tool (nil or a
3208string)) to be used for converting the document.") 3199string)) to be used for converting the document.")
3209 3200
@@ -3214,10 +3205,10 @@ string)) to be used for converting the document.")
3214 3205
3215 3206
3216(defvar rst-compile-primary-toolset 'html 3207(defvar rst-compile-primary-toolset 'html
3217 "The default toolset for rst-compile.") 3208 "The default toolset for `rst-compile'.")
3218 3209
3219(defvar rst-compile-secondary-toolset 'latex 3210(defvar rst-compile-secondary-toolset 'latex
3220 "The default toolset for rst-compile with a prefix argument.") 3211 "The default toolset for `rst-compile' with a prefix argument.")
3221 3212
3222(defun rst-compile-find-conf () 3213(defun rst-compile-find-conf ()
3223 "Look for the configuration file in the parents of the current path." 3214 "Look for the configuration file in the parents of the current path."
@@ -3286,8 +3277,8 @@ argument, select the alternative toolset."
3286 (rst-compile 't)) 3277 (rst-compile 't))
3287 3278
3288(defun rst-compile-pseudo-region () 3279(defun rst-compile-pseudo-region ()
3289 "Show the pseudo-XML rendering of the current active region, or 3280 "Show the pseudo-XML rendering of the current active region,
3290of the entire buffer, if the region is not selected." 3281or of the entire buffer, if the region is not selected."
3291 (interactive) 3282 (interactive)
3292 (with-output-to-temp-buffer "*pseudoxml*" 3283 (with-output-to-temp-buffer "*pseudoxml*"
3293 (shell-command-on-region 3284 (shell-command-on-region
@@ -3340,21 +3331,15 @@ with equal-length lines of TOCHAR."
3340cSearch for flush-left lines of char: 3331cSearch for flush-left lines of char:
3341cand replace with char: ") 3332cand replace with char: ")
3342 (save-excursion 3333 (save-excursion
3343 (let* ((fromstr (string fromchar)) 3334 (let ((searchre (concat "^" (regexp-quote (string fromchar)) "+\\( *\\)$"))
3344 (searchre (concat "^" (regexp-quote fromstr) "+ *$")) 3335 (found 0))
3345 (found 0)) 3336 (while (search-forward-regexp searchre nil t)
3346 (condition-case err 3337 (setq found (1+ found))
3347 (while t 3338 (goto-char (match-beginning 1))
3348 (search-forward-regexp searchre) 3339 (let ((width (current-column)))
3349 (setq found (1+ found)) 3340 (rst-delete-entire-line)
3350 (search-backward fromstr) ;; point will be *before* last char 3341 (insert-char tochar width)))
3351 (setq p (1+ (point))) 3342 (message (format "%d lines replaced." found)))))
3352 (beginning-of-line)
3353 (setq l (- p (point)))
3354 (rst-delete-entire-line)
3355 (insert-char tochar l))
3356 (search-failed
3357 (message (format "%d lines replaced." found)))))))
3358 3343
3359(defun rst-join-paragraph () 3344(defun rst-join-paragraph ()
3360 "Join lines in current paragraph into one line, removing end-of-lines." 3345 "Join lines in current paragraph into one line, removing end-of-lines."
@@ -3376,7 +3361,7 @@ This is useful for filling list item paragraphs."
3376(defun rst-repeat-last-character (&optional tofill) 3361(defun rst-repeat-last-character (&optional tofill)
3377 "Fills the current line up to the length of the preceding line (if not 3362 "Fills the current line up to the length of the preceding line (if not
3378empty), using the last character on the current line. If the preceding line is 3363empty), using the last character on the current line. If the preceding line is
3379empty, we use the fill-column. 3364empty, we use the `fill-column'.
3380 3365
3381If a prefix argument is provided, use the next line rather than the preceding 3366If a prefix argument is provided, use the next line rather than the preceding
3382line. 3367line.