diff options
| author | Stefan Merten | 2012-06-07 11:20:41 +0200 |
|---|---|---|
| committer | Stefan Merten | 2012-06-07 11:20:41 +0200 |
| commit | 7b4cdbf41d269c5caeb1c3906158192fbc4ef6b0 (patch) | |
| tree | 1542c91dd9adff3012cd50e26fdd52cfdb90adb7 | |
| parent | 86f158bc15cd63740131ca102179c760a691e4c8 (diff) | |
| download | emacs-7b4cdbf41d269c5caeb1c3906158192fbc4ef6b0.tar.gz emacs-7b4cdbf41d269c5caeb1c3906158192fbc4ef6b0.zip | |
* rst.el: Use `eval-when-compile' for requiring
`cl.el'. Silence compiler warnings. Fix versions.
(rst-position-if, rst-position, rst-some, rst-signum): New
functions.
(rst-shift-region, rst-adornment-level, rst-compute-tabs)
(rst-indent-line, rst-shift-region, rst-forward-line): Use new
functions.
(rst-package-emacs-version-alist): Correct Emacs version to
represent major merge with upstream.
(rst-transition, rst-adornment, rst-compile-toolsets): Fix
versions.
| -rw-r--r-- | lisp/ChangeLog | 16 | ||||
| -rw-r--r-- | lisp/textmodes/rst.el | 136 |
2 files changed, 107 insertions, 45 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d1e9b705fc5..4e85ce83503 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2012-06-07 Stefan Merten <smerten@oekonux.de> | ||
| 2 | |||
| 3 | * textmodes/rst.el: Use `eval-when-compile' for requiring `cl.el'. | ||
| 4 | Silence compiler warnings. Fix versions. | ||
| 5 | |||
| 6 | (rst-position-if, rst-position, rst-some, rst-signum): New | ||
| 7 | functions. | ||
| 8 | (rst-shift-region, rst-adornment-level, rst-compute-tabs) | ||
| 9 | (rst-indent-line, rst-shift-region, rst-forward-line): Use new | ||
| 10 | functions. | ||
| 11 | |||
| 12 | (rst-package-emacs-version-alist): Correct Emacs version to | ||
| 13 | represent major merge with upstream. | ||
| 14 | (rst-transition, rst-adornment, rst-compile-toolsets): Fix | ||
| 15 | versions. | ||
| 16 | |||
| 1 | 2012-06-06 Glenn Morris <rgm@gnu.org> | 17 | 2012-06-06 Glenn Morris <rgm@gnu.org> |
| 2 | 18 | ||
| 3 | * mail/emacsbug.el (report-emacs-bug): Add relevant EMACS env-vars. | 19 | * mail/emacsbug.el (report-emacs-bug): Add relevant EMACS env-vars. |
diff --git a/lisp/textmodes/rst.el b/lisp/textmodes/rst.el index 0474db7d40e..c09d2a60cce 100644 --- a/lisp/textmodes/rst.el +++ b/lisp/textmodes/rst.el | |||
| @@ -103,14 +103,58 @@ | |||
| 103 | 103 | ||
| 104 | ;;; Code: | 104 | ;;; Code: |
| 105 | 105 | ||
| 106 | ;; FIXME: Use `eval-when-compile' when calls to `some', `position', `signum' | 106 | ;; Only use of macros is allowed - may be replaced by `cl-lib' some time. |
| 107 | ;; and `position-if' are replaced. `catch' and `throw' may help with the | 107 | (eval-when-compile |
| 108 | ;; list operations. | 108 | (require 'cl)) |
| 109 | (require 'cl) | 109 | |
| 110 | ;; Redefine some functions from `cl.el' in a proper namespace until they may be | ||
| 111 | ;; used from there. | ||
| 112 | |||
| 113 | (defun rst-signum (x) | ||
| 114 | "Return 1 if X is positive, -1 if negative, 0 if zero." | ||
| 115 | (cond | ||
| 116 | ((> x 0) 1) | ||
| 117 | ((< x 0) -1) | ||
| 118 | (t 0))) | ||
| 119 | |||
| 120 | (defun rst-some (seq &optional pred) | ||
| 121 | "Return non-nil if any element of SEQ yields non-nil when PRED is applied. | ||
| 122 | Apply PRED to each element of list SEQ until the first non-nil | ||
| 123 | result is yielded and return this result. PRED defaults to | ||
| 124 | `identity'." | ||
| 125 | (unless pred | ||
| 126 | (setq pred 'identity)) | ||
| 127 | (catch 'rst-some | ||
| 128 | (dolist (elem seq) | ||
| 129 | (let ((r (funcall pred elem))) | ||
| 130 | (when r | ||
| 131 | (throw 'rst-some r)))))) | ||
| 132 | |||
| 133 | (defun rst-position-if (pred seq) | ||
| 134 | "Return position of first element satisfying PRED in list SEQ or nil." | ||
| 135 | (catch 'rst-position-if | ||
| 136 | (let ((i 0)) | ||
| 137 | (dolist (elem seq) | ||
| 138 | (when (funcall pred elem) | ||
| 139 | (throw 'rst-position-if i)) | ||
| 140 | (incf i))))) | ||
| 141 | |||
| 142 | (defun rst-position (elem seq) | ||
| 143 | "Return position of ELEM in list SEQ or nil. | ||
| 144 | Comparison done with `equal'." | ||
| 145 | ;; Create a closure containing `elem' so the `lambda' always sees our | ||
| 146 | ;; parameter instead of an `elem' which may be in dynamic scope at the time | ||
| 147 | ;; of execution of the `lambda'. | ||
| 148 | (lexical-let ((elem elem)) | ||
| 149 | (rst-position-if (function (lambda (e) | ||
| 150 | (equal elem e))) | ||
| 151 | seq))) | ||
| 110 | 152 | ||
| 111 | ;; FIXME: Check whether complicated `defconst's can be embedded in | 153 | ;; FIXME: Check whether complicated `defconst's can be embedded in |
| 112 | ;; `eval-when-compile'. | 154 | ;; `eval-when-compile'. |
| 113 | 155 | ||
| 156 | ;; FIXME: Check whether `lambda's can be embedded in `function'. | ||
| 157 | |||
| 114 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 158 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 115 | ;; Versions | 159 | ;; Versions |
| 116 | 160 | ||
| @@ -127,7 +171,7 @@ and before TAIL-RE and DELIM-RE in VAR or DEFAULT for no match." | |||
| 127 | ;; Use CVSHeader to really get information from CVS and not other version | 171 | ;; Use CVSHeader to really get information from CVS and not other version |
| 128 | ;; control systems. | 172 | ;; control systems. |
| 129 | (defconst rst-cvs-header | 173 | (defconst rst-cvs-header |
| 130 | "$CVSHeader: sm/rst_el/rst.el,v 1.273 2012-06-03 17:01:33 stefan Exp $") | 174 | "$CVSHeader: sm/rst_el/rst.el,v 1.282 2012-06-06 19:16:55 stefan Exp $") |
| 131 | (defconst rst-cvs-rev | 175 | (defconst rst-cvs-rev |
| 132 | (rst-extract-version "\\$" "CVSHeader: \\S + " "[0-9]+\\(?:\\.[0-9]+\\)+" | 176 | (rst-extract-version "\\$" "CVSHeader: \\S + " "[0-9]+\\(?:\\.[0-9]+\\)+" |
| 133 | " .*" rst-cvs-header "0.0") | 177 | " .*" rst-cvs-header "0.0") |
| @@ -170,10 +214,11 @@ Starts with the current official version. For developer versions | |||
| 170 | in parentheses follows the development revision and the time stamp.") | 214 | in parentheses follows the development revision and the time stamp.") |
| 171 | 215 | ||
| 172 | (defconst rst-package-emacs-version-alist | 216 | (defconst rst-package-emacs-version-alist |
| 173 | '(("1.0.0" . "24.0") | 217 | '(("1.0.0" . "24.2") |
| 174 | ("1.1.0" . "24.0") | 218 | ("1.1.0" . "24.2") |
| 175 | ("1.2.0" . "24.0") | 219 | ("1.2.0" . "24.2") |
| 176 | ("1.2.1" . "24.0"))) | 220 | ("1.2.1" . "24.2") |
| 221 | ("1.3.0" . "24.2"))) | ||
| 177 | 222 | ||
| 178 | (unless (assoc rst-official-version rst-package-emacs-version-alist) | 223 | (unless (assoc rst-official-version rst-package-emacs-version-alist) |
| 179 | (error "Version %s not listed in `rst-package-emacs-version-alist'" | 224 | (error "Version %s not listed in `rst-package-emacs-version-alist'" |
| @@ -431,6 +476,8 @@ in parentheses follows the development revision and the time stamp.") | |||
| 431 | Each entry consists of the symbol naming the regex and an | 476 | Each entry consists of the symbol naming the regex and an |
| 432 | argument list for `rst-re'.") | 477 | argument list for `rst-re'.") |
| 433 | 478 | ||
| 479 | (defvar rst-re-alist) ; Forward declare to use it in `rst-re'. | ||
| 480 | |||
| 434 | ;; FIXME: Use `sregex` or `rx` instead of re-inventing the wheel. | 481 | ;; FIXME: Use `sregex` or `rx` instead of re-inventing the wheel. |
| 435 | (defun rst-re (&rest args) | 482 | (defun rst-re (&rest args) |
| 436 | "Interpret ARGS as regular expressions and return a regex string. | 483 | "Interpret ARGS as regular expressions and return a regex string. |
| @@ -490,16 +537,16 @@ After interpretation of ARGS the results are concatenated as for | |||
| 490 | args))) | 537 | args))) |
| 491 | 538 | ||
| 492 | ;; FIXME: Remove circular dependency between `rst-re' and `rst-re-alist'. | 539 | ;; FIXME: Remove circular dependency between `rst-re' and `rst-re-alist'. |
| 493 | (defconst rst-re-alist | 540 | (with-no-warnings ; Silence byte-compiler about this construction. |
| 494 | ;; Shadow global value we are just defining so we can construct it step by | 541 | (defconst rst-re-alist |
| 495 | ;; step. | 542 | ;; Shadow global value we are just defining so we can construct it step by |
| 496 | (let (rst-re-alist) | 543 | ;; step. |
| 497 | (dolist (re rst-re-alist-def) | 544 | (let (rst-re-alist) |
| 498 | (setq rst-re-alist | 545 | (dolist (re rst-re-alist-def rst-re-alist) |
| 499 | (nconc rst-re-alist | 546 | (setq rst-re-alist |
| 500 | (list (list (car re) (apply 'rst-re (cdr re))))))) | 547 | (nconc rst-re-alist |
| 501 | rst-re-alist) | 548 | (list (list (car re) (apply 'rst-re (cdr re)))))))) |
| 502 | "Alist mapping symbols from `rst-re-alist-def' to regex strings.") | 549 | "Alist mapping symbols from `rst-re-alist-def' to regex strings.")) |
| 503 | 550 | ||
| 504 | 551 | ||
| 505 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 552 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -683,6 +730,8 @@ The hook for `text-mode' is run before this one." | |||
| 683 | :group 'rst | 730 | :group 'rst |
| 684 | :type '(hook)) | 731 | :type '(hook)) |
| 685 | 732 | ||
| 733 | ;; Pull in variable definitions silencing byte-compiler. | ||
| 734 | (require 'newcomment) | ||
| 686 | 735 | ||
| 687 | ;; Use rst-mode for *.rst and *.rest files. Many ReStructured-Text files | 736 | ;; Use rst-mode for *.rst and *.rest files. Many ReStructured-Text files |
| 688 | ;; use *.txt, but this is too generic to be set as a default. | 737 | ;; use *.txt, but this is too generic to be set as a default. |
| @@ -856,9 +905,8 @@ for modes derived from Text mode, like Mail mode." | |||
| 856 | :group 'rst | 905 | :group 'rst |
| 857 | :version "21.1") | 906 | :version "21.1") |
| 858 | 907 | ||
| 859 | ;; FIXME: The version must be represented in `rst-package-emacs-version-alist'. | ||
| 860 | (define-obsolete-variable-alias | 908 | (define-obsolete-variable-alias |
| 861 | 'rst-preferred-decorations 'rst-preferred-adornments "r6506") | 909 | 'rst-preferred-decorations 'rst-preferred-adornments "1.0.0") |
| 862 | (defcustom rst-preferred-adornments '((?= over-and-under 1) | 910 | (defcustom rst-preferred-adornments '((?= over-and-under 1) |
| 863 | (?= simple 0) | 911 | (?= simple 0) |
| 864 | (?- simple 0) | 912 | (?- simple 0) |
| @@ -1743,11 +1791,6 @@ in ADORNMENTS." | |||
| 1743 | )) | 1791 | )) |
| 1744 | ))) | 1792 | ))) |
| 1745 | 1793 | ||
| 1746 | (defun rst-position (elem list) | ||
| 1747 | "Return position of ELEM in LIST or nil." | ||
| 1748 | (let ((tail (member elem list))) | ||
| 1749 | (if tail (- (length list) (length tail))))) | ||
| 1750 | |||
| 1751 | (defun rst-straighten-adornments () | 1794 | (defun rst-straighten-adornments () |
| 1752 | "Redo all the adornments in the current buffer. | 1795 | "Redo all the adornments in the current buffer. |
| 1753 | This is done using our preferred set of adornments. This can be | 1796 | This is done using our preferred set of adornments. This can be |
| @@ -2763,9 +2806,8 @@ here." | |||
| 2763 | :group 'rst | 2806 | :group 'rst |
| 2764 | :package-version '(rst . "1.1.0")) | 2807 | :package-version '(rst . "1.1.0")) |
| 2765 | 2808 | ||
| 2766 | ;; FIXME: The version must be represented in `rst-package-emacs-version-alist'. | ||
| 2767 | (define-obsolete-variable-alias | 2809 | (define-obsolete-variable-alias |
| 2768 | 'rst-shift-basic-offset 'rst-indent-width "r6713") | 2810 | 'rst-shift-basic-offset 'rst-indent-width "1.0.0") |
| 2769 | (defcustom rst-indent-width 2 | 2811 | (defcustom rst-indent-width 2 |
| 2770 | "Indentation when there is no more indentation point given." | 2812 | "Indentation when there is no more indentation point given." |
| 2771 | :group 'rst-indent | 2813 | :group 'rst-indent |
| @@ -2890,8 +2932,7 @@ in the text above." | |||
| 2890 | (< newcol innermost)))) | 2932 | (< newcol innermost)))) |
| 2891 | (not (memq newcol tablist))) | 2933 | (not (memq newcol tablist))) |
| 2892 | (push newcol tablist)))) | 2934 | (push newcol tablist)))) |
| 2893 | (setq innermost (if (some 'identity | 2935 | (setq innermost (if (rst-some (mapcar 'cdr tabs)) ; Has inner. |
| 2894 | (mapcar 'cdr tabs)) ; Has inner. | ||
| 2895 | leftcol | 2936 | leftcol |
| 2896 | innermost)) | 2937 | innermost)) |
| 2897 | (setq leftmost leftcol))))) | 2938 | (setq leftmost leftcol))))) |
| @@ -2912,7 +2953,7 @@ relative to the content." | |||
| 2912 | (cur (current-indentation)) | 2953 | (cur (current-indentation)) |
| 2913 | (clm (current-column)) | 2954 | (clm (current-column)) |
| 2914 | (tabs (rst-compute-tabs (point))) | 2955 | (tabs (rst-compute-tabs (point))) |
| 2915 | (fnd (position cur tabs)) | 2956 | (fnd (rst-position cur tabs)) |
| 2916 | ind) | 2957 | ind) |
| 2917 | (if (and (not tabs) (not dflt)) | 2958 | (if (and (not tabs) (not dflt)) |
| 2918 | 'noindent | 2959 | 'noindent |
| @@ -2948,12 +2989,14 @@ above. If no suitable tab is found `rst-indent-width' is used." | |||
| 2948 | (let* ((cmp (if (> cnt 0) '> '<)) | 2989 | (let* ((cmp (if (> cnt 0) '> '<)) |
| 2949 | (tabs (if (> cnt 0) tabs (reverse tabs))) | 2990 | (tabs (if (> cnt 0) tabs (reverse tabs))) |
| 2950 | (len (length tabs)) | 2991 | (len (length tabs)) |
| 2951 | (dir (signum cnt)) ; Direction to take. | 2992 | (dir (rst-signum cnt)) ; Direction to take. |
| 2952 | (abs (abs cnt)) ; Absolute number of steps to take. | 2993 | (abs (abs cnt)) ; Absolute number of steps to take. |
| 2953 | ;; Get the position of the first tab beyond leftmostcol. | 2994 | ;; Get the position of the first tab beyond leftmostcol. |
| 2954 | (fnd (position-if (lambda (elt) | 2995 | (fnd (lexical-let ((cmp cmp) |
| 2955 | (funcall cmp elt leftmostcol)) | 2996 | (leftmostcol leftmostcol)) ; Create closure. |
| 2956 | tabs)) | 2997 | (rst-position-if (lambda (elt) |
| 2998 | (funcall cmp elt leftmostcol)) | ||
| 2999 | tabs))) | ||
| 2957 | ;; Virtual position of tab. | 3000 | ;; Virtual position of tab. |
| 2958 | (pos (+ (or fnd len) (1- abs))) | 3001 | (pos (+ (or fnd len) (1- abs))) |
| 2959 | (tab (if (< pos len) | 3002 | (tab (if (< pos len) |
| @@ -3136,8 +3179,8 @@ Region is from RBEG to REND. With PFXARG set the empty lines too." | |||
| 3136 | 3179 | ||
| 3137 | ;; FIXME: The obsolete variables need to disappear. | 3180 | ;; FIXME: The obsolete variables need to disappear. |
| 3138 | 3181 | ||
| 3139 | ;; FIXME LEVEL-FACE: All `:version "24.1"' attributes need to be changed to | 3182 | ;; The following versions have been done inside Emacs and should not be |
| 3140 | ;; proper `:package-version "24.1"' attributes. | 3183 | ;; replaced by `:package-version' attributes until a change. |
| 3141 | 3184 | ||
| 3142 | (defgroup rst-faces nil "Faces used in Rst Mode." | 3185 | (defgroup rst-faces nil "Faces used in Rst Mode." |
| 3143 | :group 'rst | 3186 | :group 'rst |
| @@ -3273,12 +3316,12 @@ Region is from RBEG to REND. With PFXARG set the empty lines too." | |||
| 3273 | 3316 | ||
| 3274 | (defface rst-transition '((t :inherit font-lock-keyword-face)) | 3317 | (defface rst-transition '((t :inherit font-lock-keyword-face)) |
| 3275 | "Face used for a transition." | 3318 | "Face used for a transition." |
| 3276 | :version "24.1" | 3319 | :package-version '(rst . "1.3.0") |
| 3277 | :group 'rst-faces) | 3320 | :group 'rst-faces) |
| 3278 | 3321 | ||
| 3279 | (defface rst-adornment '((t :inherit font-lock-keyword-face)) | 3322 | (defface rst-adornment '((t :inherit font-lock-keyword-face)) |
| 3280 | "Face used for the adornment of a section header." | 3323 | "Face used for the adornment of a section header." |
| 3281 | :version "24.1" | 3324 | :package-version '(rst . "1.3.0") |
| 3282 | :group 'rst-faces) | 3325 | :group 'rst-faces) |
| 3283 | 3326 | ||
| 3284 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 3327 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -3646,7 +3689,7 @@ Move N lines forward just as `forward-line'." | |||
| 3646 | (if (bolp) | 3689 | (if (bolp) |
| 3647 | moved | 3690 | moved |
| 3648 | (forward-line 0) | 3691 | (forward-line 0) |
| 3649 | (- moved (signum n))))) | 3692 | (- moved (rst-signum n))))) |
| 3650 | 3693 | ||
| 3651 | ;; FIXME: If a single line is made a section header by `rst-adjust' the header | 3694 | ;; FIXME: If a single line is made a section header by `rst-adjust' the header |
| 3652 | ;; is not always fontified immediately. | 3695 | ;; is not always fontified immediately. |
| @@ -3829,9 +3872,12 @@ beyond the existing hierarchy." | |||
| 3829 | (let* ((hier (rst-get-hierarchy)) | 3872 | (let* ((hier (rst-get-hierarchy)) |
| 3830 | (char (car key)) | 3873 | (char (car key)) |
| 3831 | (style (cdr key))) | 3874 | (style (cdr key))) |
| 3832 | (1+ (or (position-if (lambda (elt) | 3875 | (1+ (or (lexical-let ((char char) |
| 3833 | (and (equal (car elt) char) | 3876 | (style style) |
| 3834 | (equal (cadr elt) style))) hier) | 3877 | (hier hier)) ; Create closure. |
| 3878 | (rst-position-if (lambda (elt) | ||
| 3879 | (and (equal (car elt) char) | ||
| 3880 | (equal (cadr elt) style))) hier)) | ||
| 3835 | (length hier)))))) | 3881 | (length hier)))))) |
| 3836 | 3882 | ||
| 3837 | (defvar rst-font-lock-adornment-match nil | 3883 | (defvar rst-font-lock-adornment-match nil |
| @@ -3919,7 +3965,7 @@ string)) to be used for converting the document." | |||
| 3919 | (const :tag "No options" nil) | 3965 | (const :tag "No options" nil) |
| 3920 | (string :tag "Options")))) | 3966 | (string :tag "Options")))) |
| 3921 | :group 'rst | 3967 | :group 'rst |
| 3922 | :version "24.1") | 3968 | :package-version "1.2.0") |
| 3923 | 3969 | ||
| 3924 | ;; FIXME: Must be `defcustom`. | 3970 | ;; FIXME: Must be `defcustom`. |
| 3925 | (defvar rst-compile-primary-toolset 'html | 3971 | (defvar rst-compile-primary-toolset 'html |
| @@ -4067,7 +4113,7 @@ cand replace with char: ") | |||
| 4067 | (defun rst-join-paragraph () | 4113 | (defun rst-join-paragraph () |
| 4068 | "Join lines in current paragraph into one line, removing end-of-lines." | 4114 | "Join lines in current paragraph into one line, removing end-of-lines." |
| 4069 | (interactive) | 4115 | (interactive) |
| 4070 | (let ((fill-column 65000)) ; some big number. | 4116 | (let ((fill-column 65000)) ; Some big number. |
| 4071 | (call-interactively 'fill-paragraph))) | 4117 | (call-interactively 'fill-paragraph))) |
| 4072 | 4118 | ||
| 4073 | ;; FIXME: Unbound command - should be bound or removed. | 4119 | ;; FIXME: Unbound command - should be bound or removed. |