diff options
| author | Stefan Merten | 2012-05-29 22:14:18 +0200 |
|---|---|---|
| committer | Stefan Merten | 2012-05-29 22:14:18 +0200 |
| commit | 6d3f7c2ffff96b606118940cb5261239c5126f42 (patch) | |
| tree | 9fa947545d6ae3caeb7efe644dfe8a2591e04adb | |
| parent | 6dbaa1c769c3a0464ec72e4224cbd76c0356a2bf (diff) | |
| download | emacs-6d3f7c2ffff96b606118940cb5261239c5126f42.tar.gz emacs-6d3f7c2ffff96b606118940cb5261239c5126f42.zip | |
Silence `checkdoc-ispell' errors where possible. Fix authors. Improve
comments. Improve loading of `cl'.
(rst-mode-abbrev-table): Merge definition.
(rst-mode): Make sure `font-lock-defaults' is buffer local.
(rst-define-key, rst-deprecated-keys, rst-call-deprecated): Refactor.
| -rw-r--r-- | etc/NEWS | 26 | ||||
| -rw-r--r-- | lisp/ChangeLog | 113 | ||||
| -rw-r--r-- | lisp/textmodes/rst.el | 935 |
3 files changed, 601 insertions, 473 deletions
| @@ -125,31 +125,31 @@ to highlight changes in context diffs. | |||
| 125 | 125 | ||
| 126 | ** reStructuredText mode | 126 | ** reStructuredText mode |
| 127 | 127 | ||
| 128 | *** Nearly all keys are rebound making room for more keys and comply | 128 | *** Rebind nearly all keys making room for more keys and complying |
| 129 | better to usage in other modes. Bindings are described with C-c C-h. | 129 | better to usage in other modes. Describe bindings with C-c C-h. |
| 130 | 130 | ||
| 131 | *** Major revision of indentation. Now works very similarly to other modes. | 131 | *** Major revision of indentation working very similar to other |
| 132 | TAB is your friend. | 132 | modes. TAB is your friend. |
| 133 | 133 | ||
| 134 | *** Major revision of filling. Works fine with most of | 134 | *** Major revision of filling working fine with most of |
| 135 | reStructuredText syntax. Auto-filling is also supported. | 135 | reStructuredText syntax. Support auto-filling. |
| 136 | 136 | ||
| 137 | *** Major revision of comment handling. | 137 | *** Major revision of comment handling. |
| 138 | 138 | ||
| 139 | *** Major revision of fontification. Now works with `jit-lock-mode'. | 139 | *** Major revision of fontification working with `jit-lock-mode'. |
| 140 | 140 | ||
| 141 | *** reStructuredText syntax is covered more closely in many cases. | 141 | *** Cover reStructuredText syntax more closely. Improve |
| 142 | Among other things this improves the experience for Sphinx users. | 142 | the experience for Sphinx users. |
| 143 | 143 | ||
| 144 | *** `rst-insert-list' inserts a new list or continues existing lists. | 144 | *** `rst-insert-list' inserts new list or continues existing lists. |
| 145 | 145 | ||
| 146 | *** Customization is extended, corrected and improved. | 146 | *** Extend correct and improve customization. |
| 147 | 147 | ||
| 148 | *** Negative prefix argument always works for `rst-adjust'. | 148 | *** Negative prefix argument always works for `rst-adjust'. |
| 149 | 149 | ||
| 150 | *** Window configuration is reset after displaying TOC. | 150 | *** Reset window configuration after displaying TOC. |
| 151 | 151 | ||
| 152 | *** There is a package version in `rst-version'. | 152 | *** Package version in `rst-version'. |
| 153 | 153 | ||
| 154 | ** New `derived-mode' filter for Ibuffer, bound to `/ M'. | 154 | ** New `derived-mode' filter for Ibuffer, bound to `/ M'. |
| 155 | `/ m' is now bound to filter by used-mode, which used to be bound to `/ M'. | 155 | `/ m' is now bound to filter by used-mode, which used to be bound to `/ M'. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b31cc2cef5f..80cbdef406c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2012-05-29 Stefan Merten <smerten@oekonux.de> | ||
| 2 | |||
| 3 | * textmodes/rst.el: Silence `checkdoc-ispell' errors where | ||
| 4 | possible. Fix authors. Improve comments. Improve loading of | ||
| 5 | `cl'. | ||
| 6 | |||
| 7 | (rst-mode-abbrev-table): Merge definition. | ||
| 8 | (rst-mode): Make sure `font-lock-defaults' is buffer local. | ||
| 9 | (rst-define-key, rst-deprecated-keys, rst-call-deprecated): Refactor. | ||
| 10 | |||
| 1 | 2012-05-29 Ulf Jasper <ulf.jasper@web.de> | 11 | 2012-05-29 Ulf Jasper <ulf.jasper@web.de> |
| 2 | 12 | ||
| 3 | * calendar/icalendar.el | 13 | * calendar/icalendar.el |
| @@ -791,6 +801,109 @@ | |||
| 791 | * man.el (Man-unindent): Use text-property-default-nonsticky to | 801 | * man.el (Man-unindent): Use text-property-default-nonsticky to |
| 792 | prevent untabify from inheriting face properties (Bug#11408). | 802 | prevent untabify from inheriting face properties (Bug#11408). |
| 793 | 803 | ||
| 804 | 2012-05-05 Stefan Merten <smerten@oekonux.de> | ||
| 805 | |||
| 806 | * textmodes/rst.el: Major merge with upstream development up to | ||
| 807 | Docutils SVN r7399 / rst.el V1.2.1. | ||
| 808 | |||
| 809 | Clarify maintainership and authors. | ||
| 810 | |||
| 811 | (rst-extract-version, rst-cvs-header, rst-cvs-rev) | ||
| 812 | (rst-cvs-timestamp, rst-svn-rev, rst-svn-timestamp) | ||
| 813 | (rst-official-version, rst-official-cvs-rev, rst-version) | ||
| 814 | (rst-package-emacs-version-alist): New functions and variables | ||
| 815 | for version information. | ||
| 816 | |||
| 817 | (rst-bullets, rst-uri-schemes, rst-adornment-chars) | ||
| 818 | (rst-max-inline-length, rst-re-alist-def, rst-re-alist) | ||
| 819 | (rst-mode-syntax-table, rst-mode): New and corrected functions | ||
| 820 | and variables representing reStructuredText features. | ||
| 821 | |||
| 822 | (rst-re): New function for reStructuredText regexes. Use in | ||
| 823 | many places. | ||
| 824 | |||
| 825 | (rst-deprecated-keys, rst-call-deprecated, rst-define-key) | ||
| 826 | (rst-mode-map): Rebind keys. | ||
| 827 | |||
| 828 | (rst-mode-lazy, rst-font-lock-keywords) | ||
| 829 | (rst-font-lock-extend-region) | ||
| 830 | (rst-font-lock-extend-region-internal) | ||
| 831 | (rst-font-lock-extend-region-extend) | ||
| 832 | (rst-font-lock-find-unindented-line-limit) | ||
| 833 | (rst-font-lock-find-unindented-line-match) | ||
| 834 | (rst-adornment-level, rst-font-lock-adornment-level) | ||
| 835 | (rst-font-lock-adornment-match) | ||
| 836 | (rst-font-lock-handle-adornment-pre-match-form) | ||
| 837 | (rst-font-lock-handle-adornment-matcher): Major revision of | ||
| 838 | font-locking. Integrate with other code. Use `jit-lock-mode'. | ||
| 839 | |||
| 840 | (rst-preferred-adornments, rst-adjust-hook) | ||
| 841 | (rst-new-adornment-down, rst-preferred-bullets) | ||
| 842 | (rst-preferred-bullets, rst-indent, rst-indent-width) | ||
| 843 | (rst-indent-field, rst-indent-literal-normal) | ||
| 844 | (rst-indent-literal-minimized, rst-indent-comment): Change, | ||
| 845 | extend and improve customization. | ||
| 846 | |||
| 847 | (rst-line-homogeneous-p, rst-line-homogeneous-nodent-p) | ||
| 848 | (rst-normalize-cursor-position, rst-get-decoration) | ||
| 849 | (rst-straighten-deco-spacing, rst-re-bullets, rst-re-items) | ||
| 850 | (rst-rstrip, rst-toc-insert-find-delete-contents) | ||
| 851 | (rst-shift-fill-region, rst-compute-bullet-tabs) | ||
| 852 | (rst-debug-print-tabs, rst-debug-mark-found) | ||
| 853 | (rst-shift-region-guts, rst-shift-region-right) | ||
| 854 | (rst-shift-region-left, rst-use-char-classes) | ||
| 855 | (rst-font-lock-keywords-function) | ||
| 856 | (rst-font-lock-indentation-point) | ||
| 857 | (rst-font-lock-find-unindented-line-begin) | ||
| 858 | (rst-font-lock-find-unindented-line-end) | ||
| 859 | (rst-font-lock-find-unindented-line) | ||
| 860 | (rst-font-lock-adornment-point, rst-font-lock-level) | ||
| 861 | (rst-adornment-level-alist): Remove functions and variables. | ||
| 862 | |||
| 863 | (rst-compare-adornments, rst-get-adornment-match) | ||
| 864 | (rst-suggest-new-adornment, rst-get-adornments-around) | ||
| 865 | (rst-adornment-complete-p, rst-get-next-adornment) | ||
| 866 | (rst-adjust-adornment, rst-display-adornments-hierarchy) | ||
| 867 | (rst-straighten-adornments): Standardize function names to | ||
| 868 | use "adornment" instead of "decoration". Correct callers. | ||
| 869 | Similar standardizing in many places. | ||
| 870 | |||
| 871 | (rst-update-section, rst-adjust, rst-promote-region) | ||
| 872 | (rst-enumerate-region, rst-bullet-list-region) | ||
| 873 | (rst-repeat-last-character): Correct use of `interactive'. | ||
| 874 | |||
| 875 | (rst-classify-adornment, rst-find-all-adornments) | ||
| 876 | (rst-get-hierarchy, rst-adjust-adornment, rst-toc-update) | ||
| 877 | (rst-find-leftmost-column, rst-repeat-last-character): | ||
| 878 | Refactor functions. | ||
| 879 | |||
| 880 | (rst-find-title-line, rst-reset-section-caches) | ||
| 881 | (rst-get-adornments-around, rst-adjust-adornment-work) | ||
| 882 | (rst-arabic-to-roman, rst-roman-to-arabic) | ||
| 883 | (rst-insert-list-pos, rst-insert-list-new-item) | ||
| 884 | (rst-insert-list-continue, rst-insert-list, rst-forward-line): | ||
| 885 | New functions. | ||
| 886 | |||
| 887 | (rst-all-sections, rst-section-hierarchy) | ||
| 888 | (rst-arabic-to-roman, rst-initial-enums, rst-initial-items): | ||
| 889 | New variables. | ||
| 890 | |||
| 891 | (rst-toc-return-wincfg, rst-toc-quit-window): Use window | ||
| 892 | configuration instead of only buffer. Change where necessary. | ||
| 893 | |||
| 894 | (rst-line-tabs, rst-compute-tabs, rst-indent-line) | ||
| 895 | (rst-shift-region, rst-adaptive-fill): New functions for | ||
| 896 | indentation and filling. | ||
| 897 | |||
| 898 | (rst-comment-line-break, rst-comment-indent) | ||
| 899 | (rst-comment-insert-comment, rst-comment-region) | ||
| 900 | (rst-uncomment-region): New functions for handling comments. | ||
| 901 | |||
| 902 | (rst-compile): Quote shell arguments. | ||
| 903 | |||
| 904 | (rst-compile-pdf-preview, rst-compile-slides-preview): | ||
| 905 | Delete temporary files after use. | ||
| 906 | |||
| 794 | 2012-05-05 Glenn Morris <rgm@gnu.org> | 907 | 2012-05-05 Glenn Morris <rgm@gnu.org> |
| 795 | 908 | ||
| 796 | * calendar/cal-html.el: Optionally include holidays in the output. | 909 | * calendar/cal-html.el: Optionally include holidays in the output. |
diff --git a/lisp/textmodes/rst.el b/lisp/textmodes/rst.el index c7da1fb5f80..e31ab4a974b 100644 --- a/lisp/textmodes/rst.el +++ b/lisp/textmodes/rst.el | |||
| @@ -3,7 +3,8 @@ | |||
| 3 | ;; Copyright (C) 2003-2012 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2003-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Maintainer: Stefan Merten <smerten@oekonux.de> | 5 | ;; Maintainer: Stefan Merten <smerten@oekonux.de> |
| 6 | ;; Author: Martin Blais <blais@furius.ca>, | 6 | ;; Author: Stefan Merten <smerten@oekonux.de>, |
| 7 | ;; Martin Blais <blais@furius.ca>, | ||
| 7 | ;; David Goodger <goodger@python.org>, | 8 | ;; David Goodger <goodger@python.org>, |
| 8 | ;; Wei-Wei Guo <wwguocn@gmail.com> | 9 | ;; Wei-Wei Guo <wwguocn@gmail.com> |
| 9 | 10 | ||
| @@ -25,10 +26,10 @@ | |||
| 25 | ;;; Commentary: | 26 | ;;; Commentary: |
| 26 | 27 | ||
| 27 | ;; This package provides major mode rst-mode, which supports documents marked | 28 | ;; This package provides major mode rst-mode, which supports documents marked |
| 28 | ;; up using the reStructuredText format. Support includes font locking as well | 29 | ;; up using the reStructuredText format. Support includes font locking as well |
| 29 | ;; as a lot of convenience functions for editing. It does this by defining a | 30 | ;; as a lot of convenience functions for editing. It does this by defining a |
| 30 | ;; Emacs major mode: rst-mode (ReST). This mode is derived from text-mode. This | 31 | ;; Emacs major mode: rst-mode (ReST). This mode is derived from text-mode. |
| 31 | ;; package also contains: | 32 | ;; This package also contains: |
| 32 | ;; | 33 | ;; |
| 33 | ;; - Functions to automatically adjust and cycle the section underline | 34 | ;; - Functions to automatically adjust and cycle the section underline |
| 34 | ;; adornments; | 35 | ;; adornments; |
| @@ -53,12 +54,12 @@ | |||
| 53 | ;; http://docutils.sourceforge.net/docs/user/emacs.html | 54 | ;; http://docutils.sourceforge.net/docs/user/emacs.html |
| 54 | ;; | 55 | ;; |
| 55 | ;; | 56 | ;; |
| 56 | ;; There are a number of convenient keybindings provided by rst-mode. | 57 | ;; There are a number of convenient key bindings provided by rst-mode. |
| 57 | ;; For more on bindings, see rst-mode-map below. There are also many variables | 58 | ;; For more on bindings, see rst-mode-map below. There are also many variables |
| 58 | ;; that can be customized, look for defcustom in this file. | 59 | ;; that can be customized, look for defcustom in this file. |
| 59 | ;; | 60 | ;; |
| 60 | ;; If you use the table-of-contents feature, you may want to add a hook to | 61 | ;; If you use the table-of-contents feature, you may want to add a hook to |
| 61 | ;; update the TOC automatically everytime you adjust a section title:: | 62 | ;; update the TOC automatically every time you adjust a section title:: |
| 62 | ;; | 63 | ;; |
| 63 | ;; (add-hook 'rst-adjust-hook 'rst-toc-update) | 64 | ;; (add-hook 'rst-adjust-hook 'rst-toc-update) |
| 64 | ;; | 65 | ;; |
| @@ -70,7 +71,7 @@ | |||
| 70 | ;; | 71 | ;; |
| 71 | ;; | 72 | ;; |
| 72 | ;; Customization is done by customizable variables contained in customization | 73 | ;; Customization is done by customizable variables contained in customization |
| 73 | ;; group "rst" and subgroups. Group "rst" is contained in the "wp" group. | 74 | ;; group "rst" and subgroups. Group "rst" is contained in the "wp" group. |
| 74 | ;; | 75 | ;; |
| 75 | 76 | ||
| 76 | ;;; DOWNLOAD | 77 | ;;; DOWNLOAD |
| @@ -95,21 +96,23 @@ | |||
| 95 | ;; want automatically enter rst-mode from any file with compatible extensions: | 96 | ;; want automatically enter rst-mode from any file with compatible extensions: |
| 96 | ;; | 97 | ;; |
| 97 | ;; (setq auto-mode-alist | 98 | ;; (setq auto-mode-alist |
| 98 | ;; (append '(("\\.txt$" . rst-mode) | 99 | ;; (append '(("\\.txt\\'" . rst-mode) |
| 99 | ;; ("\\.rst$" . rst-mode) | 100 | ;; ("\\.rst\\'" . rst-mode) |
| 100 | ;; ("\\.rest$" . rst-mode)) auto-mode-alist)) | 101 | ;; ("\\.rest\\'" . rst-mode)) auto-mode-alist)) |
| 101 | ;; | 102 | ;; |
| 102 | 103 | ||
| 103 | ;;; Code: | 104 | ;;; Code: |
| 104 | 105 | ||
| 105 | (require 'cl) | 106 | (eval-when-compile |
| 107 | (require 'cl)) | ||
| 106 | 108 | ||
| 107 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 109 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 108 | ;; Versions | 110 | ;; Versions |
| 109 | 111 | ||
| 110 | (defun rst-extract-version (delim-re head-re re tail-re var &optional default) | 112 | (defun rst-extract-version (delim-re head-re re tail-re var &optional default) |
| 111 | "Return the version matching RE after regex DELIM-RE and HEAD-RE | 113 | "Extract the version from a variable according to the given regexes. |
| 112 | and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match" | 114 | Return the version after regex DELIM-RE and HEAD-RE matching RE |
| 115 | and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match." | ||
| 113 | (if (string-match | 116 | (if (string-match |
| 114 | (concat delim-re head-re "\\(" re "\\)" tail-re delim-re) | 117 | (concat delim-re head-re "\\(" re "\\)" tail-re delim-re) |
| 115 | var) | 118 | var) |
| @@ -117,20 +120,20 @@ and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match" | |||
| 117 | default)) | 120 | default)) |
| 118 | 121 | ||
| 119 | ;; Use CVSHeader to really get information from CVS and not other version | 122 | ;; Use CVSHeader to really get information from CVS and not other version |
| 120 | ;; control systems | 123 | ;; control systems. |
| 121 | (defconst rst-cvs-header | 124 | (defconst rst-cvs-header |
| 122 | "$CVSHeader: sm/rst_el/rst.el,v 1.257 2012-04-29 15:01:17 stefan Exp $") | 125 | "$CVSHeader: sm/rst_el/rst.el,v 1.257.2.9 2012-05-29 19:53:00 stefan Exp $") |
| 123 | (defconst rst-cvs-rev | 126 | (defconst rst-cvs-rev |
| 124 | (rst-extract-version "\\$" "CVSHeader: \\S + " "[0-9]+\\(?:\\.[0-9]+\\)+" | 127 | (rst-extract-version "\\$" "CVSHeader: \\S + " "[0-9]+\\(?:\\.[0-9]+\\)+" |
| 125 | " .*" rst-cvs-header "0.0") | 128 | " .*" rst-cvs-header "0.0") |
| 126 | "The CVS revision of this file. CVS revision is the development revision.") | 129 | "The CVS revision of this file. CVS revision is the development revision.") |
| 127 | (defconst rst-cvs-timestamp | 130 | (defconst rst-cvs-timestamp |
| 128 | (rst-extract-version "\\$" "CVSHeader: \\S + \\S + " | 131 | (rst-extract-version "\\$" "CVSHeader: \\S + \\S + " |
| 129 | "[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+" " .*" | 132 | "[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+" " .*" |
| 130 | rst-cvs-header "1970-01-01 00:00:00") | 133 | rst-cvs-header "1970-01-01 00:00:00") |
| 131 | "The CVS timestamp of this file.") | 134 | "The CVS time stamp of this file.") |
| 132 | 135 | ||
| 133 | ;; Use LastChanged... to really get information from SVN | 136 | ;; Use LastChanged... to really get information from SVN. |
| 134 | (defconst rst-svn-rev | 137 | (defconst rst-svn-rev |
| 135 | (rst-extract-version "\\$" "LastChangedRevision: " "[0-9]+" " " | 138 | (rst-extract-version "\\$" "LastChangedRevision: " "[0-9]+" " " |
| 136 | "$LastChangedRevision: 7399 $") | 139 | "$LastChangedRevision: 7399 $") |
| @@ -139,9 +142,9 @@ SVN revision is the upstream (docutils) revision.") | |||
| 139 | (defconst rst-svn-timestamp | 142 | (defconst rst-svn-timestamp |
| 140 | (rst-extract-version "\\$" "LastChangedDate: " ".+?+" " " | 143 | (rst-extract-version "\\$" "LastChangedDate: " ".+?+" " " |
| 141 | "$LastChangedDate: 2012-04-29 17:01:05 +0200 (Sun, 29 Apr 2012) $") | 144 | "$LastChangedDate: 2012-04-29 17:01:05 +0200 (Sun, 29 Apr 2012) $") |
| 142 | "The SVN timestamp of this file.") | 145 | "The SVN time stamp of this file.") |
| 143 | 146 | ||
| 144 | ;; Maintained by the release process | 147 | ;; Maintained by the release process. |
| 145 | (defconst rst-official-version | 148 | (defconst rst-official-version |
| 146 | (rst-extract-version "%" "OfficialVersion: " "[0-9]+\\(?:\\.[0-9]+\\)+" " " | 149 | (rst-extract-version "%" "OfficialVersion: " "[0-9]+\\(?:\\.[0-9]+\\)+" " " |
| 147 | "%OfficialVersion: 1.2.1 %") | 150 | "%OfficialVersion: 1.2.1 %") |
| @@ -157,8 +160,8 @@ SVN revision is the upstream (docutils) revision.") | |||
| 157 | (format "%s (development %s [%s])" rst-official-version | 160 | (format "%s (development %s [%s])" rst-official-version |
| 158 | rst-cvs-rev rst-cvs-timestamp)) | 161 | rst-cvs-rev rst-cvs-timestamp)) |
| 159 | "The version string. | 162 | "The version string. |
| 160 | Starts with the current official version. For developer versions | 163 | Starts with the current official version. For developer versions |
| 161 | in parentheses follows the development revision and the timestamp.") | 164 | in parentheses follows the development revision and the time stamp.") |
| 162 | 165 | ||
| 163 | (defconst rst-package-emacs-version-alist | 166 | (defconst rst-package-emacs-version-alist |
| 164 | '(("1.0.0" . "24.0") | 167 | '(("1.0.0" . "24.0") |
| @@ -187,12 +190,12 @@ in parentheses follows the development revision and the timestamp.") | |||
| 187 | ;; Facilities for regular expressions used everywhere | 190 | ;; Facilities for regular expressions used everywhere |
| 188 | 191 | ||
| 189 | ;; The trailing numbers in the names give the number of referenceable regex | 192 | ;; The trailing numbers in the names give the number of referenceable regex |
| 190 | ;; groups contained in the regex | 193 | ;; groups contained in the regex. |
| 191 | 194 | ||
| 192 | ;; Used to be customizable but really is not customizable but fixed by the reST | 195 | ;; Used to be customizable but really is not customizable but fixed by the reST |
| 193 | ;; syntax | 196 | ;; syntax. |
| 194 | (defconst rst-bullets | 197 | (defconst rst-bullets |
| 195 | ;; Sorted so they can form a character class when concatenated | 198 | ;; Sorted so they can form a character class when concatenated. |
| 196 | '(?- ?* ?+ ?\u2022 ?\u2023 ?\u2043) | 199 | '(?- ?* ?+ ?\u2022 ?\u2023 ?\u2043) |
| 197 | "List of all possible bullet characters for bulleted lists.") | 200 | "List of all possible bullet characters for bulleted lists.") |
| 198 | 201 | ||
| @@ -203,7 +206,7 @@ in parentheses follows the development revision and the timestamp.") | |||
| 203 | "Supported URI schemes.") | 206 | "Supported URI schemes.") |
| 204 | 207 | ||
| 205 | (defconst rst-adornment-chars | 208 | (defconst rst-adornment-chars |
| 206 | ;; Sorted so they can form a character class when concatenated | 209 | ;; Sorted so they can form a character class when concatenated. |
| 207 | '(?\] | 210 | '(?\] |
| 208 | ?! ?\" ?# ?$ ?% ?& ?' ?\( ?\) ?* ?+ ?, ?. ?/ ?: ?\; ?< ?= ?> ?? ?@ ?\[ ?\\ | 211 | ?! ?\" ?# ?$ ?% ?& ?' ?\( ?\) ?* ?+ ?, ?. ?/ ?: ?\; ?< ?= ?> ?? ?@ ?\[ ?\\ |
| 209 | ?^ ?_ ?` ?{ ?| ?} ?~ | 212 | ?^ ?_ ?` ?{ ?| ?} ?~ |
| @@ -215,45 +218,45 @@ in parentheses follows the development revision and the timestamp.") | |||
| 215 | "Maximum length of inline markup to recognize.") | 218 | "Maximum length of inline markup to recognize.") |
| 216 | 219 | ||
| 217 | (defconst rst-re-alist-def | 220 | (defconst rst-re-alist-def |
| 218 | ;; `*-beg' matches * at the beginning of a line | 221 | ;; `*-beg' matches * at the beginning of a line. |
| 219 | ;; `*-end' matches * at the end of a line | 222 | ;; `*-end' matches * at the end of a line. |
| 220 | ;; `*-prt' matches a part of * | 223 | ;; `*-prt' matches a part of *. |
| 221 | ;; `*-tag' matches * | 224 | ;; `*-tag' matches *. |
| 222 | ;; `*-sta' matches the start of * which may be followed by respective content | 225 | ;; `*-sta' matches the start of * which may be followed by respective content. |
| 223 | ;; `*-pfx' matches the delimiter left of * | 226 | ;; `*-pfx' matches the delimiter left of *. |
| 224 | ;; `*-sfx' matches the delimiter right of * | 227 | ;; `*-sfx' matches the delimiter right of *. |
| 225 | ;; `*-hlp' helper for * | 228 | ;; `*-hlp' helper for *. |
| 226 | ;; | 229 | ;; |
| 227 | ;; A trailing number says how many referenceable groups are contained. | 230 | ;; A trailing number says how many referenceable groups are contained. |
| 228 | `( | 231 | `( |
| 229 | 232 | ||
| 230 | ;; Horizontal white space (`hws') | 233 | ;; Horizontal white space (`hws') |
| 231 | (hws-prt "[\t ]") | 234 | (hws-prt "[\t ]") |
| 232 | (hws-tag hws-prt "*") ; Optional sequence of horizontal white space | 235 | (hws-tag hws-prt "*") ; Optional sequence of horizontal white space. |
| 233 | (hws-sta hws-prt "+") ; Mandatory sequence of horizontal white space | 236 | (hws-sta hws-prt "+") ; Mandatory sequence of horizontal white space. |
| 234 | 237 | ||
| 235 | ;; Lines (`lin') | 238 | ;; Lines (`lin') |
| 236 | (lin-beg "^" hws-tag) ; Beginning of a possibly indented line | 239 | (lin-beg "^" hws-tag) ; Beginning of a possibly indented line. |
| 237 | (lin-end hws-tag "$") ; End of a line with optional trailing white space | 240 | (lin-end hws-tag "$") ; End of a line with optional trailing white space. |
| 238 | (linemp-tag "^" hws-tag "$") ; Empty line with optional white space | 241 | (linemp-tag "^" hws-tag "$") ; Empty line with optional white space. |
| 239 | 242 | ||
| 240 | ;; Various tags and parts | 243 | ;; Various tags and parts |
| 241 | (ell-tag "\\.\\.\\.") ; Ellipsis | 244 | (ell-tag "\\.\\.\\.") ; Ellipsis |
| 242 | (bul-tag ,(concat "[" rst-bullets "]")) ; A bullet | 245 | (bul-tag ,(concat "[" rst-bullets "]")) ; A bullet. |
| 243 | (ltr-tag "[a-zA-Z]") ; A letter enumerator tag | 246 | (ltr-tag "[a-zA-Z]") ; A letter enumerator tag. |
| 244 | (num-prt "[0-9]") ; A number enumerator part | 247 | (num-prt "[0-9]") ; A number enumerator part. |
| 245 | (num-tag num-prt "+") ; A number enumerator tag | 248 | (num-tag num-prt "+") ; A number enumerator tag. |
| 246 | (rom-prt "[IVXLCDMivxlcdm]") ; A roman enumerator part | 249 | (rom-prt "[IVXLCDMivxlcdm]") ; A roman enumerator part. |
| 247 | (rom-tag rom-prt "+") ; A roman enumerator tag | 250 | (rom-tag rom-prt "+") ; A roman enumerator tag. |
| 248 | (aut-tag "#") ; An automatic enumerator tag | 251 | (aut-tag "#") ; An automatic enumerator tag. |
| 249 | (dcl-tag "::") ; Double colon | 252 | (dcl-tag "::") ; Double colon. |
| 250 | 253 | ||
| 251 | ;; Block lead in (`bli') | 254 | ;; Block lead in (`bli') |
| 252 | (bli-sfx (:alt hws-sta "$")) ; Suffix of a block lead-in with *optional* | 255 | (bli-sfx (:alt hws-sta "$")) ; Suffix of a block lead-in with *optional* |
| 253 | ; immediate content | 256 | ; immediate content. |
| 254 | 257 | ||
| 255 | ;; Various starts | 258 | ;; Various starts |
| 256 | (bul-sta bul-tag bli-sfx) ; Start of a bulleted item | 259 | (bul-sta bul-tag bli-sfx) ; Start of a bulleted item. |
| 257 | 260 | ||
| 258 | ;; Explicit markup tag (`exm') | 261 | ;; Explicit markup tag (`exm') |
| 259 | (exm-tag "\\.\\.") | 262 | (exm-tag "\\.\\.") |
| @@ -261,101 +264,101 @@ in parentheses follows the development revision and the timestamp.") | |||
| 261 | (exm-beg lin-beg exm-sta) | 264 | (exm-beg lin-beg exm-sta) |
| 262 | 265 | ||
| 263 | ;; Counters in enumerations (`cnt') | 266 | ;; Counters in enumerations (`cnt') |
| 264 | (cntany-tag (:alt ltr-tag num-tag rom-tag aut-tag)) ; An arbitrary counter | 267 | (cntany-tag (:alt ltr-tag num-tag rom-tag aut-tag)) ; An arbitrary counter. |
| 265 | (cntexp-tag (:alt ltr-tag num-tag rom-tag)) ; An arbitrary explicit counter | 268 | (cntexp-tag (:alt ltr-tag num-tag rom-tag)) ; An arbitrary explicit counter. |
| 266 | 269 | ||
| 267 | ;; Enumerator (`enm') | 270 | ;; Enumerator (`enm') |
| 268 | (enmany-tag (:alt | 271 | (enmany-tag (:alt |
| 269 | (:seq cntany-tag "\\.") | 272 | (:seq cntany-tag "\\.") |
| 270 | (:seq "(?" cntany-tag ")"))) ; An arbitrary enumerator | 273 | (:seq "(?" cntany-tag ")"))) ; An arbitrary enumerator. |
| 271 | (enmexp-tag (:alt | 274 | (enmexp-tag (:alt |
| 272 | (:seq cntexp-tag "\\.") | 275 | (:seq cntexp-tag "\\.") |
| 273 | (:seq "(?" cntexp-tag ")"))) ; An arbitrary explicit | 276 | (:seq "(?" cntexp-tag ")"))) ; An arbitrary explicit |
| 274 | ; enumerator | 277 | ; enumerator. |
| 275 | (enmaut-tag (:alt | 278 | (enmaut-tag (:alt |
| 276 | (:seq aut-tag "\\.") | 279 | (:seq aut-tag "\\.") |
| 277 | (:seq "(?" aut-tag ")"))) ; An automatic enumerator | 280 | (:seq "(?" aut-tag ")"))) ; An automatic enumerator. |
| 278 | (enmany-sta enmany-tag bli-sfx) ; An arbitrary enumerator start | 281 | (enmany-sta enmany-tag bli-sfx) ; An arbitrary enumerator start. |
| 279 | (enmexp-sta enmexp-tag bli-sfx) ; An arbitrary explicit enumerator start | 282 | (enmexp-sta enmexp-tag bli-sfx) ; An arbitrary explicit enumerator start. |
| 280 | (enmexp-beg lin-beg enmexp-sta) ; An arbitrary explicit enumerator start | 283 | (enmexp-beg lin-beg enmexp-sta) ; An arbitrary explicit enumerator start |
| 281 | ; at the beginning of a line | 284 | ; at the beginning of a line. |
| 282 | 285 | ||
| 283 | ;; Items may be enumerated or bulleted (`itm') | 286 | ;; Items may be enumerated or bulleted (`itm') |
| 284 | (itmany-tag (:alt enmany-tag bul-tag)) ; An arbitrary item tag | 287 | (itmany-tag (:alt enmany-tag bul-tag)) ; An arbitrary item tag. |
| 285 | (itmany-sta-1 (:grp itmany-tag) bli-sfx) ; An arbitrary item start, group | 288 | (itmany-sta-1 (:grp itmany-tag) bli-sfx) ; An arbitrary item start, group |
| 286 | ; is the item tag | 289 | ; is the item tag. |
| 287 | (itmany-beg-1 lin-beg itmany-sta-1) ; An arbitrary item start at the | 290 | (itmany-beg-1 lin-beg itmany-sta-1) ; An arbitrary item start at the |
| 288 | ; beginning of a line, group is the | 291 | ; beginning of a line, group is the |
| 289 | ; item tag | 292 | ; item tag. |
| 290 | 293 | ||
| 291 | ;; Inline markup (`ilm') | 294 | ;; Inline markup (`ilm') |
| 292 | (ilm-pfx (:alt "^" hws-prt "[-'\"([{<\u2018\u201c\u00ab\u2019/:]")) | 295 | (ilm-pfx (:alt "^" hws-prt "[-'\"([{<\u2018\u201c\u00ab\u2019/:]")) |
| 293 | (ilm-sfx (:alt "$" hws-prt "[]-'\")}>\u2019\u201d\u00bb/:.,;!?\\]")) | 296 | (ilm-sfx (:alt "$" hws-prt "[]-'\")}>\u2019\u201d\u00bb/:.,;!?\\]")) |
| 294 | 297 | ||
| 295 | ;; Inline markup content (`ilc') | 298 | ;; Inline markup content (`ilc') |
| 296 | (ilcsgl-tag "\\S ") ; A single non-white character | 299 | (ilcsgl-tag "\\S ") ; A single non-white character. |
| 297 | (ilcast-prt (:alt "[^*\\]" "\\\\.")) ; Part of non-asterisk content | 300 | (ilcast-prt (:alt "[^*\\]" "\\\\.")) ; Part of non-asterisk content. |
| 298 | (ilcbkq-prt (:alt "[^`\\]" "\\\\.")) ; Part of non-backquote content | 301 | (ilcbkq-prt (:alt "[^`\\]" "\\\\.")) ; Part of non-backquote content. |
| 299 | (ilcbkqdef-prt (:alt "[^`\\\n]" "\\\\.")) ; Part of non-backquote | 302 | (ilcbkqdef-prt (:alt "[^`\\\n]" "\\\\.")) ; Part of non-backquote |
| 300 | ; definition | 303 | ; definition. |
| 301 | (ilcbar-prt (:alt "[^|\\]" "\\\\.")) ; Part of non-vertical-bar content | 304 | (ilcbar-prt (:alt "[^|\\]" "\\\\.")) ; Part of non-vertical-bar content. |
| 302 | (ilcbardef-prt (:alt "[^|\\\n]" "\\\\.")) ; Part of non-vertical-bar | 305 | (ilcbardef-prt (:alt "[^|\\\n]" "\\\\.")) ; Part of non-vertical-bar |
| 303 | ; definition | 306 | ; definition. |
| 304 | (ilcast-sfx "[^\t *\\]") ; Suffix of non-asterisk content | 307 | (ilcast-sfx "[^\t *\\]") ; Suffix of non-asterisk content. |
| 305 | (ilcbkq-sfx "[^\t `\\]") ; Suffix of non-backquote content | 308 | (ilcbkq-sfx "[^\t `\\]") ; Suffix of non-backquote content. |
| 306 | (ilcbar-sfx "[^\t |\\]") ; Suffix of non-vertical-bar content | 309 | (ilcbar-sfx "[^\t |\\]") ; Suffix of non-vertical-bar content. |
| 307 | (ilcrep-hlp ,(format "\\{0,%d\\}" rst-max-inline-length)) ; Repeat count | 310 | (ilcrep-hlp ,(format "\\{0,%d\\}" rst-max-inline-length)) ; Repeat count. |
| 308 | (ilcast-tag (:alt ilcsgl-tag | 311 | (ilcast-tag (:alt ilcsgl-tag |
| 309 | (:seq ilcsgl-tag | 312 | (:seq ilcsgl-tag |
| 310 | ilcast-prt ilcrep-hlp | 313 | ilcast-prt ilcrep-hlp |
| 311 | ilcast-sfx))) ; Non-asterisk content | 314 | ilcast-sfx))) ; Non-asterisk content. |
| 312 | (ilcbkq-tag (:alt ilcsgl-tag | 315 | (ilcbkq-tag (:alt ilcsgl-tag |
| 313 | (:seq ilcsgl-tag | 316 | (:seq ilcsgl-tag |
| 314 | ilcbkq-prt ilcrep-hlp | 317 | ilcbkq-prt ilcrep-hlp |
| 315 | ilcbkq-sfx))) ; Non-backquote content | 318 | ilcbkq-sfx))) ; Non-backquote content. |
| 316 | (ilcbkqdef-tag (:alt ilcsgl-tag | 319 | (ilcbkqdef-tag (:alt ilcsgl-tag |
| 317 | (:seq ilcsgl-tag | 320 | (:seq ilcsgl-tag |
| 318 | ilcbkqdef-prt ilcrep-hlp | 321 | ilcbkqdef-prt ilcrep-hlp |
| 319 | ilcbkq-sfx))) ; Non-backquote definition | 322 | ilcbkq-sfx))) ; Non-backquote definition. |
| 320 | (ilcbar-tag (:alt ilcsgl-tag | 323 | (ilcbar-tag (:alt ilcsgl-tag |
| 321 | (:seq ilcsgl-tag | 324 | (:seq ilcsgl-tag |
| 322 | ilcbar-prt ilcrep-hlp | 325 | ilcbar-prt ilcrep-hlp |
| 323 | ilcbar-sfx))) ; Non-vertical-bar content | 326 | ilcbar-sfx))) ; Non-vertical-bar content. |
| 324 | (ilcbardef-tag (:alt ilcsgl-tag | 327 | (ilcbardef-tag (:alt ilcsgl-tag |
| 325 | (:seq ilcsgl-tag | 328 | (:seq ilcsgl-tag |
| 326 | ilcbardef-prt ilcrep-hlp | 329 | ilcbardef-prt ilcrep-hlp |
| 327 | ilcbar-sfx))) ; Non-vertical-bar definition | 330 | ilcbar-sfx))) ; Non-vertical-bar definition. |
| 328 | 331 | ||
| 329 | ;; Fields (`fld') | 332 | ;; Fields (`fld') |
| 330 | (fldnam-prt (:alt "[^:\n]" "\\\\:")) ; Part of a field name | 333 | (fldnam-prt (:alt "[^:\n]" "\\\\:")) ; Part of a field name. |
| 331 | (fldnam-tag fldnam-prt "+") ; A field name | 334 | (fldnam-tag fldnam-prt "+") ; A field name. |
| 332 | (fld-tag ":" fldnam-tag ":") ; A field marker | 335 | (fld-tag ":" fldnam-tag ":") ; A field marker. |
| 333 | 336 | ||
| 334 | ;; Options (`opt') | 337 | ;; Options (`opt') |
| 335 | (optsta-tag (:alt "[-+/]" "--")) ; Start of an option | 338 | (optsta-tag (:alt "[-+/]" "--")) ; Start of an option. |
| 336 | (optnam-tag "\\sw" (:alt "-" "\\sw") "*") ; Name of an option | 339 | (optnam-tag "\\sw" (:alt "-" "\\sw") "*") ; Name of an option. |
| 337 | (optarg-tag (:shy "[ =]\\S +")) ; Option argument | 340 | (optarg-tag (:shy "[ =]\\S +")) ; Option argument. |
| 338 | (optsep-tag (:shy "," hws-prt)) ; Separator between options | 341 | (optsep-tag (:shy "," hws-prt)) ; Separator between options. |
| 339 | (opt-tag (:shy optsta-tag optnam-tag optarg-tag "?")) ; A complete option | 342 | (opt-tag (:shy optsta-tag optnam-tag optarg-tag "?")) ; A complete option. |
| 340 | 343 | ||
| 341 | ;; Footnotes and citations (`fnc') | 344 | ;; Footnotes and citations (`fnc') |
| 342 | (fncnam-prt "[^\]\n]") ; Part of a footnote or citation name | 345 | (fncnam-prt "[^\]\n]") ; Part of a footnote or citation name. |
| 343 | (fncnam-tag fncnam-prt "+") ; A footnote or citation name | 346 | (fncnam-tag fncnam-prt "+") ; A footnote or citation name. |
| 344 | (fnc-tag "\\[" fncnam-tag "]") ; A complete footnote or citation tag | 347 | (fnc-tag "\\[" fncnam-tag "]") ; A complete footnote or citation tag. |
| 345 | (fncdef-tag-2 (:grp exm-sta) | 348 | (fncdef-tag-2 (:grp exm-sta) |
| 346 | (:grp fnc-tag)) ; A complete footnote or citation definition | 349 | (:grp fnc-tag)) ; A complete footnote or citation definition |
| 347 | ; tag; first group is the explicit markup | 350 | ; tag. First group is the explicit markup |
| 348 | ; start, second group is the footnote / | 351 | ; start, second group is the footnote / |
| 349 | ; citation tag | 352 | ; citation tag. |
| 350 | (fnc-sta-2 fncdef-tag-2 bli-sfx) ; Start of a footnote or citation | 353 | (fnc-sta-2 fncdef-tag-2 bli-sfx) ; Start of a footnote or citation |
| 351 | ; definition; first group is the explicit | 354 | ; definition. First group is the explicit |
| 352 | ; markup start, second group is the | 355 | ; markup start, second group is the |
| 353 | ; footnote / citation tag | 356 | ; footnote / citation tag. |
| 354 | 357 | ||
| 355 | ;; Substitutions (`sub') | 358 | ;; Substitutions (`sub') |
| 356 | (sub-tag "|" ilcbar-tag "|") ; A complete substitution tag | 359 | (sub-tag "|" ilcbar-tag "|") ; A complete substitution tag. |
| 357 | (subdef-tag "|" ilcbardef-tag "|") ; A complete substitution definition | 360 | (subdef-tag "|" ilcbardef-tag "|") ; A complete substitution definition |
| 358 | ; tag | 361 | ; tag. |
| 359 | 362 | ||
| 360 | ;; Symbol (`sym') | 363 | ;; Symbol (`sym') |
| 361 | (sym-tag (:shy "\\sw+" (:shy "\\s_\\sw+") "*")) | 364 | (sym-tag (:shy "\\sw+" (:shy "\\s_\\sw+") "*")) |
| @@ -367,62 +370,62 @@ in parentheses follows the development revision and the timestamp.") | |||
| 367 | (ado-prt "[" ,(concat rst-adornment-chars) "]") | 370 | (ado-prt "[" ,(concat rst-adornment-chars) "]") |
| 368 | (adorep3-hlp "\\{3,\\}") ; There must be at least 3 characters because | 371 | (adorep3-hlp "\\{3,\\}") ; There must be at least 3 characters because |
| 369 | ; otherwise explicit markup start would be | 372 | ; otherwise explicit markup start would be |
| 370 | ; recognized | 373 | ; recognized. |
| 371 | (adorep2-hlp "\\{2,\\}") ; As `adorep3-hlp' but when the first of three | 374 | (adorep2-hlp "\\{2,\\}") ; As `adorep3-hlp' but when the first of three |
| 372 | ; characters is matched differently | 375 | ; characters is matched differently. |
| 373 | (ado-tag-1-1 (:grp ado-prt) | 376 | (ado-tag-1-1 (:grp ado-prt) |
| 374 | "\\1" adorep2-hlp) ; A complete adornment, group is the first | 377 | "\\1" adorep2-hlp) ; A complete adornment, group is the first |
| 375 | ; adornment character and MUST be the FIRST | 378 | ; adornment character and MUST be the FIRST |
| 376 | ; group in the whole expression | 379 | ; group in the whole expression. |
| 377 | (ado-tag-1-2 (:grp ado-prt) | 380 | (ado-tag-1-2 (:grp ado-prt) |
| 378 | "\\2" adorep2-hlp) ; A complete adornment, group is the first | 381 | "\\2" adorep2-hlp) ; A complete adornment, group is the first |
| 379 | ; adornment character and MUST be the | 382 | ; adornment character and MUST be the |
| 380 | ; SECOND group in the whole expression | 383 | ; SECOND group in the whole expression. |
| 381 | (ado-beg-2-1 "^" (:grp ado-tag-1-2) | 384 | (ado-beg-2-1 "^" (:grp ado-tag-1-2) |
| 382 | lin-end) ; A complete adornment line; first group is the whole | 385 | lin-end) ; A complete adornment line; first group is the whole |
| 383 | ; adornment and MUST be the FIRST group in the whole | 386 | ; adornment and MUST be the FIRST group in the whole |
| 384 | ; expression; second group is the first adornment | 387 | ; expression; second group is the first adornment |
| 385 | ; character | 388 | ; character. |
| 386 | 389 | ||
| 387 | ;; Titles (`ttl') | 390 | ;; Titles (`ttl') |
| 388 | (ttl-tag "\\S *\\w\\S *") ; A title text | 391 | (ttl-tag "\\S *\\w\\S *") ; A title text. |
| 389 | (ttl-beg lin-beg ttl-tag) ; A title text at the beginning of a line | 392 | (ttl-beg lin-beg ttl-tag) ; A title text at the beginning of a line. |
| 390 | 393 | ||
| 391 | ;; Directives and substitution definitions (`dir') | 394 | ;; Directives and substitution definitions (`dir') |
| 392 | (dir-tag-3 (:grp exm-sta) | 395 | (dir-tag-3 (:grp exm-sta) |
| 393 | (:grp (:shy subdef-tag hws-sta) "?") | 396 | (:grp (:shy subdef-tag hws-sta) "?") |
| 394 | (:grp sym-tag dcl-tag)) ; A directive or substitution definition | 397 | (:grp sym-tag dcl-tag)) ; A directive or substitution definition |
| 395 | ; tag; first group is explicit markup | 398 | ; tag. First group is explicit markup |
| 396 | ; start, second group is a possibly | 399 | ; start, second group is a possibly |
| 397 | ; empty substitution tag, third group is | 400 | ; empty substitution tag, third group is |
| 398 | ; the directive tag including the double | 401 | ; the directive tag including the double |
| 399 | ; colon | 402 | ; colon. |
| 400 | (dir-sta-3 dir-tag-3 bli-sfx) ; Start of a directive or substitution | 403 | (dir-sta-3 dir-tag-3 bli-sfx) ; Start of a directive or substitution |
| 401 | ; definition; groups are as in dir-tag-3 | 404 | ; definition. Groups are as in dir-tag-3. |
| 402 | 405 | ||
| 403 | ;; Literal block (`lit') | 406 | ;; Literal block (`lit') |
| 404 | (lit-sta-2 (:grp (:alt "[^.\n]" "\\.[^.\n]") ".*") "?" | 407 | (lit-sta-2 (:grp (:alt "[^.\n]" "\\.[^.\n]") ".*") "?" |
| 405 | (:grp dcl-tag) "$") ; Start of a literal block; first group is | 408 | (:grp dcl-tag) "$") ; Start of a literal block. First group is |
| 406 | ; any text before the double colon tag which | 409 | ; any text before the double colon tag which |
| 407 | ; may not exist, second group is the double | 410 | ; may not exist, second group is the double |
| 408 | ; colon tag | 411 | ; colon tag. |
| 409 | 412 | ||
| 410 | ;; Comments (`cmt') | 413 | ;; Comments (`cmt') |
| 411 | (cmt-sta-1 (:grp exm-sta) "[^\[|_\n]" | 414 | (cmt-sta-1 (:grp exm-sta) "[^\[|_\n]" |
| 412 | (:alt "[^:\n]" (:seq ":" (:alt "[^:\n]" "$"))) | 415 | (:alt "[^:\n]" (:seq ":" (:alt "[^:\n]" "$"))) |
| 413 | "*$") ; Start of a comment block; first group is explicit markup | 416 | "*$") ; Start of a comment block; first group is explicit markup |
| 414 | ; start | 417 | ; start. |
| 415 | 418 | ||
| 416 | ;; Paragraphs (`par') | 419 | ;; Paragraphs (`par') |
| 417 | (par-tag- (:alt itmany-tag fld-tag opt-tag fncdef-tag-2 dir-tag-3 exm-tag) | 420 | (par-tag- (:alt itmany-tag fld-tag opt-tag fncdef-tag-2 dir-tag-3 exm-tag) |
| 418 | ) ; Tag at the beginning of a paragraph; there may be groups in | 421 | ) ; Tag at the beginning of a paragraph; there may be groups in |
| 419 | ; certain cases | 422 | ; certain cases. |
| 420 | ) | 423 | ) |
| 421 | "Definition alist of relevant regexes. | 424 | "Definition alist of relevant regexes. |
| 422 | Each entry consists of the symbol naming the regex and an | 425 | Each entry consists of the symbol naming the regex and an |
| 423 | argument list for `rst-re'.") | 426 | argument list for `rst-re'.") |
| 424 | 427 | ||
| 425 | ;; FIXME: Use `sregex` or `rx` instead of re-inventing the wheel | 428 | ;; FIXME: Use `sregex` or `rx` instead of re-inventing the wheel. |
| 426 | (defun rst-re (&rest args) | 429 | (defun rst-re (&rest args) |
| 427 | "Interpret ARGS as regular expressions and return a regex string. | 430 | "Interpret ARGS as regular expressions and return a regex string. |
| 428 | Each element of ARGS may be one of the following: | 431 | Each element of ARGS may be one of the following: |
| @@ -433,8 +436,8 @@ A character which is resolved to a quoted regex. | |||
| 433 | 436 | ||
| 434 | A symbol which is resolved to a string using `rst-re-alist-def'. | 437 | A symbol which is resolved to a string using `rst-re-alist-def'. |
| 435 | 438 | ||
| 436 | A list with a keyword in the car. Each element of the cdr of such | 439 | A list with a keyword in the car. Each element of the cdr of such |
| 437 | a list is recursively interpreted as ARGS. The results of this | 440 | a list is recursively interpreted as ARGS. The results of this |
| 438 | interpretation are concatenated according to the keyword. | 441 | interpretation are concatenated according to the keyword. |
| 439 | 442 | ||
| 440 | For the keyword `:seq' the results are simply concatenated. | 443 | For the keyword `:seq' the results are simply concatenated. |
| @@ -446,11 +449,10 @@ For the keyword `:alt' the results form an alternative (\"\\|\") | |||
| 446 | which is shy-grouped (\"\\(?:...\\)\"). | 449 | which is shy-grouped (\"\\(?:...\\)\"). |
| 447 | 450 | ||
| 448 | For the keyword `:grp' the results are concatenated and form a | 451 | For the keyword `:grp' the results are concatenated and form a |
| 449 | referenceable grouped (\"\\(...\\)\"). | 452 | referenceable group (\"\\(...\\)\"). |
| 450 | 453 | ||
| 451 | After interpretation of ARGS the results are concatenated as for | 454 | After interpretation of ARGS the results are concatenated as for |
| 452 | `:seq'. | 455 | `:seq'." |
| 453 | " | ||
| 454 | (apply 'concat | 456 | (apply 'concat |
| 455 | (mapcar | 457 | (mapcar |
| 456 | (lambda (re) | 458 | (lambda (re) |
| @@ -484,7 +486,7 @@ After interpretation of ARGS the results are concatenated as for | |||
| 484 | ;; FIXME: Remove circular dependency between `rst-re' and `rst-re-alist'. | 486 | ;; FIXME: Remove circular dependency between `rst-re' and `rst-re-alist'. |
| 485 | (defconst rst-re-alist | 487 | (defconst rst-re-alist |
| 486 | ;; Shadow global value we are just defining so we can construct it step by | 488 | ;; Shadow global value we are just defining so we can construct it step by |
| 487 | ;; step | 489 | ;; step. |
| 488 | (let (rst-re-alist) | 490 | (let (rst-re-alist) |
| 489 | (dolist (re rst-re-alist-def) | 491 | (dolist (re rst-re-alist-def) |
| 490 | (setq rst-re-alist | 492 | (setq rst-re-alist |
| @@ -495,96 +497,78 @@ After interpretation of ARGS the results are concatenated as for | |||
| 495 | 497 | ||
| 496 | 498 | ||
| 497 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 499 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 498 | ;; Mode definition. | 500 | ;; Mode definition |
| 499 | |||
| 500 | (defvar rst-deprecated-keys nil | ||
| 501 | "Alist mapping deprecated keys to the new key to use and the definition.") | ||
| 502 | |||
| 503 | (require 'edmacro) | ||
| 504 | |||
| 505 | (defun rst-call-deprecated () | ||
| 506 | (interactive) | ||
| 507 | (let* ((dep-key (this-command-keys-vector)) | ||
| 508 | (dep-key-s (format-kbd-macro dep-key)) | ||
| 509 | (fnd (assoc dep-key rst-deprecated-keys))) | ||
| 510 | (if (not fnd) | ||
| 511 | ;; Exact key sequence not found. Maybe a deprecated key sequence has | ||
| 512 | ;; been followed by another key. | ||
| 513 | (let* ((dep-key-pfx (butlast (append dep-key nil) 1)) | ||
| 514 | (dep-key-def (vconcat dep-key-pfx '(t))) | ||
| 515 | (fnd-def (assoc dep-key-def rst-deprecated-keys))) | ||
| 516 | (if (not fnd-def) | ||
| 517 | (error "Unknown deprecated key sequence %s" dep-key-s) | ||
| 518 | ;; Don't execute the command in this case | ||
| 519 | (message "[Deprecated use of key %s; use key %s instead]" | ||
| 520 | (format-kbd-macro dep-key-pfx) | ||
| 521 | (format-kbd-macro (second fnd-def))))) | ||
| 522 | (message "[Deprecated use of key %s; use key %s instead]" | ||
| 523 | dep-key-s (format-kbd-macro (second fnd))) | ||
| 524 | (call-interactively (third fnd))))) | ||
| 525 | 501 | ||
| 526 | (defun rst-define-key (keymap key def &rest deprecated) | 502 | (defun rst-define-key (keymap key def &rest deprecated) |
| 527 | "Bind like `define-key' using DEPRECATED as deprecated key definitions. | 503 | "Bind like `define-key' but add deprecated key definitions. |
| 528 | DEPRECATED key definitions should be in vector notation. These | 504 | KEYMAP, KEY, and DEF are as in `define-key'. DEPRECATED key |
| 529 | are defined as well but give an additional message." | 505 | definitions should be in vector notation. These are defined as |
| 506 | well but give an additional message." | ||
| 530 | (define-key keymap key def) | 507 | (define-key keymap key def) |
| 531 | (dolist (dep-key deprecated) | 508 | (dolist (dep-key deprecated) |
| 532 | (push (list dep-key key def) rst-deprecated-keys) | 509 | (define-key keymap dep-key |
| 533 | (define-key keymap dep-key 'rst-call-deprecated))) | 510 | `(lambda () |
| 511 | ,(format "Deprecated binding for %s, use \\[%s] instead." def def) | ||
| 512 | (interactive) | ||
| 513 | (call-interactively ',def) | ||
| 514 | (message "[Deprecated use of key %s; use key %s instead]" | ||
| 515 | (key-description (this-command-keys)) | ||
| 516 | (key-description ,key)))))) | ||
| 534 | 517 | ||
| 535 | ;; Key bindings. | 518 | ;; Key bindings. |
| 536 | (defvar rst-mode-map | 519 | (defvar rst-mode-map |
| 537 | (let ((map (make-sparse-keymap))) | 520 | (let ((map (make-sparse-keymap))) |
| 538 | 521 | ||
| 539 | ;; \C-c is the general keymap | 522 | ;; \C-c is the general keymap. |
| 540 | (rst-define-key map [?\C-c ?\C-h] 'describe-prefix-bindings) | 523 | (rst-define-key map [?\C-c ?\C-h] 'describe-prefix-bindings) |
| 541 | 524 | ||
| 542 | ;; | 525 | ;; |
| 543 | ;; Section Adornments. | 526 | ;; Section Adornments |
| 544 | ;; | 527 | ;; |
| 545 | ;; The adjustment function that adorns or rotates a section title. | 528 | ;; The adjustment function that adorns or rotates a section title. |
| 546 | (rst-define-key map [?\C-c ?\C-=] 'rst-adjust [?\C-c ?\C-a t]) | 529 | (rst-define-key map [?\C-c ?\C-=] 'rst-adjust [?\C-c ?\C-a t]) |
| 547 | (rst-define-key map [?\C-=] 'rst-adjust) ; (Does not work on the Mac OSX.) | 530 | (rst-define-key map [?\C-=] 'rst-adjust) ; (Does not work on the Mac OSX.) |
| 548 | 531 | ||
| 549 | ;; \C-c \C-a is the keymap for adornments | 532 | ;; \C-c \C-a is the keymap for adornments. |
| 550 | (rst-define-key map [?\C-c ?\C-a ?\C-h] 'describe-prefix-bindings) | 533 | (rst-define-key map [?\C-c ?\C-a ?\C-h] 'describe-prefix-bindings) |
| 551 | ;; Display the hierarchy of adornments implied by the current document contents. | 534 | ;; Display the hierarchy of adornments implied by the current document |
| 535 | ;; contents. | ||
| 552 | (rst-define-key map [?\C-c ?\C-a ?\C-d] 'rst-display-adornments-hierarchy) | 536 | (rst-define-key map [?\C-c ?\C-a ?\C-d] 'rst-display-adornments-hierarchy) |
| 553 | ;; Homogenize the adornments in the document. | 537 | ;; Homogenize the adornments in the document. |
| 554 | (rst-define-key map [?\C-c ?\C-a ?\C-s] 'rst-straighten-adornments | 538 | (rst-define-key map [?\C-c ?\C-a ?\C-s] 'rst-straighten-adornments |
| 555 | [?\C-c ?\C-s]) | 539 | [?\C-c ?\C-s]) |
| 556 | 540 | ||
| 557 | ;; | 541 | ;; |
| 558 | ;; Section Movement and Selection. | 542 | ;; Section Movement and Selection |
| 559 | ;; | 543 | ;; |
| 560 | ;; Mark the subsection where the cursor is. | 544 | ;; Mark the subsection where the cursor is. |
| 561 | (rst-define-key map [?\C-\M-h] 'rst-mark-section | 545 | (rst-define-key map [?\C-\M-h] 'rst-mark-section |
| 562 | ;; same as mark-defun sgml-mark-current-element | 546 | ;; Same as mark-defun sgml-mark-current-element. |
| 563 | [?\C-c ?\C-m]) | 547 | [?\C-c ?\C-m]) |
| 564 | ;; Move forward/backward between section titles. | 548 | ;; Move forward/backward between section titles. |
| 565 | (rst-define-key map [?\C-\M-a] 'rst-forward-section | 549 | (rst-define-key map [?\C-\M-a] 'rst-forward-section |
| 566 | ;; same as beginning-of-defun | 550 | ;; Same as beginning-of-defun. |
| 567 | [?\C-c ?\C-n]) | 551 | [?\C-c ?\C-n]) |
| 568 | (rst-define-key map [?\C-\M-e] 'rst-backward-section | 552 | (rst-define-key map [?\C-\M-e] 'rst-backward-section |
| 569 | ;; same as end-of-defun | 553 | ;; Same as end-of-defun. |
| 570 | [?\C-c ?\C-p]) | 554 | [?\C-c ?\C-p]) |
| 571 | 555 | ||
| 572 | ;; | 556 | ;; |
| 573 | ;; Operating on regions. | 557 | ;; Operating on regions |
| 574 | ;; | 558 | ;; |
| 575 | ;; \C-c \C-r is the keymap for regions | 559 | ;; \C-c \C-r is the keymap for regions. |
| 576 | (rst-define-key map [?\C-c ?\C-r ?\C-h] 'describe-prefix-bindings) | 560 | (rst-define-key map [?\C-c ?\C-r ?\C-h] 'describe-prefix-bindings) |
| 577 | ;; Makes region a line-block. | 561 | ;; Makes region a line-block. |
| 578 | (rst-define-key map [?\C-c ?\C-r ?\C-l] 'rst-line-block-region | 562 | (rst-define-key map [?\C-c ?\C-r ?\C-l] 'rst-line-block-region |
| 579 | [?\C-c ?\C-d]) | 563 | [?\C-c ?\C-d]) |
| 580 | ;; Shift region left or right according to tabs | 564 | ;; Shift region left or right according to tabs. |
| 581 | (rst-define-key map [?\C-c ?\C-r tab] 'rst-shift-region | 565 | (rst-define-key map [?\C-c ?\C-r tab] 'rst-shift-region |
| 582 | [?\C-c ?\C-r t] [?\C-c ?\C-l t]) | 566 | [?\C-c ?\C-r t] [?\C-c ?\C-l t]) |
| 583 | 567 | ||
| 584 | ;; | 568 | ;; |
| 585 | ;; Operating on lists. | 569 | ;; Operating on lists |
| 586 | ;; | 570 | ;; |
| 587 | ;; \C-c \C-l is the keymap for lists | 571 | ;; \C-c \C-l is the keymap for lists. |
| 588 | (rst-define-key map [?\C-c ?\C-l ?\C-h] 'describe-prefix-bindings) | 572 | (rst-define-key map [?\C-c ?\C-l ?\C-h] 'describe-prefix-bindings) |
| 589 | ;; Makes paragraphs in region as a bullet list. | 573 | ;; Makes paragraphs in region as a bullet list. |
| 590 | (rst-define-key map [?\C-c ?\C-l ?\C-b] 'rst-bullet-list-region | 574 | (rst-define-key map [?\C-c ?\C-l ?\C-b] 'rst-bullet-list-region |
| @@ -598,13 +582,13 @@ are defined as well but give an additional message." | |||
| 598 | ;; Make sure that all the bullets in the region are consistent. | 582 | ;; Make sure that all the bullets in the region are consistent. |
| 599 | (rst-define-key map [?\C-c ?\C-l ?\C-s] 'rst-straighten-bullets-region | 583 | (rst-define-key map [?\C-c ?\C-l ?\C-s] 'rst-straighten-bullets-region |
| 600 | [?\C-c ?\C-w]) | 584 | [?\C-c ?\C-w]) |
| 601 | ;; Insert a list item | 585 | ;; Insert a list item. |
| 602 | (rst-define-key map [?\C-c ?\C-l ?\C-i] 'rst-insert-list) | 586 | (rst-define-key map [?\C-c ?\C-l ?\C-i] 'rst-insert-list) |
| 603 | 587 | ||
| 604 | ;; | 588 | ;; |
| 605 | ;; Table-of-Contents Features. | 589 | ;; Table-of-Contents Features |
| 606 | ;; | 590 | ;; |
| 607 | ;; \C-c \C-t is the keymap for table of contents | 591 | ;; \C-c \C-t is the keymap for table of contents. |
| 608 | (rst-define-key map [?\C-c ?\C-t ?\C-h] 'describe-prefix-bindings) | 592 | (rst-define-key map [?\C-c ?\C-t ?\C-h] 'describe-prefix-bindings) |
| 609 | ;; Enter a TOC buffer to view and move to a specific section. | 593 | ;; Enter a TOC buffer to view and move to a specific section. |
| 610 | (rst-define-key map [?\C-c ?\C-t ?\C-t] 'rst-toc) | 594 | (rst-define-key map [?\C-c ?\C-t ?\C-t] 'rst-toc) |
| @@ -614,14 +598,14 @@ are defined as well but give an additional message." | |||
| 614 | ;; Update the document's TOC (without changing the cursor position). | 598 | ;; Update the document's TOC (without changing the cursor position). |
| 615 | (rst-define-key map [?\C-c ?\C-t ?\C-u] 'rst-toc-update | 599 | (rst-define-key map [?\C-c ?\C-t ?\C-u] 'rst-toc-update |
| 616 | [?\C-c ?\C-u]) | 600 | [?\C-c ?\C-u]) |
| 617 | ;; Got to the section under the cursor (cursor must be in TOC). | 601 | ;; Go to the section under the cursor (cursor must be in TOC). |
| 618 | (rst-define-key map [?\C-c ?\C-t ?\C-j] 'rst-goto-section | 602 | (rst-define-key map [?\C-c ?\C-t ?\C-j] 'rst-goto-section |
| 619 | [?\C-c ?\C-f]) | 603 | [?\C-c ?\C-f]) |
| 620 | 604 | ||
| 621 | ;; | 605 | ;; |
| 622 | ;; Converting Documents from Emacs. | 606 | ;; Converting Documents from Emacs |
| 623 | ;; | 607 | ;; |
| 624 | ;; \C-c \C-c is the keymap for compilation | 608 | ;; \C-c \C-c is the keymap for compilation. |
| 625 | (rst-define-key map [?\C-c ?\C-c ?\C-h] 'describe-prefix-bindings) | 609 | (rst-define-key map [?\C-c ?\C-c ?\C-h] 'describe-prefix-bindings) |
| 626 | ;; Run one of two pre-configured toolset commands on the document. | 610 | ;; Run one of two pre-configured toolset commands on the document. |
| 627 | (rst-define-key map [?\C-c ?\C-c ?\C-c] 'rst-compile | 611 | (rst-define-key map [?\C-c ?\C-c ?\C-c] 'rst-compile |
| @@ -644,8 +628,6 @@ This inherits from Text mode.") | |||
| 644 | 628 | ||
| 645 | 629 | ||
| 646 | ;; Abbrevs. | 630 | ;; Abbrevs. |
| 647 | (defvar rst-mode-abbrev-table nil | ||
| 648 | "Abbrev table used while in `rst-mode'.") | ||
| 649 | (define-abbrev-table 'rst-mode-abbrev-table | 631 | (define-abbrev-table 'rst-mode-abbrev-table |
| 650 | (mapcar (lambda (x) (append x '(nil 0 system))) | 632 | (mapcar (lambda (x) (append x '(nil 0 system))) |
| 651 | '(("contents" ".. contents::\n..\n ") | 633 | '(("contents" ".. contents::\n..\n ") |
| @@ -654,7 +636,8 @@ This inherits from Text mode.") | |||
| 654 | ("skip" "\n\n[...]\n\n ") | 636 | ("skip" "\n\n[...]\n\n ") |
| 655 | ("seq" "\n\n[...]\n\n ") | 637 | ("seq" "\n\n[...]\n\n ") |
| 656 | ;; FIXME: Add footnotes, links, and more. | 638 | ;; FIXME: Add footnotes, links, and more. |
| 657 | ))) | 639 | )) |
| 640 | "Abbrev table used while in `rst-mode'.") | ||
| 658 | 641 | ||
| 659 | 642 | ||
| 660 | ;; Syntax table. | 643 | ;; Syntax table. |
| @@ -711,7 +694,7 @@ highlighting. | |||
| 711 | :syntax-table rst-mode-syntax-table | 694 | :syntax-table rst-mode-syntax-table |
| 712 | :group 'rst | 695 | :group 'rst |
| 713 | 696 | ||
| 714 | ;; Paragraph recognition | 697 | ;; Paragraph recognition. |
| 715 | (set (make-local-variable 'paragraph-separate) | 698 | (set (make-local-variable 'paragraph-separate) |
| 716 | (rst-re '(:alt | 699 | (rst-re '(:alt |
| 717 | "\f" | 700 | "\f" |
| @@ -722,7 +705,7 @@ highlighting. | |||
| 722 | lin-end | 705 | lin-end |
| 723 | (:seq hws-tag par-tag- bli-sfx)))) | 706 | (:seq hws-tag par-tag- bli-sfx)))) |
| 724 | 707 | ||
| 725 | ;; Indenting and filling | 708 | ;; Indenting and filling. |
| 726 | (set (make-local-variable 'indent-line-function) 'rst-indent-line) | 709 | (set (make-local-variable 'indent-line-function) 'rst-indent-line) |
| 727 | (set (make-local-variable 'adaptive-fill-mode) t) | 710 | (set (make-local-variable 'adaptive-fill-mode) t) |
| 728 | (set (make-local-variable 'adaptive-fill-regexp) | 711 | (set (make-local-variable 'adaptive-fill-regexp) |
| @@ -730,7 +713,7 @@ highlighting. | |||
| 730 | (set (make-local-variable 'adaptive-fill-function) 'rst-adaptive-fill) | 713 | (set (make-local-variable 'adaptive-fill-function) 'rst-adaptive-fill) |
| 731 | (set (make-local-variable 'fill-paragraph-handle-comment) nil) | 714 | (set (make-local-variable 'fill-paragraph-handle-comment) nil) |
| 732 | 715 | ||
| 733 | ;; Comments | 716 | ;; Comments. |
| 734 | (set (make-local-variable 'comment-start) ".. ") | 717 | (set (make-local-variable 'comment-start) ".. ") |
| 735 | (set (make-local-variable 'comment-start-skip) | 718 | (set (make-local-variable 'comment-start-skip) |
| 736 | (rst-re 'lin-beg 'exm-tag 'bli-sfx)) | 719 | (rst-re 'lin-beg 'exm-tag 'bli-sfx)) |
| @@ -738,10 +721,12 @@ highlighting. | |||
| 738 | (set (make-local-variable 'comment-multi-line) t) | 721 | (set (make-local-variable 'comment-multi-line) t) |
| 739 | (set (make-local-variable 'comment-use-syntax) nil) | 722 | (set (make-local-variable 'comment-use-syntax) nil) |
| 740 | ;; reStructuredText has not really a comment ender but nil is not really a | 723 | ;; reStructuredText has not really a comment ender but nil is not really a |
| 741 | ;; permissible value | 724 | ;; permissible value. |
| 742 | (set (make-local-variable 'comment-end) "") | 725 | (set (make-local-variable 'comment-end) "") |
| 743 | (set (make-local-variable 'comment-end-skip) nil) | 726 | (set (make-local-variable 'comment-end-skip) nil) |
| 744 | 727 | ||
| 728 | ;; Commenting in reStructuredText is very special so use our own set of | ||
| 729 | ;; functions. | ||
| 745 | (set (make-local-variable 'comment-line-break-function) | 730 | (set (make-local-variable 'comment-line-break-function) |
| 746 | 'rst-comment-line-break) | 731 | 'rst-comment-line-break) |
| 747 | (set (make-local-variable 'comment-indent-function) | 732 | (set (make-local-variable 'comment-indent-function) |
| @@ -753,21 +738,15 @@ highlighting. | |||
| 753 | (set (make-local-variable 'uncomment-region-function) | 738 | (set (make-local-variable 'uncomment-region-function) |
| 754 | 'rst-uncomment-region) | 739 | 'rst-uncomment-region) |
| 755 | 740 | ||
| 756 | ;; Font lock | 741 | ;; Font lock. |
| 757 | (setq font-lock-defaults | 742 | (set (make-local-variable 'font-lock-defaults) |
| 758 | '(rst-font-lock-keywords | 743 | '(rst-font-lock-keywords |
| 759 | t nil nil nil | 744 | t nil nil nil |
| 760 | (font-lock-multiline . t) | 745 | (font-lock-multiline . t) |
| 761 | (font-lock-mark-block-function . mark-paragraph) | 746 | (font-lock-mark-block-function . mark-paragraph))) |
| 762 | ;; rst-mode does not need font-lock-support-mode because it's fast | ||
| 763 | ;; enough. In fact using `jit-lock-mode` slows things down | ||
| 764 | ;; considerably even if `rst-font-lock-extend-region` is in place and | ||
| 765 | ;; compiled. | ||
| 766 | ;;(font-lock-support-mode . nil) | ||
| 767 | )) | ||
| 768 | (add-hook 'font-lock-extend-region-functions 'rst-font-lock-extend-region t) | 747 | (add-hook 'font-lock-extend-region-functions 'rst-font-lock-extend-region t) |
| 769 | 748 | ||
| 770 | ;; Text after a changed line may need new fontification | 749 | ;; Text after a changed line may need new fontification. |
| 771 | (set (make-local-variable 'jit-lock-contextually) t)) | 750 | (set (make-local-variable 'jit-lock-contextually) t)) |
| 772 | 751 | ||
| 773 | ;;;###autoload | 752 | ;;;###autoload |
| @@ -789,8 +768,8 @@ for modes derived from Text mode, like Mail mode." | |||
| 789 | :group 'rst) | 768 | :group 'rst) |
| 790 | 769 | ||
| 791 | ;; FIXME: can I somehow install these too? | 770 | ;; FIXME: can I somehow install these too? |
| 792 | ;; :abbrev-table rst-mode-abbrev-table | 771 | ;; :abbrev-table rst-mode-abbrev-table |
| 793 | ;; :syntax-table rst-mode-syntax-table | 772 | ;; :syntax-table rst-mode-syntax-table |
| 794 | 773 | ||
| 795 | 774 | ||
| 796 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 775 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -883,10 +862,10 @@ for modes derived from Text mode, like Mail mode." | |||
| 883 | "Preferred hierarchy of section title adornments. | 862 | "Preferred hierarchy of section title adornments. |
| 884 | 863 | ||
| 885 | A list consisting of lists of the form (CHARACTER STYLE INDENT). | 864 | A list consisting of lists of the form (CHARACTER STYLE INDENT). |
| 886 | CHARACTER is the character used. STYLE is one of the symbols | 865 | CHARACTER is the character used. STYLE is one of the symbols |
| 887 | OVER-AND-UNDER or SIMPLE. INDENT is an integer giving the wanted | 866 | OVER-AND-UNDER or SIMPLE. INDENT is an integer giving the wanted |
| 888 | indentation for STYLE OVER-AND-UNDER. CHARACTER and STYLE are | 867 | indentation for STYLE OVER-AND-UNDER. CHARACTER and STYLE are |
| 889 | always used when a section adornment is described. In other | 868 | always used when a section adornment is described. In other |
| 890 | places t instead of a list stands for a transition. | 869 | places t instead of a list stands for a transition. |
| 891 | 870 | ||
| 892 | This sequence is consulted to offer a new adornment suggestion | 871 | This sequence is consulted to offer a new adornment suggestion |
| @@ -991,7 +970,7 @@ requested adornment." | |||
| 991 | (let ((marker (point-marker)) | 970 | (let ((marker (point-marker)) |
| 992 | len) | 971 | len) |
| 993 | 972 | ||
| 994 | ;; Fixup whitespace at the beginning and end of the line | 973 | ;; Fixup whitespace at the beginning and end of the line. |
| 995 | (if (or (null indent) (eq style 'simple)) | 974 | (if (or (null indent) (eq style 'simple)) |
| 996 | (setq indent 0)) | 975 | (setq indent 0)) |
| 997 | (beginning-of-line) | 976 | (beginning-of-line) |
| @@ -1001,10 +980,10 @@ requested adornment." | |||
| 1001 | (end-of-line) | 980 | (end-of-line) |
| 1002 | (delete-horizontal-space) | 981 | (delete-horizontal-space) |
| 1003 | 982 | ||
| 1004 | ;; Set the current column, we're at the end of the title line | 983 | ;; Set the current column, we're at the end of the title line. |
| 1005 | (setq len (+ (current-column) indent)) | 984 | (setq len (+ (current-column) indent)) |
| 1006 | 985 | ||
| 1007 | ;; Remove previous line if it is an adornment | 986 | ;; Remove previous line if it is an adornment. |
| 1008 | (save-excursion | 987 | (save-excursion |
| 1009 | (forward-line -1) | 988 | (forward-line -1) |
| 1010 | (if (and (looking-at (rst-re 'ado-beg-2-1)) | 989 | (if (and (looking-at (rst-re 'ado-beg-2-1)) |
| @@ -1013,24 +992,24 @@ requested adornment." | |||
| 1013 | (not (looking-at (rst-re 'ttl-beg))))) | 992 | (not (looking-at (rst-re 'ttl-beg))))) |
| 1014 | (rst-delete-entire-line))) | 993 | (rst-delete-entire-line))) |
| 1015 | 994 | ||
| 1016 | ;; Remove following line if it is an adornment | 995 | ;; Remove following line if it is an adornment. |
| 1017 | (save-excursion | 996 | (save-excursion |
| 1018 | (forward-line +1) | 997 | (forward-line +1) |
| 1019 | (if (looking-at (rst-re 'ado-beg-2-1)) | 998 | (if (looking-at (rst-re 'ado-beg-2-1)) |
| 1020 | (rst-delete-entire-line)) | 999 | (rst-delete-entire-line)) |
| 1021 | ;; Add a newline if we're at the end of the buffer, for the subsequence | 1000 | ;; Add a newline if we're at the end of the buffer, for the subsequence |
| 1022 | ;; inserting of the underline | 1001 | ;; inserting of the underline. |
| 1023 | (if (= (point) (buffer-end 1)) | 1002 | (if (= (point) (buffer-end 1)) |
| 1024 | (newline 1))) | 1003 | (newline 1))) |
| 1025 | 1004 | ||
| 1026 | ;; Insert overline | 1005 | ;; Insert overline. |
| 1027 | (if (eq style 'over-and-under) | 1006 | (if (eq style 'over-and-under) |
| 1028 | (save-excursion | 1007 | (save-excursion |
| 1029 | (beginning-of-line) | 1008 | (beginning-of-line) |
| 1030 | (open-line 1) | 1009 | (open-line 1) |
| 1031 | (insert (make-string len char)))) | 1010 | (insert (make-string len char)))) |
| 1032 | 1011 | ||
| 1033 | ;; Insert underline | 1012 | ;; Insert underline. |
| 1034 | (forward-line +1) | 1013 | (forward-line +1) |
| 1035 | (open-line 1) | 1014 | (open-line 1) |
| 1036 | (insert (make-string len char)) | 1015 | (insert (make-string len char)) |
| @@ -1042,17 +1021,17 @@ requested adornment." | |||
| 1042 | (defun rst-classify-adornment (adornment end) | 1021 | (defun rst-classify-adornment (adornment end) |
| 1043 | "Classify adornment for section titles and transitions. | 1022 | "Classify adornment for section titles and transitions. |
| 1044 | ADORNMENT is the complete adornment string as found in the buffer | 1023 | ADORNMENT is the complete adornment string as found in the buffer |
| 1045 | with optional trailing whitespace. END is the point after the | 1024 | with optional trailing whitespace. END is the point after the |
| 1046 | last character of ADORNMENT. | 1025 | last character of ADORNMENT. |
| 1047 | 1026 | ||
| 1048 | Return a list. The first entry is t for a transition or a | 1027 | Return a list. The first entry is t for a transition or a |
| 1049 | cons (CHARACTER . STYLE). Check `rst-preferred-adornments' for | 1028 | cons (CHARACTER . STYLE). Check `rst-preferred-adornments' for |
| 1050 | the meaning of CHARACTER and STYLE. | 1029 | the meaning of CHARACTER and STYLE. |
| 1051 | 1030 | ||
| 1052 | The remaining list forms four match groups as returned by | 1031 | The remaining list forms four match groups as returned by |
| 1053 | `match-data'. Match group 0 matches the whole construct. Match | 1032 | `match-data'. Match group 0 matches the whole construct. Match |
| 1054 | group 1 matches the overline adornment if present. Match group 2 | 1033 | group 1 matches the overline adornment if present. Match group 2 |
| 1055 | matches the section title text or the transition. Match group 3 | 1034 | matches the section title text or the transition. Match group 3 |
| 1056 | matches the underline adornment. | 1035 | matches the underline adornment. |
| 1057 | 1036 | ||
| 1058 | Return nil if no syntactically valid adornment is found." | 1037 | Return nil if no syntactically valid adornment is found." |
| @@ -1074,25 +1053,25 @@ Return nil if no syntactically valid adornment is found." | |||
| 1074 | (save-excursion | 1053 | (save-excursion |
| 1075 | (or (not (zerop (forward-line -1))) | 1054 | (or (not (zerop (forward-line -1))) |
| 1076 | (looking-at (rst-re 'lin-end))))) | 1055 | (looking-at (rst-re 'lin-end))))) |
| 1077 | (ttl-blw ; Title found below starting here | 1056 | (ttl-blw ; Title found below starting here. |
| 1078 | (save-excursion | 1057 | (save-excursion |
| 1079 | (and | 1058 | (and |
| 1080 | (zerop (forward-line 1)) | 1059 | (zerop (forward-line 1)) |
| 1081 | (looking-at (rst-re 'ttl-beg)) | 1060 | (looking-at (rst-re 'ttl-beg)) |
| 1082 | (point)))) | 1061 | (point)))) |
| 1083 | (ttl-abv ; Title found above starting here | 1062 | (ttl-abv ; Title found above starting here. |
| 1084 | (save-excursion | 1063 | (save-excursion |
| 1085 | (and | 1064 | (and |
| 1086 | (zerop (forward-line -1)) | 1065 | (zerop (forward-line -1)) |
| 1087 | (looking-at (rst-re 'ttl-beg)) | 1066 | (looking-at (rst-re 'ttl-beg)) |
| 1088 | (point)))) | 1067 | (point)))) |
| 1089 | (und-fnd ; Matching underline found starting here | 1068 | (und-fnd ; Matching underline found starting here. |
| 1090 | (save-excursion | 1069 | (save-excursion |
| 1091 | (and ttl-blw | 1070 | (and ttl-blw |
| 1092 | (zerop (forward-line 2)) | 1071 | (zerop (forward-line 2)) |
| 1093 | (looking-at (rst-re ado-re 'lin-end)) | 1072 | (looking-at (rst-re ado-re 'lin-end)) |
| 1094 | (point)))) | 1073 | (point)))) |
| 1095 | (ovr-fnd ; Matching overline found starting here | 1074 | (ovr-fnd ; Matching overline found starting here. |
| 1096 | (save-excursion | 1075 | (save-excursion |
| 1097 | (and ttl-abv | 1076 | (and ttl-abv |
| 1098 | (zerop (forward-line -2)) | 1077 | (zerop (forward-line -2)) |
| @@ -1101,14 +1080,14 @@ Return nil if no syntactically valid adornment is found." | |||
| 1101 | key beg-ovr end-ovr beg-txt end-txt beg-und end-und) | 1080 | key beg-ovr end-ovr beg-txt end-txt beg-und end-und) |
| 1102 | (cond | 1081 | (cond |
| 1103 | ((and nxt-emp prv-emp) | 1082 | ((and nxt-emp prv-emp) |
| 1104 | ;; A transition | 1083 | ;; A transition. |
| 1105 | (setq key t | 1084 | (setq key t |
| 1106 | beg-txt beg-pnt | 1085 | beg-txt beg-pnt |
| 1107 | end-txt end-pnt)) | 1086 | end-txt end-pnt)) |
| 1108 | ((or und-fnd ovr-fnd) | 1087 | ((or und-fnd ovr-fnd) |
| 1109 | ;; An overline with an underline | 1088 | ;; An overline with an underline. |
| 1110 | (setq key (cons ado-ch 'over-and-under)) | 1089 | (setq key (cons ado-ch 'over-and-under)) |
| 1111 | (let (;; Prefer overline match over underline match | 1090 | (let (;; Prefer overline match over underline match. |
| 1112 | (und-pnt (if ovr-fnd beg-pnt und-fnd)) | 1091 | (und-pnt (if ovr-fnd beg-pnt und-fnd)) |
| 1113 | (ovr-pnt (if ovr-fnd ovr-fnd beg-pnt)) | 1092 | (ovr-pnt (if ovr-fnd ovr-fnd beg-pnt)) |
| 1114 | (txt-pnt (if ovr-fnd ttl-abv ttl-blw))) | 1093 | (txt-pnt (if ovr-fnd ttl-abv ttl-blw))) |
| @@ -1122,7 +1101,7 @@ Return nil if no syntactically valid adornment is found." | |||
| 1122 | (setq beg-und (point) | 1101 | (setq beg-und (point) |
| 1123 | end-und (line-end-position)))) | 1102 | end-und (line-end-position)))) |
| 1124 | (ttl-abv | 1103 | (ttl-abv |
| 1125 | ;; An underline | 1104 | ;; An underline. |
| 1126 | (setq key (cons ado-ch 'simple) | 1105 | (setq key (cons ado-ch 'simple) |
| 1127 | beg-und beg-pnt | 1106 | beg-und beg-pnt |
| 1128 | end-und end-pnt) | 1107 | end-und end-pnt) |
| @@ -1130,7 +1109,7 @@ Return nil if no syntactically valid adornment is found." | |||
| 1130 | (setq beg-txt (point) | 1109 | (setq beg-txt (point) |
| 1131 | end-txt (line-end-position))) | 1110 | end-txt (line-end-position))) |
| 1132 | (t | 1111 | (t |
| 1133 | ;; Invalid adornment | 1112 | ;; Invalid adornment. |
| 1134 | (setq key nil))) | 1113 | (setq key nil))) |
| 1135 | (if key | 1114 | (if key |
| 1136 | (list key | 1115 | (list key |
| @@ -1141,15 +1120,15 @@ Return nil if no syntactically valid adornment is found." | |||
| 1141 | (defun rst-find-title-line () | 1120 | (defun rst-find-title-line () |
| 1142 | "Find a section title line around point and return its characteristics. | 1121 | "Find a section title line around point and return its characteristics. |
| 1143 | If the point is on an adornment line find the respective title | 1122 | If the point is on an adornment line find the respective title |
| 1144 | line. If the point is on an empty line check previous or next | 1123 | line. If the point is on an empty line check previous or next |
| 1145 | line whether it is a suitable title line and use it if so. If | 1124 | line whether it is a suitable title line and use it if so. If |
| 1146 | point is on a suitable title line use it. | 1125 | point is on a suitable title line use it. |
| 1147 | 1126 | ||
| 1148 | If no title line is found return nil. | 1127 | If no title line is found return nil. |
| 1149 | 1128 | ||
| 1150 | Otherwise return as `rst-classify-adornment' does. However, if | 1129 | Otherwise return as `rst-classify-adornment' does. However, if |
| 1151 | the title line has no syntactically valid adornment STYLE is nil | 1130 | the title line has no syntactically valid adornment STYLE is nil |
| 1152 | in the first element. If there is no adornment around the title | 1131 | in the first element. If there is no adornment around the title |
| 1153 | CHARACTER is also nil and match groups for overline and underline | 1132 | CHARACTER is also nil and match groups for overline and underline |
| 1154 | are nil." | 1133 | are nil." |
| 1155 | (save-excursion | 1134 | (save-excursion |
| @@ -1163,14 +1142,14 @@ are nil." | |||
| 1163 | (match-end 0)))) | 1142 | (match-end 0)))) |
| 1164 | (cond | 1143 | (cond |
| 1165 | ((not r) | 1144 | ((not r) |
| 1166 | ;; Invalid adornment - check whether this is an incomplete overline | 1145 | ;; Invalid adornment - check whether this is an incomplete overline. |
| 1167 | (if (and | 1146 | (if (and |
| 1168 | (zerop (forward-line 1)) | 1147 | (zerop (forward-line 1)) |
| 1169 | (looking-at (rst-re 'ttl-beg))) | 1148 | (looking-at (rst-re 'ttl-beg))) |
| 1170 | (list (cons char nil) orig-pnt (line-end-position) | 1149 | (list (cons char nil) orig-pnt (line-end-position) |
| 1171 | orig-pnt orig-end (point) (line-end-position) nil nil))) | 1150 | orig-pnt orig-end (point) (line-end-position) nil nil))) |
| 1172 | ((consp (car r)) | 1151 | ((consp (car r)) |
| 1173 | ;; A section title - not a transition | 1152 | ;; A section title - not a transition. |
| 1174 | r)))) | 1153 | r)))) |
| 1175 | ((looking-at (rst-re 'lin-end)) | 1154 | ((looking-at (rst-re 'lin-end)) |
| 1176 | (or | 1155 | (or |
| @@ -1185,14 +1164,14 @@ are nil." | |||
| 1185 | (list (cons nil nil) (point) (line-end-position) | 1164 | (list (cons nil nil) (point) (line-end-position) |
| 1186 | nil nil (point) (line-end-position) nil nil))))) | 1165 | nil nil (point) (line-end-position) nil nil))))) |
| 1187 | ((looking-at (rst-re 'ttl-beg)) | 1166 | ((looking-at (rst-re 'ttl-beg)) |
| 1188 | ;; Try to use the underline | 1167 | ;; Try to use the underline. |
| 1189 | (let ((r (rst-classify-adornment | 1168 | (let ((r (rst-classify-adornment |
| 1190 | (buffer-substring-no-properties | 1169 | (buffer-substring-no-properties |
| 1191 | (line-beginning-position 2) (line-end-position 2)) | 1170 | (line-beginning-position 2) (line-end-position 2)) |
| 1192 | (line-end-position 2)))) | 1171 | (line-end-position 2)))) |
| 1193 | (if r | 1172 | (if r |
| 1194 | r | 1173 | r |
| 1195 | ;; No valid adornment found | 1174 | ;; No valid adornment found. |
| 1196 | (list (cons nil nil) (point) (line-end-position) | 1175 | (list (cons nil nil) (point) (line-end-position) |
| 1197 | nil nil (point) (line-end-position) nil nil)))))))) | 1176 | nil nil (point) (line-end-position) nil nil)))))))) |
| 1198 | 1177 | ||
| @@ -1206,10 +1185,10 @@ t when no section adornments were found.") | |||
| 1206 | (make-variable-buffer-local 'rst-all-sections) | 1185 | (make-variable-buffer-local 'rst-all-sections) |
| 1207 | 1186 | ||
| 1208 | ;; FIXME: If this variable is set to a different value font-locking of section | 1187 | ;; FIXME: If this variable is set to a different value font-locking of section |
| 1209 | ;; headers is wrong | 1188 | ;; headers is wrong. |
| 1210 | (defvar rst-section-hierarchy nil | 1189 | (defvar rst-section-hierarchy nil |
| 1211 | "Section hierarchy in the buffer as determined by `rst-get-hierarchy'. | 1190 | "Section hierarchy in the buffer as determined by `rst-get-hierarchy'. |
| 1212 | t when no section adornments were found. Value depends on | 1191 | t when no section adornments were found. Value depends on |
| 1213 | `rst-all-sections'.") | 1192 | `rst-all-sections'.") |
| 1214 | (make-variable-buffer-local 'rst-section-hierarchy) | 1193 | (make-variable-buffer-local 'rst-section-hierarchy) |
| 1215 | 1194 | ||
| @@ -1222,7 +1201,7 @@ Should be called by interactive functions which deal with sections." | |||
| 1222 | (defun rst-find-all-adornments () | 1201 | (defun rst-find-all-adornments () |
| 1223 | "Return all the section adornments in the current buffer. | 1202 | "Return all the section adornments in the current buffer. |
| 1224 | Return a list of (LINE . ADORNMENT) with ascending LINE where | 1203 | Return a list of (LINE . ADORNMENT) with ascending LINE where |
| 1225 | LINE is the line containing the section title. ADORNMENT consists | 1204 | LINE is the line containing the section title. ADORNMENT consists |
| 1226 | of a (CHARACTER STYLE INDENT) triple as described for | 1205 | of a (CHARACTER STYLE INDENT) triple as described for |
| 1227 | `rst-preferred-adornments'. | 1206 | `rst-preferred-adornments'. |
| 1228 | 1207 | ||
| @@ -1236,15 +1215,15 @@ Uses and sets `rst-all-sections'." | |||
| 1236 | (let ((ado-data (rst-classify-adornment | 1215 | (let ((ado-data (rst-classify-adornment |
| 1237 | (match-string-no-properties 0) (point)))) | 1216 | (match-string-no-properties 0) (point)))) |
| 1238 | (when (and ado-data | 1217 | (when (and ado-data |
| 1239 | (consp (car ado-data))) ; Ignore transitions | 1218 | (consp (car ado-data))) ; Ignore transitions. |
| 1240 | (set-match-data (cdr ado-data)) | 1219 | (set-match-data (cdr ado-data)) |
| 1241 | (goto-char (match-beginning 2)) ; Goto the title start | 1220 | (goto-char (match-beginning 2)) ; Goto the title start. |
| 1242 | (push (cons (1+ (count-lines (point-min) (point))) | 1221 | (push (cons (1+ (count-lines (point-min) (point))) |
| 1243 | (list (caar ado-data) | 1222 | (list (caar ado-data) |
| 1244 | (cdar ado-data) | 1223 | (cdar ado-data) |
| 1245 | (current-indentation))) | 1224 | (current-indentation))) |
| 1246 | positions) | 1225 | positions) |
| 1247 | (goto-char (match-end 0))))) ; Go beyond the whole thing | 1226 | (goto-char (match-end 0))))) ; Go beyond the whole thing. |
| 1248 | (setq positions (nreverse positions)) | 1227 | (setq positions (nreverse positions)) |
| 1249 | (setq rst-all-sections (or positions t))))) | 1228 | (setq rst-all-sections (or positions t))))) |
| 1250 | (if (eq rst-all-sections t) | 1229 | (if (eq rst-all-sections t) |
| @@ -1274,8 +1253,8 @@ list element should be unique." | |||
| 1274 | "Return the hierarchy of section titles in the file. | 1253 | "Return the hierarchy of section titles in the file. |
| 1275 | 1254 | ||
| 1276 | Return a list of adornments that represents the hierarchy of | 1255 | Return a list of adornments that represents the hierarchy of |
| 1277 | section titles in the file. Each element consists of (CHARACTER | 1256 | section titles in the file. Each element consists of (CHARACTER |
| 1278 | STYLE INDENT) as described for `rst-find-all-adornments'. If the | 1257 | STYLE INDENT) as described for `rst-find-all-adornments'. If the |
| 1279 | line number in IGNORE is specified, a possibly adornment found on | 1258 | line number in IGNORE is specified, a possibly adornment found on |
| 1280 | that line is not taken into account when building the hierarchy. | 1259 | that line is not taken into account when building the hierarchy. |
| 1281 | 1260 | ||
| @@ -1292,7 +1271,7 @@ Uses and sets `rst-section-hierarchy' unless IGNORE is given." | |||
| 1292 | (setq rst-section-hierarchy | 1271 | (setq rst-section-hierarchy |
| 1293 | (if ignore | 1272 | (if ignore |
| 1294 | ;; Clear cache reflecting that a possible update is not | 1273 | ;; Clear cache reflecting that a possible update is not |
| 1295 | ;; reflected | 1274 | ;; reflected. |
| 1296 | nil | 1275 | nil |
| 1297 | (or r t))) | 1276 | (or r t))) |
| 1298 | r))) | 1277 | r))) |
| @@ -1378,19 +1357,19 @@ REVERSE-DIRECTION is used to reverse the cycling order." | |||
| 1378 | ))) | 1357 | ))) |
| 1379 | 1358 | ||
| 1380 | 1359 | ||
| 1381 | ;; FIXME: A line "``/`` full" is not accepted as a section title | 1360 | ;; FIXME: A line "``/`` full" is not accepted as a section title. |
| 1382 | (defun rst-adjust (pfxarg) | 1361 | (defun rst-adjust (pfxarg) |
| 1383 | "Auto-adjust the adornment around point. | 1362 | "Auto-adjust the adornment around point. |
| 1384 | 1363 | ||
| 1385 | Adjust/rotate the section adornment for the section title | 1364 | Adjust/rotate the section adornment for the section title around |
| 1386 | around point or promote/demote the adornments inside the region, | 1365 | point or promote/demote the adornments inside the region, |
| 1387 | depending on if the region is active. This function is meant to | 1366 | depending on if the region is active. This function is meant to |
| 1388 | be invoked possibly multiple times, and can vary its behavior | 1367 | be invoked possibly multiple times, and can vary its behavior |
| 1389 | with a positive prefix argument (toggle style), or with a | 1368 | with a positive PFXARG (toggle style), or with a negative |
| 1390 | negative prefix argument (alternate behavior). | 1369 | PFXARG (alternate behavior). |
| 1391 | 1370 | ||
| 1392 | This function is a bit of a swiss knife. It is meant to adjust | 1371 | This function is a bit of a swiss knife. It is meant to adjust |
| 1393 | the adornments of a section title in reStructuredText. It tries | 1372 | the adornments of a section title in reStructuredText. It tries |
| 1394 | to deal with all the possible cases gracefully and to do `the | 1373 | to deal with all the possible cases gracefully and to do `the |
| 1395 | right thing' in all cases. | 1374 | right thing' in all cases. |
| 1396 | 1375 | ||
| @@ -1403,7 +1382,7 @@ Prefix Arguments | |||
| 1403 | The method can take either (but not both) of | 1382 | The method can take either (but not both) of |
| 1404 | 1383 | ||
| 1405 | a. a (non-negative) prefix argument, which means to toggle the | 1384 | a. a (non-negative) prefix argument, which means to toggle the |
| 1406 | adornment style. Invoke with a prefix arg for example; | 1385 | adornment style. Invoke with a prefix argument for example; |
| 1407 | 1386 | ||
| 1408 | b. a negative numerical argument, which generally inverts the | 1387 | b. a negative numerical argument, which generally inverts the |
| 1409 | direction of search in the file or hierarchy. Invoke with C-- | 1388 | direction of search in the file or hierarchy. Invoke with C-- |
| @@ -1447,7 +1426,8 @@ b. a negative numerical argument, which generally inverts the | |||
| 1447 | (defun rst-adjust-adornment (pfxarg) | 1426 | (defun rst-adjust-adornment (pfxarg) |
| 1448 | "Call `rst-adjust-adornment-work' interactively. | 1427 | "Call `rst-adjust-adornment-work' interactively. |
| 1449 | 1428 | ||
| 1450 | Keep this for compatibility for older bindings (are there any?)." | 1429 | Keep this for compatibility for older bindings (are there any?). |
| 1430 | Argument PFXARG has the same meaning as for `rst-adjust'." | ||
| 1451 | (interactive "P") | 1431 | (interactive "P") |
| 1452 | 1432 | ||
| 1453 | (let* ((reverse-direction (and pfxarg (< (prefix-numeric-value pfxarg) 0))) | 1433 | (let* ((reverse-direction (and pfxarg (< (prefix-numeric-value pfxarg) 0))) |
| @@ -1661,7 +1641,7 @@ lines." | |||
| 1661 | ;; Else, we rotate, ignoring the adornment around the current | 1641 | ;; Else, we rotate, ignoring the adornment around the current |
| 1662 | ;; line... | 1642 | ;; line... |
| 1663 | (let* ((hier (rst-get-hierarchy (line-number-at-pos))) | 1643 | (let* ((hier (rst-get-hierarchy (line-number-at-pos))) |
| 1664 | ;; Suggestion, in case we need to come up with something new | 1644 | ;; Suggestion, in case we need to come up with something new. |
| 1665 | (suggestion (rst-suggest-new-adornment | 1645 | (suggestion (rst-suggest-new-adornment |
| 1666 | hier | 1646 | hier |
| 1667 | (car (rst-get-adornments-around)))) | 1647 | (car (rst-get-adornments-around)))) |
| @@ -1703,7 +1683,7 @@ hierarchy is similar to that used by `rst-adjust-adornment-work'." | |||
| 1703 | marker-list | 1683 | marker-list |
| 1704 | ) | 1684 | ) |
| 1705 | 1685 | ||
| 1706 | ;; Skip the markers that come before the region beginning | 1686 | ;; Skip the markers that come before the region beginning. |
| 1707 | (while (and cur (< (caar cur) region-begin-line)) | 1687 | (while (and cur (< (caar cur) region-begin-line)) |
| 1708 | (setq cur (cdr cur))) | 1688 | (setq cur (cdr cur))) |
| 1709 | 1689 | ||
| @@ -1768,7 +1748,7 @@ in order to adapt it to our preferred style." | |||
| 1768 | (interactive) | 1748 | (interactive) |
| 1769 | (rst-reset-section-caches) | 1749 | (rst-reset-section-caches) |
| 1770 | (save-excursion | 1750 | (save-excursion |
| 1771 | (let (;; Get a list of pairs of (level . marker) | 1751 | (let (;; Get a list of pairs of (level . marker). |
| 1772 | (levels-and-markers (mapcar | 1752 | (levels-and-markers (mapcar |
| 1773 | (lambda (ado) | 1753 | (lambda (ado) |
| 1774 | (cons (rst-position (cdr ado) | 1754 | (cons (rst-position (cdr ado) |
| @@ -1779,13 +1759,13 @@ in order to adapt it to our preferred style." | |||
| 1779 | (point-marker)))) | 1759 | (point-marker)))) |
| 1780 | (rst-find-all-adornments)))) | 1760 | (rst-find-all-adornments)))) |
| 1781 | (dolist (lm levels-and-markers) | 1761 | (dolist (lm levels-and-markers) |
| 1782 | ;; Go to the appropriate position | 1762 | ;; Go to the appropriate position. |
| 1783 | (goto-char (cdr lm)) | 1763 | (goto-char (cdr lm)) |
| 1784 | 1764 | ||
| 1785 | ;; Apply the new styule | 1765 | ;; Apply the new style. |
| 1786 | (apply 'rst-update-section (nth (car lm) rst-preferred-adornments)) | 1766 | (apply 'rst-update-section (nth (car lm) rst-preferred-adornments)) |
| 1787 | 1767 | ||
| 1788 | ;; Reset the market to avoid slowing down editing until it gets GC'ed | 1768 | ;; Reset the market to avoid slowing down editing until it gets GC'ed. |
| 1789 | (set-marker (cdr lm) nil) | 1769 | (set-marker (cdr lm) nil) |
| 1790 | ) | 1770 | ) |
| 1791 | ))) | 1771 | ))) |
| @@ -1798,7 +1778,7 @@ in order to adapt it to our preferred style." | |||
| 1798 | 1778 | ||
| 1799 | 1779 | ||
| 1800 | ;================================================= | 1780 | ;================================================= |
| 1801 | ; Borrowed from a2r.el (version 1.3), by Lawrence Mitchell <wence@gmx.li> | 1781 | ; Borrowed from a2r.el (version 1.3), by Lawrence Mitchell <wence@gmx.li>. |
| 1802 | ; I needed to make some tiny changes to the functions, so I put it here. | 1782 | ; I needed to make some tiny changes to the functions, so I put it here. |
| 1803 | ; -- Wei-Wei Guo | 1783 | ; -- Wei-Wei Guo |
| 1804 | 1784 | ||
| @@ -1849,9 +1829,9 @@ If optional ARG is non-nil, insert in current buffer." | |||
| 1849 | 1829 | ||
| 1850 | (defun rst-find-pfx-in-region (beg end pfx-re) | 1830 | (defun rst-find-pfx-in-region (beg end pfx-re) |
| 1851 | "Find all the positions of prefixes in region between BEG and END. | 1831 | "Find all the positions of prefixes in region between BEG and END. |
| 1852 | This is used to find bullets and enumerated list items. PFX-RE is | 1832 | This is used to find bullets and enumerated list items. PFX-RE is |
| 1853 | a regular expression for matching the lines after indentation | 1833 | a regular expression for matching the lines after indentation |
| 1854 | with items. Returns a list of cons cells consisting of the point | 1834 | with items. Returns a list of cons cells consisting of the point |
| 1855 | and the column of the point." | 1835 | and the column of the point." |
| 1856 | (let ((pfx ())) | 1836 | (let ((pfx ())) |
| 1857 | (save-excursion | 1837 | (save-excursion |
| @@ -1867,14 +1847,14 @@ and the column of the point." | |||
| 1867 | (or (looking-at (rst-re 'lin-end)) ; ...empty, | 1847 | (or (looking-at (rst-re 'lin-end)) ; ...empty, |
| 1868 | (> (current-column) pfx-col) ; ...deeper level, or | 1848 | (> (current-column) pfx-col) ; ...deeper level, or |
| 1869 | (and (= (current-column) pfx-col) | 1849 | (and (= (current-column) pfx-col) |
| 1870 | (looking-at pfx-re)))))) ; ...pfx at same level | 1850 | (looking-at pfx-re)))))) ; ...pfx at same level. |
| 1871 | (push (cons (point) (current-column)) | 1851 | (push (cons (point) (current-column)) |
| 1872 | pfx)) | 1852 | pfx)) |
| 1873 | (forward-line 1)) ) | 1853 | (forward-line 1)) ) |
| 1874 | (nreverse pfx))) | 1854 | (nreverse pfx))) |
| 1875 | 1855 | ||
| 1876 | (defun rst-insert-list-pos (newitem) | 1856 | (defun rst-insert-list-pos (newitem) |
| 1877 | "Arrange relative position of a newly inserted list item. | 1857 | "Arrange relative position of a newly inserted list item of style NEWITEM. |
| 1878 | 1858 | ||
| 1879 | Adding a new list might consider three situations: | 1859 | Adding a new list might consider three situations: |
| 1880 | 1860 | ||
| @@ -1922,11 +1902,11 @@ for completion and choices. | |||
| 1922 | If user selects bullets or #, it's just added with position arranged by | 1902 | If user selects bullets or #, it's just added with position arranged by |
| 1923 | `rst-insert-list-pos'. | 1903 | `rst-insert-list-pos'. |
| 1924 | 1904 | ||
| 1925 | If user selects enumerations, a further prompt is given. User need to input a | 1905 | If user selects enumerations, a further prompt is given. User need to input a |
| 1926 | starting item, for example 'e' for 'A)' style. The position is also arranged by | 1906 | starting item, for example 'e' for 'A)' style. The position is also arranged by |
| 1927 | `rst-insert-list-pos'." | 1907 | `rst-insert-list-pos'." |
| 1928 | (interactive) | 1908 | (interactive) |
| 1929 | ;; FIXME: Make this comply to `interactive' standards | 1909 | ;; FIXME: Make this comply to `interactive' standards. |
| 1930 | (let* ((itemstyle (completing-read | 1910 | (let* ((itemstyle (completing-read |
| 1931 | "Select preferred item style [#.]: " | 1911 | "Select preferred item style [#.]: " |
| 1932 | rst-initial-items nil t nil nil "#.")) | 1912 | rst-initial-items nil t nil nil "#.")) |
| @@ -1934,7 +1914,7 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by | |||
| 1934 | (match-string 0 itemstyle))) | 1914 | (match-string 0 itemstyle))) |
| 1935 | (no | 1915 | (no |
| 1936 | (save-match-data | 1916 | (save-match-data |
| 1937 | ;; FIXME: Make this comply to `interactive' standards | 1917 | ;; FIXME: Make this comply to `interactive' standards. |
| 1938 | (cond | 1918 | (cond |
| 1939 | ((equal cnt "a") | 1919 | ((equal cnt "a") |
| 1940 | (let ((itemno (read-string "Give starting value [a]: " | 1920 | (let ((itemno (read-string "Give starting value [a]: " |
| @@ -1969,10 +1949,11 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by | |||
| 1969 | :package-version '(rst . "1.1.0")) | 1949 | :package-version '(rst . "1.1.0")) |
| 1970 | 1950 | ||
| 1971 | (defun rst-insert-list-continue (curitem prefer-roman) | 1951 | (defun rst-insert-list-continue (curitem prefer-roman) |
| 1972 | "Insert a list item with list start CURITEM including its indentation level." | 1952 | "Insert a list item with list start CURITEM including its indentation level. |
| 1953 | If PREFER-ROMAN roman numbering is preferred over using letters." | ||
| 1973 | (end-of-line) | 1954 | (end-of-line) |
| 1974 | (insert | 1955 | (insert |
| 1975 | "\n" ; FIXME: Separating lines must be possible | 1956 | "\n" ; FIXME: Separating lines must be possible. |
| 1976 | (cond | 1957 | (cond |
| 1977 | ((string-match (rst-re '(:alt enmaut-tag | 1958 | ((string-match (rst-re '(:alt enmaut-tag |
| 1978 | bul-tag)) curitem) | 1959 | bul-tag)) curitem) |
| @@ -1983,17 +1964,17 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by | |||
| 1983 | nil nil curitem)) | 1964 | nil nil curitem)) |
| 1984 | ((and (string-match (rst-re 'rom-tag) curitem) | 1965 | ((and (string-match (rst-re 'rom-tag) curitem) |
| 1985 | (save-match-data | 1966 | (save-match-data |
| 1986 | (if (string-match (rst-re 'ltr-tag) curitem) ; Also a letter tag | 1967 | (if (string-match (rst-re 'ltr-tag) curitem) ; Also a letter tag. |
| 1987 | (save-excursion | 1968 | (save-excursion |
| 1988 | ;; FIXME: Assumes one line list items without separating | 1969 | ;; FIXME: Assumes one line list items without separating |
| 1989 | ;; empty lines | 1970 | ;; empty lines. |
| 1990 | (if (and (zerop (forward-line -1)) | 1971 | (if (and (zerop (forward-line -1)) |
| 1991 | (looking-at (rst-re 'enmexp-beg))) | 1972 | (looking-at (rst-re 'enmexp-beg))) |
| 1992 | (string-match | 1973 | (string-match |
| 1993 | (rst-re 'rom-tag) | 1974 | (rst-re 'rom-tag) |
| 1994 | (match-string 0)) ; Previous was a roman tag | 1975 | (match-string 0)) ; Previous was a roman tag. |
| 1995 | prefer-roman)) ; Don't know - use flag | 1976 | prefer-roman)) ; Don't know - use flag. |
| 1996 | t))) ; Not a letter tag | 1977 | t))) ; Not a letter tag. |
| 1997 | (replace-match | 1978 | (replace-match |
| 1998 | (let* ((old (match-string 0 curitem)) | 1979 | (let* ((old (match-string 0 curitem)) |
| 1999 | (new (save-match-data | 1980 | (new (save-match-data |
| @@ -2013,13 +1994,13 @@ starting item, for example 'e' for 'A)' style. The position is also arranged by | |||
| 2013 | (defun rst-insert-list (&optional prefer-roman) | 1994 | (defun rst-insert-list (&optional prefer-roman) |
| 2014 | "Insert a list item at the current point. | 1995 | "Insert a list item at the current point. |
| 2015 | 1996 | ||
| 2016 | The command can insert a new list or a continuing list. When it is called at a | 1997 | The command can insert a new list or a continuing list. When it is called at a |
| 2017 | non-list line, it will promote to insert new list. When it is called at a list | 1998 | non-list line, it will promote to insert new list. When it is called at a list |
| 2018 | line, it will insert a list with the same list style. | 1999 | line, it will insert a list with the same list style. |
| 2019 | 2000 | ||
| 2020 | 1. When inserting a new list: | 2001 | 1. When inserting a new list: |
| 2021 | 2002 | ||
| 2022 | User is asked to select the item style first, for example (a), i), +. Use TAB | 2003 | User is asked to select the item style first, for example (a), i), +. Use TAB |
| 2023 | for completion and choices. | 2004 | for completion and choices. |
| 2024 | 2005 | ||
| 2025 | (a) If user selects bullets or #, it's just added. | 2006 | (a) If user selects bullets or #, it's just added. |
| @@ -2036,7 +2017,7 @@ List style alphabetical list, such as 'a.', and roman numerical list, such as | |||
| 2036 | the problem elegantly in most situations. But when those overlapped list are | 2017 | the problem elegantly in most situations. But when those overlapped list are |
| 2037 | preceded by a blank line, it is hard to determine which type to use | 2018 | preceded by a blank line, it is hard to determine which type to use |
| 2038 | automatically. The function uses alphabetical list by default. If you want | 2019 | automatically. The function uses alphabetical list by default. If you want |
| 2039 | roman numerical list, just use a prefix (\\[universal-argument])." | 2020 | roman numerical list, just use a prefix to set PREFER-ROMAN." |
| 2040 | (interactive "P") | 2021 | (interactive "P") |
| 2041 | (beginning-of-line) | 2022 | (beginning-of-line) |
| 2042 | (if (looking-at (rst-re 'itmany-beg-1)) | 2023 | (if (looking-at (rst-re 'itmany-beg-1)) |
| @@ -2094,8 +2075,8 @@ adjust. If bullets are found on levels beyond the | |||
| 2094 | "Get the hierarchical tree of section titles. | 2075 | "Get the hierarchical tree of section titles. |
| 2095 | 2076 | ||
| 2096 | Returns a hierarchical tree of the sections titles in the | 2077 | Returns a hierarchical tree of the sections titles in the |
| 2097 | document. This can be used to generate a table of contents for | 2078 | document. This can be used to generate a table of contents for |
| 2098 | the document. The top node will always be a nil node, with the | 2079 | the document. The top node will always be a nil node, with the |
| 2099 | top level titles as children (there may potentially be more than | 2080 | top level titles as children (there may potentially be more than |
| 2100 | one). | 2081 | one). |
| 2101 | 2082 | ||
| @@ -2105,7 +2086,7 @@ string and a marker to the section in the original text document. | |||
| 2105 | If there are missing section levels, the section titles are | 2086 | If there are missing section levels, the section titles are |
| 2106 | inserted automatically, and the title string is set to nil, and | 2087 | inserted automatically, and the title string is set to nil, and |
| 2107 | the marker set to the first non-nil child of itself. | 2088 | the marker set to the first non-nil child of itself. |
| 2108 | Conceptually, the nil nodes--i.e. those which have no title--are | 2089 | Conceptually, the nil nodes--i.e.\ those which have no title--are |
| 2109 | to be considered as being the same line as their first non-nil | 2090 | to be considered as being the same line as their first non-nil |
| 2110 | child. This has advantages later in processing the graph." | 2091 | child. This has advantages later in processing the graph." |
| 2111 | 2092 | ||
| @@ -2148,14 +2129,14 @@ list destructively." | |||
| 2148 | node | 2129 | node |
| 2149 | children) | 2130 | children) |
| 2150 | 2131 | ||
| 2151 | ;; If the next adornment matches our level | 2132 | ;; If the next adornment matches our level. |
| 2152 | (when (and nado (= (car nado) lev)) | 2133 | (when (and nado (= (car nado) lev)) |
| 2153 | ;; Pop the next adornment and create the current node with it | 2134 | ;; Pop the next adornment and create the current node with it. |
| 2154 | (setcdr ados (cddr ados)) | 2135 | (setcdr ados (cddr ados)) |
| 2155 | (setq node (cdr nado)) ) | 2136 | (setq node (cdr nado)) ) |
| 2156 | ;; Else we let the node title/marker be unset. | 2137 | ;; Else we let the node title/marker be unset. |
| 2157 | 2138 | ||
| 2158 | ;; Build the child nodes | 2139 | ;; Build the child nodes. |
| 2159 | (while (and (cdr ados) (> (caadr ados) lev)) | 2140 | (while (and (cdr ados) (> (caadr ados) lev)) |
| 2160 | (setq children | 2141 | (setq children |
| 2161 | (cons (rst-section-tree-rec ados (1+ lev)) | 2142 | (cons (rst-section-tree-rec ados (1+ lev)) |
| @@ -2175,7 +2156,7 @@ list destructively." | |||
| 2175 | "Find tree node at point. | 2156 | "Find tree node at point. |
| 2176 | Given a computed and valid section tree in NODE and a point | 2157 | Given a computed and valid section tree in NODE and a point |
| 2177 | POINT (default being the current point in the current buffer), | 2158 | POINT (default being the current point in the current buffer), |
| 2178 | find and return the node within the sectree where the cursor | 2159 | find and return the node within the section tree where the cursor |
| 2179 | lives. | 2160 | lives. |
| 2180 | 2161 | ||
| 2181 | Return values: a pair of (parent path, container subtree). | 2162 | Return values: a pair of (parent path, container subtree). |
| @@ -2256,7 +2237,7 @@ to the specified level. | |||
| 2256 | The TOC is inserted indented at the current column." | 2237 | The TOC is inserted indented at the current column." |
| 2257 | (interactive "P") | 2238 | (interactive "P") |
| 2258 | (rst-reset-section-caches) | 2239 | (rst-reset-section-caches) |
| 2259 | (let* (;; Check maximum level override | 2240 | (let* (;; Check maximum level override. |
| 2260 | (rst-toc-insert-max-level | 2241 | (rst-toc-insert-max-level |
| 2261 | (if (and (integerp pfxarg) (> (prefix-numeric-value pfxarg) 0)) | 2242 | (if (and (integerp pfxarg) (> (prefix-numeric-value pfxarg) 0)) |
| 2262 | (prefix-numeric-value pfxarg) rst-toc-insert-max-level)) | 2243 | (prefix-numeric-value pfxarg) rst-toc-insert-max-level)) |
| @@ -2333,7 +2314,7 @@ level to align." | |||
| 2333 | fmt) | 2314 | fmt) |
| 2334 | (if do-child-numbering | 2315 | (if do-child-numbering |
| 2335 | (progn | 2316 | (progn |
| 2336 | ;; Add a separating dot if there is already a prefix | 2317 | ;; Add a separating dot if there is already a prefix. |
| 2337 | (when (> (length pfx) 0) | 2318 | (when (> (length pfx) 0) |
| 2338 | (string-match (rst-re "[ \t\n]*\\'") pfx) | 2319 | (string-match (rst-re "[ \t\n]*\\'") pfx) |
| 2339 | (setq pfx (concat (replace-match "" t t pfx) "."))) | 2320 | (setq pfx (concat (replace-match "" t t pfx) "."))) |
| @@ -2385,9 +2366,9 @@ file-write hook to always make it up-to-date automatically." | |||
| 2385 | (while (and | 2366 | (while (and |
| 2386 | (< (point) (point-max)) | 2367 | (< (point) (point-max)) |
| 2387 | (or (if (looking-at | 2368 | (or (if (looking-at |
| 2388 | (rst-re 'hws-sta "\\S ")) ; indented content | 2369 | (rst-re 'hws-sta "\\S ")) ; indented content. |
| 2389 | (setq last-real (point))) | 2370 | (setq last-real (point))) |
| 2390 | (looking-at (rst-re 'lin-end)))) ; empty line | 2371 | (looking-at (rst-re 'lin-end)))) ; empty line. |
| 2391 | (forward-line 1)) | 2372 | (forward-line 1)) |
| 2392 | (if last-real | 2373 | (if last-real |
| 2393 | (progn | 2374 | (progn |
| @@ -2517,12 +2498,14 @@ brings the cursor in that section." | |||
| 2517 | 2498 | ||
| 2518 | ;; FIXME: Cursor before or behind the list must be handled properly; before the | 2499 | ;; FIXME: Cursor before or behind the list must be handled properly; before the |
| 2519 | ;; list should jump to the top and behind the list to the last normal | 2500 | ;; list should jump to the top and behind the list to the last normal |
| 2520 | ;; paragraph | 2501 | ;; paragraph. |
| 2521 | (defun rst-goto-section (&optional kill) | 2502 | (defun rst-goto-section (&optional kill) |
| 2522 | "Go to the section the current line describes." | 2503 | "Go to the section the current line describes. |
| 2504 | If KILL a toc buffer is destroyed." | ||
| 2523 | (interactive) | 2505 | (interactive) |
| 2524 | (let ((pos (rst-toc-mode-find-section))) | 2506 | (let ((pos (rst-toc-mode-find-section))) |
| 2525 | (when kill | 2507 | (when kill |
| 2508 | ;; FIXME: This should rather go to `rst-toc-mode-goto-section'. | ||
| 2526 | (set-window-configuration (car rst-toc-return-wincfg)) | 2509 | (set-window-configuration (car rst-toc-return-wincfg)) |
| 2527 | (kill-buffer (get-buffer rst-toc-buffer-name))) | 2510 | (kill-buffer (get-buffer rst-toc-buffer-name))) |
| 2528 | (pop-to-buffer (marker-buffer pos)) | 2511 | (pop-to-buffer (marker-buffer pos)) |
| @@ -2549,7 +2532,8 @@ EVENT is the input event." | |||
| 2549 | (recenter 5))) | 2532 | (recenter 5))) |
| 2550 | 2533 | ||
| 2551 | (defun rst-toc-mode-mouse-goto-kill (event) | 2534 | (defun rst-toc-mode-mouse-goto-kill (event) |
| 2552 | "Same as `rst-toc-mode-mouse-goto', but kill TOC buffer as well." | 2535 | "Same as `rst-toc-mode-mouse-goto', but kill TOC buffer as well. |
| 2536 | EVENT is the input event." | ||
| 2553 | (interactive "e") | 2537 | (interactive "e") |
| 2554 | (call-interactively 'rst-toc-mode-mouse-goto event) | 2538 | (call-interactively 'rst-toc-mode-mouse-goto event) |
| 2555 | (kill-buffer (get-buffer rst-toc-buffer-name))) | 2539 | (kill-buffer (get-buffer rst-toc-buffer-name))) |
| @@ -2582,7 +2566,6 @@ EVENT is the input event." | |||
| 2582 | ;; Note: use occur-mode (replace.el) as a good example to complete missing | 2566 | ;; Note: use occur-mode (replace.el) as a good example to complete missing |
| 2583 | ;; features. | 2567 | ;; features. |
| 2584 | 2568 | ||
| 2585 | |||
| 2586 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2569 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2587 | ;; Section movement commands | 2570 | ;; Section movement commands |
| 2588 | ;; ========================= | 2571 | ;; ========================= |
| @@ -2633,12 +2616,15 @@ backwards in the file (default is to use 1)." | |||
| 2633 | (interactive) | 2616 | (interactive) |
| 2634 | (rst-forward-section -1)) | 2617 | (rst-forward-section -1)) |
| 2635 | 2618 | ||
| 2636 | (defun rst-mark-section (&optional arg allow-extend) | 2619 | ;; FIXME: What is `allow-extend' for? |
| 2637 | "Select the section that point is currently in." | 2620 | (defun rst-mark-section (&optional count allow-extend) |
| 2621 | "Select COUNT sections around point. | ||
| 2622 | Mark following sections for positive COUNT or preceding sections | ||
| 2623 | for negative COUNT." | ||
| 2638 | ;; Cloned from mark-paragraph. | 2624 | ;; Cloned from mark-paragraph. |
| 2639 | (interactive "p\np") | 2625 | (interactive "p\np") |
| 2640 | (unless arg (setq arg 1)) | 2626 | (unless count (setq count 1)) |
| 2641 | (when (zerop arg) | 2627 | (when (zerop count) |
| 2642 | (error "Cannot mark zero sections")) | 2628 | (error "Cannot mark zero sections")) |
| 2643 | (cond ((and allow-extend | 2629 | (cond ((and allow-extend |
| 2644 | (or (and (eq last-command this-command) (mark t)) | 2630 | (or (and (eq last-command this-command) (mark t)) |
| @@ -2646,12 +2632,12 @@ backwards in the file (default is to use 1)." | |||
| 2646 | (set-mark | 2632 | (set-mark |
| 2647 | (save-excursion | 2633 | (save-excursion |
| 2648 | (goto-char (mark)) | 2634 | (goto-char (mark)) |
| 2649 | (rst-forward-section arg) | 2635 | (rst-forward-section count) |
| 2650 | (point)))) | 2636 | (point)))) |
| 2651 | (t | 2637 | (t |
| 2652 | (rst-forward-section arg) | 2638 | (rst-forward-section count) |
| 2653 | (push-mark nil t t) | 2639 | (push-mark nil t t) |
| 2654 | (rst-forward-section (- arg))))) | 2640 | (rst-forward-section (- count))))) |
| 2655 | 2641 | ||
| 2656 | 2642 | ||
| 2657 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2643 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -2672,12 +2658,12 @@ backwards in the file (default is to use 1)." | |||
| 2672 | (forward-line 1))) | 2658 | (forward-line 1))) |
| 2673 | mincol)) | 2659 | mincol)) |
| 2674 | 2660 | ||
| 2661 | ;; FIXME: This definition is old and deprecated. We need to move to the newer | ||
| 2662 | ;; version below. | ||
| 2675 | (defmacro rst-iterate-leftmost-paragraphs | 2663 | (defmacro rst-iterate-leftmost-paragraphs |
| 2676 | (beg end first-only body-consequent body-alternative) | 2664 | (beg end first-only body-consequent body-alternative) |
| 2677 | "FIXME This definition is old and deprecated / we need to move | 2665 | ;; FIXME: The following comment is pretty useless. |
| 2678 | to the newer version below: | 2666 | "Call FUN at the beginning of each line, with an argument that |
| 2679 | |||
| 2680 | Call FUN at the beginning of each line, with an argument that | ||
| 2681 | specifies whether we are at the first line of a paragraph that | 2667 | specifies whether we are at the first line of a paragraph that |
| 2682 | starts at the leftmost column of the given region BEG and END. | 2668 | starts at the leftmost column of the given region BEG and END. |
| 2683 | Set FIRST-ONLY to true if you want to callback on the first line | 2669 | Set FIRST-ONLY to true if you want to callback on the first line |
| @@ -2686,7 +2672,7 @@ of each paragraph only." | |||
| 2686 | (let ((leftcol (rst-find-leftmost-column ,beg ,end)) | 2672 | (let ((leftcol (rst-find-leftmost-column ,beg ,end)) |
| 2687 | (endm (copy-marker ,end))) | 2673 | (endm (copy-marker ,end))) |
| 2688 | 2674 | ||
| 2689 | (do* (;; Iterate lines | 2675 | (do* (;; Iterate lines. |
| 2690 | (l (progn (goto-char ,beg) (back-to-indentation)) | 2676 | (l (progn (goto-char ,beg) (back-to-indentation)) |
| 2691 | (progn (forward-line 1) (back-to-indentation))) | 2677 | (progn (forward-line 1) (back-to-indentation))) |
| 2692 | 2678 | ||
| @@ -2710,6 +2696,8 @@ of each paragraph only." | |||
| 2710 | 2696 | ||
| 2711 | )))) | 2697 | )))) |
| 2712 | 2698 | ||
| 2699 | ;; FIXME: This needs to be refactored. Probably this is simply a function | ||
| 2700 | ;; applying BODY rather than a macro. | ||
| 2713 | (defmacro rst-iterate-leftmost-paragraphs-2 (spec &rest body) | 2701 | (defmacro rst-iterate-leftmost-paragraphs-2 (spec &rest body) |
| 2714 | "Evaluate BODY for each line in region defined by BEG END. | 2702 | "Evaluate BODY for each line in region defined by BEG END. |
| 2715 | LEFTMOST is set to true if the line is one of the leftmost of the | 2703 | LEFTMOST is set to true if the line is one of the leftmost of the |
| @@ -2723,7 +2711,7 @@ first of a paragraph." | |||
| 2723 | (let ((,leftmost (rst-find-leftmost-column ,beg ,end)) | 2711 | (let ((,leftmost (rst-find-leftmost-column ,beg ,end)) |
| 2724 | (endm (copy-marker ,end))) | 2712 | (endm (copy-marker ,end))) |
| 2725 | 2713 | ||
| 2726 | (do* (;; Iterate lines | 2714 | (do* (;; Iterate lines. |
| 2727 | (l (progn (goto-char ,beg) (back-to-indentation)) | 2715 | (l (progn (goto-char ,beg) (back-to-indentation)) |
| 2728 | (progn (forward-line 1) (back-to-indentation))) | 2716 | (progn (forward-line 1) (back-to-indentation))) |
| 2729 | 2717 | ||
| @@ -2751,8 +2739,9 @@ first of a paragraph." | |||
| 2751 | ;; Indentation | 2739 | ;; Indentation |
| 2752 | 2740 | ||
| 2753 | ;; FIXME: At the moment only block comments with leading empty comment line are | 2741 | ;; FIXME: At the moment only block comments with leading empty comment line are |
| 2754 | ;; supported; comment lines with leading comment markup should be also | 2742 | ;; supported. Comment lines with leading comment markup should be also |
| 2755 | ;; supported; may be a customizable option could control which style to prefer | 2743 | ;; supported. May be a customizable option could control which style to |
| 2744 | ;; prefer. | ||
| 2756 | 2745 | ||
| 2757 | (defgroup rst-indent nil "Settings for indentation in reStructuredText. | 2746 | (defgroup rst-indent nil "Settings for indentation in reStructuredText. |
| 2758 | 2747 | ||
| @@ -2772,20 +2761,17 @@ here." | |||
| 2772 | :type '(integer)) | 2761 | :type '(integer)) |
| 2773 | 2762 | ||
| 2774 | (defcustom rst-indent-field 3 | 2763 | (defcustom rst-indent-field 3 |
| 2775 | "Default indentation for first line after a field or 0 to always indent for | 2764 | "Indentation for first line after a field or 0 to always indent for content." |
| 2776 | content." | ||
| 2777 | :group 'rst-indent | 2765 | :group 'rst-indent |
| 2778 | :type '(integer)) | 2766 | :type '(integer)) |
| 2779 | 2767 | ||
| 2780 | (defcustom rst-indent-literal-normal 3 | 2768 | (defcustom rst-indent-literal-normal 3 |
| 2781 | "Default indentation for literal block after a markup on an own | 2769 | "Default indentation for literal block after a markup on an own line." |
| 2782 | line." | ||
| 2783 | :group 'rst-indent | 2770 | :group 'rst-indent |
| 2784 | :type '(integer)) | 2771 | :type '(integer)) |
| 2785 | 2772 | ||
| 2786 | (defcustom rst-indent-literal-minimized 2 | 2773 | (defcustom rst-indent-literal-minimized 2 |
| 2787 | "Default indentation for literal block after a minimized | 2774 | "Default indentation for literal block after a minimized markup." |
| 2788 | markup." | ||
| 2789 | :group 'rst-indent | 2775 | :group 'rst-indent |
| 2790 | :type '(integer)) | 2776 | :type '(integer)) |
| 2791 | 2777 | ||
| @@ -2795,30 +2781,30 @@ markup." | |||
| 2795 | :type '(integer)) | 2781 | :type '(integer)) |
| 2796 | 2782 | ||
| 2797 | ;; FIXME: Must consider other tabs: | 2783 | ;; FIXME: Must consider other tabs: |
| 2798 | ;; * Line blocks | 2784 | ;; * Line blocks |
| 2799 | ;; * Definition lists | 2785 | ;; * Definition lists |
| 2800 | ;; * Option lists | 2786 | ;; * Option lists |
| 2801 | (defun rst-line-tabs () | 2787 | (defun rst-line-tabs () |
| 2802 | "Return tabs of the current line or nil for no tab. | 2788 | "Return tabs of the current line or nil for no tab. |
| 2803 | The list is sorted so the tab where writing continues most likely | 2789 | The list is sorted so the tab where writing continues most likely |
| 2804 | is the first one. Each tab is of the form (COLUMN . INNER). | 2790 | is the first one. Each tab is of the form (COLUMN . INNER). |
| 2805 | COLUMN is the column of the tab. INNER is non-nil if this is an | 2791 | COLUMN is the column of the tab. INNER is non-nil if this is an |
| 2806 | inner tab. I.e. a tab which does come from the basic indentation | 2792 | inner tab. I.e. a tab which does come from the basic indentation |
| 2807 | and not from inner alignment points." | 2793 | and not from inner alignment points." |
| 2808 | (save-excursion | 2794 | (save-excursion |
| 2809 | (forward-line 0) | 2795 | (forward-line 0) |
| 2810 | (save-match-data | 2796 | (save-match-data |
| 2811 | (unless (looking-at (rst-re 'lin-end)) | 2797 | (unless (looking-at (rst-re 'lin-end)) |
| 2812 | (back-to-indentation) | 2798 | (back-to-indentation) |
| 2813 | ;; Current indentation is always the least likely tab | 2799 | ;; Current indendation is always the least likely tab. |
| 2814 | (let ((tabs (list (list (point) 0 nil)))) ; (POINT OFFSET INNER) | 2800 | (let ((tabs (list (list (point) 0 nil)))) ; (POINT OFFSET INNER) |
| 2815 | ;; Push inner tabs more likely to continue writing | 2801 | ;; Push inner tabs more likely to continue writing. |
| 2816 | (cond | 2802 | (cond |
| 2817 | ;; Item | 2803 | ;; Item. |
| 2818 | ((looking-at (rst-re '(:grp itmany-tag hws-sta) '(:grp "\\S ") "?")) | 2804 | ((looking-at (rst-re '(:grp itmany-tag hws-sta) '(:grp "\\S ") "?")) |
| 2819 | (when (match-string 2) | 2805 | (when (match-string 2) |
| 2820 | (push (list (match-beginning 2) 0 t) tabs))) | 2806 | (push (list (match-beginning 2) 0 t) tabs))) |
| 2821 | ;; Field | 2807 | ;; Field. |
| 2822 | ((looking-at (rst-re '(:grp fld-tag) '(:grp hws-tag) | 2808 | ((looking-at (rst-re '(:grp fld-tag) '(:grp hws-tag) |
| 2823 | '(:grp "\\S ") "?")) | 2809 | '(:grp "\\S ") "?")) |
| 2824 | (unless (zerop rst-indent-field) | 2810 | (unless (zerop rst-indent-field) |
| @@ -2829,22 +2815,22 @@ and not from inner alignment points." | |||
| 2829 | (push (list (match-end 2) | 2815 | (push (list (match-end 2) |
| 2830 | (if (string= (match-string 2) "") 1 0) | 2816 | (if (string= (match-string 2) "") 1 0) |
| 2831 | t) tabs)))) | 2817 | t) tabs)))) |
| 2832 | ;; Directive | 2818 | ;; Directive. |
| 2833 | ((looking-at (rst-re 'dir-sta-3 '(:grp "\\S ") "?")) | 2819 | ((looking-at (rst-re 'dir-sta-3 '(:grp "\\S ") "?")) |
| 2834 | (push (list (match-end 1) 0 t) tabs) | 2820 | (push (list (match-end 1) 0 t) tabs) |
| 2835 | (unless (string= (match-string 2) "") | 2821 | (unless (string= (match-string 2) "") |
| 2836 | (push (list (match-end 2) 0 t) tabs)) | 2822 | (push (list (match-end 2) 0 t) tabs)) |
| 2837 | (when (match-string 4) | 2823 | (when (match-string 4) |
| 2838 | (push (list (match-beginning 4) 0 t) tabs))) | 2824 | (push (list (match-beginning 4) 0 t) tabs))) |
| 2839 | ;; Footnote or citation definition | 2825 | ;; Footnote or citation definition. |
| 2840 | ((looking-at (rst-re 'fnc-sta-2 '(:grp "\\S ") "?")) | 2826 | ((looking-at (rst-re 'fnc-sta-2 '(:grp "\\S ") "?")) |
| 2841 | (push (list (match-end 1) 0 t) tabs) | 2827 | (push (list (match-end 1) 0 t) tabs) |
| 2842 | (when (match-string 3) | 2828 | (when (match-string 3) |
| 2843 | (push (list (match-beginning 3) 0 t) tabs))) | 2829 | (push (list (match-beginning 3) 0 t) tabs))) |
| 2844 | ;; Comment | 2830 | ;; Comment. |
| 2845 | ((looking-at (rst-re 'cmt-sta-1)) | 2831 | ((looking-at (rst-re 'cmt-sta-1)) |
| 2846 | (push (list (point) rst-indent-comment t) tabs))) | 2832 | (push (list (point) rst-indent-comment t) tabs))) |
| 2847 | ;; Start of literal block | 2833 | ;; Start of literal block. |
| 2848 | (when (looking-at (rst-re 'lit-sta-2)) | 2834 | (when (looking-at (rst-re 'lit-sta-2)) |
| 2849 | (let ((tab0 (first tabs))) | 2835 | (let ((tab0 (first tabs))) |
| 2850 | (push (list (first tab0) | 2836 | (push (list (first tab0) |
| @@ -2861,14 +2847,14 @@ and not from inner alignment points." | |||
| 2861 | (defun rst-compute-tabs (pt) | 2847 | (defun rst-compute-tabs (pt) |
| 2862 | "Build the list of possible tabs for all lines above. | 2848 | "Build the list of possible tabs for all lines above. |
| 2863 | Search backwards from point PT to build the list of possible | 2849 | Search backwards from point PT to build the list of possible |
| 2864 | tabs. Return a list of tabs sorted by likeliness to continue | 2850 | tabs. Return a list of tabs sorted by likeliness to continue |
| 2865 | writing like `rst-line-tabs'. Nearer lines have generally a | 2851 | writing like `rst-line-tabs'. Nearer lines have generally a |
| 2866 | higher likeliness than farther lines. Return nil if no tab is found | 2852 | higher likeliness than farther lines. Return nil if no tab is found |
| 2867 | in the text above." | 2853 | in the text above." |
| 2868 | (save-excursion | 2854 | (save-excursion |
| 2869 | (goto-char pt) | 2855 | (goto-char pt) |
| 2870 | (let (leftmost ; Leftmost column found so far | 2856 | (let (leftmost ; Leftmost column found so far. |
| 2871 | innermost ; Leftmost column for inner tab | 2857 | innermost ; Leftmost column for inner tab. |
| 2872 | tablist) | 2858 | tablist) |
| 2873 | (while (and (zerop (forward-line -1)) | 2859 | (while (and (zerop (forward-line -1)) |
| 2874 | (or (not leftmost) | 2860 | (or (not leftmost) |
| @@ -2876,7 +2862,7 @@ in the text above." | |||
| 2876 | (let* ((tabs (rst-line-tabs)) | 2862 | (let* ((tabs (rst-line-tabs)) |
| 2877 | (leftcol (if tabs (apply 'min (mapcar 'car tabs))))) | 2863 | (leftcol (if tabs (apply 'min (mapcar 'car tabs))))) |
| 2878 | (when tabs | 2864 | (when tabs |
| 2879 | ;; Consider only lines indented less or same if not INNERMOST | 2865 | ;; Consider only lines indented less or same if not INNERMOST. |
| 2880 | (when (or (not leftmost) | 2866 | (when (or (not leftmost) |
| 2881 | (< leftcol leftmost) | 2867 | (< leftcol leftmost) |
| 2882 | (and (not innermost) (= leftcol leftmost))) | 2868 | (and (not innermost) (= leftcol leftmost))) |
| @@ -2894,7 +2880,7 @@ in the text above." | |||
| 2894 | (not (memq newcol tablist))) | 2880 | (not (memq newcol tablist))) |
| 2895 | (push newcol tablist)))) | 2881 | (push newcol tablist)))) |
| 2896 | (setq innermost (if (some 'identity | 2882 | (setq innermost (if (some 'identity |
| 2897 | (mapcar 'cdr tabs)) ; Has inner | 2883 | (mapcar 'cdr tabs)) ; Has inner. |
| 2898 | leftcol | 2884 | leftcol |
| 2899 | innermost)) | 2885 | innermost)) |
| 2900 | (setq leftmost leftcol))))) | 2886 | (setq leftmost leftcol))))) |
| @@ -2903,13 +2889,13 @@ in the text above." | |||
| 2903 | (defun rst-indent-line (&optional dflt) | 2889 | (defun rst-indent-line (&optional dflt) |
| 2904 | "Indent current line to next best reStructuredText tab. | 2890 | "Indent current line to next best reStructuredText tab. |
| 2905 | The next best tab is taken from the tab list returned by | 2891 | The next best tab is taken from the tab list returned by |
| 2906 | `rst-compute-tabs' which is used in a cyclic manner. If the | 2892 | `rst-compute-tabs' which is used in a cyclic manner. If the |
| 2907 | current indentation does not end on a tab use the first one. If | 2893 | current indentation does not end on a tab use the first one. If |
| 2908 | the current indentation is on a tab use the next tab. This allows | 2894 | the current indentation is on a tab use the next tab. This allows |
| 2909 | a repeated use of \\[indent-for-tab-command] to cycle through all | 2895 | a repeated use of \\[indent-for-tab-command] to cycle through all |
| 2910 | possible tabs. If no indentation is possible return `noindent' or | 2896 | possible tabs. If no indentation is possible return `noindent' or |
| 2911 | use DFLT. Return the indentation indented to. When point is in | 2897 | use DFLT. Return the indentation indented to. When point is in |
| 2912 | indentation it ends up at its end. Otherwise the point is kept | 2898 | indentation it ends up at its end. Otherwise the point is kept |
| 2913 | relative to the content." | 2899 | relative to the content." |
| 2914 | (let* ((pt (point-marker)) | 2900 | (let* ((pt (point-marker)) |
| 2915 | (cur (current-indentation)) | 2901 | (cur (current-indentation)) |
| @@ -2936,46 +2922,46 @@ relative to the content." | |||
| 2936 | (defun rst-shift-region (beg end cnt) | 2922 | (defun rst-shift-region (beg end cnt) |
| 2937 | "Shift region BEG to END by CNT tabs. | 2923 | "Shift region BEG to END by CNT tabs. |
| 2938 | Shift by one tab to the right (CNT > 0) or left (CNT < 0) or | 2924 | Shift by one tab to the right (CNT > 0) or left (CNT < 0) or |
| 2939 | remove all indentation (CNT = 0). An tab is taken from the text | 2925 | remove all indentation (CNT = 0). A tab is taken from the text |
| 2940 | above. If no suitable tab is found `rst-indent-width' is used." | 2926 | above. If no suitable tab is found `rst-indent-width' is used." |
| 2941 | (interactive "r\np") | 2927 | (interactive "r\np") |
| 2942 | (let ((tabs (sort (rst-compute-tabs beg) (lambda (x y) (<= x y)))) | 2928 | (let ((tabs (sort (rst-compute-tabs beg) (lambda (x y) (<= x y)))) |
| 2943 | (leftmostcol (rst-find-leftmost-column beg end))) | 2929 | (leftmostcol (rst-find-leftmost-column beg end))) |
| 2944 | (when (or (> leftmostcol 0) (> cnt 0)) | 2930 | (when (or (> leftmostcol 0) (> cnt 0)) |
| 2945 | ;; Apply the indent | 2931 | ;; Apply the indent. |
| 2946 | (indent-rigidly | 2932 | (indent-rigidly |
| 2947 | beg end | 2933 | beg end |
| 2948 | (if (zerop cnt) | 2934 | (if (zerop cnt) |
| 2949 | (- leftmostcol) | 2935 | (- leftmostcol) |
| 2950 | ;; Find the next tab after the leftmost column | 2936 | ;; Find the next tab after the leftmost column. |
| 2951 | (let* ((cmp (if (> cnt 0) '> '<)) | 2937 | (let* ((cmp (if (> cnt 0) '> '<)) |
| 2952 | (tabs (if (> cnt 0) tabs (reverse tabs))) | 2938 | (tabs (if (> cnt 0) tabs (reverse tabs))) |
| 2953 | (len (length tabs)) | 2939 | (len (length tabs)) |
| 2954 | (dir (signum cnt)) ; Direction to take | 2940 | (dir (signum cnt)) ; Direction to take. |
| 2955 | (abs (abs cnt)) ; Absolute number of steps to take | 2941 | (abs (abs cnt)) ; Absolute number of steps to take. |
| 2956 | ;; Get the position of the first tab beyond leftmostcol | 2942 | ;; Get the position of the first tab beyond leftmostcol. |
| 2957 | (fnd (position-if (lambda (elt) | 2943 | (fnd (position-if (lambda (elt) |
| 2958 | (funcall cmp elt leftmostcol)) | 2944 | (funcall cmp elt leftmostcol)) |
| 2959 | tabs)) | 2945 | tabs)) |
| 2960 | ;; Virtual position of tab | 2946 | ;; Virtual position of tab. |
| 2961 | (pos (+ (or fnd len) (1- abs))) | 2947 | (pos (+ (or fnd len) (1- abs))) |
| 2962 | (tab (if (< pos len) | 2948 | (tab (if (< pos len) |
| 2963 | ;; Tab exists - use it | 2949 | ;; Tab exists - use it. |
| 2964 | (nth pos tabs) | 2950 | (nth pos tabs) |
| 2965 | ;; Column needs to be computed | 2951 | ;; Column needs to be computed. |
| 2966 | (let ((col (+ (or (car (last tabs)) leftmostcol) | 2952 | (let ((col (+ (or (car (last tabs)) leftmostcol) |
| 2967 | ;; Base on last known column | 2953 | ;; Base on last known column. |
| 2968 | (* (- pos (1- len)) ; Distance left | 2954 | (* (- pos (1- len)) ; Distance left. |
| 2969 | dir ; Direction to take | 2955 | dir ; Direction to take. |
| 2970 | rst-indent-width)))) | 2956 | rst-indent-width)))) |
| 2971 | (if (< col 0) 0 col))))) | 2957 | (if (< col 0) 0 col))))) |
| 2972 | (- tab leftmostcol))))))) | 2958 | (- tab leftmostcol))))))) |
| 2973 | 2959 | ||
| 2974 | ;; FIXME: A paragraph with an (incorrectly) indented second line is not filled | 2960 | ;; FIXME: A paragraph with an (incorrectly) indented second line is not filled |
| 2975 | ;; correctly:: | 2961 | ;; correctly:: |
| 2976 | ;; | 2962 | ;; |
| 2977 | ;; Some start | 2963 | ;; Some start |
| 2978 | ;; continued wrong | 2964 | ;; continued wrong |
| 2979 | (defun rst-adaptive-fill () | 2965 | (defun rst-adaptive-fill () |
| 2980 | "Return fill prefix found at point. | 2966 | "Return fill prefix found at point. |
| 2981 | Value for `adaptive-fill-function'." | 2967 | Value for `adaptive-fill-function'." |
| @@ -2983,9 +2969,9 @@ Value for `adaptive-fill-function'." | |||
| 2983 | (match-string-no-properties 0)))) | 2969 | (match-string-no-properties 0)))) |
| 2984 | (if (save-match-data | 2970 | (if (save-match-data |
| 2985 | (not (string-match comment-start-skip fnd))) | 2971 | (not (string-match comment-start-skip fnd))) |
| 2986 | ;; An non-comment prefix is fine | 2972 | ;; An non-comment prefix is fine. |
| 2987 | fnd | 2973 | fnd |
| 2988 | ;; Matches a comment - return whitespace instead | 2974 | ;; Matches a comment - return whitespace instead. |
| 2989 | (make-string (- | 2975 | (make-string (- |
| 2990 | (save-excursion | 2976 | (save-excursion |
| 2991 | (goto-char (match-end 0)) | 2977 | (goto-char (match-end 0)) |
| @@ -2999,7 +2985,8 @@ Value for `adaptive-fill-function'." | |||
| 2999 | 2985 | ||
| 3000 | (defun rst-comment-line-break (&optional soft) | 2986 | (defun rst-comment-line-break (&optional soft) |
| 3001 | "Break line and indent, continuing reStructuredText comment if within one. | 2987 | "Break line and indent, continuing reStructuredText comment if within one. |
| 3002 | Value for `comment-line-break-function'." | 2988 | Value for `comment-line-break-function'. If SOFT use soft |
| 2989 | newlines as mandated by `comment-line-break-function'." | ||
| 3003 | (if soft | 2990 | (if soft |
| 3004 | (insert-and-inherit ?\n) | 2991 | (insert-and-inherit ?\n) |
| 3005 | (newline 1)) | 2992 | (newline 1)) |
| @@ -3021,7 +3008,8 @@ Value for `comment-line-break-function'." | |||
| 3021 | (insert comment-start)) | 3008 | (insert comment-start)) |
| 3022 | 3009 | ||
| 3023 | (defun rst-comment-region (beg end &optional arg) | 3010 | (defun rst-comment-region (beg end &optional arg) |
| 3024 | "Comment the current region or uncomment it if ARG is \\[universal-argument]." | 3011 | "Comment or uncomment the current region. |
| 3012 | Region is from from BEG to END. Uncomment if ARG." | ||
| 3025 | (save-excursion | 3013 | (save-excursion |
| 3026 | (if (consp arg) | 3014 | (if (consp arg) |
| 3027 | (rst-uncomment-region beg end arg) | 3015 | (rst-uncomment-region beg end arg) |
| @@ -3038,7 +3026,7 @@ Value for `comment-line-break-function'." | |||
| 3038 | 3026 | ||
| 3039 | (defun rst-uncomment-region (beg end &optional arg) | 3027 | (defun rst-uncomment-region (beg end &optional arg) |
| 3040 | "Uncomment the current region. | 3028 | "Uncomment the current region. |
| 3041 | ARG is ignored" | 3029 | Region is from BEG to END. ARG is ignored" |
| 3042 | (save-excursion | 3030 | (save-excursion |
| 3043 | (let (bol eol) | 3031 | (let (bol eol) |
| 3044 | (goto-char beg) | 3032 | (goto-char beg) |
| @@ -3051,9 +3039,9 @@ ARG is ignored" | |||
| 3051 | 3039 | ||
| 3052 | ;;------------------------------------------------------------------------------ | 3040 | ;;------------------------------------------------------------------------------ |
| 3053 | 3041 | ||
| 3054 | ;; FIXME: these next functions should become part of a larger effort to redo the | 3042 | ;; FIXME: These next functions should become part of a larger effort to redo |
| 3055 | ;; bullets in bulleted lists. The enumerate would just be one of the possible | 3043 | ;; the bullets in bulleted lists. The enumerate would just be one of |
| 3056 | ;; outputs. | 3044 | ;; the possible outputs. |
| 3057 | ;; | 3045 | ;; |
| 3058 | ;; FIXME: We need to do the enumeration removal as well. | 3046 | ;; FIXME: We need to do the enumeration removal as well. |
| 3059 | 3047 | ||
| @@ -3083,12 +3071,12 @@ do all lines instead of just paragraphs." | |||
| 3083 | (insert " ") | 3071 | (insert " ") |
| 3084 | )) | 3072 | )) |
| 3085 | 3073 | ||
| 3086 | ;; FIXME: Does not deal with a varying number of digits appropriately | 3074 | ;; FIXME: Does not deal with a varying number of digits appropriately. |
| 3087 | ;; FIXME: Does not deal with multiple levels independently | 3075 | ;; FIXME: Does not deal with multiple levels independently. |
| 3088 | ;; FIXME: Does not indent a multiline item correctly | 3076 | ;; FIXME: Does not indent a multiline item correctly. |
| 3089 | (defun rst-convert-bullets-to-enumeration (beg end) | 3077 | (defun rst-convert-bullets-to-enumeration (beg end) |
| 3090 | "Convert the bulleted and enumerated items in the region to enumerated lists. | 3078 | "Convert the bulleted and enumerated items in the region to enumerated lists. |
| 3091 | Renumber as necessary." | 3079 | Renumber as necessary. Region is from BEG to END." |
| 3092 | (interactive "r") | 3080 | (interactive "r") |
| 3093 | (let* (;; Find items and convert the positions to markers. | 3081 | (let* (;; Find items and convert the positions to markers. |
| 3094 | (items (mapcar | 3082 | (items (mapcar |
| @@ -3113,7 +3101,7 @@ Renumber as necessary." | |||
| 3113 | 3101 | ||
| 3114 | (defun rst-line-block-region (rbeg rend &optional pfxarg) | 3102 | (defun rst-line-block-region (rbeg rend &optional pfxarg) |
| 3115 | "Toggle line block prefixes for a region. | 3103 | "Toggle line block prefixes for a region. |
| 3116 | With prefix argument set the empty lines too." | 3104 | Region is from RBEG to REND. With PFXARG set the empty lines too." |
| 3117 | (interactive "r\nP") | 3105 | (interactive "r\nP") |
| 3118 | (let ((comment-start "| ") | 3106 | (let ((comment-start "| ") |
| 3119 | (comment-end "") | 3107 | (comment-end "") |
| @@ -3135,7 +3123,7 @@ With prefix argument set the empty lines too." | |||
| 3135 | 3123 | ||
| 3136 | (require 'font-lock) | 3124 | (require 'font-lock) |
| 3137 | 3125 | ||
| 3138 | ;; FIXME: The obsolete variables need to disappear | 3126 | ;; FIXME: The obsolete variables need to disappear. |
| 3139 | 3127 | ||
| 3140 | (defgroup rst-faces nil "Faces used in Rst Mode." | 3128 | (defgroup rst-faces nil "Faces used in Rst Mode." |
| 3141 | :group 'rst | 3129 | :group 'rst |
| @@ -3279,9 +3267,10 @@ general but you do not like the details." | |||
| 3279 | :version "21.1") | 3267 | :version "21.1") |
| 3280 | 3268 | ||
| 3281 | (defun rst-set-level-default (sym val) | 3269 | (defun rst-set-level-default (sym val) |
| 3282 | "Set custom var SYM affecting section title text face and recompute the faces." | 3270 | "Set custom variable SYM affecting section title text face. |
| 3271 | Recompute the faces. VAL is the value to set." | ||
| 3283 | (custom-set-default sym val) | 3272 | (custom-set-default sym val) |
| 3284 | ;; Also defines the faces initially when all values are available | 3273 | ;; Also defines the faces initially when all values are available. |
| 3285 | (and (boundp 'rst-level-face-max) | 3274 | (and (boundp 'rst-level-face-max) |
| 3286 | (boundp 'rst-level-face-format-light) | 3275 | (boundp 'rst-level-face-format-light) |
| 3287 | (boundp 'rst-level-face-base-color) | 3276 | (boundp 'rst-level-face-base-color) |
| @@ -3290,9 +3279,9 @@ general but you do not like the details." | |||
| 3290 | (fboundp 'rst-define-level-faces) | 3279 | (fboundp 'rst-define-level-faces) |
| 3291 | (rst-define-level-faces))) | 3280 | (rst-define-level-faces))) |
| 3292 | 3281 | ||
| 3293 | ;; Faces for displaying items on several levels; these definitions define | 3282 | ;; Faces for displaying items on several levels. These definitions define |
| 3294 | ;; different shades of gray where the lightest one (i.e. least contrasting) is | 3283 | ;; different shades of gray where the lightest one (i.e. least contrasting) is |
| 3295 | ;; used for level 1 | 3284 | ;; used for level 1. |
| 3296 | (defcustom rst-level-face-max 6 | 3285 | (defcustom rst-level-face-max 6 |
| 3297 | "Maximum depth of levels for which section title faces are defined." | 3286 | "Maximum depth of levels for which section title faces are defined." |
| 3298 | :group 'rst-faces-defaults | 3287 | :group 'rst-faces-defaults |
| @@ -3362,10 +3351,10 @@ details check the Rst Faces Defaults group." | |||
| 3362 | :value-type (face)) | 3351 | :value-type (face)) |
| 3363 | :set-after '(rst-level-face-max)) | 3352 | :set-after '(rst-level-face-max)) |
| 3364 | 3353 | ||
| 3365 | ;; FIXME: It should be possible to give "#RRGGBB" type of color values | 3354 | ;; FIXME: It should be possible to give "#RRGGBB" type of color values. |
| 3366 | (defun rst-define-level-faces () | 3355 | (defun rst-define-level-faces () |
| 3367 | "Define the faces for the section title text faces from the values." | 3356 | "Define the faces for the section title text faces from the values." |
| 3368 | ;; All variables used here must be checked in `rst-set-level-default' | 3357 | ;; All variables used here must be checked in `rst-set-level-default'. |
| 3369 | (let ((i 1)) | 3358 | (let ((i 1)) |
| 3370 | (while (<= i rst-level-face-max) | 3359 | (while (<= i rst-level-face-max) |
| 3371 | (let ((sym (intern (format "rst-level-%d-face" i))) | 3360 | (let ((sym (intern (format "rst-level-%d-face" i))) |
| @@ -3387,19 +3376,20 @@ details check the Rst Faces Defaults group." | |||
| 3387 | 3376 | ||
| 3388 | (defvar rst-font-lock-keywords | 3377 | (defvar rst-font-lock-keywords |
| 3389 | ;; The reST-links in the comments below all relate to sections in | 3378 | ;; The reST-links in the comments below all relate to sections in |
| 3390 | ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html | 3379 | ;; http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html. |
| 3391 | `(;; FIXME: Block markup is not recognized in blocks after explicit markup | 3380 | `(;; FIXME: Block markup is not recognized in blocks after explicit markup |
| 3392 | ;; start | 3381 | ;; start. |
| 3393 | 3382 | ||
| 3394 | ;; Simple `Body Elements`_ | 3383 | ;; Simple `Body Elements`_ |
| 3395 | ;; `Bullet Lists`_ | 3384 | ;; `Bullet Lists`_ |
| 3396 | ;; FIXME: A bullet directly after a field name is not recognized | 3385 | ;; FIXME: A bullet directly after a field name is not recognized. |
| 3397 | (,(rst-re 'lin-beg '(:grp bul-sta)) | 3386 | (,(rst-re 'lin-beg '(:grp bul-sta)) |
| 3398 | 1 rst-block-face) | 3387 | 1 rst-block-face) |
| 3399 | ;; `Enumerated Lists`_ | 3388 | ;; `Enumerated Lists`_ |
| 3400 | (,(rst-re 'lin-beg '(:grp enmany-sta)) | 3389 | (,(rst-re 'lin-beg '(:grp enmany-sta)) |
| 3401 | 1 rst-block-face) | 3390 | 1 rst-block-face) |
| 3402 | ;; `Definition Lists`_ FIXME: missing | 3391 | ;; `Definition Lists`_ |
| 3392 | ;; FIXME: missing. | ||
| 3403 | ;; `Field Lists`_ | 3393 | ;; `Field Lists`_ |
| 3404 | (,(rst-re 'lin-beg '(:grp fld-tag) 'bli-sfx) | 3394 | (,(rst-re 'lin-beg '(:grp fld-tag) 'bli-sfx) |
| 3405 | 1 rst-external-face) | 3395 | 1 rst-external-face) |
| @@ -3408,11 +3398,12 @@ details check the Rst Faces Defaults group." | |||
| 3408 | '(:alt "$" (:seq hws-prt "\\{2\\}"))) | 3398 | '(:alt "$" (:seq hws-prt "\\{2\\}"))) |
| 3409 | 1 rst-block-face) | 3399 | 1 rst-block-face) |
| 3410 | ;; `Line Blocks`_ | 3400 | ;; `Line Blocks`_ |
| 3411 | ;; Only for lines containing no more bar - to distinguish from tables | 3401 | ;; Only for lines containing no more bar - to distinguish from tables. |
| 3412 | (,(rst-re 'lin-beg '(:grp "|" bli-sfx) "[^|\n]*$") | 3402 | (,(rst-re 'lin-beg '(:grp "|" bli-sfx) "[^|\n]*$") |
| 3413 | 1 rst-block-face) | 3403 | 1 rst-block-face) |
| 3414 | 3404 | ||
| 3415 | ;; `Tables`_ FIXME: missing | 3405 | ;; `Tables`_ |
| 3406 | ;; FIXME: missing | ||
| 3416 | 3407 | ||
| 3417 | ;; All the `Explicit Markup Blocks`_ | 3408 | ;; All the `Explicit Markup Blocks`_ |
| 3418 | ;; `Footnotes`_ / `Citations`_ | 3409 | ;; `Footnotes`_ / `Citations`_ |
| @@ -3434,11 +3425,11 @@ details check the Rst Faces Defaults group." | |||
| 3434 | (,(rst-re 'lin-beg '(:grp "__") 'bli-sfx) | 3425 | (,(rst-re 'lin-beg '(:grp "__") 'bli-sfx) |
| 3435 | 1 rst-definition-face) | 3426 | 1 rst-definition-face) |
| 3436 | 3427 | ||
| 3437 | ;; All `Inline Markup`_ - most of them may be multiline though this is | 3428 | ;; All `Inline Markup`_ |
| 3438 | ;; uninteresting | 3429 | ;; Most of them may be multiline though this is uninteresting. |
| 3439 | 3430 | ||
| 3440 | ;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented | 3431 | ;; FIXME: Condition 5 preventing fontification of e.g. "*" not implemented |
| 3441 | ;; `Strong Emphasis`_ | 3432 | ;; `Strong Emphasis`_. |
| 3442 | (,(rst-re 'ilm-pfx '(:grp "\\*\\*" ilcast-tag "\\*\\*") 'ilm-sfx) | 3433 | (,(rst-re 'ilm-pfx '(:grp "\\*\\*" ilcast-tag "\\*\\*") 'ilm-sfx) |
| 3443 | 1 rst-emphasis2-face) | 3434 | 1 rst-emphasis2-face) |
| 3444 | ;; `Emphasis`_ | 3435 | ;; `Emphasis`_ |
| @@ -3451,9 +3442,9 @@ details check the Rst Faces Defaults group." | |||
| 3451 | (,(rst-re 'ilm-pfx '(:grp "_`" ilcbkq-tag "`") 'ilm-sfx) | 3442 | (,(rst-re 'ilm-pfx '(:grp "_`" ilcbkq-tag "`") 'ilm-sfx) |
| 3452 | 1 rst-definition-face) | 3443 | 1 rst-definition-face) |
| 3453 | ;; `Hyperlink References`_ | 3444 | ;; `Hyperlink References`_ |
| 3454 | ;; FIXME: `Embedded URIs`_ not considered | 3445 | ;; FIXME: `Embedded URIs`_ not considered. |
| 3455 | ;; FIXME: Directly adjacent marked up words are not fontified correctly | 3446 | ;; FIXME: Directly adjacent marked up words are not fontified correctly |
| 3456 | ;; unless they are not separated by two spaces: foo_ bar_ | 3447 | ;; unless they are not separated by two spaces: foo_ bar_. |
| 3457 | (,(rst-re 'ilm-pfx '(:grp (:alt (:seq "`" ilcbkq-tag "`") | 3448 | (,(rst-re 'ilm-pfx '(:grp (:alt (:seq "`" ilcbkq-tag "`") |
| 3458 | (:seq "\\sw" (:alt "\\sw" "-") "+\\sw")) | 3449 | (:seq "\\sw" (:alt "\\sw" "-") "+\\sw")) |
| 3459 | "__?") 'ilm-sfx) | 3450 | "__?") 'ilm-sfx) |
| @@ -3470,19 +3461,20 @@ details check the Rst Faces Defaults group." | |||
| 3470 | 1 rst-reference-face) | 3461 | 1 rst-reference-face) |
| 3471 | ;; `Substitution References`_ | 3462 | ;; `Substitution References`_ |
| 3472 | ;; FIXME: References substitutions like |this|_ or |this|__ are not | 3463 | ;; FIXME: References substitutions like |this|_ or |this|__ are not |
| 3473 | ;; fontified correctly | 3464 | ;; fontified correctly. |
| 3474 | (,(rst-re 'ilm-pfx '(:grp sub-tag) 'ilm-sfx) | 3465 | (,(rst-re 'ilm-pfx '(:grp sub-tag) 'ilm-sfx) |
| 3475 | 1 rst-reference-face) | 3466 | 1 rst-reference-face) |
| 3476 | ;; `Standalone Hyperlinks`_ | 3467 | ;; `Standalone Hyperlinks`_ |
| 3477 | ;; FIXME: This takes it easy by using a whitespace as delimiter | 3468 | ;; FIXME: This takes it easy by using a whitespace as delimiter. |
| 3478 | (,(rst-re 'ilm-pfx '(:grp uri-tag ":\\S +") 'ilm-sfx) | 3469 | (,(rst-re 'ilm-pfx '(:grp uri-tag ":\\S +") 'ilm-sfx) |
| 3479 | 1 rst-definition-face) | 3470 | 1 rst-definition-face) |
| 3480 | (,(rst-re 'ilm-pfx '(:grp sym-tag "@" sym-tag ) 'ilm-sfx) | 3471 | (,(rst-re 'ilm-pfx '(:grp sym-tag "@" sym-tag ) 'ilm-sfx) |
| 3481 | 1 rst-definition-face) | 3472 | 1 rst-definition-face) |
| 3482 | 3473 | ||
| 3483 | ;; Do all block fontification as late as possible so 'append works | 3474 | ;; Do all block fontification as late as possible so 'append works. |
| 3484 | 3475 | ||
| 3485 | ;; Sections_ / Transitions_ - for sections this is multiline | 3476 | ;; Sections_ / Transitions_ |
| 3477 | ;; For sections this is multiline. | ||
| 3486 | (,(rst-re 'ado-beg-2-1) | 3478 | (,(rst-re 'ado-beg-2-1) |
| 3487 | (rst-font-lock-handle-adornment-matcher | 3479 | (rst-font-lock-handle-adornment-matcher |
| 3488 | (rst-font-lock-handle-adornment-pre-match-form | 3480 | (rst-font-lock-handle-adornment-pre-match-form |
| @@ -3495,13 +3487,14 @@ details check the Rst Faces Defaults group." | |||
| 3495 | 3487 | ||
| 3496 | ;; FIXME: FACESPEC could be used instead of ordinary faces to set | 3488 | ;; FIXME: FACESPEC could be used instead of ordinary faces to set |
| 3497 | ;; properties on comments and literal blocks so they are *not* | 3489 | ;; properties on comments and literal blocks so they are *not* |
| 3498 | ;; inline fontified; see (elisp)Search-based Fontification | 3490 | ;; inline fontified. See (elisp)Search-based Fontification. |
| 3499 | 3491 | ||
| 3500 | ;; FIXME: And / or use `syntax-propertize` functions as in `octave-mod.el` | 3492 | ;; FIXME: And / or use `syntax-propertize` functions as in `octave-mod.el` |
| 3501 | ;; and other V24 modes; may make `font-lock-extend-region` | 3493 | ;; and other V24 modes. May make `font-lock-extend-region` |
| 3502 | ;; superfluous | 3494 | ;; superfluous. |
| 3503 | 3495 | ||
| 3504 | ;; `Comments`_ - this is multiline | 3496 | ;; `Comments`_ |
| 3497 | ;; This is multiline. | ||
| 3505 | (,(rst-re 'lin-beg 'cmt-sta-1) | 3498 | (,(rst-re 'lin-beg 'cmt-sta-1) |
| 3506 | (1 rst-comment-face) | 3499 | (1 rst-comment-face) |
| 3507 | (rst-font-lock-find-unindented-line-match | 3500 | (rst-font-lock-find-unindented-line-match |
| @@ -3517,9 +3510,9 @@ details check the Rst Faces Defaults group." | |||
| 3517 | (0 rst-comment-face append))) | 3510 | (0 rst-comment-face append))) |
| 3518 | 3511 | ||
| 3519 | ;; FIXME: This is not rendered as comment:: | 3512 | ;; FIXME: This is not rendered as comment:: |
| 3520 | ;; .. .. list-table:: | 3513 | ;; .. .. list-table:: |
| 3521 | ;; :stub-columns: 1 | 3514 | ;; :stub-columns: 1 |
| 3522 | ;; :header-rows: 1 | 3515 | ;; :header-rows: 1 |
| 3523 | 3516 | ||
| 3524 | ;; FIXME: This is rendered wrong:: | 3517 | ;; FIXME: This is rendered wrong:: |
| 3525 | ;; | 3518 | ;; |
| @@ -3535,7 +3528,8 @@ details check the Rst Faces Defaults group." | |||
| 3535 | ;; Indentation needs to be taken from the line with the ``::`` and not from | 3528 | ;; Indentation needs to be taken from the line with the ``::`` and not from |
| 3536 | ;; the first content line. | 3529 | ;; the first content line. |
| 3537 | 3530 | ||
| 3538 | ;; `Indented Literal Blocks`_ - this is multiline | 3531 | ;; `Indented Literal Blocks`_ |
| 3532 | ;; This is multiline. | ||
| 3539 | (,(rst-re 'lin-beg 'lit-sta-2) | 3533 | (,(rst-re 'lin-beg 'lit-sta-2) |
| 3540 | (2 rst-block-face) | 3534 | (2 rst-block-face) |
| 3541 | (rst-font-lock-find-unindented-line-match | 3535 | (rst-font-lock-find-unindented-line-match |
| @@ -3543,7 +3537,8 @@ details check the Rst Faces Defaults group." | |||
| 3543 | nil | 3537 | nil |
| 3544 | (0 rst-literal-face append))) | 3538 | (0 rst-literal-face append))) |
| 3545 | 3539 | ||
| 3546 | ;; FIXME: `Quoted Literal Blocks`_ missing - this is multiline | 3540 | ;; FIXME: `Quoted Literal Blocks`_ missing. |
| 3541 | ;; This is multiline. | ||
| 3547 | 3542 | ||
| 3548 | ;; `Doctest Blocks`_ | 3543 | ;; `Doctest Blocks`_ |
| 3549 | ;; FIXME: This is wrong according to the specification: | 3544 | ;; FIXME: This is wrong according to the specification: |
| @@ -3576,8 +3571,9 @@ details check the Rst Faces Defaults group." | |||
| 3576 | (defvar font-lock-end) | 3571 | (defvar font-lock-end) |
| 3577 | 3572 | ||
| 3578 | (defun rst-font-lock-extend-region () | 3573 | (defun rst-font-lock-extend-region () |
| 3579 | "Extend the region `font-lock-beg' / `font-lock-end' iff it may | 3574 | "Extend the font-lock region if it might be in a multi-line construct. |
| 3580 | be in the middle of a multiline construct and return non-nil if so." | 3575 | Return non-nil if so. Font-lock region is from `font-lock-beg' |
| 3576 | to `font-lock-end'." | ||
| 3581 | (let ((r (rst-font-lock-extend-region-internal font-lock-beg font-lock-end))) | 3577 | (let ((r (rst-font-lock-extend-region-internal font-lock-beg font-lock-end))) |
| 3582 | (when r | 3578 | (when r |
| 3583 | (setq font-lock-beg (car r)) | 3579 | (setq font-lock-beg (car r)) |
| @@ -3585,7 +3581,7 @@ be in the middle of a multiline construct and return non-nil if so." | |||
| 3585 | t))) | 3581 | t))) |
| 3586 | 3582 | ||
| 3587 | (defun rst-font-lock-extend-region-internal (beg end) | 3583 | (defun rst-font-lock-extend-region-internal (beg end) |
| 3588 | "Check the region BEG / END for being in the middle of a multiline construct. | 3584 | "Check the region BEG / END for being in the middle of a multi-line construct. |
| 3589 | Return nil if not or a cons with new values for BEG / END" | 3585 | Return nil if not or a cons with new values for BEG / END" |
| 3590 | (let ((nbeg (rst-font-lock-extend-region-extend beg -1)) | 3586 | (let ((nbeg (rst-font-lock-extend-region-extend beg -1)) |
| 3591 | (nend (rst-font-lock-extend-region-extend end 1))) | 3587 | (nend (rst-font-lock-extend-region-extend end 1))) |
| @@ -3593,7 +3589,8 @@ Return nil if not or a cons with new values for BEG / END" | |||
| 3593 | (cons (or nbeg beg) (or nend end))))) | 3589 | (cons (or nbeg beg) (or nend end))))) |
| 3594 | 3590 | ||
| 3595 | (defun rst-forward-line (&optional n) | 3591 | (defun rst-forward-line (&optional n) |
| 3596 | "Like `forward-line' but always end up in column 0 and return accordingly." | 3592 | "Like `forward-line' but always end up in column 0 and return accordingly. |
| 3593 | Move N lines forward just as `forward-line'." | ||
| 3597 | (let ((moved (forward-line n))) | 3594 | (let ((moved (forward-line n))) |
| 3598 | (if (bolp) | 3595 | (if (bolp) |
| 3599 | moved | 3596 | moved |
| @@ -3616,41 +3613,41 @@ Return extended point or nil if not moved." | |||
| 3616 | ;; | 3613 | ;; |
| 3617 | ;; The second group consists of the adornment cases. | 3614 | ;; The second group consists of the adornment cases. |
| 3618 | (if (not (get-text-property pt 'font-lock-multiline)) | 3615 | (if (not (get-text-property pt 'font-lock-multiline)) |
| 3619 | ;; Move only if we don't start inside a multiline construct already | 3616 | ;; Move only if we don't start inside a multiline construct already. |
| 3620 | (save-excursion | 3617 | (save-excursion |
| 3621 | (let (;; non-empty non-indented line, explicit markup tag or literal | 3618 | (let (;; Non-empty non-indented line, explicit markup tag or literal |
| 3622 | ;; block tag | 3619 | ;; block tag. |
| 3623 | (stop-re (rst-re '(:alt "[^ \t\n]" | 3620 | (stop-re (rst-re '(:alt "[^ \t\n]" |
| 3624 | (:seq hws-tag exm-tag) | 3621 | (:seq hws-tag exm-tag) |
| 3625 | (:seq ".*" dcl-tag lin-end))))) | 3622 | (:seq ".*" dcl-tag lin-end))))) |
| 3626 | ;; The comments below are for dir == -1 / dir == 1 | 3623 | ;; The comments below are for dir == -1 / dir == 1. |
| 3627 | (goto-char pt) | 3624 | (goto-char pt) |
| 3628 | (forward-line 0) | 3625 | (forward-line 0) |
| 3629 | (setq pt (point)) | 3626 | (setq pt (point)) |
| 3630 | (while (and (not (looking-at stop-re)) | 3627 | (while (and (not (looking-at stop-re)) |
| 3631 | (zerop (rst-forward-line dir)))) ; try previous / next | 3628 | (zerop (rst-forward-line dir)))) ; try previous / next |
| 3632 | ; line if it exists | 3629 | ; line if it exists. |
| 3633 | (if (looking-at (rst-re 'ado-beg-2-1)) ; may be an underline / | 3630 | (if (looking-at (rst-re 'ado-beg-2-1)) ; may be an underline / |
| 3634 | ; overline | 3631 | ; overline. |
| 3635 | (if (zerop (rst-forward-line dir)) | 3632 | (if (zerop (rst-forward-line dir)) |
| 3636 | (if (looking-at (rst-re 'ttl-beg)) ; title found, i.e. | 3633 | (if (looking-at (rst-re 'ttl-beg)) ; title found, i.e. |
| 3637 | ; underline / overline | 3634 | ; underline / overline |
| 3638 | ; found | 3635 | ; found. |
| 3639 | (if (zerop (rst-forward-line dir)) | 3636 | (if (zerop (rst-forward-line dir)) |
| 3640 | (if (not | 3637 | (if (not |
| 3641 | (looking-at (rst-re 'ado-beg-2-1))) ; no | 3638 | (looking-at (rst-re 'ado-beg-2-1))) ; no |
| 3642 | ; overline / | 3639 | ; overline / |
| 3643 | ; underline | 3640 | ; underline. |
| 3644 | (rst-forward-line (- dir)))) ; step back to title | 3641 | (rst-forward-line (- dir)))) ; step back to title |
| 3645 | ; / adornment | 3642 | ; / adornment. |
| 3646 | (if (< dir 0) ; keep downward adornment | 3643 | (if (< dir 0) ; keep downward adornment. |
| 3647 | (rst-forward-line (- dir))))) ; step back to adornment | 3644 | (rst-forward-line (- dir))))) ; step back to adornment. |
| 3648 | (if (looking-at (rst-re 'ttl-beg)) ; may be a title | 3645 | (if (looking-at (rst-re 'ttl-beg)) ; may be a title. |
| 3649 | (if (zerop (rst-forward-line dir)) | 3646 | (if (zerop (rst-forward-line dir)) |
| 3650 | (if (not | 3647 | (if (not |
| 3651 | (looking-at (rst-re 'ado-beg-2-1))) ; no overline / | 3648 | (looking-at (rst-re 'ado-beg-2-1))) ; no overline / |
| 3652 | ; underline | 3649 | ; underline. |
| 3653 | (rst-forward-line (- dir)))))) ; step back to line | 3650 | (rst-forward-line (- dir)))))) ; step back to line. |
| 3654 | (if (not (= (point) pt)) | 3651 | (if (not (= (point) pt)) |
| 3655 | (point)))))) | 3652 | (point)))))) |
| 3656 | 3653 | ||
| @@ -3676,20 +3673,21 @@ point is not moved." | |||
| 3676 | (when (< (point) limit) | 3673 | (when (< (point) limit) |
| 3677 | (setq beg (point)) | 3674 | (setq beg (point)) |
| 3678 | (if (looking-at (rst-re 'lin-end)) | 3675 | (if (looking-at (rst-re 'lin-end)) |
| 3679 | (setq cand (or cand beg)) ; An empty line is a candidate | 3676 | (setq cand (or cand beg)) ; An empty line is a candidate. |
| 3680 | (move-to-column clm) | 3677 | (move-to-column clm) |
| 3681 | ;; FIXME: No indentation [(zerop clm)] must be handled in some | 3678 | ;; FIXME: No indentation [(zerop clm)] must be handled in some |
| 3682 | ;; useful way - though it is not clear what this should mean at all | 3679 | ;; useful way - though it is not clear what this should mean |
| 3680 | ;; at all. | ||
| 3683 | (if (string-match | 3681 | (if (string-match |
| 3684 | (rst-re 'linemp-tag) | 3682 | (rst-re 'linemp-tag) |
| 3685 | (buffer-substring-no-properties beg (point))) | 3683 | (buffer-substring-no-properties beg (point))) |
| 3686 | (setq cand nil) ; An indented line resets a candidate | 3684 | (setq cand nil) ; An indented line resets a candidate. |
| 3687 | (setq fnd (or cand beg))))))) | 3685 | (setq fnd (or cand beg))))))) |
| 3688 | (goto-char (or fnd start)) | 3686 | (goto-char (or fnd start)) |
| 3689 | fnd)) | 3687 | fnd)) |
| 3690 | 3688 | ||
| 3691 | (defvar rst-font-lock-find-unindented-line-begin nil | 3689 | (defvar rst-font-lock-find-unindented-line-begin nil |
| 3692 | "Beginning of the match if `rst-font-lock-find-unindented-line-end'") | 3690 | "Beginning of the match if `rst-font-lock-find-unindented-line-end'.") |
| 3693 | 3691 | ||
| 3694 | (defvar rst-font-lock-find-unindented-line-end nil | 3692 | (defvar rst-font-lock-find-unindented-line-end nil |
| 3695 | "End of the match as determined by `rst-font-lock-find-unindented-line-limit'. | 3693 | "End of the match as determined by `rst-font-lock-find-unindented-line-limit'. |
| @@ -3700,7 +3698,7 @@ Also used as a trigger for | |||
| 3700 | "Find the next unindented line relative to indentation at IND-PNT. | 3698 | "Find the next unindented line relative to indentation at IND-PNT. |
| 3701 | Return this point, the end of the buffer or nil if nothing found. | 3699 | Return this point, the end of the buffer or nil if nothing found. |
| 3702 | If IND-PNT is `next' take the indentation from the next line if | 3700 | If IND-PNT is `next' take the indentation from the next line if |
| 3703 | this is not empty and indented more than the current one. If | 3701 | this is not empty and indented more than the current one. If |
| 3704 | IND-PNT is non-nil but not a number take the indentation from the | 3702 | IND-PNT is non-nil but not a number take the indentation from the |
| 3705 | next non-empty line if this is indented more than the current | 3703 | next non-empty line if this is indented more than the current |
| 3706 | one." | 3704 | one." |
| @@ -3708,34 +3706,34 @@ one." | |||
| 3708 | (setq rst-font-lock-find-unindented-line-end | 3706 | (setq rst-font-lock-find-unindented-line-end |
| 3709 | (save-excursion | 3707 | (save-excursion |
| 3710 | (when (not (numberp ind-pnt)) | 3708 | (when (not (numberp ind-pnt)) |
| 3711 | ;; Find indentation point in next line if any | 3709 | ;; Find indentation point in next line if any. |
| 3712 | (setq ind-pnt | 3710 | (setq ind-pnt |
| 3713 | ;; FIXME: Should be refactored to two different functions | 3711 | ;; FIXME: Should be refactored to two different functions |
| 3714 | ;; giving their result to this function, may be | 3712 | ;; giving their result to this function, may be |
| 3715 | ;; integrated in caller | 3713 | ;; integrated in caller. |
| 3716 | (save-match-data | 3714 | (save-match-data |
| 3717 | (let ((cur-ind (current-indentation))) | 3715 | (let ((cur-ind (current-indentation))) |
| 3718 | (if (eq ind-pnt 'next) | 3716 | (if (eq ind-pnt 'next) |
| 3719 | (when (and (zerop (forward-line 1)) | 3717 | (when (and (zerop (forward-line 1)) |
| 3720 | (< (point) (point-max))) | 3718 | (< (point) (point-max))) |
| 3721 | ;; Not at EOF | 3719 | ;; Not at EOF. |
| 3722 | (setq rst-font-lock-find-unindented-line-begin | 3720 | (setq rst-font-lock-find-unindented-line-begin |
| 3723 | (point)) | 3721 | (point)) |
| 3724 | (when (and (not (looking-at (rst-re 'lin-end))) | 3722 | (when (and (not (looking-at (rst-re 'lin-end))) |
| 3725 | (> (current-indentation) cur-ind)) | 3723 | (> (current-indentation) cur-ind)) |
| 3726 | ;; Use end of indentation if non-empty line | 3724 | ;; Use end of indentation if non-empty line. |
| 3727 | (looking-at (rst-re 'hws-tag)) | 3725 | (looking-at (rst-re 'hws-tag)) |
| 3728 | (match-end 0))) | 3726 | (match-end 0))) |
| 3729 | ;; Skip until non-empty line or EOF | 3727 | ;; Skip until non-empty line or EOF. |
| 3730 | (while (and (zerop (forward-line 1)) | 3728 | (while (and (zerop (forward-line 1)) |
| 3731 | (< (point) (point-max)) | 3729 | (< (point) (point-max)) |
| 3732 | (looking-at (rst-re 'lin-end)))) | 3730 | (looking-at (rst-re 'lin-end)))) |
| 3733 | (when (< (point) (point-max)) | 3731 | (when (< (point) (point-max)) |
| 3734 | ;; Not at EOF | 3732 | ;; Not at EOF. |
| 3735 | (setq rst-font-lock-find-unindented-line-begin | 3733 | (setq rst-font-lock-find-unindented-line-begin |
| 3736 | (point)) | 3734 | (point)) |
| 3737 | (when (> (current-indentation) cur-ind) | 3735 | (when (> (current-indentation) cur-ind) |
| 3738 | ;; Indentation bigger than line of departure | 3736 | ;; Indentation bigger than line of departure. |
| 3739 | (looking-at (rst-re 'hws-tag)) | 3737 | (looking-at (rst-re 'hws-tag)) |
| 3740 | (match-end 0)))))))) | 3738 | (match-end 0)))))))) |
| 3741 | (when ind-pnt | 3739 | (when ind-pnt |
| @@ -3744,9 +3742,11 @@ one." | |||
| 3744 | (point-max)))))) | 3742 | (point-max)))))) |
| 3745 | 3743 | ||
| 3746 | (defun rst-font-lock-find-unindented-line-match (limit) | 3744 | (defun rst-font-lock-find-unindented-line-match (limit) |
| 3747 | "Set the match found by | 3745 | "Set the match found earlier if match were found. |
| 3746 | Match has been found by | ||
| 3748 | `rst-font-lock-find-unindented-line-limit' the first time called | 3747 | `rst-font-lock-find-unindented-line-limit' the first time called |
| 3749 | or nil." | 3748 | or no match is found. Return non-nil if match was found. LIMIT |
| 3749 | is not used but mandated by the caller." | ||
| 3750 | (when rst-font-lock-find-unindented-line-end | 3750 | (when rst-font-lock-find-unindented-line-end |
| 3751 | (set-match-data | 3751 | (set-match-data |
| 3752 | (list rst-font-lock-find-unindented-line-begin | 3752 | (list rst-font-lock-find-unindented-line-begin |
| @@ -3754,7 +3754,7 @@ or nil." | |||
| 3754 | (put-text-property rst-font-lock-find-unindented-line-begin | 3754 | (put-text-property rst-font-lock-find-unindented-line-begin |
| 3755 | rst-font-lock-find-unindented-line-end | 3755 | rst-font-lock-find-unindented-line-end |
| 3756 | 'font-lock-multiline t) | 3756 | 'font-lock-multiline t) |
| 3757 | ;; Make sure this is called only once | 3757 | ;; Make sure this is called only once. |
| 3758 | (setq rst-font-lock-find-unindented-line-end nil) | 3758 | (setq rst-font-lock-find-unindented-line-end nil) |
| 3759 | t)) | 3759 | t)) |
| 3760 | 3760 | ||
| @@ -3768,8 +3768,8 @@ Either section level of the current adornment or t for a transition.") | |||
| 3768 | (defun rst-adornment-level (key) | 3768 | (defun rst-adornment-level (key) |
| 3769 | "Return section level for adornment KEY. | 3769 | "Return section level for adornment KEY. |
| 3770 | KEY is the first element of the return list of | 3770 | KEY is the first element of the return list of |
| 3771 | `rst-classify-adornment'. If KEY is not a cons return it. If KEY is found | 3771 | `rst-classify-adornment'. If KEY is not a cons return it. If KEY is found |
| 3772 | in the hierarchy return its level. Otherwise return a level one | 3772 | in the hierarchy return its level. Otherwise return a level one |
| 3773 | beyond the existing hierarchy." | 3773 | beyond the existing hierarchy." |
| 3774 | (if (not (consp key)) | 3774 | (if (not (consp key)) |
| 3775 | key | 3775 | key |
| @@ -3783,15 +3783,16 @@ beyond the existing hierarchy." | |||
| 3783 | 3783 | ||
| 3784 | (defvar rst-font-lock-adornment-match nil | 3784 | (defvar rst-font-lock-adornment-match nil |
| 3785 | "Storage for match for current adornment. | 3785 | "Storage for match for current adornment. |
| 3786 | Set by `rst-font-lock-handle-adornment-pre-match-form'. Also used | 3786 | Set by `rst-font-lock-handle-adornment-pre-match-form'. Also used |
| 3787 | as a trigger for `rst-font-lock-handle-adornment-matcher'.") | 3787 | as a trigger for `rst-font-lock-handle-adornment-matcher'.") |
| 3788 | 3788 | ||
| 3789 | (defun rst-font-lock-handle-adornment-pre-match-form (ado ado-end) | 3789 | (defun rst-font-lock-handle-adornment-pre-match-form (ado ado-end) |
| 3790 | "Determine limit for adornments for font-locking section titles and transitions. | 3790 | "Determine limit for adornments. |
| 3791 | In fact determine all things necessary and put the result to | 3791 | Determine all things necessary for font-locking section titles |
| 3792 | and transitions and put the result to | ||
| 3792 | `rst-font-lock-adornment-match' and | 3793 | `rst-font-lock-adornment-match' and |
| 3793 | `rst-font-lock-adornment-level'. ADO is the complete adornment | 3794 | `rst-font-lock-adornment-level'. ADO is the complete adornment |
| 3794 | matched. ADO-END is the point where ADO ends. Return the point | 3795 | matched. ADO-END is the point where ADO ends. Return the point |
| 3795 | where the whole adorned construct ends. | 3796 | where the whole adorned construct ends. |
| 3796 | 3797 | ||
| 3797 | Called as a PRE-MATCH-FORM in the sense of `font-lock-keywords'." | 3798 | Called as a PRE-MATCH-FORM in the sense of `font-lock-keywords'." |
| @@ -3802,16 +3803,19 @@ Called as a PRE-MATCH-FORM in the sense of `font-lock-keywords'." | |||
| 3802 | (setq rst-font-lock-adornment-level | 3803 | (setq rst-font-lock-adornment-level |
| 3803 | (rst-adornment-level (car ado-data))) | 3804 | (rst-adornment-level (car ado-data))) |
| 3804 | (setq rst-font-lock-adornment-match (cdr ado-data)) | 3805 | (setq rst-font-lock-adornment-match (cdr ado-data)) |
| 3805 | (goto-char (nth 1 ado-data)) ; Beginning of construct | 3806 | (goto-char (nth 1 ado-data)) ; Beginning of construct. |
| 3806 | (nth 2 ado-data)))) ; End of construct | 3807 | (nth 2 ado-data)))) ; End of construct. |
| 3807 | 3808 | ||
| 3808 | (defun rst-font-lock-handle-adornment-matcher (limit) | 3809 | (defun rst-font-lock-handle-adornment-matcher (limit) |
| 3809 | "Set the match found by `rst-font-lock-handle-adornment-pre-match-form' | 3810 | "Set the match found earlier if match were found. |
| 3810 | the first time called or nil. | 3811 | Match has been found by |
| 3812 | `rst-font-lock-handle-adornment-pre-match-form' the first time | ||
| 3813 | called or no match is found. Return non-nil if match was found. | ||
| 3811 | 3814 | ||
| 3812 | Called as a MATCHER in the sense of `font-lock-keywords'." | 3815 | Called as a MATCHER in the sense of `font-lock-keywords'. |
| 3816 | LIMIT is not used but mandated by the caller." | ||
| 3813 | (let ((match rst-font-lock-adornment-match)) | 3817 | (let ((match rst-font-lock-adornment-match)) |
| 3814 | ;; May run only once - enforce this | 3818 | ;; May run only once - enforce this. |
| 3815 | (setq rst-font-lock-adornment-match nil) | 3819 | (setq rst-font-lock-adornment-match nil) |
| 3816 | (when match | 3820 | (when match |
| 3817 | (set-match-data match) | 3821 | (set-match-data match) |
| @@ -3847,12 +3851,12 @@ document with \\[rst-compile]." | |||
| 3847 | ".pdf" nil) | 3851 | ".pdf" nil) |
| 3848 | (s5 ,(if (executable-find "rst2s5.py") "rst2s5.py" "rst2s5") | 3852 | (s5 ,(if (executable-find "rst2s5.py") "rst2s5.py" "rst2s5") |
| 3849 | ".html" nil)) | 3853 | ".html" nil)) |
| 3850 | "Table describing the command to use for each toolset. | 3854 | "Table describing the command to use for each tool-set. |
| 3851 | An association list of the toolset to a list of the (command to use, | 3855 | An association list of the tool-set to a list of the (command to use, |
| 3852 | extension of produced filename, options to the tool (nil or a | 3856 | extension of produced filename, options to the tool (nil or a |
| 3853 | string)) to be used for converting the document." | 3857 | string)) to be used for converting the document." |
| 3854 | ;; FIXME: These are not options but symbols which may be referenced by | 3858 | ;; FIXME: These are not options but symbols which may be referenced by |
| 3855 | ;; `rst-compile-*-toolset` below | 3859 | ;; `rst-compile-*-toolset` below. |
| 3856 | :type '(alist :options (html latex newlatex pseudoxml xml pdf s5) | 3860 | :type '(alist :options (html latex newlatex pseudoxml xml pdf s5) |
| 3857 | :key-type symbol | 3861 | :key-type symbol |
| 3858 | :value-type (list :tag "Specification" | 3862 | :value-type (list :tag "Specification" |
| @@ -3864,13 +3868,13 @@ string)) to be used for converting the document." | |||
| 3864 | :group 'rst | 3868 | :group 'rst |
| 3865 | :version "24.1") | 3869 | :version "24.1") |
| 3866 | 3870 | ||
| 3867 | ;; FIXME: Must be `defcustom` | 3871 | ;; FIXME: Must be `defcustom`. |
| 3868 | (defvar rst-compile-primary-toolset 'html | 3872 | (defvar rst-compile-primary-toolset 'html |
| 3869 | "The default toolset for `rst-compile'.") | 3873 | "The default tool-set for `rst-compile'.") |
| 3870 | 3874 | ||
| 3871 | ;; FIXME: Must be `defcustom` | 3875 | ;; FIXME: Must be `defcustom`. |
| 3872 | (defvar rst-compile-secondary-toolset 'latex | 3876 | (defvar rst-compile-secondary-toolset 'latex |
| 3873 | "The default toolset for `rst-compile' with a prefix argument.") | 3877 | "The default tool-set for `rst-compile' with a prefix argument.") |
| 3874 | 3878 | ||
| 3875 | (defun rst-compile-find-conf () | 3879 | (defun rst-compile-find-conf () |
| 3876 | "Look for the configuration file in the parents of the current path." | 3880 | "Look for the configuration file in the parents of the current path." |
| @@ -3900,7 +3904,7 @@ string)) to be used for converting the document." | |||
| 3900 | "Compile command to convert reST document into some output file. | 3904 | "Compile command to convert reST document into some output file. |
| 3901 | Attempts to find configuration file, if it can, overrides the | 3905 | Attempts to find configuration file, if it can, overrides the |
| 3902 | options. There are two commands to choose from, with USE-ALT, | 3906 | options. There are two commands to choose from, with USE-ALT, |
| 3903 | select the alternative toolset." | 3907 | select the alternative tool-set." |
| 3904 | (interactive "P") | 3908 | (interactive "P") |
| 3905 | ;; Note: maybe we want to check if there is a Makefile too and not do anything | 3909 | ;; Note: maybe we want to check if there is a Makefile too and not do anything |
| 3906 | ;; if that is the case. I dunno. | 3910 | ;; if that is the case. I dunno. |
| @@ -3934,13 +3938,15 @@ select the alternative toolset." | |||
| 3934 | )) | 3938 | )) |
| 3935 | 3939 | ||
| 3936 | (defun rst-compile-alt-toolset () | 3940 | (defun rst-compile-alt-toolset () |
| 3937 | "Compile command with the alternative toolset." | 3941 | "Compile command with the alternative tool-set." |
| 3938 | (interactive) | 3942 | (interactive) |
| 3939 | (rst-compile t)) | 3943 | (rst-compile t)) |
| 3940 | 3944 | ||
| 3941 | (defun rst-compile-pseudo-region () | 3945 | (defun rst-compile-pseudo-region () |
| 3942 | "Show the pseudo-XML rendering of the current active region, | 3946 | "Show pseudo-XML rendering. |
| 3943 | or of the entire buffer, if the region is not selected." | 3947 | Rendering is done of the current active region, or of the entire |
| 3948 | buffer, if the region is not selected." | ||
| 3949 | ;; FIXME: The region should be given interactively. | ||
| 3944 | (interactive) | 3950 | (interactive) |
| 3945 | (with-output-to-temp-buffer "*pseudoxml*" | 3951 | (with-output-to-temp-buffer "*pseudoxml*" |
| 3946 | (shell-command-on-region | 3952 | (shell-command-on-region |
| @@ -3949,7 +3955,7 @@ or of the entire buffer, if the region is not selected." | |||
| 3949 | (cadr (assq 'pseudoxml rst-compile-toolsets)) | 3955 | (cadr (assq 'pseudoxml rst-compile-toolsets)) |
| 3950 | standard-output))) | 3956 | standard-output))) |
| 3951 | 3957 | ||
| 3952 | ;; FIXME: Should be `defcustom` | 3958 | ;; FIXME: Should be `defcustom`. |
| 3953 | (defvar rst-pdf-program "xpdf" | 3959 | (defvar rst-pdf-program "xpdf" |
| 3954 | "Program used to preview PDF files.") | 3960 | "Program used to preview PDF files.") |
| 3955 | 3961 | ||
| @@ -3966,7 +3972,7 @@ or of the entire buffer, if the region is not selected." | |||
| 3966 | ;; output. | 3972 | ;; output. |
| 3967 | )) | 3973 | )) |
| 3968 | 3974 | ||
| 3969 | ;; FIXME: Should be `defcustom` or use something like `browse-url` | 3975 | ;; FIXME: Should be `defcustom` or use something like `browse-url`. |
| 3970 | (defvar rst-slides-program "firefox" | 3976 | (defvar rst-slides-program "firefox" |
| 3971 | "Program used to preview S5 slides.") | 3977 | "Program used to preview S5 slides.") |
| 3972 | 3978 | ||
| @@ -3987,10 +3993,9 @@ or of the entire buffer, if the region is not selected." | |||
| 3987 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 3993 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 3988 | ;; Generic text functions that are more convenient than the defaults. | 3994 | ;; Generic text functions that are more convenient than the defaults. |
| 3989 | 3995 | ||
| 3990 | ;; FIXME: Unbound command - should be bound or removed | 3996 | ;; FIXME: Unbound command - should be bound or removed. |
| 3991 | (defun rst-replace-lines (fromchar tochar) | 3997 | (defun rst-replace-lines (fromchar tochar) |
| 3992 | "Replace flush-left lines, consisting of multiple FROMCHAR characters, | 3998 | "Replace flush-left lines of FROMCHAR with equal-length lines of TOCHAR." |
| 3993 | with equal-length lines of TOCHAR." | ||
| 3994 | (interactive "\ | 3999 | (interactive "\ |
| 3995 | cSearch for flush-left lines of char: | 4000 | cSearch for flush-left lines of char: |
| 3996 | cand replace with char: ") | 4001 | cand replace with char: ") |
| @@ -4005,14 +4010,14 @@ cand replace with char: ") | |||
| 4005 | (insert-char tochar width))) | 4010 | (insert-char tochar width))) |
| 4006 | (message (format "%d lines replaced." found))))) | 4011 | (message (format "%d lines replaced." found))))) |
| 4007 | 4012 | ||
| 4008 | ;; FIXME: Unbound command - should be bound or removed | 4013 | ;; FIXME: Unbound command - should be bound or removed. |
| 4009 | (defun rst-join-paragraph () | 4014 | (defun rst-join-paragraph () |
| 4010 | "Join lines in current paragraph into one line, removing end-of-lines." | 4015 | "Join lines in current paragraph into one line, removing end-of-lines." |
| 4011 | (interactive) | 4016 | (interactive) |
| 4012 | (let ((fill-column 65000)) ; some big number | 4017 | (let ((fill-column 65000)) ; some big number. |
| 4013 | (call-interactively 'fill-paragraph))) | 4018 | (call-interactively 'fill-paragraph))) |
| 4014 | 4019 | ||
| 4015 | ;; FIXME: Unbound command - should be bound or removed | 4020 | ;; FIXME: Unbound command - should be bound or removed. |
| 4016 | (defun rst-force-fill-paragraph () | 4021 | (defun rst-force-fill-paragraph () |
| 4017 | "Fill paragraph at point, first joining the paragraph's lines into one. | 4022 | "Fill paragraph at point, first joining the paragraph's lines into one. |
| 4018 | This is useful for filling list item paragraphs." | 4023 | This is useful for filling list item paragraphs." |
| @@ -4021,14 +4026,14 @@ This is useful for filling list item paragraphs." | |||
| 4021 | (fill-paragraph nil)) | 4026 | (fill-paragraph nil)) |
| 4022 | 4027 | ||
| 4023 | 4028 | ||
| 4024 | ;; FIXME: Unbound command - should be bound or removed | 4029 | ;; FIXME: Unbound command - should be bound or removed. |
| 4025 | ;; Generic character repeater function. | 4030 | ;; Generic character repeater function. |
| 4026 | ;; For sections, better to use the specialized function above, but this can | 4031 | ;; For sections, better to use the specialized function above, but this can |
| 4027 | ;; be useful for creating separators. | 4032 | ;; be useful for creating separators. |
| 4028 | (defun rst-repeat-last-character (use-next) | 4033 | (defun rst-repeat-last-character (use-next) |
| 4029 | "Fill the current line up to the length of the preceding line (if not | 4034 | "Fill the current line using the last character on the current line. |
| 4030 | empty), using the last character on the current line. If the preceding line is | 4035 | Fill up to the length of the preceding line or up to |
| 4031 | empty, we use the `fill-column'. | 4036 | `fill-column' if preceding line is empty. |
| 4032 | 4037 | ||
| 4033 | If USE-NEXT, use the next line rather than the preceding line. | 4038 | If USE-NEXT, use the next line rather than the preceding line. |
| 4034 | 4039 | ||
| @@ -4058,18 +4063,19 @@ column is used (fill-column vs. end of previous/next line)." | |||
| 4058 | )) ) | 4063 | )) ) |
| 4059 | (end-of-line) | 4064 | (end-of-line) |
| 4060 | (if (> (current-column) rightmost-column) | 4065 | (if (> (current-column) rightmost-column) |
| 4061 | ;; shave characters off the end | 4066 | ;; Shave characters off the end. |
| 4062 | (delete-region (- (point) | 4067 | (delete-region (- (point) |
| 4063 | (- (current-column) rightmost-column)) | 4068 | (- (current-column) rightmost-column)) |
| 4064 | (point)) | 4069 | (point)) |
| 4065 | ;; fill with last characters | 4070 | ;; Fill with last characters. |
| 4066 | (insert-char (preceding-char) | 4071 | (insert-char (preceding-char) |
| 4067 | (- rightmost-column (current-column)))) | 4072 | (- rightmost-column (current-column)))) |
| 4068 | )) | 4073 | )) |
| 4069 | 4074 | ||
| 4070 | 4075 | ||
| 4071 | (defun rst-portable-mark-active-p () | 4076 | (defun rst-portable-mark-active-p () |
| 4072 | "A portable function that returns non-nil if the mark is active." | 4077 | "Return non-nil if the mark is active. |
| 4078 | This is a portable function." | ||
| 4073 | (cond | 4079 | (cond |
| 4074 | ((fboundp 'region-active-p) (region-active-p)) | 4080 | ((fboundp 'region-active-p) (region-active-p)) |
| 4075 | ((boundp 'transient-mark-mode) (and transient-mark-mode mark-active)) | 4081 | ((boundp 'transient-mark-mode) (and transient-mark-mode mark-active)) |
| @@ -4077,4 +4083,13 @@ column is used (fill-column vs. end of previous/next line)." | |||
| 4077 | 4083 | ||
| 4078 | 4084 | ||
| 4079 | (provide 'rst) | 4085 | (provide 'rst) |
| 4080 | ;;; rst.el ends here | 4086 | |
| 4087 | ;; LocalWords: docutils http sourceforge rst html wp svn svnroot txt reST regex | ||
| 4088 | ;; LocalWords: regexes alist seq alt grp keymap abbrev overline overlines toc | ||
| 4089 | ;; LocalWords: XML PNT propertized referencable | ||
| 4090 | |||
| 4091 | ;; Local Variables: | ||
| 4092 | ;; sentence-end-double-space: t | ||
| 4093 | ;; End: | ||
| 4094 | |||
| 4095 | ;;; rst.el ends here. | ||