summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorsmerten <smerten@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2012-06-16 09:41:40 +0000
committersmerten <smerten@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2012-06-16 09:41:40 +0000
commit49f750c1c0adb07a8107817f602281af98a9638b (patch)
treeb48ef3a133248683fb9fe7966e5067ed709fc2f1 /tools
parent712890980556b4aa67e8fb42629cb33bdb7c8b83 (diff)
downloaddocutils-49f750c1c0adb07a8107817f602281af98a9638b.tar.gz
Major merge with Emacs source tree. Docutils SVN version and Emacs
trunk are kept in sync from now on. New version is supposed to appear in Emacs 24.2. User visible changes: * Switch meaning of keybindings ``C-M-a`` and ``C-M-e`` They were wrong in the first place :-( . Sorry for changing bindings again. * Added faces `rst-transition` and `rst-adornment` New faces are used instead of directly using `font-lock-keyword-face`. * Improved customization of `rst-adornment-faces-alist` Hopefully this will not break existing customization. * Character syntax adopted to match plain text again Other code improvements suggested by Emacs developers: * Replaced use of `defun`\s from `cl.el` by own definitions * Improved lots and lots of comments and documentation strings including spelling fixes * Fixed version stuff * Improved some functions * Byte-compiling emits no warnings and works * Added tests Other improvements: * Default for customizing `rst-adornment-faces-alist` is now safe Thanks to Samuel Bronson for the patch. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7444 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'tools')
-rw-r--r--tools/editors/emacs/IDEAS.rst28
-rw-r--r--tools/editors/emacs/rst.el1191
-rw-r--r--tools/editors/emacs/tests/Makefile11
-rw-r--r--tools/editors/emacs/tests/re.el15
4 files changed, 699 insertions, 546 deletions
diff --git a/tools/editors/emacs/IDEAS.rst b/tools/editors/emacs/IDEAS.rst
index afd9c79ad..93fc8cce2 100644
--- a/tools/editors/emacs/IDEAS.rst
+++ b/tools/editors/emacs/IDEAS.rst
@@ -161,13 +161,35 @@ Imenu support
Outline support
===============
-* Support for `outline-mode' / `allout-mode' would be nice
+* Support for `outline-mode` / `allout-mode` would be nice
* Should consider section titles
-* May be folding is also possible
+ * May be item lists can also be included
- * For item lists
+ * Using `allout-mode` is difficult
+
+ * It's not customizable enough for the complex syntax of
+ reStructuredText
+
+ * However, some commands make sense
+
+ * Motion commands
+
+ * Exposure commands
+
+ * Some alteration commands
+
+ * Should be reimplemented
+
+ * Key bindings need to be reused
+
+ * However, care must be taken if a file uses `allout-mode` for
+ instance by comment strings
+
+ * In this case key bindings must not be overridden
+
+ * A command adding / updating `allout-mode` tags could be a solution
Sophisticated filling
=====================
diff --git a/tools/editors/emacs/rst.el b/tools/editors/emacs/rst.el
index 0d5ec4eb6..ac4fcdce1 100644
--- a/tools/editors/emacs/rst.el
+++ b/tools/editors/emacs/rst.el
@@ -3,7 +3,8 @@
;; Copyright (C) 2003-2012 Free Software Foundation, Inc.
;; Maintainer: Stefan Merten <smerten@oekonux.de>
-;; Author: Martin Blais <blais@furius.ca>,
+;; Author: Stefan Merten <smerten@oekonux.de>,
+;; Martin Blais <blais@furius.ca>,
;; David Goodger <goodger@python.org>,
;; Wei-Wei Guo <wwguocn@gmail.com>
@@ -25,10 +26,10 @@
;;; Commentary:
;; This package provides major mode rst-mode, which supports documents marked
-;; up using the reStructuredText format. Support includes font locking as well
-;; as a lot of convenience functions for editing. It does this by defining a
-;; Emacs major mode: rst-mode (ReST). This mode is derived from text-mode. This
-;; package also contains:
+;; up using the reStructuredText format. Support includes font locking as well
+;; as a lot of convenience functions for editing. It does this by defining a
+;; Emacs major mode: rst-mode (ReST). This mode is derived from text-mode.
+;; This package also contains:
;;
;; - Functions to automatically adjust and cycle the section underline
;; adornments;
@@ -53,12 +54,12 @@
;; http://docutils.sourceforge.net/docs/user/emacs.html
;;
;;
-;; There are a number of convenient keybindings provided by rst-mode.
+;; There are a number of convenient key bindings provided by rst-mode.
;; For more on bindings, see rst-mode-map below. There are also many variables
;; that can be customized, look for defcustom in this file.
;;
;; If you use the table-of-contents feature, you may want to add a hook to
-;; update the TOC automatically everytime you adjust a section title::
+;; update the TOC automatically every time you adjust a section title::
;;
;; (add-hook 'rst-adjust-hook 'rst-toc-update)
;;
@@ -70,7 +71,7 @@
;;
;;
;; Customization is done by customizable variables contained in customization
-;; group "rst" and subgroups. Group "rst" is contained in the "wp" group.
+;; group "rst" and subgroups. Group "rst" is contained in the "wp" group.
;;
;;; DOWNLOAD
@@ -95,21 +96,72 @@
;; want automatically enter rst-mode from any file with compatible extensions:
;;
;; (setq auto-mode-alist
-;; (append '(("\\.txt$" . rst-mode)
-;; ("\\.rst$" . rst-mode)
-;; ("\\.rest$" . rst-mode)) auto-mode-alist))
+;; (append '(("\\.txt\\'" . rst-mode)
+;; ("\\.rst\\'" . rst-mode)
+;; ("\\.rest\\'" . rst-mode)) auto-mode-alist))
;;
;;; Code:
-(require 'cl)
+;; FIXME: When 24.1 is common place remove use of `lexical-let' and put "-*-
+;; lexical-binding: t -*-" in the first line.
+
+;; Only use of macros is allowed - may be replaced by `cl-lib' some time.
+(eval-when-compile
+ (require 'cl))
+
+;; Redefine some functions from `cl.el' in a proper namespace until they may be
+;; used from there.
+
+(defun rst-signum (x)
+ "Return 1 if X is positive, -1 if negative, 0 if zero."
+ (cond
+ ((> x 0) 1)
+ ((< x 0) -1)
+ (t 0)))
+
+(defun rst-some (seq &optional pred)
+ "Return non-nil if any element of SEQ yields non-nil when PRED is applied.
+Apply PRED to each element of list SEQ until the first non-nil
+result is yielded and return this result. PRED defaults to
+`identity'."
+ (unless pred
+ (setq pred 'identity))
+ (catch 'rst-some
+ (dolist (elem seq)
+ (let ((r (funcall pred elem)))
+ (when r
+ (throw 'rst-some r))))))
+
+(defun rst-position-if (pred seq)
+ "Return position of first element satisfying PRED in list SEQ or nil."
+ (catch 'rst-position-if
+ (let ((i 0))
+ (dolist (elem seq)
+ (when (funcall pred elem)
+ (throw 'rst-position-if i))
+ (incf i)))))
+
+(defun rst-position (elem seq)
+ "Return position of ELEM in list SEQ or nil.
+Comparison done with `equal'."
+ ;; Create a closure containing `elem' so the `lambda' always sees our
+ ;; parameter instead of an `elem' which may be in dynamic scope at the time
+ ;; of execution of the `lambda'.
+ (lexical-let ((elem elem))
+ (rst-position-if (function (lambda (e)
+ (equal elem e)))
+ seq)))
+
+;; FIXME: Embed complicated `defconst's in `eval-when-compile'.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Versions
(defun rst-extract-version (delim-re head-re re tail-re var &optional default)
- "Return the version matching RE after regex DELIM-RE and HEAD-RE
-and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match"
+ "Extract the version from a variable according to the given regexes.
+Return the version after regex DELIM-RE and HEAD-RE matching RE
+and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match."
(if (string-match
(concat delim-re head-re "\\(" re "\\)" tail-re delim-re)
var)
@@ -117,20 +169,20 @@ and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match"
default))
;; Use CVSHeader to really get information from CVS and not other version
-;; control systems
+;; control systems.
(defconst rst-cvs-header
- "$CVSHeader: sm/rst_el/rst.el,v 1.256 2012-04-29 15:00:50 stefan Exp $")
+ "$CVSHeader: sm/rst_el/rst.el,v 1.286 2012-06-16 09:41:21 stefan Exp $")
(defconst rst-cvs-rev
(rst-extract-version "\\$" "CVSHeader: \\S + " "[0-9]+\\(?:\\.[0-9]+\\)+"
" .*" rst-cvs-header "0.0")
- "The CVS revision of this file. CVS revision is the development revision.")
+ "The CVS revision of this file. CVS revision is the development revision.")
(defconst rst-cvs-timestamp
(rst-extract-version "\\$" "CVSHeader: \\S + \\S + "
"[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+" " .*"
rst-cvs-header "1970-01-01 00:00:00")
- "The CVS timestamp of this file.")
+ "The CVS time stamp of this file.")
-;; Use LastChanged... to really get information from SVN
+;; Use LastChanged... to really get information from SVN.
(defconst rst-svn-rev
(rst-extract-version "\\$" "LastChangedRevision: " "[0-9]+" " "
"$LastChangedRevision$")
@@ -139,16 +191,16 @@ SVN revision is the upstream (docutils) revision.")
(defconst rst-svn-timestamp
(rst-extract-version "\\$" "LastChangedDate: " ".+?+" " "
"$LastChangedDate$")
- "The SVN timestamp of this file.")
+ "The SVN time stamp of this file.")
-;; Maintained by the release process
+;; Maintained by the release process.
(defconst rst-official-version
(rst-extract-version "%" "OfficialVersion: " "[0-9]+\\(?:\\.[0-9]+\\)+" " "
- "%OfficialVersion: 1.2.1 %")
+ "%OfficialVersion: 1.3.0 %")
"Official version of the package.")
(defconst rst-official-cvs-rev
(rst-extract-version "[%$]" "Revision: " "[0-9]+\\(?:\\.[0-9]+\\)+" " "
- "%Revision: 1.256 %")
+ "$Revision$")
"CVS revision of this file in the official version.")
(defconst rst-version
@@ -157,14 +209,15 @@ SVN revision is the upstream (docutils) revision.")
(format "%s (development %s [%s])" rst-official-version
rst-cvs-rev rst-cvs-timestamp))
"The version string.
-Starts with the current official version. For developer versions
-in parentheses follows the development revision and the timestamp.")
+Starts with the current official version. For developer versions
+in parentheses follows the development revision and the time stamp.")
(defconst rst-package-emacs-version-alist
- '(("1.0.0" . "24.0")
- ("1.1.0" . "24.0")
- ("1.2.0" . "24.0")
- ("1.2.1" . "24.0")))
+ '(("1.0.0" . "24.2")
+ ("1.1.0" . "24.2")
+ ("1.2.0" . "24.2")
+ ("1.2.1" . "24.2")
+ ("1.3.0" . "24.2")))
(unless (assoc rst-official-version rst-package-emacs-version-alist)
(error "Version %s not listed in `rst-package-emacs-version-alist'"
@@ -187,12 +240,12 @@ in parentheses follows the development revision and the timestamp.")
;; Facilities for regular expressions used everywhere
;; The trailing numbers in the names give the number of referenceable regex
-;; groups contained in the regex
+;; groups contained in the regex.
;; Used to be customizable but really is not customizable but fixed by the reST
-;; syntax
+;; syntax.
(defconst rst-bullets
- ;; Sorted so they can form a character class when concatenated
+ ;; Sorted so they can form a character class when concatenated.
'(?- ?* ?+ ?\u2022 ?\u2023 ?\u2043)
"List of all possible bullet characters for bulleted lists.")
@@ -203,7 +256,7 @@ in parentheses follows the development revision and the timestamp.")
"Supported URI schemes.")
(defconst rst-adornment-chars
- ;; Sorted so they can form a character class when concatenated
+ ;; Sorted so they can form a character class when concatenated.
'(?\]
?! ?\" ?# ?$ ?% ?& ?' ?\( ?\) ?* ?+ ?, ?. ?/ ?: ?\; ?< ?= ?> ?? ?@ ?\[ ?\\
?^ ?_ ?` ?{ ?| ?} ?~
@@ -215,45 +268,45 @@ in parentheses follows the development revision and the timestamp.")
"Maximum length of inline markup to recognize.")
(defconst rst-re-alist-def
- ;; `*-beg' matches * at the beginning of a line
- ;; `*-end' matches * at the end of a line
- ;; `*-prt' matches a part of *
- ;; `*-tag' matches *
- ;; `*-sta' matches the start of * which may be followed by respective content
- ;; `*-pfx' matches the delimiter left of *
- ;; `*-sfx' matches the delimiter right of *
- ;; `*-hlp' helper for *
+ ;; `*-beg' matches * at the beginning of a line.
+ ;; `*-end' matches * at the end of a line.
+ ;; `*-prt' matches a part of *.
+ ;; `*-tag' matches *.
+ ;; `*-sta' matches the start of * which may be followed by respective content.
+ ;; `*-pfx' matches the delimiter left of *.
+ ;; `*-sfx' matches the delimiter right of *.
+ ;; `*-hlp' helper for *.
;;
;; A trailing number says how many referenceable groups are contained.
`(
;; Horizontal white space (`hws')
(hws-prt "[\t ]")
- (hws-tag hws-prt "*") ; Optional sequence of horizontal white space
- (hws-sta hws-prt "+") ; Mandatory sequence of horizontal white space
+ (hws-tag hws-prt "*") ; Optional sequence of horizontal white space.
+ (hws-sta hws-prt "+") ; Mandatory sequence of horizontal white space.
;; Lines (`lin')
- (lin-beg "^" hws-tag) ; Beginning of a possibly indented line
- (lin-end hws-tag "$") ; End of a line with optional trailing white space
- (linemp-tag "^" hws-tag "$") ; Empty line with optional white space
+ (lin-beg "^" hws-tag) ; Beginning of a possibly indented line.
+ (lin-end hws-tag "$") ; End of a line with optional trailing white space.
+ (linemp-tag "^" hws-tag "$") ; Empty line with optional white space.
;; Various tags and parts
(ell-tag "\\.\\.\\.") ; Ellipsis
- (bul-tag ,(concat "[" rst-bullets "]")) ; A bullet
- (ltr-tag "[a-zA-Z]") ; A letter enumerator tag
- (num-prt "[0-9]") ; A number enumerator part
- (num-tag num-prt "+") ; A number enumerator tag
- (rom-prt "[IVXLCDMivxlcdm]") ; A roman enumerator part
- (rom-tag rom-prt "+") ; A roman enumerator tag
- (aut-tag "#") ; An automatic enumerator tag
- (dcl-tag "::") ; Double colon
+ (bul-tag ,(concat "[" rst-bullets "]")) ; A bullet.
+ (ltr-tag "[a-zA-Z]") ; A letter enumerator tag.
+ (num-prt "[0-9]") ; A number enumerator part.
+ (num-tag num-prt "+") ; A number enumerator tag.
+ (rom-prt "[IVXLCDMivxlcdm]") ; A roman enumerator part.
+ (rom-tag rom-prt "+") ; A roman enumerator tag.
+ (aut-tag "#") ; An automatic enumerator tag.
+ (dcl-tag "::") ; Double colon.
;; Block lead in (`bli')
(bli-sfx (:alt hws-sta "$")) ; Suffix of a block lead-in with *optional*
- ; immediate content
+ ; immediate content.
;; Various starts
- (bul-sta bul-tag bli-sfx) ; Start of a bulleted item
+ (bul-sta bul-tag bli-sfx) ; Start of a bulleted item.
;; Explicit markup tag (`exm')
(exm-tag "\\.\\.")
@@ -261,104 +314,105 @@ in parentheses follows the development revision and the timestamp.")
(exm-beg lin-beg exm-sta)
;; Counters in enumerations (`cnt')
- (cntany-tag (:alt ltr-tag num-tag rom-tag aut-tag)) ; An arbitrary counter
- (cntexp-tag (:alt ltr-tag num-tag rom-tag)) ; An arbitrary explicit counter
+ (cntany-tag (:alt ltr-tag num-tag rom-tag aut-tag)) ; An arbitrary counter.
+ (cntexp-tag (:alt ltr-tag num-tag rom-tag)) ; An arbitrary explicit counter.
;; Enumerator (`enm')
(enmany-tag (:alt
(:seq cntany-tag "\\.")
- (:seq "(?" cntany-tag ")"))) ; An arbitrary enumerator
+ (:seq "(?" cntany-tag ")"))) ; An arbitrary enumerator.
(enmexp-tag (:alt
(:seq cntexp-tag "\\.")
(:seq "(?" cntexp-tag ")"))) ; An arbitrary explicit
- ; enumerator
+ ; enumerator.
(enmaut-tag (:alt
(:seq aut-tag "\\.")
- (:seq "(?" aut-tag ")"))) ; An automatic enumerator
- (enmany-sta enmany-tag bli-sfx) ; An arbitrary enumerator start
- (enmexp-sta enmexp-tag bli-sfx) ; An arbitrary explicit enumerator start
+ (:seq "(?" aut-tag ")"))) ; An automatic enumerator.
+ (enmany-sta enmany-tag bli-sfx) ; An arbitrary enumerator start.
+ (enmexp-sta enmexp-tag bli-sfx) ; An arbitrary explicit enumerator start.
(enmexp-beg lin-beg enmexp-sta) ; An arbitrary explicit enumerator start
- ; at the beginning of a line
+ ; at the beginning of a line.
;; Items may be enumerated or bulleted (`itm')
- (itmany-tag (:alt enmany-tag bul-tag)) ; An arbitrary item tag
+ (itmany-tag (:alt enmany-tag bul-tag)) ; An arbitrary item tag.
(itmany-sta-1 (:grp itmany-tag) bli-sfx) ; An arbitrary item start, group
- ; is the item tag
+ ; is the item tag.
(itmany-beg-1 lin-beg itmany-sta-1) ; An arbitrary item start at the
; beginning of a line, group is the
- ; item tag
+ ; item tag.
;; Inline markup (`ilm')
(ilm-pfx (:alt "^" hws-prt "[-'\"([{<\u2018\u201c\u00ab\u2019/:]"))
(ilm-sfx (:alt "$" hws-prt "[]-'\")}>\u2019\u201d\u00bb/:.,;!?\\]"))
;; Inline markup content (`ilc')
- (ilcsgl-tag "\\S ") ; A single non-white character
- (ilcast-prt (:alt "[^*\\]" "\\\\.")) ; Part of non-asterisk content
- (ilcbkq-prt (:alt "[^`\\]" "\\\\.")) ; Part of non-backquote content
+ (ilcsgl-tag "\\S ") ; A single non-white character.
+ (ilcast-prt (:alt "[^*\\]" "\\\\.")) ; Part of non-asterisk content.
+ (ilcbkq-prt (:alt "[^`\\]" "\\\\.")) ; Part of non-backquote content.
(ilcbkqdef-prt (:alt "[^`\\\n]" "\\\\.")) ; Part of non-backquote
- ; definition
- (ilcbar-prt (:alt "[^|\\]" "\\\\.")) ; Part of non-vertical-bar content
+ ; definition.
+ (ilcbar-prt (:alt "[^|\\]" "\\\\.")) ; Part of non-vertical-bar content.
(ilcbardef-prt (:alt "[^|\\\n]" "\\\\.")) ; Part of non-vertical-bar
- ; definition
- (ilcast-sfx "[^\t *\\]") ; Suffix of non-asterisk content
- (ilcbkq-sfx "[^\t `\\]") ; Suffix of non-backquote content
- (ilcbar-sfx "[^\t |\\]") ; Suffix of non-vertical-bar content
- (ilcrep-hlp ,(format "\\{0,%d\\}" rst-max-inline-length)) ; Repeat count
+ ; definition.
+ (ilcast-sfx "[^\t *\\]") ; Suffix of non-asterisk content.
+ (ilcbkq-sfx "[^\t `\\]") ; Suffix of non-backquote content.
+ (ilcbar-sfx "[^\t |\\]") ; Suffix of non-vertical-bar content.
+ (ilcrep-hlp ,(format "\\{0,%d\\}" rst-max-inline-length)) ; Repeat count.
(ilcast-tag (:alt ilcsgl-tag
(:seq ilcsgl-tag
ilcast-prt ilcrep-hlp
- ilcast-sfx))) ; Non-asterisk content
+ ilcast-sfx))) ; Non-asterisk content.
(ilcbkq-tag (:alt ilcsgl-tag
(:seq ilcsgl-tag
ilcbkq-prt ilcrep-hlp
- ilcbkq-sfx))) ; Non-backquote content
+ ilcbkq-sfx))) ; Non-backquote content.
(ilcbkqdef-tag (:alt ilcsgl-tag
(:seq ilcsgl-tag
ilcbkqdef-prt ilcrep-hlp
- ilcbkq-sfx))) ; Non-backquote definition
+ ilcbkq-sfx))) ; Non-backquote definition.
(ilcbar-tag (:alt ilcsgl-tag
(:seq ilcsgl-tag
ilcbar-prt ilcrep-hlp
- ilcbar-sfx))) ; Non-vertical-bar content
+ ilcbar-sfx))) ; Non-vertical-bar content.
(ilcbardef-tag (:alt ilcsgl-tag
(:seq ilcsgl-tag
ilcbardef-prt ilcrep-hlp
- ilcbar-sfx))) ; Non-vertical-bar definition
+ ilcbar-sfx))) ; Non-vertical-bar definition.
;; Fields (`fld')
- (fldnam-prt (:alt "[^:\n]" "\\\\:")) ; Part of a field name
- (fldnam-tag fldnam-prt "+") ; A field name
- (fld-tag ":" fldnam-tag ":") ; A field marker
+ (fldnam-prt (:alt "[^:\n]" "\\\\:")) ; Part of a field name.
+ (fldnam-tag fldnam-prt "+") ; A field name.
+ (fld-tag ":" fldnam-tag ":") ; A field marker.
;; Options (`opt')
- (optsta-tag (:alt "[-+/]" "--")) ; Start of an option
- (optnam-tag "\\sw" (:alt "-" "\\sw") "*") ; Name of an option
- (optarg-tag (:shy "[ =]\\S +")) ; Option argument
- (optsep-tag (:shy "," hws-prt)) ; Separator between options
- (opt-tag (:shy optsta-tag optnam-tag optarg-tag "?")) ; A complete option
+ (optsta-tag (:alt "[-+/]" "--")) ; Start of an option.
+ (optnam-tag "\\sw" (:alt "-" "\\sw") "*") ; Name of an option.
+ (optarg-tag (:shy "[ =]\\S +")) ; Option argument.
+ (optsep-tag (:shy "," hws-prt)) ; Separator between options.
+ (opt-tag (:shy optsta-tag optnam-tag optarg-tag "?")) ; A complete option.
;; Footnotes and citations (`fnc')
- (fncnam-prt "[^\]\n]") ; Part of a footnote or citation name
- (fncnam-tag fncnam-prt "+") ; A footnote or citation name
- (fnc-tag "\\[" fncnam-tag "]") ; A complete footnote or citation tag
+ (fncnam-prt "[^\]\n]") ; Part of a footnote or citation name.
+ (fncnam-tag fncnam-prt "+") ; A footnote or citation name.
+ (fnc-tag "\\[" fncnam-tag "]") ; A complete footnote or citation tag.
(fncdef-tag-2 (:grp exm-sta)
(:grp fnc-tag)) ; A complete footnote or citation definition
- ; tag; first group is the explicit markup
+ ; tag. First group is the explicit markup
; start, second group is the footnote /
- ; citation tag
+ ; citation tag.
(fnc-sta-2 fncdef-tag-2 bli-sfx) ; Start of a footnote or citation
- ; definition; first group is the explicit
+ ; definition. First group is the explicit
; markup start, second group is the
- ; footnote / citation tag
+ ; footnote / citation tag.
;; Substitutions (`sub')
- (sub-tag "|" ilcbar-tag "|") ; A complete substitution tag
+ (sub-tag "|" ilcbar-tag "|") ; A complete substitution tag.
(subdef-tag "|" ilcbardef-tag "|") ; A complete substitution definition
- ; tag
+ ; tag.
;; Symbol (`sym')
- (sym-tag (:shy "\\sw+" (:shy "\\s_\\sw+") "*"))
+ (sym-prt "[-+.:_]") ; Non-word part of a symbol.
+ (sym-tag (:shy "\\sw+" (:shy sym-prt "\\sw+") "*"))
;; URIs (`uri')
(uri-tag (:alt ,@rst-uri-schemes))
@@ -367,62 +421,64 @@ in parentheses follows the development revision and the timestamp.")
(ado-prt "[" ,(concat rst-adornment-chars) "]")
(adorep3-hlp "\\{3,\\}") ; There must be at least 3 characters because
; otherwise explicit markup start would be
- ; recognized
+ ; recognized.
(adorep2-hlp "\\{2,\\}") ; As `adorep3-hlp' but when the first of three
- ; characters is matched differently
+ ; characters is matched differently.
(ado-tag-1-1 (:grp ado-prt)
"\\1" adorep2-hlp) ; A complete adornment, group is the first
; adornment character and MUST be the FIRST
- ; group in the whole expression
+ ; group in the whole expression.
(ado-tag-1-2 (:grp ado-prt)
"\\2" adorep2-hlp) ; A complete adornment, group is the first
; adornment character and MUST be the
- ; SECOND group in the whole expression
+ ; SECOND group in the whole expression.
(ado-beg-2-1 "^" (:grp ado-tag-1-2)
lin-end) ; A complete adornment line; first group is the whole
; adornment and MUST be the FIRST group in the whole
; expression; second group is the first adornment
- ; character
+ ; character.
;; Titles (`ttl')
- (ttl-tag "\\S *\\w\\S *") ; A title text
- (ttl-beg lin-beg ttl-tag) ; A title text at the beginning of a line
+ (ttl-tag "\\S *\\w\\S *") ; A title text.
+ (ttl-beg lin-beg ttl-tag) ; A title text at the beginning of a line.
;; Directives and substitution definitions (`dir')
(dir-tag-3 (:grp exm-sta)
(:grp (:shy subdef-tag hws-sta) "?")
(:grp sym-tag dcl-tag)) ; A directive or substitution definition
- ; tag; first group is explicit markup
+ ; tag. First group is explicit markup
; start, second group is a possibly
; empty substitution tag, third group is
; the directive tag including the double
- ; colon
+ ; colon.
(dir-sta-3 dir-tag-3 bli-sfx) ; Start of a directive or substitution
- ; definition; groups are as in dir-tag-3
+ ; definition. Groups are as in dir-tag-3.
;; Literal block (`lit')
(lit-sta-2 (:grp (:alt "[^.\n]" "\\.[^.\n]") ".*") "?"
- (:grp dcl-tag) "$") ; Start of a literal block; first group is
+ (:grp dcl-tag) "$") ; Start of a literal block. First group is
; any text before the double colon tag which
; may not exist, second group is the double
- ; colon tag
+ ; colon tag.
;; Comments (`cmt')
(cmt-sta-1 (:grp exm-sta) "[^\[|_\n]"
(:alt "[^:\n]" (:seq ":" (:alt "[^:\n]" "$")))
"*$") ; Start of a comment block; first group is explicit markup
- ; start
+ ; start.
;; Paragraphs (`par')
(par-tag- (:alt itmany-tag fld-tag opt-tag fncdef-tag-2 dir-tag-3 exm-tag)
) ; Tag at the beginning of a paragraph; there may be groups in
- ; certain cases
+ ; certain cases.
)
"Definition alist of relevant regexes.
Each entry consists of the symbol naming the regex and an
argument list for `rst-re'.")
-;; FIXME: Use `sregex` or `rx` instead of re-inventing the wheel
+(defvar rst-re-alist) ; Forward declare to use it in `rst-re'.
+
+;; FIXME: Use `sregex` or `rx` instead of re-inventing the wheel.
(defun rst-re (&rest args)
"Interpret ARGS as regular expressions and return a regex string.
Each element of ARGS may be one of the following:
@@ -433,8 +489,8 @@ A character which is resolved to a quoted regex.
A symbol which is resolved to a string using `rst-re-alist-def'.
-A list with a keyword in the car. Each element of the cdr of such
-a list is recursively interpreted as ARGS. The results of this
+A list with a keyword in the car. Each element of the cdr of such
+a list is recursively interpreted as ARGS. The results of this
interpretation are concatenated according to the keyword.
For the keyword `:seq' the results are simply concatenated.
@@ -446,11 +502,10 @@ For the keyword `:alt' the results form an alternative (\"\\|\")
which is shy-grouped (\"\\(?:...\\)\").
For the keyword `:grp' the results are concatenated and form a
-referencable grouped (\"\\(...\\)\").
+referenceable group (\"\\(...\\)\").
After interpretation of ARGS the results are concatenated as for
-`:seq'.
-"
+`:seq'."
(apply 'concat
(mapcar
(lambda (re)
@@ -459,7 +514,7 @@ After interpretation of ARGS the results are concatenated as for
re)
((symbolp re)
(cadr (assoc re rst-re-alist)))
- ((char-valid-p re)
+ ((characterp re)
(regexp-quote (char-to-string re)))
((listp re)
(let ((nested
@@ -481,109 +536,93 @@ After interpretation of ARGS the results are concatenated as for
(error "Unknown object type for building regex: %s" re))))
args)))
-(defconst rst-re-alist
- ;; Shadow global value we are just defining so we can construct it step by
- ;; step
- (let (rst-re-alist)
- (dolist (re rst-re-alist-def)
- (setq rst-re-alist
- (nconc rst-re-alist
- (list (list (car re) (apply 'rst-re (cdr re)))))))
- rst-re-alist)
- "Alist mapping symbols from `rst-re-alist-def' to regex strings.")
+;; FIXME: Remove circular dependency between `rst-re' and `rst-re-alist'.
+(with-no-warnings ; Silence byte-compiler about this construction.
+ (defconst rst-re-alist
+ ;; Shadow global value we are just defining so we can construct it step by
+ ;; step.
+ (let (rst-re-alist)
+ (dolist (re rst-re-alist-def rst-re-alist)
+ (setq rst-re-alist
+ (nconc rst-re-alist
+ (list (list (car re) (apply 'rst-re (cdr re))))))))
+ "Alist mapping symbols from `rst-re-alist-def' to regex strings."))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Mode definition.
-
-(defvar rst-deprecated-keys nil
- "Alist mapping deprecated keys to the new key to use and the definition.")
-
-(require 'edmacro)
-
-(defun rst-call-deprecated ()
- (interactive)
- (let* ((dep-key (this-command-keys-vector))
- (dep-key-s (format-kbd-macro dep-key))
- (fnd (assoc dep-key rst-deprecated-keys)))
- (if (not fnd)
- ;; Exact key sequence not found. Maybe a deprecated key sequence has
- ;; been followed by another key.
- (let* ((dep-key-pfx (butlast (append dep-key nil) 1))
- (dep-key-def (vconcat dep-key-pfx '(t)))
- (fnd-def (assoc dep-key-def rst-deprecated-keys)))
- (if (not fnd-def)
- (error "Unknown deprecated key sequence %s" dep-key-s)
- ;; Don't execute the command in this case
- (message "[Deprecated use of key %s; use key %s instead]"
- (format-kbd-macro dep-key-pfx)
- (format-kbd-macro (second fnd-def)))))
- (message "[Deprecated use of key %s; use key %s instead]"
- dep-key-s (format-kbd-macro (second fnd)))
- (call-interactively (third fnd)))))
+;; Mode definition
(defun rst-define-key (keymap key def &rest deprecated)
- "Bind like `define-key' using DEPRECATED as deprecated key definitions.
-DEPRECATED key definitions should be in vector notation. These
-are defined as well but give an additional message."
+ "Bind like `define-key' but add deprecated key definitions.
+KEYMAP, KEY, and DEF are as in `define-key'. DEPRECATED key
+definitions should be in vector notation. These are defined as
+well but give an additional message."
(define-key keymap key def)
(dolist (dep-key deprecated)
- (push (list dep-key key def) rst-deprecated-keys)
- (define-key keymap dep-key 'rst-call-deprecated)))
+ (define-key keymap dep-key
+ `(lambda ()
+ ,(format "Deprecated binding for %s, use \\[%s] instead." def def)
+ (interactive)
+ (call-interactively ',def)
+ (message "[Deprecated use of key %s; use key %s instead]"
+ (key-description (this-command-keys))
+ (key-description ,key))))))
;; Key bindings.
(defvar rst-mode-map
(let ((map (make-sparse-keymap)))
- ;; \C-c is the general keymap
+ ;; \C-c is the general keymap.
(rst-define-key map [?\C-c ?\C-h] 'describe-prefix-bindings)
;;
- ;; Section Adornments.
+ ;; Section Adornments
;;
;; The adjustment function that adorns or rotates a section title.
(rst-define-key map [?\C-c ?\C-=] 'rst-adjust [?\C-c ?\C-a t])
(rst-define-key map [?\C-=] 'rst-adjust) ; (Does not work on the Mac OSX.)
- ;; \C-c \C-a is the keymap for adornments
+ ;; \C-c \C-a is the keymap for adornments.
(rst-define-key map [?\C-c ?\C-a ?\C-h] 'describe-prefix-bindings)
- ;; Display the hierarchy of adornments implied by the current document contents.
+ ;; Display the hierarchy of adornments implied by the current document
+ ;; contents.
(rst-define-key map [?\C-c ?\C-a ?\C-d] 'rst-display-adornments-hierarchy)
;; Homogenize the adornments in the document.
(rst-define-key map [?\C-c ?\C-a ?\C-s] 'rst-straighten-adornments
[?\C-c ?\C-s])
;;
- ;; Section Movement and Selection.
+ ;; Section Movement and Selection
;;
;; Mark the subsection where the cursor is.
(rst-define-key map [?\C-\M-h] 'rst-mark-section
- ;; same as mark-defun sgml-mark-current-element
+ ;; Same as mark-defun sgml-mark-current-element.
[?\C-c ?\C-m])
- ;; Move forward/backward between section titles.
- (rst-define-key map [?\C-\M-a] 'rst-forward-section
- ;; same as beginning-of-defun
+ ;; Move backward/forward between section titles.
+ ;; FIXME: Also bind similar to outline mode.
+ (rst-define-key map [?\C-\M-a] 'rst-backward-section
+ ;; Same as beginning-of-defun.
[?\C-c ?\C-n])
- (rst-define-key map [?\C-\M-e] 'rst-backward-section
- ;; same as end-of-defun
+ (rst-define-key map [?\C-\M-e] 'rst-forward-section
+ ;; Same as end-of-defun.
[?\C-c ?\C-p])
;;
- ;; Operating on regions.
+ ;; Operating on regions
;;
- ;; \C-c \C-r is the keymap for regions
+ ;; \C-c \C-r is the keymap for regions.
(rst-define-key map [?\C-c ?\C-r ?\C-h] 'describe-prefix-bindings)
;; Makes region a line-block.
(rst-define-key map [?\C-c ?\C-r ?\C-l] 'rst-line-block-region
[?\C-c ?\C-d])
- ;; Shift region left or right according to tabs
+ ;; Shift region left or right according to tabs.
(rst-define-key map [?\C-c ?\C-r tab] 'rst-shift-region
[?\C-c ?\C-r t] [?\C-c ?\C-l t])
;;
- ;; Operating on lists.
+ ;; Operating on lists
;;
- ;; \C-c \C-l is the keymap for lists
+ ;; \C-c \C-l is the keymap for lists.
(rst-define-key map [?\C-c ?\C-l ?\C-h] 'describe-prefix-bindings)
;; Makes paragraphs in region as a bullet list.
(rst-define-key map [?\C-c ?\C-l ?\C-b] 'rst-bullet-list-region
@@ -597,13 +636,13 @@ are defined as well but give an additional message."
;; Make sure that all the bullets in the region are consistent.
(rst-define-key map [?\C-c ?\C-l ?\C-s] 'rst-straighten-bullets-region
[?\C-c ?\C-w])
- ;; Insert a list item
+ ;; Insert a list item.
(rst-define-key map [?\C-c ?\C-l ?\C-i] 'rst-insert-list)
;;
- ;; Table-of-Contents Features.
+ ;; Table-of-Contents Features
;;
- ;; \C-c \C-t is the keymap for table of contents
+ ;; \C-c \C-t is the keymap for table of contents.
(rst-define-key map [?\C-c ?\C-t ?\C-h] 'describe-prefix-bindings)
;; Enter a TOC buffer to view and move to a specific section.
(rst-define-key map [?\C-c ?\C-t ?\C-t] 'rst-toc)
@@ -613,14 +652,14 @@ are defined as well but give an additional message."
;; Update the document's TOC (without changing the cursor position).
(rst-define-key map [?\C-c ?\C-t ?\C-u] 'rst-toc-update
[?\C-c ?\C-u])
- ;; Got to the section under the cursor (cursor must be in TOC).
+ ;; Go to the section under the cursor (cursor must be in TOC).
(rst-define-key map [?\C-c ?\C-t ?\C-j] 'rst-goto-section
[?\C-c ?\C-f])
;;
- ;; Converting Documents from Emacs.
+ ;; Converting Documents from Emacs
;;
- ;; \C-c \C-c is the keymap for compilation
+ ;; \C-c \C-c is the keymap for compilation.
(rst-define-key map [?\C-c ?\C-c ?\C-h] 'describe-prefix-bindings)
;; Run one of two pre-configured toolset commands on the document.
(rst-define-key map [?\C-c ?\C-c ?\C-c] 'rst-compile
@@ -643,8 +682,6 @@ This inherits from Text mode.")
;; Abbrevs.
-(defvar rst-mode-abbrev-table nil
- "Abbrev table used while in `rst-mode'.")
(define-abbrev-table 'rst-mode-abbrev-table
(mapcar (lambda (x) (append x '(nil 0 system)))
'(("contents" ".. contents::\n..\n ")
@@ -653,28 +690,27 @@ This inherits from Text mode.")
("skip" "\n\n[...]\n\n ")
("seq" "\n\n[...]\n\n ")
;; FIXME: Add footnotes, links, and more.
- )))
+ ))
+ "Abbrev table used while in `rst-mode'.")
;; Syntax table.
(defvar rst-mode-syntax-table
(let ((st (copy-syntax-table text-mode-syntax-table)))
-
(modify-syntax-entry ?$ "." st)
(modify-syntax-entry ?% "." st)
(modify-syntax-entry ?& "." st)
(modify-syntax-entry ?' "." st)
(modify-syntax-entry ?* "." st)
- (modify-syntax-entry ?+ "_" st)
- (modify-syntax-entry ?. "_" st)
+ (modify-syntax-entry ?+ "." st)
+ (modify-syntax-entry ?- "." st)
(modify-syntax-entry ?/ "." st)
- (modify-syntax-entry ?: "_" st)
(modify-syntax-entry ?< "." st)
(modify-syntax-entry ?= "." st)
(modify-syntax-entry ?> "." st)
(modify-syntax-entry ?\\ "\\" st)
+ (modify-syntax-entry ?_ "." st)
(modify-syntax-entry ?| "." st)
- (modify-syntax-entry ?_ "_" st)
(modify-syntax-entry ?\u00ab "." st)
(modify-syntax-entry ?\u00bb "." st)
(modify-syntax-entry ?\u2018 "." st)
@@ -692,6 +728,8 @@ The hook for `text-mode' is run before this one."
:group 'rst
:type '(hook))
+;; Pull in variable definitions silencing byte-compiler.
+(require 'newcomment)
;; Use rst-mode for *.rst and *.rest files. Many ReStructured-Text files
;; use *.txt, but this is too generic to be set as a default.
@@ -710,7 +748,7 @@ highlighting.
:syntax-table rst-mode-syntax-table
:group 'rst
- ;; Paragraph recognition
+ ;; Paragraph recognition.
(set (make-local-variable 'paragraph-separate)
(rst-re '(:alt
"\f"
@@ -721,7 +759,7 @@ highlighting.
lin-end
(:seq hws-tag par-tag- bli-sfx))))
- ;; Indenting and filling
+ ;; Indenting and filling.
(set (make-local-variable 'indent-line-function) 'rst-indent-line)
(set (make-local-variable 'adaptive-fill-mode) t)
(set (make-local-variable 'adaptive-fill-regexp)
@@ -729,7 +767,7 @@ highlighting.
(set (make-local-variable 'adaptive-fill-function) 'rst-adaptive-fill)
(set (make-local-variable 'fill-paragraph-handle-comment) nil)
- ;; Comments
+ ;; Comments.
(set (make-local-variable 'comment-start) ".. ")
(set (make-local-variable 'comment-start-skip)
(rst-re 'lin-beg 'exm-tag 'bli-sfx))
@@ -737,10 +775,12 @@ highlighting.
(set (make-local-variable 'comment-multi-line) t)
(set (make-local-variable 'comment-use-syntax) nil)
;; reStructuredText has not really a comment ender but nil is not really a
- ;; permissible value
+ ;; permissible value.
(set (make-local-variable 'comment-end) "")
(set (make-local-variable 'comment-end-skip) nil)
+ ;; Commenting in reStructuredText is very special so use our own set of
+ ;; functions.
(set (make-local-variable 'comment-line-break-function)
'rst-comment-line-break)
(set (make-local-variable 'comment-indent-function)
@@ -752,21 +792,15 @@ highlighting.
(set (make-local-variable 'uncomment-region-function)
'rst-uncomment-region)
- ;; Font lock
- (setq font-lock-defaults
- '(rst-font-lock-keywords
- t nil nil nil
- (font-lock-multiline . t)
- (font-lock-mark-block-function . mark-paragraph)
- ;; rst-mode does not need font-lock-support-mode because it's fast
- ;; enough. In fact using `jit-lock-mode` slows things down
- ;; considerably even if `rst-font-lock-extend-region` is in place and
- ;; compiled.
- ;;(font-lock-support-mode . nil)
- ))
+ ;; Font lock.
+ (set (make-local-variable 'font-lock-defaults)
+ '(rst-font-lock-keywords
+ t nil nil nil
+ (font-lock-multiline . t)
+ (font-lock-mark-block-function . mark-paragraph)))
(add-hook 'font-lock-extend-region-functions 'rst-font-lock-extend-region t)
- ;; Text after a changed line may need new fontification
+ ;; Text after a changed line may need new fontification.
(set (make-local-variable 'jit-lock-contextually) t))
;;;###autoload
@@ -788,8 +822,8 @@ for modes derived from Text mode, like Mail mode."
:group 'rst)
;; FIXME: can I somehow install these too?
-;; :abbrev-table rst-mode-abbrev-table
-;; :syntax-table rst-mode-syntax-table
+;; :abbrev-table rst-mode-abbrev-table
+;; :syntax-table rst-mode-syntax-table
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -870,7 +904,7 @@ for modes derived from Text mode, like Mail mode."
:version "21.1")
(define-obsolete-variable-alias
- 'rst-preferred-decorations 'rst-preferred-adornments "r6506")
+ 'rst-preferred-decorations 'rst-preferred-adornments "1.0.0")
(defcustom rst-preferred-adornments '((?= over-and-under 1)
(?= simple 0)
(?- simple 0)
@@ -882,10 +916,10 @@ for modes derived from Text mode, like Mail mode."
"Preferred hierarchy of section title adornments.
A list consisting of lists of the form (CHARACTER STYLE INDENT).
-CHARACTER is the character used. STYLE is one of the symbols
-OVER-AND-UNDER or SIMPLE. INDENT is an integer giving the wanted
-indentation for STYLE OVER-AND-UNDER. CHARACTER and STYLE are
-always used when a section adornment is described. In other
+CHARACTER is the character used. STYLE is one of the symbols
+OVER-AND-UNDER or SIMPLE. INDENT is an integer giving the wanted
+indentation for STYLE OVER-AND-UNDER. CHARACTER and STYLE are
+always used when a section adornment is described. In other
places t instead of a list stands for a transition.
This sequence is consulted to offer a new adornment suggestion
@@ -990,7 +1024,7 @@ requested adornment."
(let ((marker (point-marker))
len)
- ;; Fixup whitespace at the beginning and end of the line
+ ;; Fixup whitespace at the beginning and end of the line.
(if (or (null indent) (eq style 'simple))
(setq indent 0))
(beginning-of-line)
@@ -1000,10 +1034,10 @@ requested adornment."
(end-of-line)
(delete-horizontal-space)
- ;; Set the current column, we're at the end of the title line
+ ;; Set the current column, we're at the end of the title line.
(setq len (+ (current-column) indent))
- ;; Remove previous line if it is an adornment
+ ;; Remove previous line if it is an adornment.
(save-excursion
(forward-line -1)
(if (and (looking-at (rst-re 'ado-beg-2-1))
@@ -1012,24 +1046,24 @@ requested adornment."
(not (looking-at (rst-re 'ttl-beg)))))
(rst-delete-entire-line)))
- ;; Remove following line if it is an adornment
+ ;; Remove following line if it is an adornment.
(save-excursion
(forward-line +1)
(if (looking-at (rst-re 'ado-beg-2-1))
(rst-delete-entire-line))
;; Add a newline if we're at the end of the buffer, for the subsequence
- ;; inserting of the underline
+ ;; inserting of the underline.
(if (= (point) (buffer-end 1))
(newline 1)))
- ;; Insert overline
+ ;; Insert overline.
(if (eq style 'over-and-under)
(save-excursion
(beginning-of-line)
(open-line 1)
(insert (make-string len char))))
- ;; Insert underline
+ ;; Insert underline.
(forward-line +1)
(open-line 1)
(insert (make-string len char))
@@ -1041,17 +1075,17 @@ requested adornment."
(defun rst-classify-adornment (adornment end)
"Classify adornment for section titles and transitions.
ADORNMENT is the complete adornment string as found in the buffer
-with optional trailing whitespace. END is the point after the
+with optional trailing whitespace. END is the point after the
last character of ADORNMENT.
-Return a list. The first entry is t for a transition or a
-cons (CHARACTER . STYLE). Check `rst-preferred-adornments' for
+Return a list. The first entry is t for a transition or a
+cons (CHARACTER . STYLE). Check `rst-preferred-adornments' for
the meaning of CHARACTER and STYLE.
The remaining list forms four match groups as returned by
-`match-data'. Match group 0 matches the whole construct. Match
-group 1 matches the overline adornment if present. Match group 2
-matches the section title text or the transition. Match group 3
+`match-data'. Match group 0 matches the whole construct. Match
+group 1 matches the overline adornment if present. Match group 2
+matches the section title text or the transition. Match group 3
matches the underline adornment.
Return nil if no syntactically valid adornment is found."
@@ -1065,33 +1099,33 @@ Return nil if no syntactically valid adornment is found."
(beg-pnt (progn
(forward-line 0)
(point)))
- (nxt-emp ; Next line inexistant or empty
+ (nxt-emp ; Next line nonexistent or empty
(save-excursion
(or (not (zerop (forward-line 1)))
(looking-at (rst-re 'lin-end)))))
- (prv-emp ; Previous line inexistant or empty
+ (prv-emp ; Previous line nonexistent or empty
(save-excursion
(or (not (zerop (forward-line -1)))
(looking-at (rst-re 'lin-end)))))
- (ttl-blw ; Title found below starting here
+ (ttl-blw ; Title found below starting here.
(save-excursion
(and
(zerop (forward-line 1))
(looking-at (rst-re 'ttl-beg))
(point))))
- (ttl-abv ; Title found above starting here
+ (ttl-abv ; Title found above starting here.
(save-excursion
(and
(zerop (forward-line -1))
(looking-at (rst-re 'ttl-beg))
(point))))
- (und-fnd ; Matching underline found starting here
+ (und-fnd ; Matching underline found starting here.
(save-excursion
(and ttl-blw
(zerop (forward-line 2))
(looking-at (rst-re ado-re 'lin-end))
(point))))
- (ovr-fnd ; Matching overline found starting here
+ (ovr-fnd ; Matching overline found starting here.
(save-excursion
(and ttl-abv
(zerop (forward-line -2))
@@ -1100,14 +1134,14 @@ Return nil if no syntactically valid adornment is found."
key beg-ovr end-ovr beg-txt end-txt beg-und end-und)
(cond
((and nxt-emp prv-emp)
- ;; A transition
+ ;; A transition.
(setq key t
beg-txt beg-pnt
end-txt end-pnt))
((or und-fnd ovr-fnd)
- ;; An overline with an underline
+ ;; An overline with an underline.
(setq key (cons ado-ch 'over-and-under))
- (let (;; Prefer overline match over underline match
+ (let (;; Prefer overline match over underline match.
(und-pnt (if ovr-fnd beg-pnt und-fnd))
(ovr-pnt (if ovr-fnd ovr-fnd beg-pnt))
(txt-pnt (if ovr-fnd ttl-abv ttl-blw)))
@@ -1121,7 +1155,7 @@ Return nil if no syntactically valid adornment is found."
(setq beg-und (point)
end-und (line-end-position))))
(ttl-abv
- ;; An underline
+ ;; An underline.
(setq key (cons ado-ch 'simple)
beg-und beg-pnt
end-und end-pnt)
@@ -1129,7 +1163,7 @@ Return nil if no syntactically valid adornment is found."
(setq beg-txt (point)
end-txt (line-end-position)))
(t
- ;; Invalid adornment
+ ;; Invalid adornment.
(setq key nil)))
(if key
(list key
@@ -1140,15 +1174,15 @@ Return nil if no syntactically valid adornment is found."
(defun rst-find-title-line ()
"Find a section title line around point and return its characteristics.
If the point is on an adornment line find the respective title
-line. If the point is on an empty line check previous or next
-line whether it is a suitable title line and use it if so. If
+line. If the point is on an empty line check previous or next
+line whether it is a suitable title line and use it if so. If
point is on a suitable title line use it.
If no title line is found return nil.
-Otherwise return as `rst-classify-adornment' does. However, if
+Otherwise return as `rst-classify-adornment' does. However, if
the title line has no syntactically valid adornment STYLE is nil
-in the first element. If there is no adornment around the title
+in the first element. If there is no adornment around the title
CHARACTER is also nil and match groups for overline and underline
are nil."
(save-excursion
@@ -1162,14 +1196,14 @@ are nil."
(match-end 0))))
(cond
((not r)
- ;; Invalid adornment - check whether this is an incomplete overline
+ ;; Invalid adornment - check whether this is an incomplete overline.
(if (and
(zerop (forward-line 1))
(looking-at (rst-re 'ttl-beg)))
(list (cons char nil) orig-pnt (line-end-position)
orig-pnt orig-end (point) (line-end-position) nil nil)))
((consp (car r))
- ;; A section title - not a transition
+ ;; A section title - not a transition.
r))))
((looking-at (rst-re 'lin-end))
(or
@@ -1184,14 +1218,14 @@ are nil."
(list (cons nil nil) (point) (line-end-position)
nil nil (point) (line-end-position) nil nil)))))
((looking-at (rst-re 'ttl-beg))
- ;; Try to use the underline
+ ;; Try to use the underline.
(let ((r (rst-classify-adornment
- (buffer-substring-no-properties
+ (buffer-substring-no-properties
(line-beginning-position 2) (line-end-position 2))
(line-end-position 2))))
(if r
r
- ;; No valid adornment found
+ ;; No valid adornment found.
(list (cons nil nil) (point) (line-end-position)
nil nil (point) (line-end-position) nil nil))))))))
@@ -1199,29 +1233,29 @@ are nil."
;; current section adornment in a buffer local cache. Thus they can be used for
;; font-locking and manipulation commands.
-(defun rst-reset-section-caches ()
- "Reset all section cache variables.
-Should be called by interactive functions which deal with sections."
- (setq rst-all-sections nil
- rst-section-hierarchy nil))
-
(defvar rst-all-sections nil
"All section adornments in the buffer as found by `rst-find-all-adornments'.
t when no section adornments were found.")
(make-variable-buffer-local 'rst-all-sections)
;; FIXME: If this variable is set to a different value font-locking of section
-;; headers is wrong
+;; headers is wrong.
(defvar rst-section-hierarchy nil
"Section hierarchy in the buffer as determined by `rst-get-hierarchy'.
-t when no section adornments were found. Value depends on
+t when no section adornments were found. Value depends on
`rst-all-sections'.")
(make-variable-buffer-local 'rst-section-hierarchy)
+(defun rst-reset-section-caches ()
+ "Reset all section cache variables.
+Should be called by interactive functions which deal with sections."
+ (setq rst-all-sections nil
+ rst-section-hierarchy nil))
+
(defun rst-find-all-adornments ()
"Return all the section adornments in the current buffer.
Return a list of (LINE . ADORNMENT) with ascending LINE where
-LINE is the line containing the section title. ADORNMENT consists
+LINE is the line containing the section title. ADORNMENT consists
of a (CHARACTER STYLE INDENT) triple as described for
`rst-preferred-adornments'.
@@ -1235,15 +1269,15 @@ Uses and sets `rst-all-sections'."
(let ((ado-data (rst-classify-adornment
(match-string-no-properties 0) (point))))
(when (and ado-data
- (consp (car ado-data))) ; Ignore transitions
+ (consp (car ado-data))) ; Ignore transitions.
(set-match-data (cdr ado-data))
- (goto-char (match-beginning 2)) ; Goto the title start
+ (goto-char (match-beginning 2)) ; Goto the title start.
(push (cons (1+ (count-lines (point-min) (point)))
(list (caar ado-data)
(cdar ado-data)
(current-indentation)))
positions)
- (goto-char (match-end 0))))) ; Go beyond the whole thing
+ (goto-char (match-end 0))))) ; Go beyond the whole thing.
(setq positions (nreverse positions))
(setq rst-all-sections (or positions t)))))
(if (eq rst-all-sections t)
@@ -1273,8 +1307,8 @@ list element should be unique."
"Return the hierarchy of section titles in the file.
Return a list of adornments that represents the hierarchy of
-section titles in the file. Each element consists of (CHARACTER
-STYLE INDENT) as described for `rst-find-all-adornments'. If the
+section titles in the file. Each element consists of (CHARACTER
+STYLE INDENT) as described for `rst-find-all-adornments'. If the
line number in IGNORE is specified, a possibly adornment found on
that line is not taken into account when building the hierarchy.
@@ -1291,7 +1325,7 @@ Uses and sets `rst-section-hierarchy' unless IGNORE is given."
(setq rst-section-hierarchy
(if ignore
;; Clear cache reflecting that a possible update is not
- ;; reflected
+ ;; reflected.
nil
(or r t)))
r)))
@@ -1377,19 +1411,19 @@ REVERSE-DIRECTION is used to reverse the cycling order."
)))
-;; FIXME: A line "``/`` full" is not accepted as a section title
+;; FIXME: A line "``/`` full" is not accepted as a section title.
(defun rst-adjust (pfxarg)
"Auto-adjust the adornment around point.
-Adjust/rotate the section adornment for the section title
-around point or promote/demote the adornments inside the region,
+Adjust/rotate the section adornment for the section title around
+point or promote/demote the adornments inside the region,
depending on if the region is active. This function is meant to
be invoked possibly multiple times, and can vary its behavior
-with a positive prefix argument (toggle style), or with a
-negative prefix argument (alternate behavior).
+with a positive PFXARG (toggle style), or with a negative
+PFXARG (alternate behavior).
-This function is a bit of a swiss knife. It is meant to adjust
-the adornments of a section title in reStructuredText. It tries
+This function is a bit of a swiss knife. It is meant to adjust
+the adornments of a section title in reStructuredText. It tries
to deal with all the possible cases gracefully and to do `the
right thing' in all cases.
@@ -1402,7 +1436,7 @@ Prefix Arguments
The method can take either (but not both) of
a. a (non-negative) prefix argument, which means to toggle the
- adornment style. Invoke with a prefix arg for example;
+ adornment style. Invoke with a prefix argument for example;
b. a negative numerical argument, which generally inverts the
direction of search in the file or hierarchy. Invoke with C--
@@ -1446,7 +1480,8 @@ b. a negative numerical argument, which generally inverts the
(defun rst-adjust-adornment (pfxarg)
"Call `rst-adjust-adornment-work' interactively.
-Keep this for compatibility for older bindings (are there any?)."
+Keep this for compatibility for older bindings (are there any?).
+Argument PFXARG has the same meaning as for `rst-adjust'."
(interactive "P")
(let* ((reverse-direction (and pfxarg (< (prefix-numeric-value pfxarg) 0)))
@@ -1660,7 +1695,7 @@ lines."
;; Else, we rotate, ignoring the adornment around the current
;; line...
(let* ((hier (rst-get-hierarchy (line-number-at-pos)))
- ;; Suggestion, in case we need to come up with something new
+ ;; Suggestion, in case we need to come up with something new.
(suggestion (rst-suggest-new-adornment
hier
(car (rst-get-adornments-around))))
@@ -1702,7 +1737,7 @@ hierarchy is similar to that used by `rst-adjust-adornment-work'."
marker-list
)
- ;; Skip the markers that come before the region beginning
+ ;; Skip the markers that come before the region beginning.
(while (and cur (< (caar cur) region-begin-line))
(setq cur (cdr cur)))
@@ -1754,11 +1789,6 @@ in ADORNMENTS."
))
)))
-(defun rst-position (elem list)
- "Return position of ELEM in LIST or nil."
- (let ((tail (member elem list)))
- (if tail (- (length list) (length tail)))))
-
(defun rst-straighten-adornments ()
"Redo all the adornments in the current buffer.
This is done using our preferred set of adornments. This can be
@@ -1767,7 +1797,7 @@ in order to adapt it to our preferred style."
(interactive)
(rst-reset-section-caches)
(save-excursion
- (let (;; Get a list of pairs of (level . marker)
+ (let (;; Get a list of pairs of (level . marker).
(levels-and-markers (mapcar
(lambda (ado)
(cons (rst-position (cdr ado)
@@ -1778,13 +1808,13 @@ in order to adapt it to our preferred style."
(point-marker))))
(rst-find-all-adornments))))
(dolist (lm levels-and-markers)
- ;; Go to the appropriate position
+ ;; Go to the appropriate position.
(goto-char (cdr lm))
- ;; Apply the new styule
+ ;; Apply the new style.
(apply 'rst-update-section (nth (car lm) rst-preferred-adornments))
- ;; Reset the market to avoid slowing down editing until it gets GC'ed
+ ;; Reset the marker to avoid slowing down editing until it gets GC'ed.
(set-marker (cdr lm) nil)
)
)))
@@ -1797,7 +1827,7 @@ in order to adapt it to our preferred style."
;=================================================
-; Borrowed from a2r.el (version 1.3), by Lawrence Mitchell <wence@gmx.li>
+; Borrowed from a2r.el (version 1.3), by Lawrence Mitchell <wence@gmx.li>.
; I needed to make some tiny changes to the functions, so I put it here.
; -- Wei-Wei Guo
@@ -1848,9 +1878,9 @@ If optional ARG is non-nil, insert in current buffer."
(defun rst-find-pfx-in-region (beg end pfx-re)
"Find all the positions of prefixes in region between BEG and END.
-This is used to find bullets and enumerated list items. PFX-RE is
+This is used to find bullets and enumerated list items. PFX-RE is
a regular expression for matching the lines after indentation
-with items. Returns a list of cons cells consisting of the point
+with items. Returns a list of cons cells consisting of the point
and the column of the point."
(let ((pfx ()))
(save-excursion
@@ -1866,14 +1896,14 @@ and the column of the point."
(or (looking-at (rst-re 'lin-end)) ; ...empty,
(> (current-column) pfx-col) ; ...deeper level, or
(and (= (current-column) pfx-col)
- (looking-at pfx-re)))))) ; ...pfx at same level
+ (looking-at pfx-re)))))) ; ...pfx at same level.
(push (cons (point) (current-column))
pfx))
(forward-line 1)) )
(nreverse pfx)))
(defun rst-insert-list-pos (newitem)
- "Arrange relative position of a newly inserted list item.
+ "Arrange relative position of a newly inserted list item of style NEWITEM.
Adding a new list might consider three situations:
@@ -1900,6 +1930,7 @@ Other situations are just ignored and left to users themselves."
(end-of-line)
(insert "\n\n" newitem " ")))
+;; FIXME: Isn't this a `defconst'?
(defvar rst-initial-enums
(let (vals)
(dolist (fmt '("%s." "(%s)" "%s)"))
@@ -1908,6 +1939,7 @@ Other situations are just ignored and left to users themselves."
(cons "#." (nreverse vals)))
"List of initial enumerations.")
+;; FIXME: Isn't this a `defconst'?
(defvar rst-initial-items
(append (mapcar 'char-to-string rst-bullets) rst-initial-enums)
"List of initial items. It's collection of bullets and enumerations.")
@@ -1916,16 +1948,16 @@ Other situations are just ignored and left to users themselves."
"Insert a new list item.
User is asked to select the item style first, for example (a), i), +. Use TAB
-for completition and choices.
+for completion and choices.
If user selects bullets or #, it's just added with position arranged by
`rst-insert-list-pos'.
-If user selects enumerations, a further prompt is given. User need to input a
+If user selects enumerations, a further prompt is given. User need to input a
starting item, for example 'e' for 'A)' style. The position is also arranged by
`rst-insert-list-pos'."
(interactive)
- ;; FIXME: Make this comply to `interactive' standards
+ ;; FIXME: Make this comply to `interactive' standards.
(let* ((itemstyle (completing-read
"Select preferred item style [#.]: "
rst-initial-items nil t nil nil "#."))
@@ -1933,7 +1965,7 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by
(match-string 0 itemstyle)))
(no
(save-match-data
- ;; FIXME: Make this comply to `interactive' standards
+ ;; FIXME: Make this comply to `interactive' standards.
(cond
((equal cnt "a")
(let ((itemno (read-string "Give starting value [a]: "
@@ -1968,10 +2000,11 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by
:package-version '(rst . "1.1.0"))
(defun rst-insert-list-continue (curitem prefer-roman)
- "Insert a list item with list start CURITEM including its indentation level."
+ "Insert a list item with list start CURITEM including its indentation level.
+If PREFER-ROMAN roman numbering is preferred over using letters."
(end-of-line)
(insert
- "\n" ; FIXME: Separating lines must be possible
+ "\n" ; FIXME: Separating lines must be possible.
(cond
((string-match (rst-re '(:alt enmaut-tag
bul-tag)) curitem)
@@ -1982,17 +2015,17 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by
nil nil curitem))
((and (string-match (rst-re 'rom-tag) curitem)
(save-match-data
- (if (string-match (rst-re 'ltr-tag) curitem) ; Also a letter tag
+ (if (string-match (rst-re 'ltr-tag) curitem) ; Also a letter tag.
(save-excursion
;; FIXME: Assumes one line list items without separating
- ;; empty lines
+ ;; empty lines.
(if (and (zerop (forward-line -1))
(looking-at (rst-re 'enmexp-beg)))
(string-match
(rst-re 'rom-tag)
- (match-string 0)) ; Previous was a roman tag
- prefer-roman)) ; Don't know - use flag
- t))) ; Not a letter tag
+ (match-string 0)) ; Previous was a roman tag.
+ prefer-roman)) ; Don't know - use flag.
+ t))) ; Not a letter tag.
(replace-match
(let* ((old (match-string 0 curitem))
(new (save-match-data
@@ -2012,14 +2045,14 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by
(defun rst-insert-list (&optional prefer-roman)
"Insert a list item at the current point.
-The command can insert a new list or a continuing list. When it is called at a
-non-list line, it will promote to insert new list. When it is called at a list
+The command can insert a new list or a continuing list. When it is called at a
+non-list line, it will promote to insert new list. When it is called at a list
line, it will insert a list with the same list style.
1. When inserting a new list:
-User is asked to select the item style first, for example (a), i), +. Use TAB
-for completition and choices.
+User is asked to select the item style first, for example (a), i), +. Use TAB
+for completion and choices.
(a) If user selects bullets or #, it's just added.
(b) If user selects enumerations, a further prompt is given. User needs to
@@ -2035,7 +2068,7 @@ List style alphabetical list, such as 'a.', and roman numerical list, such as
the problem elegantly in most situations. But when those overlapped list are
preceded by a blank line, it is hard to determine which type to use
automatically. The function uses alphabetical list by default. If you want
-roman numerical list, just use a prefix (\\[universal-argument])."
+roman numerical list, just use a prefix to set PREFER-ROMAN."
(interactive "P")
(beginning-of-line)
(if (looking-at (rst-re 'itmany-beg-1))
@@ -2093,8 +2126,8 @@ adjust. If bullets are found on levels beyond the
"Get the hierarchical tree of section titles.
Returns a hierarchical tree of the sections titles in the
-document. This can be used to generate a table of contents for
-the document. The top node will always be a nil node, with the
+document. This can be used to generate a table of contents for
+the document. The top node will always be a nil node, with the
top level titles as children (there may potentially be more than
one).
@@ -2104,7 +2137,7 @@ string and a marker to the section in the original text document.
If there are missing section levels, the section titles are
inserted automatically, and the title string is set to nil, and
the marker set to the first non-nil child of itself.
-Conceptually, the nil nodes--i.e. those which have no title--are
+Conceptually, the nil nodes--i.e.\ those which have no title--are
to be considered as being the same line as their first non-nil
child. This has advantages later in processing the graph."
@@ -2147,14 +2180,14 @@ list destructively."
node
children)
- ;; If the next adornment matches our level
+ ;; If the next adornment matches our level.
(when (and nado (= (car nado) lev))
- ;; Pop the next adornment and create the current node with it
+ ;; Pop the next adornment and create the current node with it.
(setcdr ados (cddr ados))
(setq node (cdr nado)) )
;; Else we let the node title/marker be unset.
- ;; Build the child nodes
+ ;; Build the child nodes.
(while (and (cdr ados) (> (caadr ados) lev))
(setq children
(cons (rst-section-tree-rec ados (1+ lev))
@@ -2174,7 +2207,7 @@ list destructively."
"Find tree node at point.
Given a computed and valid section tree in NODE and a point
POINT (default being the current point in the current buffer),
-find and return the node within the sectree where the cursor
+find and return the node within the section tree where the cursor
lives.
Return values: a pair of (parent path, container subtree).
@@ -2255,7 +2288,7 @@ to the specified level.
The TOC is inserted indented at the current column."
(interactive "P")
(rst-reset-section-caches)
- (let* (;; Check maximum level override
+ (let* (;; Check maximum level override.
(rst-toc-insert-max-level
(if (and (integerp pfxarg) (> (prefix-numeric-value pfxarg) 0))
(prefix-numeric-value pfxarg) rst-toc-insert-max-level))
@@ -2332,7 +2365,7 @@ level to align."
fmt)
(if do-child-numbering
(progn
- ;; Add a separating dot if there is already a prefix
+ ;; Add a separating dot if there is already a prefix.
(when (> (length pfx) 0)
(string-match (rst-re "[ \t\n]*\\'") pfx)
(setq pfx (concat (replace-match "" t t pfx) ".")))
@@ -2384,9 +2417,9 @@ file-write hook to always make it up-to-date automatically."
(while (and
(< (point) (point-max))
(or (if (looking-at
- (rst-re 'hws-sta "\\S ")) ; indented content
+ (rst-re 'hws-sta "\\S ")) ; indented content.
(setq last-real (point)))
- (looking-at (rst-re 'lin-end)))) ; empty line
+ (looking-at (rst-re 'lin-end)))) ; empty line.
(forward-line 1))
(if last-real
(progn
@@ -2516,12 +2549,14 @@ brings the cursor in that section."
;; FIXME: Cursor before or behind the list must be handled properly; before the
;; list should jump to the top and behind the list to the last normal
-;; paragraph
+;; paragraph.
(defun rst-goto-section (&optional kill)
- "Go to the section the current line describes."
+ "Go to the section the current line describes.
+If KILL a toc buffer is destroyed."
(interactive)
(let ((pos (rst-toc-mode-find-section)))
(when kill
+ ;; FIXME: This should rather go to `rst-toc-mode-goto-section'.
(set-window-configuration (car rst-toc-return-wincfg))
(kill-buffer (get-buffer rst-toc-buffer-name)))
(pop-to-buffer (marker-buffer pos))
@@ -2548,7 +2583,8 @@ EVENT is the input event."
(recenter 5)))
(defun rst-toc-mode-mouse-goto-kill (event)
- "Same as `rst-toc-mode-mouse-goto', but kill TOC buffer as well."
+ "Same as `rst-toc-mode-mouse-goto', but kill TOC buffer as well.
+EVENT is the input event."
(interactive "e")
(call-interactively 'rst-toc-mode-mouse-goto event)
(kill-buffer (get-buffer rst-toc-buffer-name)))
@@ -2581,7 +2617,6 @@ EVENT is the input event."
;; Note: use occur-mode (replace.el) as a good example to complete missing
;; features.
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section movement commands
;; =========================
@@ -2632,12 +2667,15 @@ backwards in the file (default is to use 1)."
(interactive)
(rst-forward-section -1))
-(defun rst-mark-section (&optional arg allow-extend)
- "Select the section that point is currently in."
+;; FIXME: What is `allow-extend' for?
+(defun rst-mark-section (&optional count allow-extend)
+ "Select COUNT sections around point.
+Mark following sections for positive COUNT or preceding sections
+for negative COUNT."
;; Cloned from mark-paragraph.
(interactive "p\np")
- (unless arg (setq arg 1))
- (when (zerop arg)
+ (unless count (setq count 1))
+ (when (zerop count)
(error "Cannot mark zero sections"))
(cond ((and allow-extend
(or (and (eq last-command this-command) (mark t))
@@ -2645,12 +2683,12 @@ backwards in the file (default is to use 1)."
(set-mark
(save-excursion
(goto-char (mark))
- (rst-forward-section arg)
+ (rst-forward-section count)
(point))))
(t
- (rst-forward-section arg)
+ (rst-forward-section count)
(push-mark nil t t)
- (rst-forward-section (- arg)))))
+ (rst-forward-section (- count)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -2671,12 +2709,12 @@ backwards in the file (default is to use 1)."
(forward-line 1)))
mincol))
+;; FIXME: This definition is old and deprecated. We need to move to the newer
+;; version below.
(defmacro rst-iterate-leftmost-paragraphs
(beg end first-only body-consequent body-alternative)
- "FIXME This definition is old and deprecated / we need to move
-to the newer version below:
-
-Call FUN at the beginning of each line, with an argument that
+ ;; FIXME: The following comment is pretty useless.
+ "Call FUN at the beginning of each line, with an argument that
specifies whether we are at the first line of a paragraph that
starts at the leftmost column of the given region BEG and END.
Set FIRST-ONLY to true if you want to callback on the first line
@@ -2685,7 +2723,7 @@ of each paragraph only."
(let ((leftcol (rst-find-leftmost-column ,beg ,end))
(endm (copy-marker ,end)))
- (do* (;; Iterate lines
+ (do* (;; Iterate lines.
(l (progn (goto-char ,beg) (back-to-indentation))
(progn (forward-line 1) (back-to-indentation)))
@@ -2709,6 +2747,8 @@ of each paragraph only."
))))
+;; FIXME: This needs to be refactored. Probably this is simply a function
+;; applying BODY rather than a macro.
(defmacro rst-iterate-leftmost-paragraphs-2 (spec &rest body)
"Evaluate BODY for each line in region defined by BEG END.
LEFTMOST is set to true if the line is one of the leftmost of the
@@ -2722,7 +2762,7 @@ first of a paragraph."
(let ((,leftmost (rst-find-leftmost-column ,beg ,end))
(endm (copy-marker ,end)))
- (do* (;; Iterate lines
+ (do* (;; Iterate lines.
(l (progn (goto-char ,beg) (back-to-indentation))
(progn (forward-line 1) (back-to-indentation)))
@@ -2750,74 +2790,72 @@ first of a paragraph."
;; Indentation
;; FIXME: At the moment only block comments with leading empty comment line are
-;; supported; comment lines with leading comment markup should be also
-;; supported; may be a customizable option could control which style to prefer
+;; supported. Comment lines with leading comment markup should be also
+;; supported. May be a customizable option could control which style to
+;; prefer.
-(defgroup rst-indent nil "Settings for indendation in reStructuredText.
+(defgroup rst-indent nil "Settings for indentation in reStructuredText.
-In reStructuredText indendation points are usually determined by
+In reStructuredText indentation points are usually determined by
preceding lines. Sometimes the syntax allows arbitrary
-indendation points such as where to start the first line
+indentation points such as where to start the first line
following a directive. These indentation widths can be customized
here."
:group 'rst
:package-version '(rst . "1.1.0"))
(define-obsolete-variable-alias
- 'rst-shift-basic-offset 'rst-indent-width "r6713")
+ 'rst-shift-basic-offset 'rst-indent-width "1.0.0")
(defcustom rst-indent-width 2
"Indentation when there is no more indentation point given."
:group 'rst-indent
:type '(integer))
(defcustom rst-indent-field 3
- "Default indendation for first line after a field or 0 to always indent for
-content."
+ "Indentation for first line after a field or 0 to always indent for content."
:group 'rst-indent
:type '(integer))
(defcustom rst-indent-literal-normal 3
- "Default indendation for literal block after a markup on an own
-line."
+ "Default indentation for literal block after a markup on an own line."
:group 'rst-indent
:type '(integer))
(defcustom rst-indent-literal-minimized 2
- "Default indendation for literal block after a minimized
-markup."
+ "Default indentation for literal block after a minimized markup."
:group 'rst-indent
:type '(integer))
(defcustom rst-indent-comment 3
- "Default indendation for first line of a comment."
+ "Default indentation for first line of a comment."
:group 'rst-indent
:type '(integer))
;; FIXME: Must consider other tabs:
-;; * Line blocks
-;; * Definition lists
-;; * Option lists
+;; * Line blocks
+;; * Definition lists
+;; * Option lists
(defun rst-line-tabs ()
"Return tabs of the current line or nil for no tab.
The list is sorted so the tab where writing continues most likely
-is the first one. Each tab is of the form (COLUMN . INNER).
-COLUMN is the column of the tab. INNER is non-nil if this is an
-inner tab. I.e. a tab which does come from the basic indentation
+is the first one. Each tab is of the form (COLUMN . INNER).
+COLUMN is the column of the tab. INNER is non-nil if this is an
+inner tab. I.e. a tab which does come from the basic indentation
and not from inner alignment points."
(save-excursion
(forward-line 0)
(save-match-data
(unless (looking-at (rst-re 'lin-end))
(back-to-indentation)
- ;; Current indendation is always the least likely tab
+ ;; Current indendation is always the least likely tab.
(let ((tabs (list (list (point) 0 nil)))) ; (POINT OFFSET INNER)
- ;; Push inner tabs more likely to continue writing
+ ;; Push inner tabs more likely to continue writing.
(cond
- ;; Item
+ ;; Item.
((looking-at (rst-re '(:grp itmany-tag hws-sta) '(:grp "\\S ") "?"))
(when (match-string 2)
(push (list (match-beginning 2) 0 t) tabs)))
- ;; Field
+ ;; Field.
((looking-at (rst-re '(:grp fld-tag) '(:grp hws-tag)
'(:grp "\\S ") "?"))
(unless (zerop rst-indent-field)
@@ -2828,22 +2866,22 @@ and not from inner alignment points."
(push (list (match-end 2)
(if (string= (match-string 2) "") 1 0)
t) tabs))))
- ;; Directive
+ ;; Directive.
((looking-at (rst-re 'dir-sta-3 '(:grp "\\S ") "?"))
(push (list (match-end 1) 0 t) tabs)
(unless (string= (match-string 2) "")
(push (list (match-end 2) 0 t) tabs))
(when (match-string 4)
(push (list (match-beginning 4) 0 t) tabs)))
- ;; Footnote or citation definition
+ ;; Footnote or citation definition.
((looking-at (rst-re 'fnc-sta-2 '(:grp "\\S ") "?"))
(push (list (match-end 1) 0 t) tabs)
(when (match-string 3)
(push (list (match-beginning 3) 0 t) tabs)))
- ;; Comment
+ ;; Comment.
((looking-at (rst-re 'cmt-sta-1))
(push (list (point) rst-indent-comment t) tabs)))
- ;; Start of literal block
+ ;; Start of literal block.
(when (looking-at (rst-re 'lit-sta-2))
(let ((tab0 (first tabs)))
(push (list (first tab0)
@@ -2860,14 +2898,14 @@ and not from inner alignment points."
(defun rst-compute-tabs (pt)
"Build the list of possible tabs for all lines above.
Search backwards from point PT to build the list of possible
-tabs. Return a list of tabs sorted by likeliness to continue
-writing like `rst-line-tabs'. Nearer lines have generally a
-higher likeliness than farer lines. Return nil if no tab is found
+tabs. Return a list of tabs sorted by likeliness to continue
+writing like `rst-line-tabs'. Nearer lines have generally a
+higher likeliness than farther lines. Return nil if no tab is found
in the text above."
(save-excursion
(goto-char pt)
- (let (leftmost ; Leftmost column found so far
- innermost ; Leftmost column for inner tab
+ (let (leftmost ; Leftmost column found so far.
+ innermost ; Leftmost column for inner tab.
tablist)
(while (and (zerop (forward-line -1))
(or (not leftmost)
@@ -2875,7 +2913,7 @@ in the text above."
(let* ((tabs (rst-line-tabs))
(leftcol (if tabs (apply 'min (mapcar 'car tabs)))))
(when tabs
- ;; Consider only lines indented less or same if not INNERMOST
+ ;; Consider only lines indented less or same if not INNERMOST.
(when (or (not leftmost)
(< leftcol leftmost)
(and (not innermost) (= leftcol leftmost)))
@@ -2892,8 +2930,7 @@ in the text above."
(< newcol innermost))))
(not (memq newcol tablist)))
(push newcol tablist))))
- (setq innermost (if (some 'identity
- (mapcar 'cdr tabs)) ; Has inner
+ (setq innermost (if (rst-some (mapcar 'cdr tabs)) ; Has inner.
leftcol
innermost))
(setq leftmost leftcol)))))
@@ -2902,19 +2939,19 @@ in the text above."
(defun rst-indent-line (&optional dflt)
"Indent current line to next best reStructuredText tab.
The next best tab is taken from the tab list returned by
-`rst-compute-tabs' which is used in a cyclic manner. If the
-current indentation does not end on a tab use the first one. If
-the current indentation is on a tab use the next tab. This allows
+`rst-compute-tabs' which is used in a cyclic manner. If the
+current indentation does not end on a tab use the first one. If
+the current indentation is on a tab use the next tab. This allows
a repeated use of \\[indent-for-tab-command] to cycle through all
-possible tabs. If no indentation is possible return `noindent' or
-use DFLT. Return the indentation indented to. When point is in
-indentation it ends up at its end. Otherwise the point is kept
+possible tabs. If no indentation is possible return `noindent' or
+use DFLT. Return the indentation indented to. When point is in
+indentation it ends up at its end. Otherwise the point is kept
relative to the content."
(let* ((pt (point-marker))
(cur (current-indentation))
(clm (current-column))
(tabs (rst-compute-tabs (point)))
- (fnd (position cur tabs))
+ (fnd (rst-position cur tabs))
ind)
(if (and (not tabs) (not dflt))
'noindent
@@ -2935,46 +2972,48 @@ relative to the content."
(defun rst-shift-region (beg end cnt)
"Shift region BEG to END by CNT tabs.
Shift by one tab to the right (CNT > 0) or left (CNT < 0) or
-remove all indentation (CNT = 0). An tab is taken from the text
-above. If no suitable tab is found `rst-indent-width' is used."
+remove all indentation (CNT = 0). A tab is taken from the text
+above. If no suitable tab is found `rst-indent-width' is used."
(interactive "r\np")
(let ((tabs (sort (rst-compute-tabs beg) (lambda (x y) (<= x y))))
(leftmostcol (rst-find-leftmost-column beg end)))
(when (or (> leftmostcol 0) (> cnt 0))
- ;; Apply the indent
+ ;; Apply the indent.
(indent-rigidly
beg end
(if (zerop cnt)
(- leftmostcol)
- ;; Find the next tab after the leftmost column
+ ;; Find the next tab after the leftmost column.
(let* ((cmp (if (> cnt 0) '> '<))
(tabs (if (> cnt 0) tabs (reverse tabs)))
(len (length tabs))
- (dir (signum cnt)) ; Direction to take
- (abs (abs cnt)) ; Absolute number of steps to take
- ;; Get the position of the first tab beyond leftmostcol
- (fnd (position-if (lambda (elt)
- (funcall cmp elt leftmostcol))
- tabs))
- ;; Virtual position of tab
+ (dir (rst-signum cnt)) ; Direction to take.
+ (abs (abs cnt)) ; Absolute number of steps to take.
+ ;; Get the position of the first tab beyond leftmostcol.
+ (fnd (lexical-let ((cmp cmp)
+ (leftmostcol leftmostcol)) ; Create closure.
+ (rst-position-if (lambda (elt)
+ (funcall cmp elt leftmostcol))
+ tabs)))
+ ;; Virtual position of tab.
(pos (+ (or fnd len) (1- abs)))
(tab (if (< pos len)
- ;; Tab exists - use it
+ ;; Tab exists - use it.
(nth pos tabs)
- ;; Column needs to be computed
+ ;; Column needs to be computed.
(let ((col (+ (or (car (last tabs)) leftmostcol)
- ;; Base on last known column
- (* (- pos (1- len)) ; Distance left
- dir ; Direction to take
+ ;; Base on last known column.
+ (* (- pos (1- len)) ; Distance left.
+ dir ; Direction to take.
rst-indent-width))))
(if (< col 0) 0 col)))))
(- tab leftmostcol)))))))
;; FIXME: A paragraph with an (incorrectly) indented second line is not filled
-;; correctly::
+;; correctly::
;;
-;; Some start
-;; continued wrong
+;; Some start
+;; continued wrong
(defun rst-adaptive-fill ()
"Return fill prefix found at point.
Value for `adaptive-fill-function'."
@@ -2982,9 +3021,9 @@ Value for `adaptive-fill-function'."
(match-string-no-properties 0))))
(if (save-match-data
(not (string-match comment-start-skip fnd)))
- ;; An non-comment prefix is fine
+ ;; An non-comment prefix is fine.
fnd
- ;; Matches a comment - return whitespace instead
+ ;; Matches a comment - return whitespace instead.
(make-string (-
(save-excursion
(goto-char (match-end 0))
@@ -2998,7 +3037,8 @@ Value for `adaptive-fill-function'."
(defun rst-comment-line-break (&optional soft)
"Break line and indent, continuing reStructuredText comment if within one.
-Value for `comment-line-break-function'."
+Value for `comment-line-break-function'. If SOFT use soft
+newlines as mandated by `comment-line-break-function'."
(if soft
(insert-and-inherit ?\n)
(newline 1))
@@ -3020,7 +3060,8 @@ Value for `comment-line-break-function'."
(insert comment-start))
(defun rst-comment-region (beg end &optional arg)
- "Comment the current region or uncomment it if ARG is \\[universal-argument]."
+ "Comment or uncomment the current region.
+Region is from from BEG to END. Uncomment if ARG."
(save-excursion
(if (consp arg)
(rst-uncomment-region beg end arg)
@@ -3037,7 +3078,7 @@ Value for `comment-line-break-function'."
(defun rst-uncomment-region (beg end &optional arg)
"Uncomment the current region.
-ARG is ignored"
+Region is from BEG to END. ARG is ignored"
(save-excursion
(let (bol eol)
(goto-char beg)
@@ -3050,9 +3091,9 @@ ARG is ignored"
;;------------------------------------------------------------------------------
-;; FIXME: these next functions should become part of a larger effort to redo the
-;; bullets in bulleted lists. The enumerate would just be one of the possible
-;; outputs.
+;; FIXME: These next functions should become part of a larger effort to redo
+;; the bullets in bulleted lists. The enumerate would just be one of
+;; the possible outputs.
;;
;; FIXME: We need to do the enumeration removal as well.
@@ -3082,12 +3123,12 @@ do all lines instead of just paragraphs."
(insert " ")
))
-;; FIXME: Does not deal with a varying number of digits appropriately
-;; FIXME: Does not deal with multiple levels independently
-;; FIXME: Does not indent a multiline item correctly
+;; FIXME: Does not deal with a varying number of digits appropriately.
+;; FIXME: Does not deal with multiple levels independently.
+;; FIXME: Does not indent a multiline item correctly.
(defun rst-convert-bullets-to-enumeration (beg end)
"Convert the bulleted and enumerated items in the region to enumerated lists.
-Renumber as necessary."
+Renumber as necessary. Region is from BEG to END."
(interactive "r")
(let* (;; Find items and convert the positions to markers.
(items (mapcar
@@ -3112,7 +3153,7 @@ Renumber as necessary."
(defun rst-line-block-region (rbeg rend &optional pfxarg)
"Toggle line block prefixes for a region.
-With prefix argument set the empty lines too."
+Region is from RBEG to REND. With PFXARG set the empty lines too."
(interactive "r\nP")
(let ((comment-start "| ")
(comment-end "")
@@ -3134,7 +3175,10 @@ With prefix argument set the empty lines too."
(require 'font-lock)
-;; FIXME: The obsolete variables need to disappear
+;; FIXME: The obsolete variables need to disappear.
+
+;; The following versions have been done inside Emacs and should not be
+;; replaced by `:package-version' attributes until a change.
(defgroup rst-faces nil "Faces used in Rst Mode."
:group 'rst
@@ -3268,8 +3312,27 @@ With prefix argument set the empty lines too."
"customize the face `rst-reference' instead."
"24.1")
+(defface rst-transition '((t :inherit font-lock-keyword-face))
+ "Face used for a transition."
+ :package-version '(rst . "1.3.0")
+ :group 'rst-faces)
+
+(defface rst-adornment '((t :inherit font-lock-keyword-face))
+ "Face used for the adornment of a section header."
+ :package-version '(rst . "1.3.0")
+ :group 'rst-faces)
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; FIXME LEVEL-FACE: May be this complicated mechanism should be replaced
+;; simply by a number of customizable faces `rst-header-%d'
+;; which by default are set properly for dark and light
+;; background. Initialization should come from the old
+;; variables if they exist. A maximum level of 6 should
+;; suffice - after that the last level should be repeated.
+;; Only `rst-adornment-faces-alist' is needed outside this
+;; block. Would also fix docutils-Bugs-3479594.
+
(defgroup rst-faces-defaults nil
"Values used to generate default faces for section titles on all levels.
Tweak these if you are content with how section title faces are built in
@@ -3278,9 +3341,10 @@ general but you do not like the details."
:version "21.1")
(defun rst-set-level-default (sym val)
- "Set custom var SYM affecting section title text face and recompute the faces."
+ "Set custom variable SYM affecting section title text face.
+Recompute the faces. VAL is the value to set."
(custom-set-default sym val)
- ;; Also defines the faces initially when all values are available
+ ;; Also defines the faces initially when all values are available.
(and (boundp 'rst-level-face-max)
(boundp 'rst-level-face-format-light)
(boundp 'rst-level-face-base-color)
@@ -3289,19 +3353,27 @@ general but you do not like the details."
(fboundp 'rst-define-level-faces)
(rst-define-level-faces)))
-;; Faces for displaying items on several levels; these definitions define
-;; different shades of gray where the lightest one (i.e. least contrasting) is
-;; used for level 1
+;; Faces for displaying items on several levels. These definitions define
+;; different shades of gray where the lightest one (i.e. least contrasting on a
+;; light background) is used for level 1.
(defcustom rst-level-face-max 6
"Maximum depth of levels for which section title faces are defined."
:group 'rst-faces-defaults
:type '(integer)
:set 'rst-set-level-default)
+;; FIXME: It should be possible to give "#RRGGBB" type of color values.
+;; Together with a `rst-level-face-end-light' this could be used for
+;; computing steps.
+;; FIXME: This variable should be combined with `rst-level-face-format-light'
+;; to a single string.
(defcustom rst-level-face-base-color "grey"
"Base name of the color for creating background colors in section title faces."
:group 'rst-faces-defaults
:type '(string)
:set 'rst-set-level-default)
+;; FIXME LEVEL-FACE: This needs to be done differently: The faces must specify
+;; how they behave for dark and light background using the
+;; relevant options explained in `defface'.
(defcustom rst-level-face-base-light
(if (eq frame-background-mode 'dark)
15
@@ -3318,6 +3390,12 @@ This value is expanded by `format' with an integer."
:group 'rst-faces-defaults
:type '(string)
:set 'rst-set-level-default)
+;; FIXME LEVEL-FACE: This needs to be done differently: The faces must specify
+;; how they behave for dark and light background using the
+;; relevant options explained in `defface'.
+;; FIXME: Alternatively there could be a customizable variable
+;; `rst-level-face-end-light' which defines the end value and steps are
+;; computed
(defcustom rst-level-face-step-light
(if (eq frame-background-mode 'dark)
7
@@ -3337,68 +3415,73 @@ This color is used as background for section title text on level
:set 'rst-set-level-default)
(defcustom rst-adornment-faces-alist
- (let ((alist '((t . font-lock-keyword-face)
- (nil . font-lock-keyword-face)))
+ ;; FIXME LEVEL-FACE: Must be redone if `rst-level-face-max' is changed
+ (let ((alist (copy-list '((t . rst-transition)
+ (nil . rst-adornment))))
(i 1))
(while (<= i rst-level-face-max)
(nconc alist (list (cons i (intern (format "rst-level-%d-face" i)))))
(setq i (1+ i)))
alist)
"Faces for the various adornment types.
-Key is a number (for the section title text of that level),
-t (for transitions) or nil (for section title adornment).
-If you generally do not like how section title text faces are
-set up tweak here. If the general idea is ok for you but you do not like the
-details check the Rst Faces Defaults group."
+Key is a number (for the section title text of that level
+starting with 1), t (for transitions) or nil (for section title
+adornment). If you generally do not like how section title text
+faces are set up tweak here. If the general idea is ok for you
+but you do not like the details check the Rst Faces Defaults
+group."
:group 'rst-faces
:type '(alist
:key-type
(choice
- (integer
- :tag
- "Section level (may not be bigger than `rst-level-face-max')")
- (boolean :tag "transitions (on) / section title adornment (off)"))
+ (integer :tag "Section level")
+ (const :tag "transitions" t)
+ (const :tag "section title adornment" nil))
:value-type (face))
:set-after '(rst-level-face-max))
-;; FIXME: It should be possible to give "#RRGGBB" type of color values
(defun rst-define-level-faces ()
"Define the faces for the section title text faces from the values."
- ;; All variables used here must be checked in `rst-set-level-default'
+ ;; All variables used here must be checked in `rst-set-level-default'.
(let ((i 1))
(while (<= i rst-level-face-max)
(let ((sym (intern (format "rst-level-%d-face" i)))
- (doc (format "Face for showing section title text at level %d" i))
+ (doc (format "Default face for showing section title text at level %d.
+This symbol is *not* meant for customization but modified if a
+variable of the `rst-faces-defaults' group is customized. Use
+`rst-adornment-faces-alist' for customization instead." i))
(col (format (concat "%s" rst-level-face-format-light)
rst-level-face-base-color
(+ (* (1- i) rst-level-face-step-light)
rst-level-face-base-light))))
- (unless (facep sym)
- (make-empty-face sym)
- (set-face-doc-string sym doc)
- (set-face-background sym col)
- (set sym sym))
+ (make-empty-face sym)
+ (set-face-doc-string sym doc)
+ (set-face-background sym col)
+ (set sym sym)
(setq i (1+ i))))))
+;; FIXME LEVEL-FACE: This is probably superfluous since it is done by the
+;; customization / `rst-set-level-default'.
(rst-define-level-faces)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar rst-font-lock-keywords
;; The reST-links in the comments below all relate to sections in
- ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
+ ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html.
`(;; FIXME: Block markup is not recognized in blocks after explicit markup
- ;; start
+ ;; start.
;; Simple `Body Elements`_
;; `Bullet Lists`_
- ;; FIXME: A bullet directly after a field name is not recognized
+ ;; FIXME: A bullet directly after a field name is not recognized.
(,(rst-re 'lin-beg '(:grp bul-sta))
1 rst-block-face)
;; `Enumerated Lists`_
(,(rst-re 'lin-beg '(:grp enmany-sta))
1 rst-block-face)
- ;; `Definition Lists`_ FIXME: missing
+ ;; `Definition Lists`_
+ ;; FIXME: missing.
;; `Field Lists`_
(,(rst-re 'lin-beg '(:grp fld-tag) 'bli-sfx)
1 rst-external-face)
@@ -3407,11 +3490,12 @@ details check the Rst Faces Defaults group."
'(:alt "$" (:seq hws-prt "\\{2\\}")))
1 rst-block-face)
;; `Line Blocks`_
- ;; Only for lines containing no more bar - to distinguish from tables
+ ;; Only for lines containing no more bar - to distinguish from tables.
(,(rst-re 'lin-beg '(:grp "|" bli-sfx) "[^|\n]*$")
1 rst-block-face)
- ;; `Tables`_ FIXME: missing
+ ;; `Tables`_
+ ;; FIXME: missing
;; All the `Explicit Markup Blocks`_
;; `Footnotes`_ / `Citations`_
@@ -3433,11 +3517,11 @@ details check the Rst Faces Defaults group."
(,(rst-re 'lin-beg '(:grp "__") 'bli-sfx)
1 rst-definition-face)
- ;; All `Inline Markup`_ - most of them may be multiline though this is
- ;; uninteresting
+ ;; All `Inline Markup`_
+ ;; Most of them may be multiline though this is uninteresting.
;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented
- ;; `Strong Emphasis`_
+ ;; `Strong Emphasis`_.
(,(rst-re 'ilm-pfx '(:grp "\\*\\*" ilcast-tag "\\*\\*") 'ilm-sfx)
1 rst-emphasis2-face)
;; `Emphasis`_
@@ -3450,9 +3534,9 @@ details check the Rst Faces Defaults group."
(,(rst-re 'ilm-pfx '(:grp "_`" ilcbkq-tag "`") 'ilm-sfx)
1 rst-definition-face)
;; `Hyperlink References`_
- ;; FIXME: `Embedded URIs`_ not considered
- ;; FIXME: Directly adjacing marked up words are not fontified correctly
- ;; unless they are not separated by two spaces: foo_ bar_
+ ;; FIXME: `Embedded URIs`_ not considered.
+ ;; FIXME: Directly adjacent marked up words are not fontified correctly
+ ;; unless they are not separated by two spaces: foo_ bar_.
(,(rst-re 'ilm-pfx '(:grp (:alt (:seq "`" ilcbkq-tag "`")
(:seq "\\sw" (:alt "\\sw" "-") "+\\sw"))
"__?") 'ilm-sfx)
@@ -3469,19 +3553,20 @@ details check the Rst Faces Defaults group."
1 rst-reference-face)
;; `Substitution References`_
;; FIXME: References substitutions like |this|_ or |this|__ are not
- ;; fontified correctly
+ ;; fontified correctly.
(,(rst-re 'ilm-pfx '(:grp sub-tag) 'ilm-sfx)
1 rst-reference-face)
;; `Standalone Hyperlinks`_
- ;; FIXME: This takes it easy by using a whitespace as delimiter
+ ;; FIXME: This takes it easy by using a whitespace as delimiter.
(,(rst-re 'ilm-pfx '(:grp uri-tag ":\\S +") 'ilm-sfx)
1 rst-definition-face)
(,(rst-re 'ilm-pfx '(:grp sym-tag "@" sym-tag ) 'ilm-sfx)
1 rst-definition-face)
- ;; Do all block fontification as late as possible so 'append works
+ ;; Do all block fontification as late as possible so 'append works.
- ;; Sections_ / Transitions_ - for sections this is multiline
+ ;; Sections_ / Transitions_
+ ;; For sections this is multiline.
(,(rst-re 'ado-beg-2-1)
(rst-font-lock-handle-adornment-matcher
(rst-font-lock-handle-adornment-pre-match-form
@@ -3494,13 +3579,14 @@ details check the Rst Faces Defaults group."
;; FIXME: FACESPEC could be used instead of ordinary faces to set
;; properties on comments and literal blocks so they are *not*
- ;; inline fontified; see (elisp)Search-based Fontification
+ ;; inline fontified. See (elisp)Search-based Fontification.
;; FIXME: And / or use `syntax-propertize` functions as in `octave-mod.el`
- ;; and other V24 modes; may make `font-lock-extend-region`
- ;; superfluous
+ ;; and other V24 modes. May make `font-lock-extend-region`
+ ;; superfluous.
- ;; `Comments`_ - this is multiline
+ ;; `Comments`_
+ ;; This is multiline.
(,(rst-re 'lin-beg 'cmt-sta-1)
(1 rst-comment-face)
(rst-font-lock-find-unindented-line-match
@@ -3516,9 +3602,9 @@ details check the Rst Faces Defaults group."
(0 rst-comment-face append)))
;; FIXME: This is not rendered as comment::
- ;; .. .. list-table::
- ;; :stub-columns: 1
- ;; :header-rows: 1
+ ;; .. .. list-table::
+ ;; :stub-columns: 1
+ ;; :header-rows: 1
;; FIXME: This is rendered wrong::
;;
@@ -3534,7 +3620,8 @@ details check the Rst Faces Defaults group."
;; Indentation needs to be taken from the line with the ``::`` and not from
;; the first content line.
- ;; `Indented Literal Blocks`_ - this is multiline
+ ;; `Indented Literal Blocks`_
+ ;; This is multiline.
(,(rst-re 'lin-beg 'lit-sta-2)
(2 rst-block-face)
(rst-font-lock-find-unindented-line-match
@@ -3542,7 +3629,8 @@ details check the Rst Faces Defaults group."
nil
(0 rst-literal-face append)))
- ;; FIXME: `Quoted Literal Blocks`_ missing - this is multiline
+ ;; FIXME: `Quoted Literal Blocks`_ missing.
+ ;; This is multiline.
;; `Doctest Blocks`_
;; FIXME: This is wrong according to the specification:
@@ -3571,9 +3659,13 @@ details check the Rst Faces Defaults group."
)
"Keywords to highlight in rst mode.")
+(defvar font-lock-beg)
+(defvar font-lock-end)
+
(defun rst-font-lock-extend-region ()
- "Extend the region `font-lock-beg' / `font-lock-end' iff it may
-be in the middle of a multiline construct and return non-nil if so."
+ "Extend the font-lock region if it might be in a multi-line construct.
+Return non-nil if so. Font-lock region is from `font-lock-beg'
+to `font-lock-end'."
(let ((r (rst-font-lock-extend-region-internal font-lock-beg font-lock-end)))
(when r
(setq font-lock-beg (car r))
@@ -3581,7 +3673,7 @@ be in the middle of a multiline construct and return non-nil if so."
t)))
(defun rst-font-lock-extend-region-internal (beg end)
- "Check the region BEG / END for being in the middle of a multiline construct.
+ "Check the region BEG / END for being in the middle of a multi-line construct.
Return nil if not or a cons with new values for BEG / END"
(let ((nbeg (rst-font-lock-extend-region-extend beg -1))
(nend (rst-font-lock-extend-region-extend end 1)))
@@ -3589,13 +3681,16 @@ Return nil if not or a cons with new values for BEG / END"
(cons (or nbeg beg) (or nend end)))))
(defun rst-forward-line (&optional n)
- "Like `forward-line' but always end up in column 0 and return accordingly."
+ "Like `forward-line' but always end up in column 0 and return accordingly.
+Move N lines forward just as `forward-line'."
(let ((moved (forward-line n)))
(if (bolp)
moved
(forward-line 0)
- (- moved (signum n)))))
+ (- moved (rst-signum n)))))
+;; FIXME: If a single line is made a section header by `rst-adjust' the header
+;; is not always fontified immediately.
(defun rst-font-lock-extend-region-extend (pt dir)
"Extend the region starting at point PT and extending in direction DIR.
Return extended point or nil if not moved."
@@ -3606,47 +3701,47 @@ Return extended point or nil if not moved."
;;
;; * literal blocks following "::"
;;
- ;; which are both indented. Thus indendation is the first thing recognized
+ ;; which are both indented. Thus indentation is the first thing recognized
;; here. The second criteria is an explicit markup tag which may be a comment
;; or a double colon at the end of a line.
;;
;; The second group consists of the adornment cases.
(if (not (get-text-property pt 'font-lock-multiline))
- ;; Move only if we don't start inside a multiline construct already
+ ;; Move only if we don't start inside a multiline construct already.
(save-excursion
- (let (;; non-empty non-indented line, explicit markup tag or literal
- ;; block tag
+ (let (;; Non-empty non-indented line, explicit markup tag or literal
+ ;; block tag.
(stop-re (rst-re '(:alt "[^ \t\n]"
(:seq hws-tag exm-tag)
(:seq ".*" dcl-tag lin-end)))))
- ;; The comments below are for dir == -1 / dir == 1
+ ;; The comments below are for dir == -1 / dir == 1.
(goto-char pt)
(forward-line 0)
(setq pt (point))
(while (and (not (looking-at stop-re))
(zerop (rst-forward-line dir)))) ; try previous / next
- ; line if it exists
+ ; line if it exists.
(if (looking-at (rst-re 'ado-beg-2-1)) ; may be an underline /
- ; overline
+ ; overline.
(if (zerop (rst-forward-line dir))
(if (looking-at (rst-re 'ttl-beg)) ; title found, i.e.
; underline / overline
- ; found
+ ; found.
(if (zerop (rst-forward-line dir))
(if (not
(looking-at (rst-re 'ado-beg-2-1))) ; no
; overline /
- ; underline
+ ; underline.
(rst-forward-line (- dir)))) ; step back to title
- ; / adornment
- (if (< dir 0) ; keep downward adornment
- (rst-forward-line (- dir))))) ; step back to adornment
- (if (looking-at (rst-re 'ttl-beg)) ; may be a title
+ ; / adornment.
+ (if (< dir 0) ; keep downward adornment.
+ (rst-forward-line (- dir))))) ; step back to adornment.
+ (if (looking-at (rst-re 'ttl-beg)) ; may be a title.
(if (zerop (rst-forward-line dir))
(if (not
(looking-at (rst-re 'ado-beg-2-1))) ; no overline /
- ; underline
- (rst-forward-line (- dir)))))) ; step back to line
+ ; underline.
+ (rst-forward-line (- dir)))))) ; step back to line.
(if (not (= (point) pt))
(point))))))
@@ -3672,20 +3767,21 @@ point is not moved."
(when (< (point) limit)
(setq beg (point))
(if (looking-at (rst-re 'lin-end))
- (setq cand (or cand beg)) ; An empty line is a candidate
+ (setq cand (or cand beg)) ; An empty line is a candidate.
(move-to-column clm)
;; FIXME: No indentation [(zerop clm)] must be handled in some
- ;; useful way - though it is not clear what this should mean at all
+ ;; useful way - though it is not clear what this should mean
+ ;; at all.
(if (string-match
(rst-re 'linemp-tag)
(buffer-substring-no-properties beg (point)))
- (setq cand nil) ; An indented line resets a candidate
+ (setq cand nil) ; An indented line resets a candidate.
(setq fnd (or cand beg)))))))
(goto-char (or fnd start))
fnd))
(defvar rst-font-lock-find-unindented-line-begin nil
- "Beginning of the match if `rst-font-lock-find-unindented-line-end'")
+ "Beginning of the match if `rst-font-lock-find-unindented-line-end'.")
(defvar rst-font-lock-find-unindented-line-end nil
"End of the match as determined by `rst-font-lock-find-unindented-line-limit'.
@@ -3693,10 +3789,10 @@ Also used as a trigger for
`rst-font-lock-find-unindented-line-match'.")
(defun rst-font-lock-find-unindented-line-limit (ind-pnt)
- "Find the next unindented line relative to indenation at IND-PNT.
+ "Find the next unindented line relative to indentation at IND-PNT.
Return this point, the end of the buffer or nil if nothing found.
If IND-PNT is `next' take the indentation from the next line if
-this is not empty and indented more than the current one. If
+this is not empty and indented more than the current one. If
IND-PNT is non-nil but not a number take the indentation from the
next non-empty line if this is indented more than the current
one."
@@ -3704,34 +3800,34 @@ one."
(setq rst-font-lock-find-unindented-line-end
(save-excursion
(when (not (numberp ind-pnt))
- ;; Find indentation point in next line if any
+ ;; Find indentation point in next line if any.
(setq ind-pnt
;; FIXME: Should be refactored to two different functions
;; giving their result to this function, may be
- ;; integrated in caller
+ ;; integrated in caller.
(save-match-data
(let ((cur-ind (current-indentation)))
(if (eq ind-pnt 'next)
(when (and (zerop (forward-line 1))
(< (point) (point-max)))
- ;; Not at EOF
+ ;; Not at EOF.
(setq rst-font-lock-find-unindented-line-begin
(point))
(when (and (not (looking-at (rst-re 'lin-end)))
(> (current-indentation) cur-ind))
- ;; Use end of indentation if non-empty line
+ ;; Use end of indentation if non-empty line.
(looking-at (rst-re 'hws-tag))
(match-end 0)))
- ;; Skip until non-empty line or EOF
+ ;; Skip until non-empty line or EOF.
(while (and (zerop (forward-line 1))
(< (point) (point-max))
(looking-at (rst-re 'lin-end))))
(when (< (point) (point-max))
- ;; Not at EOF
+ ;; Not at EOF.
(setq rst-font-lock-find-unindented-line-begin
(point))
(when (> (current-indentation) cur-ind)
- ;; Indentation bigger than line of departure
+ ;; Indentation bigger than line of departure.
(looking-at (rst-re 'hws-tag))
(match-end 0))))))))
(when ind-pnt
@@ -3740,9 +3836,11 @@ one."
(point-max))))))
(defun rst-font-lock-find-unindented-line-match (limit)
- "Set the match found by
+ "Set the match found earlier if match were found.
+Match has been found by
`rst-font-lock-find-unindented-line-limit' the first time called
-or nil."
+or no match is found. Return non-nil if match was found. LIMIT
+is not used but mandated by the caller."
(when rst-font-lock-find-unindented-line-end
(set-match-data
(list rst-font-lock-find-unindented-line-begin
@@ -3750,7 +3848,7 @@ or nil."
(put-text-property rst-font-lock-find-unindented-line-begin
rst-font-lock-find-unindented-line-end
'font-lock-multiline t)
- ;; Make sure this is called only once
+ ;; Make sure this is called only once.
(setq rst-font-lock-find-unindented-line-end nil)
t))
@@ -3764,30 +3862,34 @@ Either section level of the current adornment or t for a transition.")
(defun rst-adornment-level (key)
"Return section level for adornment KEY.
KEY is the first element of the return list of
-`rst-classify-adornment'. If KEY is not a cons return it. If KEY is found
-in the hierarchy return its level. Otherwise return a level one
+`rst-classify-adornment'. If KEY is not a cons return it. If KEY is found
+in the hierarchy return its level. Otherwise return a level one
beyond the existing hierarchy."
(if (not (consp key))
key
(let* ((hier (rst-get-hierarchy))
(char (car key))
(style (cdr key)))
- (1+ (or (position-if (lambda (elt)
- (and (equal (car elt) char)
- (equal (cadr elt) style))) hier)
+ (1+ (or (lexical-let ((char char)
+ (style style)
+ (hier hier)) ; Create closure.
+ (rst-position-if (lambda (elt)
+ (and (equal (car elt) char)
+ (equal (cadr elt) style))) hier))
(length hier))))))
(defvar rst-font-lock-adornment-match nil
"Storage for match for current adornment.
-Set by `rst-font-lock-handle-adornment-pre-match-form'. Also used
+Set by `rst-font-lock-handle-adornment-pre-match-form'. Also used
as a trigger for `rst-font-lock-handle-adornment-matcher'.")
(defun rst-font-lock-handle-adornment-pre-match-form (ado ado-end)
- "Determine limit for adornments for font-locking section titles and transitions.
-In fact determine all things necessary and put the result to
+ "Determine limit for adornments.
+Determine all things necessary for font-locking section titles
+and transitions and put the result to
`rst-font-lock-adornment-match' and
-`rst-font-lock-adornment-level'. ADO is the complete adornment
-matched. ADO-END is the point where ADO ends. Return the point
+`rst-font-lock-adornment-level'. ADO is the complete adornment
+matched. ADO-END is the point where ADO ends. Return the point
where the whole adorned construct ends.
Called as a PRE-MATCH-FORM in the sense of `font-lock-keywords'."
@@ -3798,16 +3900,19 @@ Called as a PRE-MATCH-FORM in the sense of `font-lock-keywords'."
(setq rst-font-lock-adornment-level
(rst-adornment-level (car ado-data)))
(setq rst-font-lock-adornment-match (cdr ado-data))
- (goto-char (nth 1 ado-data)) ; Beginning of construct
- (nth 2 ado-data)))) ; End of construct
+ (goto-char (nth 1 ado-data)) ; Beginning of construct.
+ (nth 2 ado-data)))) ; End of construct.
(defun rst-font-lock-handle-adornment-matcher (limit)
- "Set the match found by `rst-font-lock-handle-adornment-pre-match-form'
-the first time called or nil.
+ "Set the match found earlier if match were found.
+Match has been found by
+`rst-font-lock-handle-adornment-pre-match-form' the first time
+called or no match is found. Return non-nil if match was found.
-Called as a MATCHER in the sense of `font-lock-keywords'."
+Called as a MATCHER in the sense of `font-lock-keywords'.
+LIMIT is not used but mandated by the caller."
(let ((match rst-font-lock-adornment-match))
- ;; May run only once - enforce this
+ ;; May run only once - enforce this.
(setq rst-font-lock-adornment-match nil)
(when match
(set-match-data match)
@@ -3843,12 +3948,12 @@ document with \\[rst-compile]."
".pdf" nil)
(s5 ,(if (executable-find "rst2s5.py") "rst2s5.py" "rst2s5")
".html" nil))
- "Table describing the command to use for each toolset.
-An association list of the toolset to a list of the (command to use,
+ "Table describing the command to use for each tool-set.
+An association list of the tool-set to a list of the (command to use,
extension of produced filename, options to the tool (nil or a
string)) to be used for converting the document."
;; FIXME: These are not options but symbols which may be referenced by
- ;; `rst-compile-*-toolset` below
+ ;; `rst-compile-*-toolset` below.
:type '(alist :options (html latex newlatex pseudoxml xml pdf s5)
:key-type symbol
:value-type (list :tag "Specification"
@@ -3858,15 +3963,15 @@ string)) to be used for converting the document."
(const :tag "No options" nil)
(string :tag "Options"))))
:group 'rst
- :version "24.1")
+ :package-version "1.2.0")
-;; FIXME: Must be `defcustom`
+;; FIXME: Must be `defcustom`.
(defvar rst-compile-primary-toolset 'html
- "The default toolset for `rst-compile'.")
+ "The default tool-set for `rst-compile'.")
-;; FIXME: Must be `defcustom`
+;; FIXME: Must be `defcustom`.
(defvar rst-compile-secondary-toolset 'latex
- "The default toolset for `rst-compile' with a prefix argument.")
+ "The default tool-set for `rst-compile' with a prefix argument.")
(defun rst-compile-find-conf ()
"Look for the configuration file in the parents of the current path."
@@ -3896,7 +4001,7 @@ string)) to be used for converting the document."
"Compile command to convert reST document into some output file.
Attempts to find configuration file, if it can, overrides the
options. There are two commands to choose from, with USE-ALT,
-select the alternative toolset."
+select the alternative tool-set."
(interactive "P")
;; Note: maybe we want to check if there is a Makefile too and not do anything
;; if that is the case. I dunno.
@@ -3930,13 +4035,15 @@ select the alternative toolset."
))
(defun rst-compile-alt-toolset ()
- "Compile command with the alternative toolset."
+ "Compile command with the alternative tool-set."
(interactive)
(rst-compile t))
(defun rst-compile-pseudo-region ()
- "Show the pseudo-XML rendering of the current active region,
-or of the entire buffer, if the region is not selected."
+ "Show pseudo-XML rendering.
+Rendering is done of the current active region, or of the entire
+buffer, if the region is not selected."
+ ;; FIXME: The region should be given interactively.
(interactive)
(with-output-to-temp-buffer "*pseudoxml*"
(shell-command-on-region
@@ -3945,7 +4052,7 @@ or of the entire buffer, if the region is not selected."
(cadr (assq 'pseudoxml rst-compile-toolsets))
standard-output)))
-;; FIXME: Should be `defcustom`
+;; FIXME: Should be `defcustom`.
(defvar rst-pdf-program "xpdf"
"Program used to preview PDF files.")
@@ -3962,7 +4069,7 @@ or of the entire buffer, if the region is not selected."
;; output.
))
-;; FIXME: Should be `defcustom` or use something like `browse-url`
+;; FIXME: Should be `defcustom` or use something like `browse-url`.
(defvar rst-slides-program "firefox"
"Program used to preview S5 slides.")
@@ -3983,10 +4090,9 @@ or of the entire buffer, if the region is not selected."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Generic text functions that are more convenient than the defaults.
-;; FIXME: Unbound command - should be bound or removed
+;; FIXME: Unbound command - should be bound or removed.
(defun rst-replace-lines (fromchar tochar)
- "Replace flush-left lines, consisting of multiple FROMCHAR characters,
-with equal-length lines of TOCHAR."
+ "Replace flush-left lines of FROMCHAR with equal-length lines of TOCHAR."
(interactive "\
cSearch for flush-left lines of char:
cand replace with char: ")
@@ -4001,14 +4107,14 @@ cand replace with char: ")
(insert-char tochar width)))
(message (format "%d lines replaced." found)))))
-;; FIXME: Unbound command - should be bound or removed
+;; FIXME: Unbound command - should be bound or removed.
(defun rst-join-paragraph ()
"Join lines in current paragraph into one line, removing end-of-lines."
(interactive)
- (let ((fill-column 65000)) ; some big number
+ (let ((fill-column 65000)) ; Some big number.
(call-interactively 'fill-paragraph)))
-;; FIXME: Unbound command - should be bound or removed
+;; FIXME: Unbound command - should be bound or removed.
(defun rst-force-fill-paragraph ()
"Fill paragraph at point, first joining the paragraph's lines into one.
This is useful for filling list item paragraphs."
@@ -4017,14 +4123,14 @@ This is useful for filling list item paragraphs."
(fill-paragraph nil))
-;; FIXME: Unbound command - should be bound or removed
+;; FIXME: Unbound command - should be bound or removed.
;; Generic character repeater function.
;; For sections, better to use the specialized function above, but this can
;; be useful for creating separators.
(defun rst-repeat-last-character (use-next)
- "Fill the current line up to the length of the preceding line (if not
-empty), using the last character on the current line. If the preceding line is
-empty, we use the `fill-column'.
+ "Fill the current line using the last character on the current line.
+Fill up to the length of the preceding line or up to
+`fill-column' if preceding line is empty.
If USE-NEXT, use the next line rather than the preceding line.
@@ -4054,23 +4160,34 @@ column is used (fill-column vs. end of previous/next line)."
)) )
(end-of-line)
(if (> (current-column) rightmost-column)
- ;; shave characters off the end
+ ;; Shave characters off the end.
(delete-region (- (point)
(- (current-column) rightmost-column))
(point))
- ;; fill with last characters
+ ;; Fill with last characters.
(insert-char (preceding-char)
(- rightmost-column (current-column))))
))
(defun rst-portable-mark-active-p ()
- "A portable function that returns non-nil if the mark is active."
+ "Return non-nil if the mark is active.
+This is a portable function."
(cond
((fboundp 'region-active-p) (region-active-p))
((boundp 'transient-mark-mode) (and transient-mark-mode mark-active))
(t mark-active)))
+
+;; LocalWords: docutils http sourceforge rst html wp svn svnroot txt reST regex
+;; LocalWords: regexes alist seq alt grp keymap abbrev overline overlines toc
+;; LocalWords: XML PNT propertized
+
+;; Local Variables:
+;; sentence-end-double-space: t
+;; End:
+
(provide 'rst)
+
;;; rst.el ends here
diff --git a/tools/editors/emacs/tests/Makefile b/tools/editors/emacs/tests/Makefile
index e6a217476..eadb79943 100644
--- a/tools/editors/emacs/tests/Makefile
+++ b/tools/editors/emacs/tests/Makefile
@@ -2,15 +2,24 @@
EMACS = /usr/bin/emacs
ERT = ~/lib/emacs/ert
+RST_EL = ../rst.el
EMACS_ERT_PFX = $(EMACS) --batch --quick --directory=$(ERT) --load=ert.el
EMACS_ERT_SFX = --funcall=ert-run-tests-batch-and-exit
ERT_TESTS := $(filter-out ert-%,$(wildcard *.el))
-all:
+EMACS_COMPILE_PFX = $(EMACS) --batch --quick --eval '(progn \
+ (setq byte-compile-error-on-warn t) \
+ (kill-emacs (if (byte-compile-file
+EMACS_COMPILE_SFX = ) 0 1)))'
+
+all: compile tests
tests:
$(EMACS_ERT_PFX) $(addprefix -l ,$(ERT_TESTS)) $(EMACS_ERT_SFX)
+compile:
+ $(EMACS_COMPILE_PFX) "$(RST_EL)" $(EMACS_COMPILE_SFX) 2>&1 \
+
clean:
diff --git a/tools/editors/emacs/tests/re.el b/tools/editors/emacs/tests/re.el
index fa86d4f09..946801892 100644
--- a/tools/editors/emacs/tests/re.el
+++ b/tools/editors/emacs/tests/re.el
@@ -634,7 +634,8 @@ and the numbered matches are compared."
(cons "\\[^|\n]\\+" "\\(?:\\S \\|\\S \\(?:[^|\\\n]\\|\\\\.\\)\\{0,1000\\}[^ |\\]\\)"
) ;; Symbol name more sophisticated
(cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
- "\\(?:\\sw+\\(?:\\s_\\sw+\\)*\\)") ;; New syntax for symbols
+ "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
+ ;; symbols
(cons "\\\\(\\[\t " "\\(?:[\t ") ;; Make a group shy
))
(should (re-equal-matches
@@ -762,9 +763,11 @@ and the numbered matches are compared."
(cons "\\\\(:" "\\(?::") ;; Make a group shy
(cons "\\\\(:" "\\(?::") ;; Make a group shy
(cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
- "\\(?:\\sw+\\(?:\\s_\\sw+\\)*\\)") ;; New syntax for symbols
+ "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
+ ;; symbols
(cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
- "\\(?:\\sw+\\(?:\\s_\\sw+\\)*\\)") ;; New syntax for symbols
+ "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
+ ;; symbols
(cons (regexp-quote "\\\\]") "\\]") ;; Remove superfluous quote
(cons (regexp-quote "\\|$") "")
(cons (regexp-quote "\\([\t ]")
@@ -823,9 +826,11 @@ and the numbered matches are compared."
(cons 2 1))
(cons "^\\\\(" "\\(?:") ;; Make a group shy
(cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
- "\\(?:\\sw+\\(?:\\s_\\sw+\\)*\\)") ;; New syntax for symbols
+ "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
+ ;; symbols
(cons (regexp-quote "\\(\\sw\\|\\s_\\)+")
- "\\(?:\\sw+\\(?:\\s_\\sw+\\)*\\)") ;; New syntax for symbols
+ "\\(?:\\sw+\\(?:[-+.:_]\\sw+\\)*\\)") ;; New syntax for
+ ;; symbols
(cons (regexp-quote "\\|$") "")
(cons (regexp-quote "\\([\t ]")
"\\(?:$\\|[\t ]") ;; Move "$" in regex and make a group shy