annotate lisp/textmodes/rst.el @ 108765:d835100c3e8b

Replace Lisp calls to delete-backward-char by delete-char. * bs.el, expand.el, ido.el, image-dired.el, lpr.el, pcomplete.el, skeleton.el, term.el, time.el, wid-edit.el, woman.el, calc/calc-graph.el, calc/calc-help.el, calc/calc-incom.el, calc/calc.el, emacs-cl-extra.el, emacs-cl-loaddefs.el, emulation/cua-rect.el, emulation/viper-ex.el, eshell/esh-test.el, eshell/eshell.el, gnus/gnus-uu.el, gnus/nndoc.el, gnus/nnrss.el, gnus/rfc2047.el, gnus/utf7.el, international/utf-7.el, language/ethio-util.el, mh-e/mh-alias.el, mh-e/mh-search.el, net/imap.el, net/rcirc.el, obsolete/complete.el, play/decipher.el, progmodes/ada-mode.el, progmodes/cc-awk.el, progmodes/dcl-mode.el, progmodes/ps-mode.el, progmodes/verilog-mode.el, progmodes/vhdl-mode.el, textmodes/bibtex.el, textmodes/fill.el, textmodes/reftex-auc.el, textmodes/rst.el, textmodes/sgml-mode.el, textmodes/table.el, textmodes/texinfmt.el: Replace Lisp calls to delete-backward-char by calls to delete-char.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 24 May 2010 22:11:08 -0400
parents 4f21cfcfbb42
children e7a37ab07782
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; rst.el --- Mode for viewing and editing reStructuredText-documents.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105870
diff changeset
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Authors: Martin Blais <blais@furius.ca>,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7 ;; Stefan Merten <smerten@oekonux.de>,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8 ;; David Goodger <goodger@python.org>
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15 ;; (at your option) any later version.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20 ;; GNU General Public License for more details.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
21
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
24
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25 ;;; Commentary:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27 ;; This package provides major mode rst-mode, which supports documents marked up
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
28 ;; using the reStructuredText format. Support includes font locking as well as
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
29 ;; some convenience functions for editing. It does this by defining a Emacs
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
30 ;; major mode: rst-mode (ReST). This mode is derived from text-mode (and
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
31 ;; inherits much of it). This package also contains:
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33 ;; - Functions to automatically adjust and cycle the section underline
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;; decorations;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35 ;; - A mode that displays the table of contents and allows you to jump anywhere
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 ;; from it;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 ;; - Functions to insert and automatically update a TOC in your source
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 ;; document;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 ;; - Font-lock highlighting of notable reStructuredText structures;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40 ;; - Some other convenience functions.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
42 ;; See the accompanying document in the docutils documentation about
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43 ;; the contents of this package and how to use it.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
45 ;; For more information about reStructuredText, see
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46 ;; http://docutils.sourceforge.net/rst.html
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
48 ;; For full details on how to use the contents of this file, see
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 ;; http://docutils.sourceforge.net/docs/user/emacs.html
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 ;;
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
52 ;; There are a number of convenient keybindings provided by rst-mode.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
53 ;; The main one is
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 ;; C-c C-a (also C-=): rst-adjust
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 ;; Updates or rotates the section title around point or promotes/demotes the
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
58 ;; decorations within the region (see full details below). Note that C-= is a
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 ;; good binding, since it allows you to specify a negative arg easily with C--
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 ;; C-= (easy to type), as well as ordinary prefix arg with C-u C-=.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 ;;
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
62 ;; For more on bindings, see rst-mode-map below. There are also many variables
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63 ;; that can be customized, look for defcustom and defvar in this file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65 ;; If you use the table-of-contents feature, you may want to add a hook to
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 ;; update the TOC automatically everytime you adjust a section title::
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 ;; (add-hook 'rst-adjust-hook 'rst-toc-update)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 ;;
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
70 ;; Syntax highlighting: font-lock is enabled by default. If you want to turn
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
71 ;; off syntax highlighting to rst-mode, you can use the following::
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 ;; (setq font-lock-global-modes '(not rst-mode ...))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 ;; CUSTOMIZATION
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 ;; rst
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 ;; ---
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81 ;; This group contains some general customizable features.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 ;; The group is contained in the wp group.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 ;; rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 ;; ---------
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
87 ;; This group contains all necessary for customizing fonts. The default
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 ;; settings use standard font-lock-*-face's so if you set these to your
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 ;; liking they are probably good in rst-mode also.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 ;; The group is contained in the faces group as well as in the rst group.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 ;; rst-faces-defaults
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 ;; ------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 ;; This group contains all necessary for customizing the default fonts used for
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 ;; section title faces.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 ;; The general idea for section title faces is to have a non-default background
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
99 ;; but do not change the background. The section level is shown by the
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
100 ;; lightness of the background color. If you like this general idea of
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 ;; generating faces for section titles but do not like the details this group
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
102 ;; is the point where you can customize the details. If you do not like the
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103 ;; general idea, however, you should customize the faces used in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104 ;; rst-adornment-faces-alist.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106 ;; Note: If you are using a dark background please make sure the variable
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
107 ;; frame-background-mode is set to the symbol dark. This triggers
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108 ;; some default values which are probably right for you.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110 ;; The group is contained in the rst-faces group.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
111 ;;
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
112 ;; All customizable features have a comment explaining their meaning.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
113 ;; Refer to the customization of your Emacs (try ``M-x customize``).
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
114
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
115
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 ;;; DOWNLOAD
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 ;; The latest version of this file lies in the docutils source code repository:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 ;; http://svn.berlios.de/svnroot/repos/docutils/trunk/docutils/tools/editors/emacs/rst.el
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 ;;; INSTALLATION
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
123
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
124 ;; Add the following lines to your `.emacs' file:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126 ;; (require 'rst)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
128 ;; If you are using `.txt' as a standard extension for reST files as
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
129 ;; http://docutils.sourceforge.net/FAQ.html#what-s-the-standard-filename-extension-for-a-restructuredtext-file
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
130 ;; suggests you may use one of the `Local Variables in Files' mechanism Emacs
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
131 ;; provides to set the major mode automatically. For instance you may use::
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
132 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
133 ;; .. -*- mode: rst -*-
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
134 ;;
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
135 ;; in the very first line of your file. The following code is useful if you
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
136 ;; want automatically enter rst-mode from any file with compatible extensions:
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
137 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
138 ;; (setq auto-mode-alist
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
139 ;; (append '(("\\.txt$" . rst-mode)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
140 ;; ("\\.rst$" . rst-mode)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
141 ;; ("\\.rest$" . rst-mode)) auto-mode-alist))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
142 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
143
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
144 ;;; BUGS
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
146 ;; - rst-enumeration-region: Select a single paragraph, with the top at one
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147 ;; blank line before the beginning, and it will fail.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
148 ;; - The active region goes away when we shift it left or right, and this
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
149 ;; prevents us from refilling it automatically when shifting many times.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
150 ;; - The suggested decorations when adjusting should not have to cycle
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
151 ;; below one below the last section decoration level preceding the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
152 ;; cursor. We need to fix that.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
153
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
154 ;;; TODO LIST
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
155
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
156 ;; rst-toc-insert features
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
157 ;; ------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
158 ;; - rst-toc-insert: We should parse the contents:: options to figure out how
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
159 ;; deep to render the inserted TOC.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160 ;; - On load, detect any existing TOCs and set the properties for links.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
161 ;; - TOC insertion should have an option to add empty lines.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162 ;; - TOC insertion should deal with multiple lines.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163 ;; - There is a bug on redo after undo of adjust when rst-adjust-hook uses the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 ;; automatic toc update. The cursor ends up in the TOC and this is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 ;; annoying. Gotta fix that.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 ;; - numbering: automatically detect if we have a section-numbering directive in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 ;; the corresponding section, to render the toc.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 ;; bulleted and enumerated list items
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 ;; ----------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 ;; - We need to provide way to rebullet bulleted lists, and that would include
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 ;; automatic enumeration as well.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 ;; Other
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 ;; -----
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176 ;; - It would be nice to differentiate between text files using
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 ;; reStructuredText_ and other general text files. If we had a
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 ;; function to automatically guess whether a .txt file is following the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 ;; reStructuredText_ conventions, we could trigger rst-mode without
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
180 ;; having to hard-code this in every text file, nor forcing the user to
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 ;; add a local mode variable at the top of the file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 ;; We could perform this guessing by searching for a valid decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183 ;; at the top of the document or searching for reStructuredText_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184 ;; directives further on.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186 ;; - We should support imenu in our major mode, with the menu filled with the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 ;; section titles (this should be really easy).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
188 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189 ;; - We should rename "adornment" to "decoration" or vice-versa in this
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
190 ;; document (Stefan's code ("adornment") vs Martin ("decoration")), maybe some
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191 ;; functions even overlap.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
192 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 ;; - We need to automatically recenter on rst-forward-section movement commands.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
194
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
196 ;;; HISTORY
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
198
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
199 ;;; Code:
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
200
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
202 (defgroup rst nil "Support for reStructuredText documents."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 :group 'wp
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
204 :version "23.1"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 :link '(url-link "http://docutils.sourceforge.net/rst.html"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
206
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
208
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
209
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
211 ;; Define some generic support functions.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
212
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
213 (eval-when-compile (require 'cl)) ;; We need this for destructuring-bind below.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
214
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
215
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
216 ;; From Emacs-22
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
217 (unless (fboundp 'line-number-at-pos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
218 (defun line-number-at-pos (&optional pos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
219 "Return (narrowed) buffer line number at position POS.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
220 If POS is nil, use current buffer location."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
221 (let ((opoint (or pos (point))) start)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
222 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
223 (goto-char (point-min))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
224 (setq start (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
225 (goto-char opoint)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
226 (forward-line 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
227 (1+ (count-lines start (point)))))) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
228
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
229
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
230
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
232 ;; Mode definition.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
234 ;; Key bindings.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
235 (defvar rst-mode-map
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236 (let ((map (make-sparse-keymap)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
238 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
239 ;; Section Decorations.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
240 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
241 ;; The adjustment function that decorates or rotates a section title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242 (define-key map [(control c) (control a)] 'rst-adjust)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
243 (define-key map [(control c) (control ?=)] 'rst-adjust)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
244 (define-key map [(control ?=)] 'rst-adjust) ;; (Does not work on the Mac OSX.)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
245 ;; Display the hierarchy of decorations implied by the current document contents.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
246 (define-key map [(control c) (control h)] 'rst-display-decorations-hierarchy)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
247 ;; Homogeneize the decorations in the document.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
248 (define-key map [(control c) (control s)] 'rst-straighten-decorations)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249 ;; (define-key map [(control c) (control s)] 'rst-straighten-deco-spacing)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
250
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
251 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
252 ;; Section Movement and Selection.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
253 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
254 ;; Mark the subsection where the cursor is.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
255 (define-key map [(control c) (control m)] 'rst-mark-section)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
256 ;; Move forward/backward between section titles.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
257 (define-key map [(control c) (control n)] 'rst-forward-section)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
258 (define-key map [(control c) (control p)] 'rst-backward-section)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
259
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
260 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
261 ;; Operating on Blocks of Text.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263 ;; Makes paragraphs in region as a bullet list.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
264 (define-key map [(control c) (control b)] 'rst-bullet-list-region)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
265 ;; Makes paragraphs in region as a enumeration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
266 (define-key map [(control c) (control e)] 'rst-enumerate-region)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
267 ;; Converts bullets to an enumeration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
268 (define-key map [(control c) (control v)] 'rst-convert-bullets-to-enumeration)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
269 ;; Makes region a line-block.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
270 (define-key map [(control c) (control d)] 'rst-line-block-region)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
271 ;; Make sure that all the bullets in the region are consistent.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272 (define-key map [(control c) (control w)] 'rst-straighten-bullets-region)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
273 ;; Shift region left or right (taking into account of enumerations/bullets, etc.).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
274 (define-key map [(control c) (control l)] 'rst-shift-region-left)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
275 (define-key map [(control c) (control r)] 'rst-shift-region-right)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
276 ;; Comment/uncomment the active region.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
277 (define-key map [(control c) (control c)] 'comment-region)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
278
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
279 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
280 ;; Table-of-Contents Features.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
281 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
282 ;; Enter a TOC buffer to view and move to a specific section.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
283 (define-key map [(control c) (control t)] 'rst-toc)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
284 ;; Insert a TOC here.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
285 (define-key map [(control c) (control i)] 'rst-toc-insert)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
286 ;; Update the document's TOC (without changing the cursor position).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
287 (define-key map [(control c) (control u)] 'rst-toc-update)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288 ;; Got to the section under the cursor (cursor must be in TOC).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
289 (define-key map [(control c) (control f)] 'rst-goto-section)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
290
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
291 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
292 ;; Converting Documents from Emacs.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
293 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294 ;; Run one of two pre-configured toolset commands on the document.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295 (define-key map [(control c) (?1)] 'rst-compile)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
296 (define-key map [(control c) (?2)] 'rst-compile-alt-toolset)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
297 ;; Convert the active region to pseudo-xml using the docutils tools.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
298 (define-key map [(control c) (?3)] 'rst-compile-pseudo-region)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299 ;; Convert the current document to PDF and launch a viewer on the results.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (define-key map [(control c) (?4)] 'rst-compile-pdf-preview)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
301 ;; Convert the current document to S5 slides and view in a web browser.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
302 (define-key map [(control c) (?5)] 'rst-compile-slides-preview)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
303
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 map)
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
305 "Keymap for reStructuredText mode commands.
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
306 This inherits from Text mode.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
307
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
308
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309 ;; Abbrevs.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (defvar rst-mode-abbrev-table nil
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
311 "Abbrev table used while in Rst mode.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
312 (define-abbrev-table 'rst-mode-abbrev-table
102125
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
313 (mapcar (lambda (x) (append x '(nil 0 system)))
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
314 '(("contents" ".. contents::\n..\n ")
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
315 ("con" ".. contents::\n..\n ")
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
316 ("cont" "[...]")
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
317 ("skip" "\n\n[...]\n\n ")
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
318 ("seq" "\n\n[...]\n\n ")
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
319 ;; FIXME: Add footnotes, links, and more.
057f38650810 (rst-mode-abbrev-table): Mark entries as `system'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
320 )))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
322
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
323 ;; Syntax table.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
324 (defvar rst-mode-syntax-table
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
325 (let ((st (copy-syntax-table text-mode-syntax-table)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
326
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
327 (modify-syntax-entry ?$ "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 (modify-syntax-entry ?% "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (modify-syntax-entry ?& "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
330 (modify-syntax-entry ?' "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
331 (modify-syntax-entry ?* "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332 (modify-syntax-entry ?+ "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 (modify-syntax-entry ?. "_" st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334 (modify-syntax-entry ?/ "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 (modify-syntax-entry ?< "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
336 (modify-syntax-entry ?= "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
337 (modify-syntax-entry ?> "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338 (modify-syntax-entry ?\\ "\\" st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
339 (modify-syntax-entry ?| "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
340 (modify-syntax-entry ?_ "." st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342 st)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 "Syntax table used while in `rst-mode'.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
346 (defcustom rst-mode-hook nil
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
347 "Hook run when Rst mode is turned on.
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
348 The hook for Text mode is run before this one."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
349 :group 'rst
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
350 :type '(hook))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
351
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
352
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
353 (defcustom rst-mode-lazy t
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
354 "If non-nil Rst mode tries to font-lock multi-line elements correctly.
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
355 Because this is really slow it should be set to nil if neither `jit-lock-mode'
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
356 not `lazy-lock-mode' and activated.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
357
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
358 If nil, comments and literal blocks are font-locked only on the line they start.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
360 The value of this variable is used when Rst mode is turned on."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
361 :group 'rst
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
362 :type '(boolean))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
363
96127
8b630d07bb3f (auto-mode-alist): Use rst-mode for *.rst and *.rest files.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96126
diff changeset
364 ;; Use rst-mode for *.rst and *.rest files. Many ReStructured-Text files
8b630d07bb3f (auto-mode-alist): Use rst-mode for *.rst and *.rest files.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96126
diff changeset
365 ;; use *.txt, but this is too generic to be set as a default.
105870
26baacb565b0 * textmodes/tex-mode.el (tex-alt-dvi-print-command)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 104543
diff changeset
366 ;;;###autoload (add-to-list 'auto-mode-alist (purecopy '("\\.re?st\\'" . rst-mode)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
367 ;;;###autoload
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
368 (define-derived-mode rst-mode text-mode "ReST"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
369 "Major mode for editing reStructuredText documents.
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
370 \\<rst-mode-map>
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371 There are a number of convenient keybindings provided by
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
372 Rst mode. The main one is \\[rst-adjust], it updates or rotates
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
373 the section title around point or promotes/demotes the
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
374 decorations within the region (see full details below).
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
375 Use negative prefix arg to rotate in the other direction.
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
376
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
377 Turning on `rst-mode' calls the normal hooks `text-mode-hook'
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
378 and `rst-mode-hook'. This mode also supports font-lock
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
379 highlighting. You may customize `rst-mode-lazy' to toggle
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
380 font-locking of blocks.
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
381
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
382 \\{rst-mode-map}"
96175
7f68a049c054 (rst-mode): Put docstring in right place.
John Paul Wallington <jpw@pobox.com>
parents: 96139
diff changeset
383 :abbrev-table rst-mode-abbrev-table
7f68a049c054 (rst-mode): Put docstring in right place.
John Paul Wallington <jpw@pobox.com>
parents: 96139
diff changeset
384 :syntax-table rst-mode-syntax-table
7f68a049c054 (rst-mode): Put docstring in right place.
John Paul Wallington <jpw@pobox.com>
parents: 96139
diff changeset
385 :group 'rst
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
386
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
387 (set (make-local-variable 'paragraph-separate) paragraph-start)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 (set (make-local-variable 'indent-line-function) 'indent-relative-maybe)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 (set (make-local-variable 'paragraph-start)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
390 "\f\\|>*[ \t]*$\\|>*[ \t]*[-+*] \\|>*[ \t]*[0-9#]+\\. ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
391 (set (make-local-variable 'adaptive-fill-mode) t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
392
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 ;; FIXME: No need to reset this.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
394 ;; (set (make-local-variable 'indent-line-function) 'indent-relative)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
396 ;; The details of the following comment setup is important because it affects
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
397 ;; auto-fill, and it is pretty common in running text to have an ellipsis
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
398 ;; ("...") which trips because of the rest comment syntax (".. ").
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399 (set (make-local-variable 'comment-start) ".. ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
400 (set (make-local-variable 'comment-start-skip) "^\\.\\. ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
401 (set (make-local-variable 'comment-multi-line) nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
402
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
403 ;; Special variables
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404 (make-local-variable 'rst-adornment-level-alist)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 ;; Font lock
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
407 (set (make-local-variable 'font-lock-defaults)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
408 '(rst-font-lock-keywords-function
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
409 t nil nil nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
410 (font-lock-mark-block-function . mark-paragraph)))
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
411 ;; `jit-lock-mode' has been the default since Emacs-21.1, so there's no
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
412 ;; point messing around with font-lock-support-mode any more.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
413 ;; (when (boundp 'font-lock-support-mode)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
414 ;; ;; rst-mode has its own mind about font-lock-support-mode
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
415 ;; (make-local-variable 'font-lock-support-mode)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
416 ;; ;; jit-lock-mode replaced lazy-lock-mode in GNU Emacs 21.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
417 ;; (let ((jit-or-lazy-lock-mode
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
418 ;; (cond
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
419 ;; ((fboundp 'lazy-lock-mode) 'lazy-lock-mode)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
420 ;; ((fboundp 'jit-lock-mode) 'jit-lock-mode)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
421 ;; ;; if neither lazy-lock nor jit-lock is supported,
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
422 ;; ;; tell user and disable rst-mode-lazy
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
423 ;; (t (when rst-mode-lazy
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
424 ;; (message "Disabled lazy fontification, because no known support mode found.")
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
425 ;; (setq rst-mode-lazy nil))))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
426 ;; (cond
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
427 ;; ((and (not rst-mode-lazy) (not font-lock-support-mode)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
428 ;; ;; No support mode set and none required - leave it alone
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
429 ;; ((or (not font-lock-support-mode) ;; No support mode set (but required)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
430 ;; (symbolp font-lock-support-mode)) ;; or a fixed mode for all
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
431 ;; (setq font-lock-support-mode
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
432 ;; (list (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
433 ;; (cons t font-lock-support-mode))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
434 ;; ((and (listp font-lock-support-mode)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
435 ;; (not (assoc 'rst-mode font-lock-support-mode)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
436 ;; ;; A list of modes missing rst-mode
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
437 ;; (setq font-lock-support-mode
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
438 ;; (cons (cons 'rst-mode (and rst-mode-lazy jit-or-lazy-lock-mode))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
439 ;; font-lock-support-mode))))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
443
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
444 ;;;###autoload
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
445 (define-minor-mode rst-minor-mode
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
446 "ReST Minor Mode.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
447 Toggle ReST minor mode.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448 With no argument, this command toggles the mode.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449 Non-null prefix argument turns on the mode.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
450 Null prefix argument turns off the mode.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
452 When ReST minor mode is enabled, the ReST mode keybindings
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
453 are installed on top of the major mode bindings. Use this
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
454 for modes derived from Text mode, like Mail mode."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
455 ;; The initial value.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
456 nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
457 ;; The indicator for the mode line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
458 " ReST"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
459 ;; The minor mode bindings.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
460 rst-mode-map
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
461 :group 'rst)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
462
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
463 ;; FIXME: can I somehow install these too?
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
464 ;; :abbrev-table rst-mode-abbrev-table
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
465 ;; :syntax-table rst-mode-syntax-table
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
466
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
467
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
468
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
469
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
470
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
471 ;; Bulleted item lists.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
472 (defcustom rst-bullets
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
473 '(?- ?* ?+)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
474 "List of all possible bullet characters for bulleted lists."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
475 :group 'rst)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
476
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
477
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
478
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
479
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481 ;; Section Decoration Adjusment
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
482 ;; ============================
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
483 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
484 ;; The following functions implement a smart automatic title sectioning feature.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485 ;; The idea is that with the cursor sitting on a section title, we try to get as
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
486 ;; much information from context and try to do the best thing automatically.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
487 ;; This function can be invoked many times and/or with prefix argument to rotate
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488 ;; between the various sectioning decorations.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
489 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
490 ;; Definitions: the two forms of sectioning define semantically separate section
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
491 ;; levels. A sectioning DECORATION consists in:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
492 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
493 ;; - a CHARACTER
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
494 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
495 ;; - a STYLE which can be either of 'simple' or 'over-and-under'.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 ;; - an INDENT (meaningful for the over-and-under style only) which determines
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
498 ;; how many characters and over-and-under style is hanging outside of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
499 ;; title at the beginning and ending.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
500 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501 ;; Important note: an existing decoration must be formed by at least two
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502 ;; characters to be recognized.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
503 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
504 ;; Here are two examples of decorations (| represents the window border, column
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 ;; 0):
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
506 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
507 ;; |
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508 ;; 1. char: '-' e |Some Title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509 ;; style: simple |----------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
510 ;; |
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
511 ;; 2. char: '=' |==============
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
512 ;; style: over-and-under | Some Title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
513 ;; indent: 2 |==============
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514 ;; |
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
515 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
516 ;; Some notes:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
517 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 ;; - The underlining character that is used depends on context. The file is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
519 ;; scanned to find other sections and an appropriate character is selected.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520 ;; If the function is invoked on a section that is complete, the character is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
521 ;; rotated among the existing section decorations.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
522 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
523 ;; Note that when rotating the characters, if we come to the end of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 ;; hierarchy of decorations, the variable rst-preferred-decorations is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
525 ;; consulted to propose a new underline decoration, and if continued, we cycle
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
526 ;; the decorations all over again. Set this variable to nil if you want to
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
527 ;; limit the underlining character propositions to the existing decorations in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
528 ;; the file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
529 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
530 ;; - A prefix argument can be used to alternate the style.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
531 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
532 ;; - An underline/overline that is not extended to the column at which it should
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
533 ;; be hanging is dubbed INCOMPLETE. For example::
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
534 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
535 ;; |Some Title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
536 ;; |-------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
537 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
538 ;; Examples of default invocation:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
539 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
540 ;; |Some Title ---> |Some Title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
541 ;; | |----------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
543 ;; |Some Title ---> |Some Title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
544 ;; |----- |----------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
545 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 ;; | |------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
547 ;; | Some Title ---> | Some Title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
548 ;; | |------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
549 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
550 ;; In over-and-under style, when alternating the style, a variable is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551 ;; available to select how much default indent to use (it can be zero). Note
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 ;; that if the current section decoration already has an indent, we don't
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
553 ;; adjust it to the default, we rather use the current indent that is already
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
554 ;; there for adjustment (unless we cycle, in which case we use the indent
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 ;; that has been found previously).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
557 (defgroup rst-adjust nil
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
558 "Settings for adjustment and cycling of section title decorations."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
559 :group 'rst
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
560 :version "21.1")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
561
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
562 (defcustom rst-preferred-decorations '( (?= over-and-under 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
563 (?= simple 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
564 (?- simple 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
565 (?~ simple 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
566 (?+ simple 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
567 (?` simple 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
568 (?# simple 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
569 (?@ simple 0) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
570 "Preferred ordering of section title decorations.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
571
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
572 This sequence is consulted to offer a new decoration suggestion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
573 when we rotate the underlines at the end of the existing
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
574 hierarchy of characters, or when there is no existing section
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575 title in the file."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576 :group 'rst-adjust)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
577
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
578
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
579 (defcustom rst-default-indent 1
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
580 "Number of characters to indent the section title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
581
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
582 This is used for when toggling decoration styles, when switching
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
583 from a simple decoration style to a over-and-under decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
584 style."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
585 :group 'rst-adjust)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
586
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
587
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
588 (defvar rst-section-text-regexp "^[ \t]*\\S-*\\w\\S-*"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
589 "Regular expression for valid section title text.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
590
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
591
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
592 (defun rst-line-homogeneous-p (&optional accept-special)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
593 "Return true if the line is homogeneous.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
594
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
595 Predicate that returns the unique char if the current line is
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
596 composed only of a single repeated non-whitespace character.
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
597 This returns the char even if there is whitespace at the
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
598 beginning of the line.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
599
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
600 If ACCEPT-SPECIAL is specified we do not ignore special sequences
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
601 which normally we would ignore when doing a search on many lines.
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
602 For example, normally we have cases to ignore commonly occurring
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
603 patterns, such as :: or ...; with the flag do not ignore them."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
604 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
605 (back-to-indentation)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
606 (unless (looking-at "\n")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
607 (let ((c (thing-at-point 'char)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
608 (if (and (looking-at (format "[%s]+[ \t]*$" c))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
609 (or accept-special
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
610 (and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
611 ;; Common patterns.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
612 (not (looking-at "::[ \t]*$"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
613 (not (looking-at "\\.\\.\\.[ \t]*$"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
614 ;; Discard one char line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
615 (not (looking-at ".[ \t]*$"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
616 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
617 (string-to-char c))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
618 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
619 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
620
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
621 (defun rst-line-homogeneous-nodent-p (&optional accept-special)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
622 "Return true if the line is homogeneous with no indent.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
623 See `rst-line-homogeneous-p' about ACCEPT-SPECIAL."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
624 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
625 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
626 (if (looking-at "^[ \t]+")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
627 nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
628 (rst-line-homogeneous-p accept-special)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
629 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
630
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
631
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
632 (defun rst-compare-decorations (deco1 deco2)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
633 "Compare decorations.
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
634 Return true if both DECO1 and DECO2 decorations are equal,
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
635 according to restructured text semantics (only the character and
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
636 the style are compared, the indentation does not matter)."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
637 (and (eq (car deco1) (car deco2))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
638 (eq (cadr deco1) (cadr deco2))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
639
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
640
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
641 (defun rst-get-decoration-match (hier deco)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
642 "Return the index (level) in hierarchy HIER of decoration DECO.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
643 This basically just searches for the item using the appropriate
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
644 comparison and returns the index. Return nil if the item is
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
645 not found."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
646 (let ((cur hier))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
647 (while (and cur (not (rst-compare-decorations (car cur) deco)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
648 (setq cur (cdr cur)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
649 cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
650
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
651
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
652 (defun rst-suggest-new-decoration (alldecos &optional prev)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
653 "Suggest a new, different decoration from all that have been seen.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
654
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
655 ALLDECOS is the set of all decorations, including the line numbers.
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
656 PREV is the optional previous decoration, in order to suggest a
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
657 better match."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
658
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
659 ;; For all the preferred decorations...
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
660 (let* (
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
661 ;; If 'prev' is given, reorder the list to start searching after the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
662 ;; match.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
663 (fplist
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
664 (cdr (rst-get-decoration-match rst-preferred-decorations prev)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
665
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
666 ;; List of candidates to search.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
667 (curpotential (append fplist rst-preferred-decorations)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
668 (while
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
669 ;; For all the decorations...
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
670 (let ((cur alldecos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
671 found)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
672 (while (and cur (not found))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673 (if (rst-compare-decorations (car cur) (car curpotential))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
674 ;; Found it!
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
675 (setq found (car curpotential))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
676 (setq cur (cdr cur))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
677 found)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
678
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
679 (setq curpotential (cdr curpotential)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
680
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
681 (copy-sequence (car curpotential))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
683 (defun rst-delete-entire-line ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
684 "Delete the entire current line without using the `kill-ring'."
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
685 (delete-region (line-beginning-position)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
686 (line-beginning-position 2)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
687
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
688 (defun rst-update-section (char style &optional indent)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
689 "Unconditionally update the style of a section decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
690
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
691 Do this using the given character CHAR, with STYLE 'simple
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
692 or 'over-and-under, and with indent INDENT. If the STYLE
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
693 is 'simple, whitespace before the title is removed (indent
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
694 is always assumed to be 0).
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
695
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
696 If there are existing overline and/or underline from the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
697 existing decoration, they are removed before adding the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698 requested decoration."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
699
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
700 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
701 (let (marker
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
702 len)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
703
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
704 (end-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
705 (setq marker (point-marker))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
706
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
707 ;; Fixup whitespace at the beginning and end of the line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
708 (if (or (null indent) (eq style 'simple))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
709 (setq indent 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
710 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
711 (delete-horizontal-space)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
712 (insert (make-string indent ? ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
713
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
714 (end-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
715 (delete-horizontal-space)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
716
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
717 ;; Set the current column, we're at the end of the title line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
718 (setq len (+ (current-column) indent))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
719
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
720 ;; Remove previous line if it consists only of a single repeated character
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
721 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
722 (forward-line -1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
723 (and (rst-line-homogeneous-p 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 ;; Avoid removing the underline of a title right above us.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725 (save-excursion (forward-line -1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726 (not (looking-at rst-section-text-regexp)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727 (rst-delete-entire-line)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
729 ;; Remove following line if it consists only of a single repeated
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730 ;; character
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
731 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 (forward-line +1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733 (and (rst-line-homogeneous-p 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
734 (rst-delete-entire-line))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
735 ;; Add a newline if we're at the end of the buffer, for the subsequence
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
736 ;; inserting of the underline
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
737 (if (= (point) (buffer-end 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
738 (newline 1)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
739
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
740 ;; Insert overline
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
741 (if (eq style 'over-and-under)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
742 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
743 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 (open-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
745 (insert (make-string len char))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
746
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
747 ;; Insert underline
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
748 (forward-line +1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
749 (open-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
750 (insert (make-string len char))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
751
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
752 (forward-line +1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
753 (goto-char marker)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
754 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
755
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
756
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 (defun rst-normalize-cursor-position ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
758 "Normalize the cursor position.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
759 If the cursor is on a decoration line or an empty line , place it
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
760 on the section title line (at the end). Returns the line offset
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
761 by which the cursor was moved. This works both over or under a
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762 line."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
763 (if (save-excursion (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
764 (or (rst-line-homogeneous-p 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
765 (looking-at "^[ \t]*$")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
767 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
768 (cond
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
769 ((save-excursion (forward-line -1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
770 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
771 (and (looking-at rst-section-text-regexp)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
772 (not (rst-line-homogeneous-p 1))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
773 (progn (forward-line -1) -1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
774 ((save-excursion (forward-line +1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
775 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
776 (and (looking-at rst-section-text-regexp)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
777 (not (rst-line-homogeneous-p 1))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
778 (progn (forward-line +1) +1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
779 (t 0)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
780 0 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
781
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
782
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
783 (defun rst-find-all-decorations ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
784 "Find all the decorations in the file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
785 Return a list of (line, decoration) pairs. Each decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
786 consists in a (char, style, indent) triple.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
787
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
788 This function does not detect the hierarchy of decorations, it
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
789 just finds all of them in a file. You can then invoke another
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
790 function to remove redundancies and inconsistencies."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
791
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
792 (let (positions
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
793 (curline 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
794 ;; Iterate over all the section titles/decorations in the file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
795 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
796 (goto-char (point-min))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
797 (while (< (point) (buffer-end 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
798 (if (rst-line-homogeneous-nodent-p)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
799 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
800 (setq curline (+ curline (rst-normalize-cursor-position)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
801
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
802 ;; Here we have found a potential site for a decoration,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
803 ;; characterize it.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
804 (let ((deco (rst-get-decoration)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
805 (if (cadr deco) ;; Style is existing.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
806 ;; Found a real decoration site.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
807 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
808 (push (cons curline deco) positions)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
809 ;; Push beyond the underline.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
810 (forward-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
811 (setq curline (+ curline 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
812 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
813 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
814 (forward-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
815 (setq curline (+ curline 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
816 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
817 (reverse positions)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
818
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
819
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
820 (defun rst-infer-hierarchy (decorations)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
821 "Build a hierarchy of decorations using the list of given DECORATIONS.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
822
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
823 This function expects a list of (char, style, indent) decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
824 specifications, in order that they appear in a file, and will
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
825 infer a hierarchy of section levels by removing decorations that
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
826 have already been seen in a forward traversal of the decorations,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
827 comparing just the character and style.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
828
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
829 Similarly returns a list of (char, style, indent), where each
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
830 list element should be unique."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
831
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
832 (let ((hierarchy-alist (list)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
833 (dolist (x decorations)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
834 (let ((char (car x))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
835 (style (cadr x)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
836 (unless (assoc (cons char style) hierarchy-alist)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
837 (push (cons (cons char style) x) hierarchy-alist))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
838 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
839
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
840 (mapcar 'cdr (nreverse hierarchy-alist))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
841 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
842
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
843
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
844 (defun rst-get-hierarchy (&optional alldecos ignore)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
845 "Return the hierarchy of section titles in the file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
846
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
847 Return a list of decorations that represents the hierarchy of
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
848 section titles in the file. Reuse the list of decorations
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
849 already computed in ALLDECOS if present. If the line number in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
850 IGNORE is specified, the decoration found on that line (if there
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
851 is one) is not taken into account when building the hierarchy."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
852 (let ((all (or alldecos (rst-find-all-decorations))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
853 (setq all (assq-delete-all ignore all))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
854 (rst-infer-hierarchy (mapcar 'cdr all))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
855
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
856
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
857 (defun rst-get-decoration (&optional point)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
858 "Get the decoration at POINT.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
859
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
860 Looks around point and finds the characteristics of the
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
861 decoration that is found there. Assumes that the cursor is
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
862 already placed on the title line (and not on the overline or
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
863 underline).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
864
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
865 This function returns a (char, style, indent) triple. If the
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
866 characters of overline and underline are different, return
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
867 the underline character. The indent is always calculated.
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
868 A decoration can be said to exist if the style is not nil.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
869
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
870 A point can be specified to go to the given location before
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
871 extracting the decoration."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
872
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
873 (let (char style indent)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
874 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
875 (if point (goto-char point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
876 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
877 (if (looking-at rst-section-text-regexp)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
878 (let* ((over (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
879 (forward-line -1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
880 (rst-line-homogeneous-nodent-p)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
881
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
882 (under (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
883 (forward-line +1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
884 (rst-line-homogeneous-nodent-p)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
885 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
886
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
887 ;; Check that the line above the overline is not part of a title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
888 ;; above it.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
889 (if (and over
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
890 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
891 (and (equal (forward-line -2) 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
892 (looking-at rst-section-text-regexp))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
893 (setq over nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
894
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
895 (cond
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
896 ;; No decoration found, leave all return values nil.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
897 ((and (eq over nil) (eq under nil)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
898
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
899 ;; Overline only, leave all return values nil.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
900 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
901 ;; Note: we don't return the overline character, but it could
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
902 ;; perhaps in some cases be used to do something.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
903 ((and over (eq under nil)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
904
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
905 ;; Underline only.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
906 ((and under (eq over nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
907 (setq char under
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
908 style 'simple))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
909
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
910 ;; Both overline and underline.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
911 (t
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
912 (setq char under
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
913 style 'over-and-under))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
914 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
915 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
916 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
917 ;; Find indentation.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
918 (setq indent (save-excursion (back-to-indentation) (current-column)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
919 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
920 ;; Return values.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
921 (list char style indent)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
922
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
923
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
924 (defun rst-get-decorations-around (&optional alldecos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
925 "Return the decorations around point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
926
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
927 Given the list of all decorations ALLDECOS (with positions),
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
928 find the decorations before and after the given point.
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
929 A list of the previous and next decorations is returned."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
930 (let* ((all (or alldecos (rst-find-all-decorations)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
931 (curline (line-number-at-pos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
932 prev next
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
933 (cur all))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
934
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
935 ;; Search for the decorations around the current line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
936 (while (and cur (< (caar cur) curline))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
937 (setq prev cur
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
938 cur (cdr cur)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
939 ;; 'cur' is the following decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
940
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
941 (if (and cur (caar cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
942 (setq next (if (= curline (caar cur)) (cdr cur) cur)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
943
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
944 (mapcar 'cdar (list prev next))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
945 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
946
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
947
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
948 (defun rst-decoration-complete-p (deco)
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
949 "Return true if the decoration DECO around point is complete."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
950 ;; Note: we assume that the detection of the overline as being the underline
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
951 ;; of a preceding title has already been detected, and has been eliminated
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
952 ;; from the decoration that is given to us.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
953
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
954 ;; There is some sectioning already present, so check if the current
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
955 ;; sectioning is complete and correct.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
956 (let* ((char (car deco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
957 (style (cadr deco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
958 (indent (caddr deco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
959 (endcol (save-excursion (end-of-line) (current-column)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
960 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
961 (if char
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
962 (let ((exps (concat "^"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
963 (regexp-quote (make-string (+ endcol indent) char))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
964 "$")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
965 (and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
966 (save-excursion (forward-line +1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
967 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
968 (looking-at exps))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
969 (or (not (eq style 'over-and-under))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
970 (save-excursion (forward-line -1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
971 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
972 (looking-at exps))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
973 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
974 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
975
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
976
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
977 (defun rst-get-next-decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
978 (curdeco hier &optional suggestion reverse-direction)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
979 "Get the next decoration for CURDECO, in given hierarchy HIER.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
980 If suggesting, suggest for new decoration SUGGESTION.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
981 REVERSE-DIRECTION is used to reverse the cycling order."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
982
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
983 (let* (
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
984 (char (car curdeco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
985 (style (cadr curdeco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
986
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
987 ;; Build a new list of decorations for the rotation.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
988 (rotdecos
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
989 (append hier
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
990 ;; Suggest a new decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
991 (list suggestion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
992 ;; If nothing to suggest, use first decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
993 (car hier)))) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
994 (or
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
995 ;; Search for next decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
996 (cadr
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
997 (let ((cur (if reverse-direction rotdecos
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
998 (reverse rotdecos))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
999 (while (and cur
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1000 (not (and (eq char (caar cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1001 (eq style (cadar cur)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1002 (setq cur (cdr cur)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1003 cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1004
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1005 ;; If not found, take the first of all decorations.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1006 suggestion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1007 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1008
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1009
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1010 (defun rst-adjust ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1011 "Auto-adjust the decoration around point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1012
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1013 Adjust/rotate the section decoration for the section title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1014 around point or promote/demote the decorations inside the region,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1015 depending on if the region is active. This function is meant to
96376
c3309dba6542 American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 96175
diff changeset
1016 be invoked possibly multiple times, and can vary its behavior
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1017 with a positive prefix argument (toggle style), or with a
96376
c3309dba6542 American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 96175
diff changeset
1018 negative prefix argument (alternate behavior).
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1019
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1020 This function is the main focus of this module and is a bit of a
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1021 swiss knife. It is meant as the single most essential function
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1022 to be bound to invoke to adjust the decorations of a section
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1023 title in restructuredtext. It tries to deal with all the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1024 possible cases gracefully and to do `the right thing' in all
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1025 cases.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1026
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1027 See the documentations of `rst-adjust-decoration' and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1028 `rst-promote-region' for full details.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1029
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1030 Prefix Arguments
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1031 ================
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1032
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1033 The method can take either (but not both) of
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1034
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1035 a. a (non-negative) prefix argument, which means to toggle the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1036 decoration style. Invoke with a prefix arg for example;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1037
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1038 b. a negative numerical argument, which generally inverts the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1039 direction of search in the file or hierarchy. Invoke with C--
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1040 prefix for example."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1041 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1042
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1043 (let* (;; Save our original position on the current line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1044 (origpt (set-marker (make-marker) (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1045
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1046 ;; Parse the positive and negative prefix arguments.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1047 (reverse-direction
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1048 (and current-prefix-arg
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1049 (< (prefix-numeric-value current-prefix-arg) 0)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1050 (toggle-style
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1051 (and current-prefix-arg (not reverse-direction))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1052
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1053 (if (rst-portable-mark-active-p)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1054 ;; Adjust decorations within region.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1055 (rst-promote-region current-prefix-arg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1056 ;; Adjust decoration around point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1057 (rst-adjust-decoration toggle-style reverse-direction))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1058
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1059 ;; Run the hooks to run after adjusting.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1060 (run-hooks 'rst-adjust-hook)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1061
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1062 ;; Make sure to reset the cursor position properly after we're done.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1063 (goto-char origpt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1064
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1065 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1066
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1067 (defvar rst-adjust-hook nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1068 "Hooks to be run after running `rst-adjust'.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1069
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1070 (defvar rst-new-decoration-down nil
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1071 "Non-nil if new decoration is added deeper.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1072 If non-nil, a new decoration being added will be initialized to
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1073 be one level down from the previous decoration. If nil, a new
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1074 decoration will be equal to the level of the previous
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1075 decoration.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1076
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1077 (defun rst-adjust-decoration (&optional toggle-style reverse-direction)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1078 "Adjust/rotate the section decoration for the section title around point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1079
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1080 This function is meant to be invoked possibly multiple times, and
96376
c3309dba6542 American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 96175
diff changeset
1081 can vary its behavior with a true TOGGLE-STYLE argument, or with
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1082 a REVERSE-DIRECTION argument.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1083
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1084 General Behavior
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1085 ================
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1086
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1087 The next action it takes depends on context around the point, and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1088 it is meant to be invoked possibly more than once to rotate among
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1089 the various possibilities. Basically, this function deals with:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1090
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1091 - adding a decoration if the title does not have one;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1092
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1093 - adjusting the length of the underline characters to fit a
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1094 modified title;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1095
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1096 - rotating the decoration in the set of already existing
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1097 sectioning decorations used in the file;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1098
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1099 - switching between simple and over-and-under styles.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1100
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1101 You should normally not have to read all the following, just
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1102 invoke the method and it will do the most obvious thing that you
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1103 would expect.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1104
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1105
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1106 Decoration Definitions
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1107 ======================
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1108
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1109 The decorations consist in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1110
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1111 1. a CHARACTER
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1112
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1113 2. a STYLE which can be either of 'simple' or 'over-and-under'.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1114
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1115 3. an INDENT (meaningful for the over-and-under style only)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1116 which determines how many characters and over-and-under
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1117 style is hanging outside of the title at the beginning and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1118 ending.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1119
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1120 See source code for mode details.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1121
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1122
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1123 Detailed Behavior Description
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1124 =============================
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1125
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1126 Here are the gory details of the algorithm (it seems quite
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1127 complicated, but really, it does the most obvious thing in all
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1128 the particular cases):
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1129
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1130 Before applying the decoration change, the cursor is placed on
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1131 the closest line that could contain a section title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1132
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1133 Case 1: No Decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1134 ---------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1135
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1136 If the current line has no decoration around it,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1137
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1138 - search backwards for the last previous decoration, and apply
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1139 the decoration one level lower to the current line. If there
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1140 is no defined level below this previous decoration, we suggest
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1141 the most appropriate of the `rst-preferred-decorations'.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1142
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1143 If REVERSE-DIRECTION is true, we simply use the previous
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1144 decoration found directly.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1145
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1146 - if there is no decoration found in the given direction, we use
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1147 the first of `rst-preferred-decorations'.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1148
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1149 The prefix argument forces a toggle of the prescribed decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1150 style.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1151
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1152 Case 2: Incomplete Decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1153 -----------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1154
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1155 If the current line does have an existing decoration, but the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1156 decoration is incomplete, that is, the underline/overline does
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1157 not extend to exactly the end of the title line (it is either too
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1158 short or too long), we simply extend the length of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1159 underlines/overlines to fit exactly the section title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1160
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1161 If the prefix argument is given, we toggle the style of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1162 decoration as well.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1163
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1164 REVERSE-DIRECTION has no effect in this case.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1165
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1166 Case 3: Complete Existing Decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1167 ------------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1168
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1169 If the decoration is complete (i.e. the underline (overline)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1170 length is already adjusted to the end of the title line), we
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1171 search/parse the file to establish the hierarchy of all the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1172 decorations (making sure not to include the decoration around
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1173 point), and we rotate the current title's decoration from within
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1174 that list (by default, going *down* the hierarchy that is present
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1175 in the file, i.e. to a lower section level). This is meant to be
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1176 used potentially multiple times, until the desired decoration is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1177 found around the title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1178
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1179 If we hit the boundary of the hierarchy, exactly one choice from
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1180 the list of preferred decorations is suggested/chosen, the first
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1181 of those decoration that has not been seen in the file yet (and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1182 not including the decoration around point), and the next
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1183 invocation rolls over to the other end of the hierarchy (i.e. it
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1184 cycles). This allows you to avoid having to set which character
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1185 to use.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1186
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1187 If REVERSE-DIRECTION is true, the effect is to change the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1188 direction of rotation in the hierarchy of decorations, thus
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1189 instead going *up* the hierarchy.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1190
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1191 However, if there is a non-negative prefix argument, we do not
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1192 rotate the decoration, but instead simply toggle the style of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1193 current decoration (this should be the most common way to toggle
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1194 the style of an existing complete decoration).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1195
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1196
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1197 Point Location
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1198 ==============
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1199
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1200 The invocation of this function can be carried out anywhere
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1201 within the section title line, on an existing underline or
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1202 overline, as well as on an empty line following a section title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1203 This is meant to be as convenient as possible.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1204
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1205
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1206 Indented Sections
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1207 =================
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1208
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1209 Indented section titles such as ::
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1210
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1211 My Title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1212 --------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1213
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1214 are invalid in restructuredtext and thus not recognized by the
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1215 parser. This code will thus not work in a way that would support
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1216 indented sections (it would be ambiguous anyway).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1217
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1218
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1219 Joint Sections
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1220 ==============
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1221
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1222 Section titles that are right next to each other may not be
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1223 treated well. More work might be needed to support those, and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1224 special conditions on the completeness of existing decorations
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1225 might be required to make it non-ambiguous.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1226
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1227 For now we assume that the decorations are disjoint, that is,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1228 there is at least a single line between the titles/decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1229 lines.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1230
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1231
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1232 Suggested Binding
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1233 =================
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1234
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1235 We suggest that you bind this function on C-=. It is close to
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1236 C-- so a negative argument can be easily specified with a flick
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1237 of the right hand fingers and the binding is unused in `text-mode'."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1238 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1239
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1240 ;; If we were invoked directly, parse the prefix arguments into the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1241 ;; arguments of the function.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1242 (if current-prefix-arg
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1243 (setq reverse-direction
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1244 (and current-prefix-arg
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1245 (< (prefix-numeric-value current-prefix-arg) 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1246
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1247 toggle-style
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1248 (and current-prefix-arg (not reverse-direction))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1249
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1250 (let* (;; Check if we're on an underline around a section title, and move the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1251 ;; cursor to the title if this is the case.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1252 (moved (rst-normalize-cursor-position))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1253
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1254 ;; Find the decoration and completeness around point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1255 (curdeco (rst-get-decoration))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1256 (char (car curdeco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1257 (style (cadr curdeco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1258 (indent (caddr curdeco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1259
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1260 ;; New values to be computed.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1261 char-new style-new indent-new
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1262 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1263
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1264 ;; We've moved the cursor... if we're not looking at some text, we have
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1265 ;; nothing to do.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1266 (if (save-excursion (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1267 (looking-at rst-section-text-regexp))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1268 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1269 (cond
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1270 ;;-------------------------------------------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1271 ;; Case 1: No Decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1272 ((and (eq char nil) (eq style nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1273
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1274 (let* ((alldecos (rst-find-all-decorations))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1275
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1276 (around (rst-get-decorations-around alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1277 (prev (car around))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1278 cur
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1279
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1280 (hier (rst-get-hierarchy alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1281 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1282
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1283 ;; Advance one level down.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1284 (setq cur
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1285 (if prev
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1286 (if (not reverse-direction)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1287 (or (funcall (if rst-new-decoration-down 'cadr 'car)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1288 (rst-get-decoration-match hier prev))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1289 (rst-suggest-new-decoration hier prev))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1290 prev)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1291 (copy-sequence (car rst-preferred-decorations))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1292
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1293 ;; Invert the style if requested.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1294 (if toggle-style
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1295 (setcar (cdr cur) (if (eq (cadr cur) 'simple)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1296 'over-and-under 'simple)) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1297
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1298 (setq char-new (car cur)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1299 style-new (cadr cur)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1300 indent-new (caddr cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1301 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1302
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1303 ;;-------------------------------------------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1304 ;; Case 2: Incomplete Decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1305 ((not (rst-decoration-complete-p curdeco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1306
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1307 ;; Invert the style if requested.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1308 (if toggle-style
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1309 (setq style (if (eq style 'simple) 'over-and-under 'simple)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1310
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1311 (setq char-new char
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1312 style-new style
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1313 indent-new indent))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1314
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1315 ;;-------------------------------------------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1316 ;; Case 3: Complete Existing Decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1317 (t
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1318 (if toggle-style
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1319
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1320 ;; Simply switch the style of the current decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1321 (setq char-new char
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1322 style-new (if (eq style 'simple) 'over-and-under 'simple)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1323 indent-new rst-default-indent)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1324
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1325 ;; Else, we rotate, ignoring the decoration around the current
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1326 ;; line...
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1327 (let* ((alldecos (rst-find-all-decorations))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1328
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1329 (hier (rst-get-hierarchy alldecos (line-number-at-pos)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1330
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1331 ;; Suggestion, in case we need to come up with something
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1332 ;; new
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1333 (suggestion (rst-suggest-new-decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1334 hier
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1335 (car (rst-get-decorations-around alldecos))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1336
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1337 (nextdeco (rst-get-next-decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1338 curdeco hier suggestion reverse-direction))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1339
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1340 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1341
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1342 ;; Indent, if present, always overrides the prescribed indent.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1343 (setq char-new (car nextdeco)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1344 style-new (cadr nextdeco)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1345 indent-new (caddr nextdeco))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1346
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1347 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1348 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1349
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1350 ;; Override indent with present indent!
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1351 (setq indent-new (if (> indent 0) indent indent-new))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1352
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1353 (if (and char-new style-new)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1354 (rst-update-section char-new style-new indent-new))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1355 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1356
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1357
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1358 ;; Correct the position of the cursor to more accurately reflect where it
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1359 ;; was located when the function was invoked.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1360 (unless (= moved 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1361 (forward-line (- moved))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1362 (end-of-line))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1363
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1364 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1365
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1366 ;; Maintain an alias for compatibility.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1367 (defalias 'rst-adjust-section-title 'rst-adjust)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1368
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1369
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1370 (defun rst-promote-region (&optional demote)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1371 "Promote the section titles within the region.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1372
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
1373 With argument DEMOTE or a prefix argument, demote the section
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
1374 titles instead. The algorithm used at the boundaries of the
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
1375 hierarchy is similar to that used by `rst-adjust-decoration'."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1376 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1377
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1378 (let* ((demote (or current-prefix-arg demote))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1379 (alldecos (rst-find-all-decorations))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1380 (cur alldecos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1381
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1382 (hier (rst-get-hierarchy alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1383 (suggestion (rst-suggest-new-decoration hier))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1384
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1385 (region-begin-line (line-number-at-pos (region-beginning)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1386 (region-end-line (line-number-at-pos (region-end)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1387
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1388 marker-list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1389 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1390
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1391 ;; Skip the markers that come before the region beginning
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1392 (while (and cur (< (caar cur) region-begin-line))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1393 (setq cur (cdr cur)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1394
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1395 ;; Create a list of markers for all the decorations which are found within
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1396 ;; the region.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1397 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1398 (let (m line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1399 (while (and cur (< (setq line (caar cur)) region-end-line))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1400 (setq m (make-marker))
104543
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1401 (goto-char (point-min))
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1402 (forward-line (1- line))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1403 (push (list (set-marker m (point)) (cdar cur)) marker-list)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1404 (setq cur (cdr cur)) ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1405
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1406 ;; Apply modifications.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1407 (let (nextdeco)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1408 (dolist (p marker-list)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1409 ;; Go to the decoration to promote.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1410 (goto-char (car p))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1411
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1412 ;; Rotate the next decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1413 (setq nextdeco (rst-get-next-decoration
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1414 (cadr p) hier suggestion demote))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1415
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1416 ;; Update the decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1417 (apply 'rst-update-section nextdeco)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1418
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1419 ;; Clear marker to avoid slowing down the editing after we're done.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1420 (set-marker (car p) nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1421 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1422 (setq deactivate-mark nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1423 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1424
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1425
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1426
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1427 (defun rst-display-decorations-hierarchy (&optional decorations)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1428 "Display the current file's section title decorations hierarchy.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1429 This function expects a list of (char, style, indent) triples in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1430 DECORATIONS."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1431 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1432
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1433 (if (not decorations)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1434 (setq decorations (rst-get-hierarchy)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1435 (with-output-to-temp-buffer "*rest section hierarchy*"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1436 (let ((level 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1437 (with-current-buffer standard-output
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1438 (dolist (x decorations)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1439 (insert (format "\nSection Level %d" level))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1440 (apply 'rst-update-section x)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1441 (goto-char (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1442 (insert "\n")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1443 (incf level)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1444 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1445 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1446
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1447 (defun rst-position (elem list)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1448 "Return position of ELEM in LIST or nil."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1449 (let ((tail (member elem list)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1450 (if tail (- (length list) (length tail)))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1451
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1452 (defun rst-straighten-decorations ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1453 "Redo all the decorations in the current buffer.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1454 This is done using our preferred set of decorations. This can be
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1455 used, for example, when using somebody else's copy of a document,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1456 in order to adapt it to our preferred style."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1457 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1458 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1459 (let* ((alldecos (rst-find-all-decorations))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1460 (hier (rst-get-hierarchy alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1461
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1462 ;; Get a list of pairs of (level . marker)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1463 (levels-and-markers (mapcar
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1464 (lambda (deco)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1465 (cons (rst-position (cdr deco) hier)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1466 (let ((m (make-marker)))
104543
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1467 (goto-char (point-min))
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1468 (forward-line (1- (car deco)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1469 (set-marker m (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1470 m)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1471 alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1472 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1473 (dolist (lm levels-and-markers)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1474 ;; Go to the appropriate position
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1475 (goto-char (cdr lm))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1476
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1477 ;; Apply the new styule
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1478 (apply 'rst-update-section (nth (car lm) rst-preferred-decorations))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1479
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1480 ;; Reset the market to avoid slowing down editing until it gets GC'ed
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1481 (set-marker (cdr lm) nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1482 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1483 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1484
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1485
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1486
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1487
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1488 (defun rst-straighten-deco-spacing ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1489 "Adjust the spacing before and after decorations in the entire document.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1490 The spacing will be set to two blank lines before the first two
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1491 section levels, and one blank line before any of the other
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1492 section levels."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1493 ;; FIXME: we need to take care of subtitle at some point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1494 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1495 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1496 (let* ((alldecos (rst-find-all-decorations)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1497
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1498 ;; Work the list from the end, so that we don't have to use markers to
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1499 ;; adjust for the changes in the document.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1500 (dolist (deco (nreverse alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1501 ;; Go to the appropriate position.
104543
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1502 (goto-char (point-min))
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1503 (forward-line (1- (car deco)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1504 (insert "@\n")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1505 ;; FIXME: todo, we
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1506 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1507 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1508
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1509
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1510 (defun rst-find-pfx-in-region (beg end pfx-re)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1511 "Find all the positions of prefixes in region between BEG and END.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1512 This is used to find bullets and enumerated list items. PFX-RE
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1513 is a regular expression for matching the lines with items."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1514 (let (pfx)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1515 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1516 (goto-char beg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1517 (while (< (point) end)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1518 (back-to-indentation)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1519 (when (and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1520 (looking-at pfx-re)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1521 (let ((pfx-col (current-column)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1522 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1523 (forward-line -1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1524 (back-to-indentation)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1525 (or (looking-at "^[ \t]*$")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1526 (> (current-column) pfx-col)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1527 (and (= (current-column) pfx-col)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1528 (looking-at pfx-re))))))
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1529 (push (cons (point) (current-column))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1530 pfx))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1531 (forward-line 1)) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1532 (nreverse pfx)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1533
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1534 (defvar rst-re-bullets
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1535 (format "\\([%s][ \t]\\)[^ \t]" (regexp-quote (concat rst-bullets)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1536 "Regexp for finding bullets.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1537
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1538 ;; (defvar rst-re-enumerations
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1539 ;; "\\(\\(#\\|[0-9]+\\)\\.[ \t]\\)[^ \t]"
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1540 ;; "Regexp for finding bullets.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1541
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1542 (defvar rst-re-items
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1543 (format "\\(%s\\|%s\\)[^ \t]"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1544 (format "[%s][ \t]" (regexp-quote (concat rst-bullets)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1545 "\\(#\\|[0-9]+\\)\\.[ \t]")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1546 "Regexp for finding bullets.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1547
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1548 (defvar rst-preferred-bullets
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1549 '(?- ?* ?+)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1550 "List of favourite bullets to set for straightening bullets.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1551
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1552 (defun rst-straighten-bullets-region (beg end)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1553 "Make all the bulleted list items in the region consistent.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1554 The region is specified between BEG and END. You can use this
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1555 after you have merged multiple bulleted lists to make them use
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1556 the same/correct/consistent bullet characters.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1557
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1558 See variable `rst-preferred-bullets' for the list of bullets to
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1559 adjust. If bullets are found on levels beyond the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1560 `rst-preferred-bullets' list, they are not modified."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1561 (interactive "r")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1562
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1563 (let ((bullets (rst-find-pfx-in-region beg end
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1564 rst-re-bullets))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1565 (levtable (make-hash-table :size 4)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1566
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1567 ;; Create a map of levels to list of positions.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1568 (dolist (x bullets)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1569 (let ((key (cdr x)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1570 (puthash key
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1571 (append (gethash key levtable (list))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1572 (list (car x)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1573 levtable)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1574
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1575 ;; Sort this map and create a new map of prefix char and list of positions.
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1576 (let ((poslist ())) ; List of (indent . positions).
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1577 (maphash (lambda (x y) (push (cons x y) poslist)) levtable)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1578
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1579 (let ((bullets rst-preferred-bullets))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1580 (dolist (x (sort poslist 'car-less-than-car))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1581 (when bullets
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1582 ;; Apply the characters.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1583 (dolist (pos (cdr x))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1584 (goto-char pos)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1585 (delete-char 1)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1586 (insert (string (car bullets))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1587 (setq bullets (cdr bullets))))))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1588
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1589 (defun rst-rstrip (str)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1590 "Strips the whitespace at the end of string STR."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1591 (string-match "[ \t\n]*\\'" str)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1592 (substring str 0 (match-beginning 0)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1593
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1594 (defun rst-get-stripped-line ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1595 "Return the line at cursor, stripped from whitespace."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1596 (re-search-forward "\\S-.*\\S-" (line-end-position))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1597 (buffer-substring-no-properties (match-beginning 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1598 (match-end 0)) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1599
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1600 (defun rst-section-tree (alldecos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1601 "Get the hierarchical tree of section titles.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1602
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1603 Returns a hierarchical tree of the sections titles in the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1604 document, for decorations ALLDECOS. This can be used to generate
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1605 a table of contents for the document. The top node will always
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1606 be a nil node, with the top level titles as children (there may
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1607 potentially be more than one).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1608
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1609 Each section title consists in a cons of the stripped title
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1610 string and a marker to the section in the original text document.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1611
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1612 If there are missing section levels, the section titles are
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1613 inserted automatically, and the title string is set to nil, and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1614 the marker set to the first non-nil child of itself.
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1615 Conceptually, the nil nodes--i.e. those which have no title--are
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1616 to be considered as being the same line as their first non-nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1617 child. This has advantages later in processing the graph."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1618
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1619 (let* ((hier (rst-get-hierarchy alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1620 (levels (make-hash-table :test 'equal :size 10))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1621 lines)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1622
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1623 (let ((lev 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1624 (dolist (deco hier)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1625 ;; Compare just the character and indent in the hash table.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1626 (puthash (cons (car deco) (cadr deco)) lev levels)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1627 (incf lev)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1628
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1629 ;; Create a list of lines that contains (text, level, marker) for each
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1630 ;; decoration.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1631 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1632 (setq lines
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1633 (mapcar (lambda (deco)
104543
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1634 (goto-char (point-min))
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
1635 (forward-line (1- (car deco)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1636 (list (gethash (cons (cadr deco) (caddr deco)) levels)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1637 (rst-get-stripped-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1638 (let ((m (make-marker)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1639 (beginning-of-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1640 (set-marker m (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1641 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1642 alldecos)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1643
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1644 (let ((lcontnr (cons nil lines)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1645 (rst-section-tree-rec lcontnr -1))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1646
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1647
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1648 (defun rst-section-tree-rec (decos lev)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1649 "Recursive guts of the section tree construction.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1650 DECOS is a cons cell whose cdr is the remaining list of
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
1651 decorations, and we change it as we consume them. LEV is
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
1652 the current level of that node. This function returns a
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
1653 pair of the subtree that was built. This treats the DECOS
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
1654 list destructively."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1655
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1656 (let ((ndeco (cadr decos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1657 node
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1658 children)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1659
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1660 ;; If the next decoration matches our level
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1661 (when (and ndeco (= (car ndeco) lev))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1662 ;; Pop the next decoration and create the current node with it
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1663 (setcdr decos (cddr decos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1664 (setq node (cdr ndeco)) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1665 ;; Else we let the node title/marker be unset.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1666
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1667 ;; Build the child nodes
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1668 (while (and (cdr decos) (> (caadr decos) lev))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1669 (setq children
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1670 (cons (rst-section-tree-rec decos (1+ lev))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1671 children)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1672 (setq children (reverse children))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1673
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1674 ;; If node is still unset, we use the marker of the first child.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1675 (when (eq node nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1676 (setq node (cons nil (cdaar children))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1677
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1678 ;; Return this node with its children.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1679 (cons node children)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1680 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1681
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1682
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1683 (defun rst-section-tree-point (node &optional point)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1684 "Find tree node at point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1685 Given a computed and valid section tree in NODE and a point
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1686 POINT (default being the current point in the current buffer),
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1687 find and return the node within the sectree where the cursor
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1688 lives.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1689
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1690 Return values: a pair of (parent path, container subtree).
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1691 The parent path is simply a list of the nodes above the
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1692 container subtree node that we're returning."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1693
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1694 (let (path outtree)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1695
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1696 (let* ((curpoint (or point (point))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1697
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1698 ;; Check if we are before the current node.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1699 (if (and (cadar node) (>= curpoint (cadar node)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1700
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1701 ;; Iterate all the children, looking for one that might contain the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1702 ;; current section.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1703 (let ((curnode (cdr node))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1704 last)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1705
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1706 (while (and curnode (>= curpoint (cadaar curnode)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1707 (setq last curnode
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1708 curnode (cdr curnode)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1709
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1710 (if last
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1711 (let ((sub (rst-section-tree-point (car last) curpoint)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1712 (setq path (car sub)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1713 outtree (cdr sub)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1714 (setq outtree node))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1715
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1716 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1717 (cons (cons (car node) path) outtree)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1718 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1719
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1720
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1721 (defgroup rst-toc nil
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1722 "Settings for reStructuredText table of contents."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1723 :group 'rst
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1724 :version "21.1")
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1725
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1726 (defcustom rst-toc-indent 2
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1727 "Indentation for table-of-contents display.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1728 Also used for formatting insertion, when numbering is disabled."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1729 :group 'rst-toc)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1730
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1731 (defcustom rst-toc-insert-style 'fixed
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1732 "Insertion style for table-of-contents.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1733 Set this to one of the following values to determine numbering and
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1734 indentation style:
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1735 - plain: no numbering (fixed indentation)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1736 - fixed: numbering, but fixed indentation
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1737 - aligned: numbering, titles aligned under each other
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1738 - listed: numbering, with dashes like list items (EXPERIMENTAL)"
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1739 :group 'rst-toc)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1740
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1741 (defcustom rst-toc-insert-number-separator " "
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1742 "Separator that goes between the TOC number and the title."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1743 :group 'rst-toc)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1744
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1745 ;; This is used to avoid having to change the user's mode.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1746 (defvar rst-toc-insert-click-keymap
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1747 (let ((map (make-sparse-keymap)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1748 (define-key map [mouse-1] 'rst-toc-mode-mouse-goto)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1749 map)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1750 "(Internal) What happens when you click on propertized text in the TOC.")
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1751
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1752 (defcustom rst-toc-insert-max-level nil
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1753 "If non-nil, maximum depth of the inserted TOC."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1754 :group 'rst-toc)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1755
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1756
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1757 (defun rst-toc-insert (&optional pfxarg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1758 "Insert a simple text rendering of the table of contents.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1759 By default the top level is ignored if there is only one, because
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1760 we assume that the document will have a single title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1761
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1762 If a numeric prefix argument PFXARG is given, insert the TOC up
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1763 to the specified level.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1764
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1765 The TOC is inserted indented at the current column."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1766
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1767 (interactive "P")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1768
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1769 (let* (;; Check maximum level override
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1770 (rst-toc-insert-max-level
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1771 (if (and (integerp pfxarg) (> (prefix-numeric-value pfxarg) 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1772 (prefix-numeric-value pfxarg) rst-toc-insert-max-level))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1773
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1774 ;; Get the section tree for the current cursor point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1775 (sectree-pair
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1776 (rst-section-tree-point
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1777 (rst-section-tree (rst-find-all-decorations))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1778
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1779 ;; Figure out initial indent.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1780 (initial-indent (make-string (current-column) ? ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1781 (init-point (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1782
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1783 (when (cddr sectree-pair)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1784 (rst-toc-insert-node (cdr sectree-pair) 0 initial-indent "")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1785
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1786 ;; Fixup for the first line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1787 (delete-region init-point (+ init-point (length initial-indent)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1788
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1789 ;; Delete the last newline added.
108765
d835100c3e8b Replace Lisp calls to delete-backward-char by delete-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107445
diff changeset
1790 (delete-char -1)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1791 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1792
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1793 (defun rst-toc-insert-node (node level indent pfx)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1794 "Insert tree node NODE in table-of-contents.
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1795 Recursive function that does printing of the inserted toc.
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1796 LEVEL is the depth level of the sections in the tree.
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1797 INDENT is the indentation string. PFX is the prefix numbering,
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1798 that includes the alignment necessary for all the children of
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1799 level to align."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1800
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1801 ;; Note: we do child numbering from the parent, so we start number the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1802 ;; children one level before we print them.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1803 (let ((do-print (> level 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1804 (count 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1805 (when do-print
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1806 (insert indent)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1807 (let ((b (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1808 (unless (equal rst-toc-insert-style 'plain)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1809 (insert pfx rst-toc-insert-number-separator))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1810 (insert (or (caar node) "[missing node]"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1811 ;; Add properties to the text, even though in normal text mode it
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1812 ;; won't be doing anything for now. Not sure that I want to change
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1813 ;; mode stuff. At least the highlighting gives the idea that this
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1814 ;; is generated automatically.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1815 (put-text-property b (point) 'mouse-face 'highlight)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1816 (put-text-property b (point) 'rst-toc-target (cadar node))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1817 (put-text-property b (point) 'keymap rst-toc-insert-click-keymap)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1818
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1819 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1820 (insert "\n")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1821
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1822 ;; Prepare indent for children.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1823 (setq indent
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1824 (cond
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1825 ((eq rst-toc-insert-style 'plain)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1826 (concat indent (make-string rst-toc-indent ? )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1827
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1828 ((eq rst-toc-insert-style 'fixed)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1829 (concat indent (make-string rst-toc-indent ? )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1830
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1831 ((eq rst-toc-insert-style 'aligned)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1832 (concat indent (make-string (+ (length pfx) 2) ? )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1833
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1834 ((eq rst-toc-insert-style 'listed)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1835 (concat (substring indent 0 -3)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1836 (concat (make-string (+ (length pfx) 2) ? ) " - ")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1837 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1838 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1839
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1840 (if (or (eq rst-toc-insert-max-level nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1841 (< level rst-toc-insert-max-level))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1842 (let ((do-child-numbering (>= level 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1843 fmt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1844 (if do-child-numbering
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1845 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1846 ;; Add a separating dot if there is already a prefix
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1847 (if (> (length pfx) 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1848 (setq pfx (concat (rst-rstrip pfx) ".")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1849
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1850 ;; Calculate the amount of space that the prefix will require
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1851 ;; for the numbers.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1852 (if (cdr node)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1853 (setq fmt (format "%%-%dd"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1854 (1+ (floor (log10 (length
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1855 (cdr node))))))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1856 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1857
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1858 (dolist (child (cdr node))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1859 (rst-toc-insert-node child
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1860 (1+ level)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1861 indent
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1862 (if do-child-numbering
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1863 (concat pfx (format fmt count)) pfx))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1864 (incf count)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1865
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1866 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1867
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1868
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1869 (defun rst-toc-insert-find-delete-contents ()
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1870 "Find and delete an existing comment after the first contents directive.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1871 Delete that region. Return t if found and the cursor is left after the comment."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1872 (goto-char (point-min))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1873 ;; We look for the following and the following only (in other words, if your
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1874 ;; syntax differs, this won't work. If you would like a more flexible thing,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1875 ;; contact the author, I just can't imagine that this requirement is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1876 ;; unreasonable for now).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1877 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1878 ;; .. contents:: [...anything here...]
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1879 ;; ..
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1880 ;; XXXXXXXX
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1881 ;; XXXXXXXX
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1882 ;; [more lines]
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1883 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1884 (let ((beg
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1885 (re-search-forward "^\\.\\. contents[ \t]*::\\(.*\\)\n\\.\\."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1886 nil t))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1887 last-real)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1888 (when beg
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1889 ;; Look for the first line that starts at the first column.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1890 (forward-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1891 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1892 (while (and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1893 (< (point) (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1894 (or (and (looking-at "[ \t]+[^ \t]") (setq last-real (point)) t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1895 (looking-at "[ \t]*$")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1896 (forward-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1897 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1898 (if last-real
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1899 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1900 (goto-char last-real)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1901 (end-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1902 (delete-region beg (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1903 (goto-char beg))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1904 t
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1905 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1906
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1907 (defun rst-toc-update ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1908 "Automatically find the contents section of a document and update.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1909 Updates the inserted TOC if present. You can use this in your
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1910 file-write hook to always make it up-to-date automatically."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1911 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1912 (let ((p (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1913 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1914 (when (rst-toc-insert-find-delete-contents)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1915 (insert "\n ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1916 (rst-toc-insert)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1917 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1918 ;; Somehow save-excursion does not really work well.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1919 (goto-char p))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1920 ;; Note: always return nil, because this may be used as a hook.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1921 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1922
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1923 ;; Note: we cannot bind the TOC update on file write because it messes with
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1924 ;; undo. If we disable undo, since it adds and removes characters, the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1925 ;; positions in the undo list are not making sense anymore. Dunno what to do
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1926 ;; with this, it would be nice to update when saving.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1927 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1928 ;; (add-hook 'write-contents-hooks 'rst-toc-update-fun)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1929 ;; (defun rst-toc-update-fun ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1930 ;; ;; Disable undo for the write file hook.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1931 ;; (let ((buffer-undo-list t)) (rst-toc-update) ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1932
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1933 (defalias 'rst-toc-insert-update 'rst-toc-update) ;; backwards compat.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1934
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1935 ;;------------------------------------------------------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1936
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1937 (defun rst-toc-node (node level)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1938 "Recursive function that does insert NODE at LEVEL in the table-of-contents."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1939
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1940 (if (> level 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1941 (let ((b (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1942 ;; Insert line text.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1943 (insert (make-string (* rst-toc-indent (1- level)) ? ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1944 (insert (or (caar node) "[missing node]"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1945
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1946 ;; Highlight lines.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1947 (put-text-property b (point) 'mouse-face 'highlight)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1948
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1949 ;; Add link on lines.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1950 (put-text-property b (point) 'rst-toc-target (cadar node))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1951
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1952 (insert "\n")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1953 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1954
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1955 (dolist (child (cdr node))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1956 (rst-toc-node child (1+ level))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1957
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1958 (defun rst-toc-count-lines (node target-node)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1959 "Count the number of lines from NODE to the TARGET-NODE node.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1960 This recursive function returns a cons of the number of
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1961 additional lines that have been counted for its node and
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
1962 children, and t if the node has been found."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1963
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1964 (let ((count 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1965 found)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1966 (if (eq node target-node)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1967 (setq found t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1968 (let ((child (cdr node)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1969 (while (and child (not found))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1970 (let ((cl (rst-toc-count-lines (car child) target-node)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1971 (setq count (+ count (car cl))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1972 found (cdr cl)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1973 child (cdr child))))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1974 (cons count found)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1975
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1976 (defvar rst-toc-buffer-name "*Table of Contents*"
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1977 "Name of the Table of Contents buffer.")
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1978
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1979 (defvar rst-toc-return-buffer nil
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1980 "Buffer to which to return when leaving the TOC.")
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
1981
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1982
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1983 (defun rst-toc ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1984 "Display a table-of-contents.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1985 Finds all the section titles and their decorations in the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1986 file, and displays a hierarchically-organized list of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1987 titles, which is essentially a table-of-contents of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1988 document.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1989
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1990 The Emacs buffer can be navigated, and selecting a section
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1991 brings the cursor in that section."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1992 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1993 (let* ((curbuf (current-buffer))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1994
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1995 ;; Get the section tree
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1996 (alldecos (rst-find-all-decorations))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1997 (sectree (rst-section-tree alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1998
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1999 (our-node (cdr (rst-section-tree-point sectree)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2000 line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2001
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2002 ;; Create a temporary buffer.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2003 (buf (get-buffer-create rst-toc-buffer-name))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2004 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2005
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2006 (with-current-buffer buf
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2007 (let ((inhibit-read-only t))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2008 (rst-toc-mode)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2009 (delete-region (point-min) (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2010 (insert (format "Table of Contents: %s\n" (or (caar sectree) "")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2011 (put-text-property (point-min) (point)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2012 'face (list '(background-color . "gray")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2013 (rst-toc-node sectree 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2014
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2015 ;; Count the lines to our found node.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2016 (let ((linefound (rst-toc-count-lines sectree our-node)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2017 (setq line (if (cdr linefound) (car linefound) 0)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2018 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2019 (display-buffer buf)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2020 (pop-to-buffer buf)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2021
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2022 ;; Save the buffer to return to.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2023 (set (make-local-variable 'rst-toc-return-buffer) curbuf)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2024
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2025 ;; Move the cursor near the right section in the TOC.
104543
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
2026 (goto-char (point-min))
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
2027 (forward-line (1- line))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2028 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2029
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2030
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2031 (defun rst-toc-mode-find-section ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2032 "Get the section from text property at point."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2033 (let ((pos (get-text-property (point) 'rst-toc-target)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2034 (unless pos
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2035 (error "No section on this line"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2036 (unless (buffer-live-p (marker-buffer pos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2037 (error "Buffer for this section was killed"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2038 pos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2039
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2040 (defun rst-goto-section (&optional kill)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2041 "Go to the section the current line describes."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2042 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2043 (let ((pos (rst-toc-mode-find-section)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2044 (when kill
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2045 (kill-buffer (get-buffer rst-toc-buffer-name)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2046 (pop-to-buffer (marker-buffer pos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2047 (goto-char pos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2048 ;; FIXME: make the recentering conditional on scroll.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2049 (recenter 5)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2050
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2051 (defun rst-toc-mode-goto-section ()
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
2052 "Go to the section the current line describes and kill the TOC buffer."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2053 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2054 (rst-goto-section t))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2055
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2056 (defun rst-toc-mode-mouse-goto (event)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2057 "In `rst-toc' mode, go to the occurrence whose line you click on.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2058 EVENT is the input event."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2059 (interactive "e")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2060 (let (pos)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2061 (with-current-buffer (window-buffer (posn-window (event-end event)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2062 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2063 (goto-char (posn-point (event-end event)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2064 (setq pos (rst-toc-mode-find-section))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2065 (pop-to-buffer (marker-buffer pos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2066 (goto-char pos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2067 (recenter 5)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2068
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2069 (defun rst-toc-mode-mouse-goto-kill (event)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2070 "Same as `rst-toc-mode-mouse-goto', but kill TOC buffer as well."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2071 (interactive "e")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2072 (call-interactively 'rst-toc-mode-mouse-goto event)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2073 (kill-buffer (get-buffer rst-toc-buffer-name)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2074
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2075 (defun rst-toc-quit-window ()
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2076 "Leave the current TOC buffer."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2077 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2078 (quit-window)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2079 (pop-to-buffer rst-toc-return-buffer))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2080
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2081 (defvar rst-toc-mode-map
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2082 (let ((map (make-sparse-keymap)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2083 (define-key map [mouse-1] 'rst-toc-mode-mouse-goto-kill)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2084 (define-key map [mouse-2] 'rst-toc-mode-mouse-goto)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2085 (define-key map "\C-m" 'rst-toc-mode-goto-section)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2086 (define-key map "f" 'rst-toc-mode-goto-section)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2087 (define-key map "q" 'rst-toc-quit-window)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2088 (define-key map "z" 'kill-this-buffer)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2089 map)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2090 "Keymap for `rst-toc-mode'.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2091
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2092 (put 'rst-toc-mode 'mode-class 'special)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2093
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2094 ;; Could inherit from the new `special-mode'.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2095 (define-derived-mode rst-toc-mode nil "ReST-TOC"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2096 "Major mode for output from \\[rst-toc], the table-of-contents for the document."
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2097 (setq buffer-read-only t))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2098
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2099 ;; Note: use occur-mode (replace.el) as a good example to complete missing
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2100 ;; features.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2101
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2102
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2104 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2105 ;; Section movement commands.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2106 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2107
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2108 (defun rst-forward-section (&optional offset)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2109 "Skip to the next restructured text section title.
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2110 OFFSET specifies how many titles to skip. Use a negative OFFSET to move
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2111 backwards in the file (default is to use 1)."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2112 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2113 (let* (;; Default value for offset.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2114 (offset (or offset 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2115
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2116 ;; Get all the decorations in the file, with their line numbers.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2117 (alldecos (rst-find-all-decorations))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2118
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2119 ;; Get the current line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2120 (curline (line-number-at-pos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2121
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2122 (cur alldecos)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2123 (idx 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2124 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2125
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2126 ;; Find the index of the "next" decoration w.r.t. to the current line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2127 (while (and cur (< (caar cur) curline))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2128 (setq cur (cdr cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2129 (incf idx))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2130 ;; 'cur' is the decoration on or following the current line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2131
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2132 (if (and (> offset 0) cur (= (caar cur) curline))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2133 (incf idx))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2134
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2135 ;; Find the final index.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2136 (setq idx (+ idx (if (> offset 0) (- offset 1) offset)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2137 (setq cur (nth idx alldecos))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2138
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2139 ;; If the index is positive, goto the line, otherwise go to the buffer
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2140 ;; boundaries.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2141 (if (and cur (>= idx 0))
104543
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
2142 (progn
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
2143 (goto-char (point-min))
da8b3e61b182 Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents: 102125
diff changeset
2144 (forward-line (1- (car cur))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2145 (if (> offset 0) (goto-char (point-max)) (goto-char (point-min))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2146 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2147
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2148 (defun rst-backward-section ()
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
2149 "Like `rst-forward-section', except move back one title."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2150 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2151 (rst-forward-section -1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2152
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2153 (defun rst-mark-section (&optional arg allow-extend)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2154 "Select the section that point is currently in."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2155 ;; Cloned from mark-paragraph.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2156 (interactive "p\np")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2157 (unless arg (setq arg 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2158 (when (zerop arg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2159 (error "Cannot mark zero sections"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2160 (cond ((and allow-extend
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2161 (or (and (eq last-command this-command) (mark t))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2162 (rst-portable-mark-active-p)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2163 (set-mark
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2164 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2165 (goto-char (mark))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2166 (rst-forward-section arg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2167 (point))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2168 (t
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2169 (rst-forward-section arg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2170 (push-mark nil t t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2171 (rst-forward-section (- arg)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2172
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2173
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2174
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2175
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2176
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2177
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2179 ;; Functions to work on item lists (e.g. indent/dedent, enumerate), which are
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2180 ;; always 2 or 3 characters apart horizontally with rest.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2181
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2182 ;; (FIXME: there is currently a bug that makes the region go away when we do that.)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2183 (defvar rst-shift-fill-region nil
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2184 "If non-nil, automatically re-fill the region that is being shifted.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2185
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2186 (defun rst-find-leftmost-column (beg end)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2187 "Find the leftmost column in the region."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2188 (let ((mincol 1000))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2189 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2190 (goto-char beg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2191 (while (< (point) end)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2192 (back-to-indentation)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2193 (unless (looking-at "[ \t]*$")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2194 (setq mincol (min mincol (current-column))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2195 (forward-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2196 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2197 mincol))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2198
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2199
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2200 ;; What we really need to do is compute all the possible alignment possibilities
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2201 ;; and then select one.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2202 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2203 ;; .. line-block::
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2204 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2205 ;; a) sdjsds
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2206 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2207 ;; - sdjsd jsjds
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2208 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2209 ;; sdsdsjdsj
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2210 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2211 ;; 11. sjdss jddjs
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2212 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2213 ;; * * * * * * *
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2214 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2215 ;; Move backwards, accumulate the beginning positions, and also the second
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2216 ;; positions, in case the line matches the bullet pattern, and then sort.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2217
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2218 (defun rst-compute-bullet-tabs (&optional pt)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2219 "Build the list of possible horizontal alignment points.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2220 Search backwards from point (or point PT if specified) to
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2221 build the list of possible horizontal alignment points that
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2222 includes the beginning and contents of a restructuredtext
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2223 bulleted or enumerated list item. Return a sorted list
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2224 of (COLUMN-NUMBER . LINE) pairs."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2225 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2226 (when pt (goto-char pt))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2227
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2228 ;; We work our way backwards and towards the left.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2229 (let ((leftcol 100000) ;; Current column.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2230 (tablist nil) ;; List of tab positions.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2231 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2232
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2233 ;; Start by skipping the current line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2234 (beginning-of-line 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2235
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2236 ;; Search backwards for each line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2237 (while (and (> (point) (point-min))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2238 (> leftcol 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2239
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2240 ;; Skip empty lines.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2241 (unless (looking-at "^[ \t]*$")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2242 ;; Inspect the current non-empty line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2243 (back-to-indentation)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2244
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2245 ;; Skip lines that are beyond the current column (we want to move
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2246 ;; towards the left).
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2247 (let ((col (current-column)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2248 (when (< col leftcol)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2249
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2250 ;; Add the beginning of the line as a tabbing point.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2251 (unless (memq col (mapcar 'car tablist))
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2252 (push (cons col (point)) tablist))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2253
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2254 ;; Look at the line to figure out if it is a bulleted or enumerate
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2255 ;; list item.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2256 (when (looking-at
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2257 (concat
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2258 "\\(?:"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2259 "\\(\\(?:[0-9a-zA-Z#]\\{1,3\\}[.):-]\\|[*+-]\\)[ \t]+\\)[^ \t\n]"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2260 "\\|"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2261 (format "\\(%s%s+[ \t]+\\)[^ \t\n]"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2262 (regexp-quote (thing-at-point 'char))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2263 (regexp-quote (thing-at-point 'char)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2264 "\\)"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2265 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2266 ;; Add the column of the contained item.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2267 (let* ((matchlen (length (or (match-string 1) (match-string 2))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2268 (newcol (+ col matchlen)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2269 (unless (or (>= newcol leftcol)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2270 (memq (+ col matchlen) (mapcar 'car tablist)))
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2271 (push (cons (+ col matchlen) (+ (point) matchlen))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2272 tablist)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2273 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2274
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2275 (setq leftcol col)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2276 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2277
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2278 ;; Move backwards one line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2279 (beginning-of-line 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2280
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2281 (sort tablist (lambda (x y) (<= (car x) (car y))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2282 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2283
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2284 (defun rst-debug-print-tabs (tablist)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2285 "Insert a line and place special characters at the tab points in TABLIST."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2286 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2287 (insert (concat "\n" (make-string 1000 ? ) "\n"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2288 (beginning-of-line 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2289 (dolist (col tablist)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2290 (beginning-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2291 (forward-char (car col))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2292 (delete-char 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2293 (insert "@")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2294 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2295
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2296 (defun rst-debug-mark-found (tablist)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2297 "Insert a line and place special characters at the tab points in TABLIST."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2298 (dolist (col tablist)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2299 (when (cdr col)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2300 (goto-char (cdr col))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2301 (insert "@"))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2302
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2303
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2304 (defvar rst-shift-basic-offset 2
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2305 "Basic horizontal shift distance when there is no preceding alignment tabs.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2306
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2307 (defun rst-shift-region-guts (find-next-fun offset-fun)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2308 "(See `rst-shift-region-right' for a description)."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2309 (let* ((mbeg (set-marker (make-marker) (region-beginning)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2310 (mend (set-marker (make-marker) (region-end)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2311 (tabs (rst-compute-bullet-tabs mbeg))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2312 (leftmostcol (rst-find-leftmost-column (region-beginning) (region-end)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2313 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2314 ;; Add basic offset tabs at the end of the list. This is a better
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2315 ;; implementation technique than hysteresis and a basic offset because it
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2316 ;; insures that movement in both directions is consistently using the same
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2317 ;; column positions. This makes it more predictable.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2318 (setq tabs
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2319 (append tabs
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2320 (mapcar (lambda (x) (cons x nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2321 (let ((maxcol 120)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2322 (max-lisp-eval-depth 2000))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2323 (flet ((addnum (x)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2324 (if (> x maxcol)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2325 nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2326 (cons x (addnum
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2327 (+ x rst-shift-basic-offset))))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2328 (addnum (or (caar (last tabs)) 0))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2329 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2330
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2331 ;; (For debugging.)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2332 ;;; (save-excursion (goto-char mbeg) (forward-char -1) (rst-debug-print-tabs tabs))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2333 ;;; (print tabs)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2334 ;;; (save-excursion (rst-debug-mark-found tabs))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2335
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2336 ;; Apply the indent.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2337 (indent-rigidly
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2338 mbeg mend
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2339
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2340 ;; Find the next tab after the leftmost columnt.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2341 (let ((tab (funcall find-next-fun tabs leftmostcol)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2342
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2343 (if tab
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2344 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2345 (when (cdar tab)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2346 (message "Aligned on '%s'"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2347 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2348 (goto-char (cdar tab))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2349 (buffer-substring-no-properties
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2350 (line-beginning-position)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2351 (line-end-position))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2352 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2353 (- (caar tab) leftmostcol)) ;; Num chars.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2354
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2355 ;; Otherwise use the basic offset
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2356 (funcall offset-fun rst-shift-basic-offset)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2357 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2358
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2359 ;; Optionally reindent.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2360 (when rst-shift-fill-region
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2361 (fill-region mbeg mend))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2362 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2363
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2364 (defun rst-shift-region-right (pfxarg)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2365 "Indent region ridigly, by a few characters to the right.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2366 This function first computes all possible alignment columns by
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2367 inspecting the lines preceding the region for bulleted or
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2368 enumerated list items. If the leftmost column is beyond the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2369 preceding lines, the region is moved to the right by
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2370 `rst-shift-basic-offset'. With a prefix argument, do not
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2371 automatically fill the region."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2372 (interactive "P")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2373 (let ((rst-shift-fill-region
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2374 (if (not pfxarg) rst-shift-fill-region)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2375 (rst-shift-region-guts (lambda (tabs leftmostcol)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2376 (let ((cur tabs))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2377 (while (and cur (<= (caar cur) leftmostcol))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2378 (setq cur (cdr cur)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2379 cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2380 'identity
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2381 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2382
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2383 (defun rst-shift-region-left (pfxarg)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2384 "Like `rst-shift-region-right', except we move to the left.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2385 Also, if invoked with a negative prefix arg, the entire
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2386 indentation is removed, up to the leftmost character in the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2387 region, and automatic filling is disabled."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2388 (interactive "P")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2389 (let ((mbeg (set-marker (make-marker) (region-beginning)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2390 (mend (set-marker (make-marker) (region-end)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2391 (leftmostcol (rst-find-leftmost-column
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2392 (region-beginning) (region-end)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2393 (rst-shift-fill-region
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2394 (if (not pfxarg) rst-shift-fill-region)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2395
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2396 (when (> leftmostcol 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2397 (if (and pfxarg (< (prefix-numeric-value pfxarg) 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2398 (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2399 (indent-rigidly (region-beginning) (region-end) (- leftmostcol))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2400 (when rst-shift-fill-region
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2401 (fill-region mbeg mend))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2402 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2403 (rst-shift-region-guts (lambda (tabs leftmostcol)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2404 (let ((cur (reverse tabs)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2405 (while (and cur (>= (caar cur) leftmostcol))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2406 (setq cur (cdr cur)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2407 cur))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2408 '-
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2409 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2410 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2411
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2412 (defmacro rst-iterate-leftmost-paragraphs
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2413 (beg end first-only body-consequent body-alternative)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2414 "FIXME This definition is old and deprecated / we need to move
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2415 to the newer version below:
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2416
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2417 Call FUN at the beginning of each line, with an argument that
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2418 specifies whether we are at the first line of a paragraph that
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2419 starts at the leftmost column of the given region BEG and END.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2420 Set FIRST-ONLY to true if you want to callback on the first line
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2421 of each paragraph only."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2422 `(save-excursion
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2423 (let ((leftcol (rst-find-leftmost-column ,beg ,end))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2424 (endm (set-marker (make-marker) ,end))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2425 )
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2426
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2427 (do* (;; Iterate lines
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2428 (l (progn (goto-char ,beg) (back-to-indentation))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2429 (progn (forward-line 1) (back-to-indentation)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2430
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2431 (previous nil valid)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2432
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2433 (curcol (current-column)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2434 (current-column))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2435
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2436 (valid (and (= curcol leftcol)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2437 (not (looking-at "[ \t]*$")))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2438 (and (= curcol leftcol)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2439 (not (looking-at "[ \t]*$"))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2440 )
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2441 ((>= (point) endm))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2442
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2443 (if (if ,first-only
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2444 (and valid (not previous))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2445 valid)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2446 ,body-consequent
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2447 ,body-alternative)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2448
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2449 ))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2450
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2451
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2452 (defmacro rst-iterate-leftmost-paragraphs-2 (spec &rest body)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2453 "Evaluate BODY for each line in region defined by BEG END.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2454 LEFTMOST is set to true if the line is one of the leftmost of the
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2455 entire paragraph. PARABEGIN is set to true if the line is the
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2456 first of a paragraph."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2457 (declare (indent 1) (debug (sexp body)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2458 (destructuring-bind
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2459 (beg end parabegin leftmost isleftmost isempty) spec
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2460
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2461 `(save-excursion
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2462 (let ((,leftmost (rst-find-leftmost-column ,beg ,end))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2463 (endm (set-marker (make-marker) ,end))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2464 )
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2465
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2466 (do* (;; Iterate lines
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2467 (l (progn (goto-char ,beg) (back-to-indentation))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2468 (progn (forward-line 1) (back-to-indentation)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2469
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2470 (empty-line-previous nil ,isempty)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2471
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2472 (,isempty (looking-at "[ \t]*$")
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2473 (looking-at "[ \t]*$"))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2474
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2475 (,parabegin (not ,isempty)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2476 (and empty-line-previous
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2477 (not ,isempty)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2478
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2479 (,isleftmost (and (not ,isempty)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2480 (= (current-column) ,leftmost))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2481 (and (not ,isempty)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2482 (= (current-column) ,leftmost)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2483 )
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2484 ((>= (point) endm))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2485
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2486 (progn ,@body)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2487
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2488 )))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2489
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2490
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2491 ;;------------------------------------------------------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2492
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2493 ;; FIXME: these next functions should become part of a larger effort to redo the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2494 ;; bullets in bulletted lists. The enumerate would just be one of the possible
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2495 ;; outputs.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2496 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2497 ;; FIXME: TODO we need to do the enumeration removal as well.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2498
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2499 (defun rst-enumerate-region (beg end)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2500 "Add enumeration to all the leftmost paragraphs in the given region.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2501 The region is specified between BEG and END. With prefix argument,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2502 do all lines instead of just paragraphs."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2503 (interactive "r")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2504 (let ((count 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2505 (last-insert-len nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2506 (rst-iterate-leftmost-paragraphs
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2507 beg end (not current-prefix-arg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2508 (let ((ins-string (format "%d. " (incf count))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2509 (setq last-insert-len (length ins-string))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2510 (insert ins-string))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2511 (insert (make-string last-insert-len ?\ ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2512 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2513
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2514 (defun rst-bullet-list-region (beg end)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2515 "Add bullets to all the leftmost paragraphs in the given region.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2516 The region is specified between BEG and END. With prefix argument,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2517 do all lines instead of just paragraphs."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2518 (interactive "r")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2519 (rst-iterate-leftmost-paragraphs
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2520 beg end (not current-prefix-arg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2521 (insert "- ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2522 (insert " ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2523 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2524
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2525
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2526 ;; FIXME: there are some problems left with the following function
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2527 ;; implementation:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2528 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2529 ;; * It does not deal with a varying number of digits appropriately
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2530 ;; * It does not deal with multiple levels independently, and it should.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2531 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2532 ;; I suppose it does 90% of the job for now.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2533
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2534 (defun rst-convert-bullets-to-enumeration (beg end)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2535 "Convert all the bulleted items and enumerated items in the
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2536 region to enumerated lists, renumbering as necessary."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2537 (interactive "r")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2538 (let* (;; Find items and convert the positions to markers.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2539 (items (mapcar
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2540 (lambda (x)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2541 (cons (let ((m (make-marker)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2542 (set-marker m (car x))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2543 m)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2544 (cdr x)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2545 (rst-find-pfx-in-region beg end rst-re-items)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2546 (count 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2547 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2548 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2549 (dolist (x items)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2550 (goto-char (car x))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2551 (looking-at rst-re-items)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2552 (replace-match (format "%d. " count) nil nil nil 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2553 (incf count)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2554 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2555 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2556
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2557
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2558
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2559 ;;------------------------------------------------------------------------------
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2560
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2561 (defun rst-line-block-region (rbeg rend &optional pfxarg)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2562 "Toggle line block prefixes for a region.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2563 With prefix argument set the empty lines too."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2564 (interactive "r\nP")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2565 (let ((comment-start "| ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2566 (comment-end "")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2567 (comment-start-skip "| ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2568 (comment-style 'indent)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2569 (force (not (not pfxarg))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2570 (rst-iterate-leftmost-paragraphs-2
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2571 (rbeg rend parbegin leftmost isleft isempty)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2572 (when (or force (not isempty))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2573 (move-to-column leftmost force)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2574 (delete-region (point) (+ (point) (- (current-indentation) leftmost)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2575 (insert "| ")))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2576
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2577
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2578
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2579 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2580
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2581 (require 'font-lock)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2582
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
2583 (defgroup rst-faces nil "Faces used in Rst Mode."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2584 :group 'rst
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2585 :group 'faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2586 :version "21.1")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2587
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2588 (defface rst-block '((t :inherit font-lock-keyword-face))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2589 "Face used for all syntax marking up a special block."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2590 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2591 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2592
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2593 (defcustom rst-block-face 'rst-block
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2594 "All syntax marking up a special block."
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2595 :version "24.1"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2596 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2597 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2598 (make-obsolete-variable 'rst-block-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2599 "customize the face `rst-block' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2600 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2601
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2602 (defface rst-external '((t :inherit font-lock-type-face))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2603 "Face used for field names and interpreted text."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2604 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2605 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2606
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2607 (defcustom rst-external-face 'rst-external
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2608 "Field names and interpreted text."
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2609 :version "24.1"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2610 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2611 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2612 (make-obsolete-variable 'rst-external-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2613 "customize the face `rst-external' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2614 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2615
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2616 (defface rst-definition '((t :inherit font-lock-function-name-face))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2617 "Face used for all other defining constructs."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2618 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2619 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2620
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2621 (defcustom rst-definition-face 'rst-definition
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2622 "All other defining constructs."
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2623 :version "24.1"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2624 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2625 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2626 (make-obsolete-variable 'rst-definition-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2627 "customize the face `rst-definition' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2628 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2629
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2630 ;; XEmacs compatibility (?).
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2631 (defface rst-directive (if (boundp 'font-lock-builtin-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2632 '((t :inherit font-lock-builtin-face))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2633 '((t :inherit font-lock-preprocessor-face)))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2634 "Face used for directives and roles."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2635 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2636 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2637
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2638 (defcustom rst-directive-face 'rst-directive
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2639 "Directives and roles."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2640 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2641 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2642 (make-obsolete-variable 'rst-directive-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2643 "customize the face `rst-directive' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2644 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2645
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2646 (defface rst-comment '((t :inherit font-lock-comment-face))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2647 "Face used for comments."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2648 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2649 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2650
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2651 (defcustom rst-comment-face 'rst-comment
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2652 "Comments."
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2653 :version "24.1"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2654 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2655 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2656 (make-obsolete-variable 'rst-comment-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2657 "customize the face `rst-comment' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2658 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2659
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2660 (defface rst-emphasis1 '((t :inherit italic))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2661 "Face used for simple emphasis."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2662 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2663 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2664
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2665 (defcustom rst-emphasis1-face 'rst-emphasis1
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2666 "Simple emphasis."
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2667 :version "24.1"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2668 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2669 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2670 (make-obsolete-variable 'rst-emphasis1-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2671 "customize the face `rst-emphasis1' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2672 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2673
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2674 (defface rst-emphasis2 '((t :inherit bold))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2675 "Face used for double emphasis."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2676 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2677 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2678
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2679 (defcustom rst-emphasis2-face 'rst-emphasis2
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2680 "Double emphasis."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2681 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2682 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2683 (make-obsolete-variable 'rst-emphasis2-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2684 "customize the face `rst-emphasis2' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2685 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2686
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2687 (defface rst-literal '((t :inherit font-lock-string-face))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2688 "Face used for literal text."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2689 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2690 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2691
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2692 (defcustom rst-literal-face 'rst-literal
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2693 "Literal text."
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2694 :version "24.1"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2695 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2696 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2697 (make-obsolete-variable 'rst-literal-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2698 "customize the face `rst-literal' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2699 "24.1")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2700
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2701 (defface rst-reference '((t :inherit font-lock-variable-name-face))
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2702 "Face used for references to a definition."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2703 :version "24.1"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2704 :group 'rst-faces)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2705
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2706 (defcustom rst-reference-face 'rst-reference
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2707 "References to a definition."
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2708 :version "24.1"
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2709 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2710 :type '(face))
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2711 (make-obsolete-variable 'rst-reference-face
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2712 "customize the face `rst-reference' instead."
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2713 "24.1")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2714
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2716
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2717 (defgroup rst-faces-defaults nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2718 "Values used to generate default faces for section titles on all levels.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2719 Tweak these if you are content with how section title faces are built in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2720 general but you do not like the details."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2721 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2722 :version "21.1")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2723
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2724 (defun rst-set-level-default (sym val)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2725 "Set custom var SYM affecting section title text face and recompute the faces."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2726 (custom-set-default sym val)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2727 ;; Also defines the faces initially when all values are available
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2728 (and (boundp 'rst-level-face-max)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2729 (boundp 'rst-level-face-format-light)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2730 (boundp 'rst-level-face-base-color)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2731 (boundp 'rst-level-face-step-light)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2732 (boundp 'rst-level-face-base-light)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2733 (fboundp 'rst-define-level-faces)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2734 (rst-define-level-faces)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2735
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2736 ;; Faces for displaying items on several levels; these definitions define
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2737 ;; different shades of grey where the lightest one (i.e. least contrasting) is
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2738 ;; used for level 1
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2739 (defcustom rst-level-face-max 6
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2740 "Maximum depth of levels for which section title faces are defined."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2741 :group 'rst-faces-defaults
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2742 :type '(integer)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2743 :set 'rst-set-level-default)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2744 (defcustom rst-level-face-base-color "grey"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2745 "The base name of the color to be used for creating background colors in
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
2746 section title faces for all levels."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2747 :group 'rst-faces-defaults
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2748 :type '(string)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2749 :set 'rst-set-level-default)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2750 (defcustom rst-level-face-base-light
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2751 (if (eq frame-background-mode 'dark)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2752 15
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2753 85)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2754 "The lightness factor for the base color. This value is used for level 1.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2755 The default depends on whether the value of `frame-background-mode' is
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2756 `dark' or not."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2757 :group 'rst-faces-defaults
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2758 :type '(integer)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2759 :set 'rst-set-level-default)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2760 (defcustom rst-level-face-format-light "%2d"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2761 "The format for the lightness factor appended to the base name of the color.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2762 This value is expanded by `format' with an integer."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2763 :group 'rst-faces-defaults
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2764 :type '(string)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2765 :set 'rst-set-level-default)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2766 (defcustom rst-level-face-step-light
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2767 (if (eq frame-background-mode 'dark)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2768 7
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2769 -7)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2770 "The step width to use for the next color.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2771 The formula
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2772
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2773 `rst-level-face-base-light'
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2774 + (`rst-level-face-max' - 1) * `rst-level-face-step-light'
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2775
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2776 must result in a color level which appended to `rst-level-face-base-color'
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2777 using `rst-level-face-format-light' results in a valid color such as `grey50'.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2778 This color is used as background for section title text on level
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2779 `rst-level-face-max'."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2780 :group 'rst-faces-defaults
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2781 :type '(integer)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2782 :set 'rst-set-level-default)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2783
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2784 (defcustom rst-adornment-faces-alist
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2785 (let ((alist '((t . font-lock-keyword-face)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2786 (nil . font-lock-keyword-face)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2787 (i 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2788 (while (<= i rst-level-face-max)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2789 (nconc alist (list (cons i (intern (format "rst-level-%d-face" i)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2790 (setq i (1+ i)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2791 alist)
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2792 "Faces for the various adornment types.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2793 Key is a number (for the section title text of that level),
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2794 t (for transitions) or nil (for section title adornment).
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2795 If you generally do not like how section title text faces are
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2796 set up tweak here. If the general idea is ok for you but you do not like the
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2797 details check the Rst Faces Defaults group."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2798 :group 'rst-faces
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2799 :type '(alist
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2800 :key-type
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2801 (choice
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2802 (integer
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2803 :tag
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2804 "Section level (may not be bigger than `rst-level-face-max')")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2805 (boolean :tag "transitions (on) / section title adornment (off)"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2806 :value-type (face))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2807 :set-after '(rst-level-face-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2808
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2809 (defun rst-define-level-faces ()
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2810 "Define the faces for the section title text faces from the values."
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2811 ;; All variables used here must be checked in `rst-set-level-default'
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2812 (let ((i 1))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2813 (while (<= i rst-level-face-max)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2814 (let ((sym (intern (format "rst-level-%d-face" i)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2815 (doc (format "Face for showing section title text at level %d" i))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2816 (col (format (concat "%s" rst-level-face-format-light)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2817 rst-level-face-base-color
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2818 (+ (* (1- i) rst-level-face-step-light)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2819 rst-level-face-base-light))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2820 (make-empty-face sym)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2821 (set-face-doc-string sym doc)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2822 (set-face-background sym col)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2823 (set sym sym)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2824 (setq i (1+ i))))))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
2825
96139
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
2826 (rst-define-level-faces)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2827
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2828
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2829 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2830 ;; Font lock
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2831
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2832 (defvar rst-use-char-classes
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2833 (string-match "[[:alpha:]]" "b")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2834 "Non-nil if we can use the character classes in our regexps.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2835
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2836 (defun rst-font-lock-keywords-function ()
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
2837 "Return keywords to highlight in Rst mode according to current settings."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2838 ;; The reST-links in the comments below all relate to sections in
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2839 ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2840 (let* ( ;; This gets big - so let's define some abbreviations
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2841 ;; horizontal white space
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2842 (re-hws "[\t ]")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2843 ;; beginning of line with possible indentation
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2844 (re-bol (concat "^" re-hws "*"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2845 ;; Separates block lead-ins from their content
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2846 (re-blksep1 (concat "\\(" re-hws "+\\|$\\)"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2847 ;; explicit markup tag
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2848 (re-emt "\\.\\.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2849 ;; explicit markup start
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2850 (re-ems (concat re-emt re-hws "+"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2851 ;; inline markup prefix
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2852 (re-imp1 (concat "\\(^\\|" re-hws "\\|[-'\"([{</:]\\)"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2853 ;; inline markup suffix
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2854 (re-ims1 (concat "\\(" re-hws "\\|[]-'\")}>/:.,;!?\\]\\|$\\)"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2855 ;; symbol character
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2856 (re-sym1 "\\(\\sw\\|\\s_\\)")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2857 ;; inline markup content begin
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2858 (re-imbeg2 "\\(\\S \\|\\S \\([^")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2859
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2860 ;; There seems to be a bug leading to error "Stack overflow in regexp
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2861 ;; matcher" when "|" or "\\*" are the characters searched for
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2862 (re-imendbeg
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2863 (if (< emacs-major-version 21)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2864 "]"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2865 "\\]\\|\\\\."))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2866 ;; inline markup content end
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2867 (re-imend (concat re-imendbeg "\\)*[^\t \\\\]\\)"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2868 ;; inline markup content without asterisk
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2869 (re-ima2 (concat re-imbeg2 "*" re-imend))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2870 ;; inline markup content without backquote
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2871 (re-imb2 (concat re-imbeg2 "`" re-imend))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2872 ;; inline markup content without vertical bar
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2873 (re-imv2 (concat re-imbeg2 "|" re-imend))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2874 ;; Supported URI schemes
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2875 (re-uris1 "\\(acap\\|cid\\|data\\|dav\\|fax\\|file\\|ftp\\|gopher\\|http\\|https\\|imap\\|ldap\\|mailto\\|mid\\|modem\\|news\\|nfs\\|nntp\\|pop\\|prospero\\|rtsp\\|service\\|sip\\|tel\\|telnet\\|tip\\|urn\\|vemmi\\|wais\\)")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2876 ;; Line starting with adornment and optional whitespace; complete
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2877 ;; adornment is in (match-string 1); there must be at least 3
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2878 ;; characters because otherwise explicit markup start would be
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2879 ;; recognized
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2880 (re-ado2 (concat "^\\(\\(["
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2881 (if rst-use-char-classes
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2882 "^[:word:][:space:][:cntrl:]" "^\\w \t\x00-\x1F")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2883 "]\\)\\2\\2+\\)" re-hws "*$"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2884 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2885 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2886 ;; FIXME: Block markup is not recognized in blocks after explicit markup
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2887 ;; start
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2888
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2889 ;; Simple `Body Elements`_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2890 ;; `Bullet Lists`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2891 `(,(concat re-bol "\\([-*+]" re-blksep1 "\\)")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2892 1 rst-block-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2893 ;; `Enumerated Lists`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2894 `(,(concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2895 re-blksep1 "\\)")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2896 1 rst-block-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2897 ;; `Definition Lists`_ FIXME: missing
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2898 ;; `Field Lists`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2899 `(,(concat re-bol "\\(:[^:\n]+:\\)" re-blksep1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2900 1 rst-external-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2901 ;; `Option Lists`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2902 `(,(concat re-bol "\\(\\(\\(\\([-+/]\\|--\\)\\sw\\(-\\|\\sw\\)*"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2903 "\\([ =]\\S +\\)?\\)\\(,[\t ]\\)?\\)+\\)\\($\\|[\t ]\\{2\\}\\)")
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2904 1 rst-block-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2905
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2906 ;; `Tables`_ FIXME: missing
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2907
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2908 ;; All the `Explicit Markup Blocks`_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2909 ;; `Footnotes`_ / `Citations`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2910 `(,(concat re-bol "\\(" re-ems "\\[[^[\n]+\\]\\)" re-blksep1)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2911 1 rst-definition-face)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2912 ;; `Directives`_ / `Substitution Definitions`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2913 `(,(concat re-bol "\\(" re-ems "\\)\\(\\(|[^|\n]+|[\t ]+\\)?\\)\\("
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2914 re-sym1 "+::\\)" re-blksep1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2915 (1 rst-directive-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2916 (2 rst-definition-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2917 (4 rst-directive-face))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2918 ;; `Hyperlink Targets`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2919 `(,(concat re-bol "\\(" re-ems "_\\([^:\\`\n]\\|\\\\.\\|`[^`\n]+`\\)+:\\)"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2920 re-blksep1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2921 1 rst-definition-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2922 `(,(concat re-bol "\\(__\\)" re-blksep1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2923 1 rst-definition-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2924
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2925 ;; All `Inline Markup`_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2926 ;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2927 ;; `Strong Emphasis`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2928 `(,(concat re-imp1 "\\(\\*\\*" re-ima2 "\\*\\*\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2929 2 rst-emphasis2-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2930 ;; `Emphasis`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2931 `(,(concat re-imp1 "\\(\\*" re-ima2 "\\*\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2932 2 rst-emphasis1-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2933 ;; `Inline Literals`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2934 `(,(concat re-imp1 "\\(``" re-imb2 "``\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2935 2 rst-literal-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2936 ;; `Inline Internal Targets`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2937 `(,(concat re-imp1 "\\(_`" re-imb2 "`\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2938 2 rst-definition-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2939 ;; `Hyperlink References`_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2940 ;; FIXME: `Embedded URIs`_ not considered
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2941 `(,(concat re-imp1 "\\(\\(`" re-imb2 "`\\|\\(\\sw\\(\\sw\\|-\\)+\\sw\\)\\)__?\\)" re-ims1)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2942 2 rst-reference-face)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2943 ;; `Interpreted Text`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2944 `(,(concat re-imp1 "\\(\\(:" re-sym1 "+:\\)?\\)\\(`" re-imb2 "`\\)\\(\\(:"
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2945 re-sym1 "+:\\)?\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2946 (2 rst-directive-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2947 (5 rst-external-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2948 (8 rst-directive-face))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2949 ;; `Footnote References`_ / `Citation References`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2950 `(,(concat re-imp1 "\\(\\[[^]]+\\]_\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2951 2 rst-reference-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2952 ;; `Substitution References`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2953 `(,(concat re-imp1 "\\(|" re-imv2 "|\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2954 2 rst-reference-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2955 ;; `Standalone Hyperlinks`_
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2956 `(;; FIXME: This takes it easy by using a whitespace as delimiter
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2957 ,(concat re-imp1 "\\(" re-uris1 ":\\S +\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2958 2 rst-definition-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2959 `(,(concat re-imp1 "\\(" re-sym1 "+@" re-sym1 "+\\)" re-ims1)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2960 2 rst-definition-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2961
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2962 ;; Do all block fontification as late as possible so 'append works
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2963
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2964 ;; Sections_ / Transitions_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2965 (append
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2966 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2967 re-ado2)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2968 (if (not rst-mode-lazy)
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2969 '(1 rst-block-face)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2970 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2971 (list 'rst-font-lock-handle-adornment
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2972 '(progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2973 (setq rst-font-lock-adornment-point (match-end 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2974 (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2975 nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2976 (list 1 '(cdr (assoc nil rst-adornment-faces-alist))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2977 'append t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2978 (list 2 '(cdr (assoc rst-font-lock-level
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2979 rst-adornment-faces-alist))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2980 'append t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2981 (list 3 '(cdr (assoc nil rst-adornment-faces-alist))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2982 'append t)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2983
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2984 ;; `Comments`_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2985 (append
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2986 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2987 (concat re-bol "\\(" re-ems "\\)\[^[|_]\\([^:\n]\\|:\\([^:\n]\\|$\\)\\)*$")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2988
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2989 '(1 rst-comment-face))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2990 (if rst-mode-lazy
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2991 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2992 (list 'rst-font-lock-find-unindented-line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2993 '(progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2994 (setq rst-font-lock-indentation-point (match-end 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2995 (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2996 nil
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
2997 '(0 rst-comment-face append)))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2998 (append
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2999 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3000 (concat re-bol "\\(" re-emt "\\)\\(\\s *\\)$")
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3001 '(1 rst-comment-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3002 '(2 rst-comment-face))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3003 (if rst-mode-lazy
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3004 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3005 (list 'rst-font-lock-find-unindented-line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3006 '(progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3007 (setq rst-font-lock-indentation-point 'next)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3008 (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3009 nil
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3010 '(0 rst-comment-face append)))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3011
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3012 ;; `Literal Blocks`_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3013 (append
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3014 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3015 (concat re-bol "\\(\\([^.\n]\\|\\.[^.\n]\\).*\\)?\\(::\\)$")
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3016 '(3 rst-block-face))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3017 (if rst-mode-lazy
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3018 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3019 (list 'rst-font-lock-find-unindented-line
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3020 '(progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3021 (setq rst-font-lock-indentation-point t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3022 (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3023 nil
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3024 '(0 rst-literal-face append)))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3025
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3026 ;; `Doctest Blocks`_
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3027 (append
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3028 (list
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3029 (concat re-bol "\\(>>>\\|\\.\\.\\.\\)\\(.+\\)")
107445
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3030 '(1 rst-block-face)
4f21cfcfbb42 Use faces not variables for font-lock customization in rst.el.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3031 '(2 rst-literal-face)))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3032 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3033
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3034
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3035
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3036 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3037 ;; Indented blocks
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3038
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3039 (defun rst-forward-indented-block (&optional column limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3040 "Move forward across one indented block.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3041 Find the next non-empty line which is not indented at least to COLUMN (defaults
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3042 to the column of the point). Moves point to first character of this line or the
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3043 first empty line immediately before it and returns that position. If there is
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3044 no such line before LIMIT (defaults to the end of the buffer) returns nil and
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3045 point is not moved."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3046 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3047 (let ((clm (or column (current-column)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3048 (start (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3049 fnd beg cand)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3050 (if (not limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3051 (setq limit (point-max)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3052 (save-match-data
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3053 (while (and (not fnd) (< (point) limit))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3054 (forward-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3055 (when (< (point) limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3056 (setq beg (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3057 (if (looking-at "\\s *$")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3058 (setq cand (or cand beg)) ; An empty line is a candidate
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3059 (move-to-column clm)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3060 ;; FIXME: No indentation [(zerop clm)] must be handled in some
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3061 ;; useful way - though it is not clear what this should mean at all
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3062 (if (string-match
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3063 "^\\s *$" (buffer-substring-no-properties beg (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3064 (setq cand nil) ; An indented line resets a candidate
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3065 (setq fnd (or cand beg)))))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3066 (goto-char (or fnd start))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3067 fnd))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3068
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3069 ;; Stores the point where the current indentation ends if a number. If `next'
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3070 ;; indicates `rst-font-lock-find-unindented-line' shall take the indentation
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3071 ;; from the next line if this is not empty. If non-nil indicates
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3072 ;; `rst-font-lock-find-unindented-line' shall take the indentation from the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3073 ;; next non-empty line. Also used as a trigger for
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3074 ;; `rst-font-lock-find-unindented-line'.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3075 (defvar rst-font-lock-indentation-point nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3076
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3077 (defun rst-font-lock-find-unindented-line (limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3078 (let* ((ind-pnt rst-font-lock-indentation-point)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3079 (beg-pnt ind-pnt))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3080 ;; May run only once - enforce this
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3081 (setq rst-font-lock-indentation-point nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3082 (when (and ind-pnt (not (numberp ind-pnt)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3083 ;; Find indentation point in next line if any
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3084 (setq ind-pnt
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3085 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3086 (save-match-data
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3087 (if (eq ind-pnt 'next)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3088 (when (and (zerop (forward-line 1)) (< (point) limit))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3089 (setq beg-pnt (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3090 (when (not (looking-at "\\s *$"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3091 (looking-at "\\s *")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3092 (match-end 0)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3093 (while (and (zerop (forward-line 1)) (< (point) limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3094 (looking-at "\\s *$")))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3095 (when (< (point) limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3096 (setq beg-pnt (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3097 (looking-at "\\s *")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3098 (match-end 0)))))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3099 (when ind-pnt
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3100 (goto-char ind-pnt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3101 ;; Always succeeds because the limit set by PRE-MATCH-FORM is the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3102 ;; ultimate point to find
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3103 (goto-char (or (rst-forward-indented-block nil limit) limit))
96139
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3104 (save-excursion
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3105 ;; Include subsequent empty lines in the font-lock block,
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3106 ;; in case the user subsequently changes the indentation of the next
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3107 ;; non-empty line to move it into the indented element.
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3108 (skip-chars-forward " \t\n")
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3109 (put-text-property beg-pnt (point) 'font-lock-multiline t))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3110 (set-match-data (list beg-pnt (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3111 t)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3112
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3114 ;; Adornments
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3115
96139
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3116 (defvar rst-font-lock-adornment-point nil
96497
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
3117 "Stores the point where the current adornment ends.
885e5368ecb2 Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents: 96376
diff changeset
3118 Also used as a trigger for `rst-font-lock-handle-adornment'.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3119
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3120 ;; Here `rst-font-lock-handle-adornment' stores the section level of the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3121 ;; current adornment or t for a transition.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3122 (defvar rst-font-lock-level nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3123
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3124 ;; FIXME: It would be good if this could be used to markup section titles of
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3125 ;; given level with a special key; it would be even better to be able to
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3126 ;; customize this so it can be used for a generally available personal style
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3127 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3128 ;; FIXME: There should be some way to reset and reload this variable - probably
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3129 ;; a special key
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3130 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3131 ;; FIXME: Some support for `outline-mode' would be nice which should be based
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3132 ;; on this information
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3133 (defvar rst-adornment-level-alist nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3134 "Associates adornments with section levels.
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3135 The key is a two character string. The first character is the adornment
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3136 character. The second character distinguishes underline section titles (`u')
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3137 from overline/underline section titles (`o'). The value is the section level.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3138
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3139 This is made buffer local on start and adornments found during font lock are
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3140 entered.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3141
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3142 ;; Returns section level for adornment key KEY. Adds new section level if KEY
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3143 ;; is not found and ADD. If KEY is not a string it is simply returned.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3144 (defun rst-adornment-level (key &optional add)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3145 (let ((fnd (assoc key rst-adornment-level-alist))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3146 (new 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3147 (cond
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3148 ((not (stringp key))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3149 key)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3150 (fnd
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3151 (cdr fnd))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3152 (add
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3153 (while (rassoc new rst-adornment-level-alist)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3154 (setq new (1+ new)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3155 (setq rst-adornment-level-alist
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3156 (append rst-adornment-level-alist (list (cons key new))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3157 new))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3158
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3159 ;; Classifies adornment for section titles and transitions. ADORNMENT is the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3160 ;; complete adornment string as found in the buffer. END is the point after the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3161 ;; last character of ADORNMENT. For overline section adornment LIMIT limits the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3162 ;; search for the matching underline. Returns a list. The first entry is t for
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3163 ;; a transition, or a key string for `rst-adornment-level' for a section title.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3164 ;; The following eight values forming four match groups as can be used for
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3165 ;; `set-match-data'. First match group contains the maximum points of the whole
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3166 ;; construct. Second and last match group matched pure section title adornment
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3167 ;; while third match group matched the section title text or the transition.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3168 ;; Each group but the first may or may not exist.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3169 (defun rst-classify-adornment (adornment end limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3170 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3171 (save-match-data
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3172 (goto-char end)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3173 (let ((ado-ch (aref adornment 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3174 (ado-re (regexp-quote adornment))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3175 (end-pnt (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3176 (beg-pnt (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3177 (forward-line 0)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3178 (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3179 (nxt-emp
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3180 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3181 (or (not (zerop (forward-line 1)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3182 (looking-at "\\s *$"))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3183 (prv-emp
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3184 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3185 (or (not (zerop (forward-line -1)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3186 (looking-at "\\s *$"))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3187 key beg-ovr end-ovr beg-txt end-txt beg-und end-und)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3188 (cond
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3189 ((and nxt-emp prv-emp)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3190 ;; A transition
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3191 (setq key t)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3192 (setq beg-txt beg-pnt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3193 (setq end-txt end-pnt))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3194 (prv-emp
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3195 ;; An overline
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3196 (setq key (concat (list ado-ch) "o"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3197 (setq beg-ovr beg-pnt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3198 (setq end-ovr end-pnt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3199 (forward-line 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3200 (setq beg-txt (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3201 (while (and (< (point) limit) (not end-txt))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3202 (if (looking-at "\\s *$")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3203 ;; No underline found
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3204 (setq end-txt (1- (point)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3205 (when (looking-at (concat "\\(" ado-re "\\)\\s *$"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3206 (setq end-und (match-end 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3207 (setq beg-und (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3208 (setq end-txt (1- beg-und))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3209 (forward-line 1)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3210 (t
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3211 ;; An underline
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3212 (setq key (concat (list ado-ch) "u"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3213 (setq beg-und beg-pnt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3214 (setq end-und end-pnt)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3215 (setq end-txt (1- beg-und))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3216 (setq beg-txt (progn
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3217 (if (re-search-backward "^\\s *$" 1 'move)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3218 (forward-line 1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3219 (point)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3220 (list key
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3221 (or beg-ovr beg-txt beg-und)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3222 (or end-und end-txt end-und)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3223 beg-ovr end-ovr beg-txt end-txt beg-und end-und)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3224
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3225 ;; Handles adornments for font-locking section titles and transitions. Returns
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3226 ;; three match groups. First and last match group matched pure overline /
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3227 ;; underline adornment while second group matched section title text. Each
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3228 ;; group may not exist.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3229 (defun rst-font-lock-handle-adornment (limit)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3230 (let ((ado-pnt rst-font-lock-adornment-point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3231 ;; May run only once - enforce this
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3232 (setq rst-font-lock-adornment-point nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3233 (if ado-pnt
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3234 (let* ((ado (rst-classify-adornment (match-string-no-properties 1)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3235 ado-pnt limit))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3236 (key (car ado))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3237 (mtc (cdr ado)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3238 (setq rst-font-lock-level (rst-adornment-level key t))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3239 (goto-char (nth 1 mtc))
96139
f55e63ce44fd Run rst-define-level-faces when loading.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96130
diff changeset
3240 (put-text-property (nth 0 mtc) (nth 1 mtc) 'font-lock-multiline t)
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3241 (set-match-data mtc)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3242 t))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3243
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3244
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3245
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3246
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3248 ;; Support for conversion from within Emacs
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3249
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3250 (defgroup rst-compile nil
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3251 "Settings for support of conversion of reStructuredText
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3252 document with \\[rst-compile]."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3253 :group 'rst
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3254 :version "21.1")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3255
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3256 (defvar rst-compile-toolsets
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3257 '((html . ("rst2html.py" ".html" nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3258 (latex . ("rst2latex.py" ".tex" nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3259 (newlatex . ("rst2newlatex.py" ".tex" nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3260 (pseudoxml . ("rst2pseudoxml.py" ".xml" nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3261 (xml . ("rst2xml.py" ".xml" nil)))
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3262 "Table describing the command to use for each toolset.
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3263 An association list of the toolset to a list of the (command to use,
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3264 extension of produced filename, options to the tool (nil or a
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3265 string)) to be used for converting the document.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3266
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3267 ;; Note for Python programmers not familiar with association lists: you can set
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3268 ;; values in an alists like this, e.g. :
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3269 ;; (setcdr (assq 'html rst-compile-toolsets)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3270 ;; '("rst2html.py" ".htm" "--stylesheet=/docutils.css"))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3271
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3272
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3273 (defvar rst-compile-primary-toolset 'html
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3274 "The default toolset for `rst-compile'.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3275
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3276 (defvar rst-compile-secondary-toolset 'latex
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3277 "The default toolset for `rst-compile' with a prefix argument.")
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3278
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3279 (defun rst-compile-find-conf ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3280 "Look for the configuration file in the parents of the current path."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3281 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3282 (let ((file-name "docutils.conf")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3283 (buffer-file (buffer-file-name)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3284 ;; Move up in the dir hierarchy till we find a change log file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3285 (let* ((dir (file-name-directory buffer-file))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3286 (prevdir nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3287 (while (and (or (not (string= dir prevdir))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3288 (setq dir nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3289 nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3290 (not (file-exists-p (concat dir file-name))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3291 ;; Move up to the parent dir and try again.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3292 (setq prevdir dir)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3293 (setq dir (expand-file-name (file-name-directory
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3294 (directory-file-name
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3295 (file-name-directory dir)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3296 )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3297 (or (and dir (concat dir file-name)) nil)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3298 )))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3299
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3300
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3301 (require 'compile)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3302
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3303 (defun rst-compile (&optional pfxarg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3304 "Compile command to convert reST document into some output file.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3305 Attempts to find configuration file, if it can, overrides the
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3306 options. There are two commands to choose from, with a prefix
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3307 argument, select the alternative toolset."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3308 (interactive "P")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3309 ;; Note: maybe we want to check if there is a Makefile too and not do anything
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3310 ;; if that is the case. I dunno.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3311 (let* ((toolset (cdr (assq (if pfxarg
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3312 rst-compile-secondary-toolset
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3313 rst-compile-primary-toolset)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3314 rst-compile-toolsets)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3315 (command (car toolset))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3316 (extension (cadr toolset))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3317 (options (caddr toolset))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3318 (conffile (rst-compile-find-conf))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3319 (bufname (file-name-nondirectory buffer-file-name))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3320 (outname (file-name-sans-extension bufname)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3321
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3322 ;; Set compile-command before invocation of compile.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3323 (set (make-local-variable 'compile-command)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3324 (mapconcat 'identity
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3325 (list command
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3326 (or options "")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3327 (if conffile
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3328 (concat "--config=\"" conffile "\"")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3329 "")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3330 bufname
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3331 (concat outname extension))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3332 " "))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3333
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3334 ;; Invoke the compile command.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3335 (if (or compilation-read-command current-prefix-arg)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3336 (call-interactively 'compile)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3337 (compile compile-command))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3338 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3339
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3340 (defun rst-compile-alt-toolset ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3341 "Compile command with the alternative toolset."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3342 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3343 (rst-compile 't))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3344
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3345 (defun rst-compile-pseudo-region ()
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3346 "Show the pseudo-XML rendering of the current active region,
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3347 or of the entire buffer, if the region is not selected."
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3348 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3349 (with-output-to-temp-buffer "*pseudoxml*"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3350 (shell-command-on-region
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3351 (if mark-active (region-beginning) (point-min))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3352 (if mark-active (region-end) (point-max))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3353 "rst2pseudoxml.py"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3354 standard-output)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3355
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3356 (defvar rst-pdf-program "xpdf"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3357 "Program used to preview PDF files.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3358
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3359 (defun rst-compile-pdf-preview ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3360 "Convert the document to a PDF file and launch a preview program."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3361 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3362 (let* ((tmp-filename "/tmp/out.pdf")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3363 (command (format "rst2pdf.py %s %s && %s %s"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3364 buffer-file-name tmp-filename
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3365 rst-pdf-program tmp-filename)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3366 (start-process-shell-command "rst-pdf-preview" nil command)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3367 ;; Note: you could also use (compile command) to view the compilation
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3368 ;; output.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3369 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3370
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3371 (defvar rst-slides-program "firefox"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3372 "Program used to preview S5 slides.")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3373
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3374 (defun rst-compile-slides-preview ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3375 "Convert the document to an S5 slide presentation and launch a preview program."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3376 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3377 (let* ((tmp-filename "/tmp/slides.html")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3378 (command (format "rst2s5.py %s %s && %s %s"
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3379 buffer-file-name tmp-filename
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3380 rst-slides-program tmp-filename)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3381 (start-process-shell-command "rst-slides-preview" nil command)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3382 ;; Note: you could also use (compile command) to view the compilation
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3383 ;; output.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3384 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3385
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3386
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3387
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3389 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3390 ;; Generic text functions that are more convenient than the defaults.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3391 ;;
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3392
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3393 (defun rst-replace-lines (fromchar tochar)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3394 "Replace flush-left lines, consisting of multiple FROMCHAR characters,
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3395 with equal-length lines of TOCHAR."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3396 (interactive "\
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3397 cSearch for flush-left lines of char:
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3398 cand replace with char: ")
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3399 (save-excursion
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3400 (let ((searchre (concat "^" (regexp-quote (string fromchar)) "+\\( *\\)$"))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3401 (found 0))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3402 (while (search-forward-regexp searchre nil t)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3403 (setq found (1+ found))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3404 (goto-char (match-beginning 1))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3405 (let ((width (current-column)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3406 (rst-delete-entire-line)
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3407 (insert-char tochar width)))
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3408 (message (format "%d lines replaced." found)))))
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3409
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3410 (defun rst-join-paragraph ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3411 "Join lines in current paragraph into one line, removing end-of-lines."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3412 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3413 (let ((fill-column 65000)) ; some big number
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3414 (call-interactively 'fill-paragraph)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3415
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3416 (defun rst-force-fill-paragraph ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3417 "Fill paragraph at point, first joining the paragraph's lines into one.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3418 This is useful for filling list item paragraphs."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3419 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3420 (rst-join-paragraph)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3421 (fill-paragraph nil))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3422
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3423
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3424 ;; Generic character repeater function.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3425 ;; For sections, better to use the specialized function above, but this can
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3426 ;; be useful for creating separators.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3427 (defun rst-repeat-last-character (&optional tofill)
100495
c648cd1e2e46 * textmodes/rst.el (rst-promote-region): Reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 96497
diff changeset
3428 "Fill the current line up to the length of the preceding line (if not
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3429 empty), using the last character on the current line. If the preceding line is
96126
fcd827c4a553 Fix up docstring conventions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 96117
diff changeset
3430 empty, we use the `fill-column'.
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3431
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3432 If a prefix argument is provided, use the next line rather than the preceding
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3433 line.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3434
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3435 If the current line is longer than the desired length, shave the characters off
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3436 the current line to fit the desired length.
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3437
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3438 As an added convenience, if the command is repeated immediately, the alternative
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3439 column is used (fill-column vs. end of previous/next line)."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3440 (interactive)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3441 (let* ((curcol (current-column))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3442 (curline (+ (count-lines (point-min) (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3443 (if (eq curcol 0) 1 0)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3444 (lbp (line-beginning-position 0))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3445 (prevcol (if (and (= curline 1) (not current-prefix-arg))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3446 fill-column
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3447 (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3448 (forward-line (if current-prefix-arg 1 -1))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3449 (end-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3450 (skip-chars-backward " \t" lbp)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3451 (let ((cc (current-column)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3452 (if (= cc 0) fill-column cc)))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3453 (rightmost-column
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3454 (cond (tofill fill-column)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3455 ((equal last-command 'rst-repeat-last-character)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3456 (if (= curcol fill-column) prevcol fill-column))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3457 (t (save-excursion
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3458 (if (= prevcol 0) fill-column prevcol)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3459 )) )
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3460 (end-of-line)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3461 (if (> (current-column) rightmost-column)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3462 ;; shave characters off the end
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3463 (delete-region (- (point)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3464 (- (current-column) rightmost-column))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3465 (point))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3466 ;; fill with last characters
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3467 (insert-char (preceding-char)
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3468 (- rightmost-column (current-column))))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3469 ))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3470
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3471
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3472 (defun rst-portable-mark-active-p ()
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3473 "A portable function that returns non-nil if the mark is active."
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3474 (cond
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3475 ((fboundp 'region-active-p) (region-active-p))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3476 ((boundp 'transient-mark-mode) transient-mark-mode mark-active)))
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3477
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3478
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3479
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3480 (provide 'rst)
96130
b0875b652dc2 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 96127
diff changeset
3481
b0875b652dc2 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 96127
diff changeset
3482 ;; arch-tag: 255ac0a3-a689-44cb-8643-04ca55ae490d
96117
8e11daf373e3 New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3483 ;;; rst.el ends here