diff options
| author | Michal Nazarewicz | 2014-05-27 21:00:44 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-05-27 21:00:44 -0400 |
| commit | fc21a7de3a92a38c5b00ce64a81c8668d0482fbb (patch) | |
| tree | 5791ec3019cdb37ff4798f9ec4f93a79a815038d | |
| parent | 4c539a7b387874577136190d8e1a413da1d7e240 (diff) | |
| download | emacs-fc21a7de3a92a38c5b00ce64a81c8668d0482fbb.tar.gz emacs-fc21a7de3a92a38c5b00ce64a81c8668d0482fbb.zip | |
* test/automated/tildify-tests.el: New file.
* lisp/textmodes/tildify.el (tildify-buffer, tildify-region):
Add dont-ask option.
Fixes: debbugs:17547
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/textmodes/tildify.el | 22 | ||||
| -rw-r--r-- | test/ChangeLog | 4 | ||||
| -rw-r--r-- | test/automated/tildify-tests.el | 106 |
4 files changed, 128 insertions, 9 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 22e88a453ce..01f68d8c338 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-05-21 Michal Nazarewicz <mina86@mina86.com> | ||
| 2 | |||
| 3 | * textmodes/tildify.el (tildify-buffer, tildify-region): | ||
| 4 | Add dont-ask option. | ||
| 5 | |||
| 1 | 2014-05-28 Stefan Monnier <monnier@iro.umontreal.ca> | 6 | 2014-05-28 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 7 | ||
| 3 | * subr.el (zerop): Move from C. Add compiler-macro (bug#17475). | 8 | * subr.el (zerop): Move from C. Add compiler-macro (bug#17475). |
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el index 9732e7fa649..339f9006cf2 100644 --- a/lisp/textmodes/tildify.el +++ b/lisp/textmodes/tildify.el | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1997-2014 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1997-2014 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Milan Zamazal <pdm@zamazal.org> | 5 | ;; Author: Milan Zamazal <pdm@zamazal.org> |
| 6 | ;; Version: 4.5 | 6 | ;; Version: 4.5.1 |
| 7 | ;; Keywords: text, TeX, SGML, wp | 7 | ;; Keywords: text, TeX, SGML, wp |
| 8 | 8 | ||
| 9 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| @@ -172,20 +172,22 @@ END-REGEX defines end of the corresponding text part and can be either: | |||
| 172 | ;;; *** Interactive functions *** | 172 | ;;; *** Interactive functions *** |
| 173 | 173 | ||
| 174 | ;;;###autoload | 174 | ;;;###autoload |
| 175 | (defun tildify-region (beg end) | 175 | (defun tildify-region (beg end &optional dont-ask) |
| 176 | "Add hard spaces in the region between BEG and END. | 176 | "Add hard spaces in the region between BEG and END. |
| 177 | See variables `tildify-pattern-alist', `tildify-string-alist', and | 177 | See variables `tildify-pattern-alist', `tildify-string-alist', and |
| 178 | `tildify-ignored-environments-alist' for information about configuration | 178 | `tildify-ignored-environments-alist' for information about configuration |
| 179 | parameters. | 179 | parameters. |
| 180 | This function performs no refilling of the changed text." | 180 | This function performs no refilling of the changed text. |
| 181 | (interactive "*r") | 181 | If DONT-ASK is set, or called interactively with prefix argument, user |
| 182 | won't be prompted for confirmation of each substitution." | ||
| 183 | (interactive "*rP") | ||
| 182 | (setq tildify-count 0) | 184 | (setq tildify-count 0) |
| 183 | (let (a | 185 | (let (a |
| 184 | z | 186 | z |
| 185 | (marker-end (copy-marker end)) | 187 | (marker-end (copy-marker end)) |
| 186 | end-env | 188 | end-env |
| 187 | finish | 189 | finish |
| 188 | (ask t) | 190 | (ask (not dont-ask)) |
| 189 | (case-fold-search nil) | 191 | (case-fold-search nil) |
| 190 | (regexp (tildify-build-regexp)) ; beginnings of environments | 192 | (regexp (tildify-build-regexp)) ; beginnings of environments |
| 191 | aux) | 193 | aux) |
| @@ -226,14 +228,16 @@ This function performs no refilling of the changed text." | |||
| 226 | (message "%d spaces replaced." tildify-count)) | 228 | (message "%d spaces replaced." tildify-count)) |
| 227 | 229 | ||
| 228 | ;;;###autoload | 230 | ;;;###autoload |
| 229 | (defun tildify-buffer () | 231 | (defun tildify-buffer (&optional dont-ask) |
| 230 | "Add hard spaces in the current buffer. | 232 | "Add hard spaces in the current buffer. |
| 231 | See variables `tildify-pattern-alist', `tildify-string-alist', and | 233 | See variables `tildify-pattern-alist', `tildify-string-alist', and |
| 232 | `tildify-ignored-environments-alist' for information about configuration | 234 | `tildify-ignored-environments-alist' for information about configuration |
| 233 | parameters. | 235 | parameters. |
| 234 | This function performs no refilling of the changed text." | 236 | This function performs no refilling of the changed text. |
| 235 | (interactive "*") | 237 | If DONT-ASK is set, or called interactively with prefix argument, user |
| 236 | (tildify-region (point-min) (point-max))) | 238 | won't be prompted for confirmation of each substitution." |
| 239 | (interactive "*P") | ||
| 240 | (tildify-region (point-min) (point-max) dont-ask)) | ||
| 237 | 241 | ||
| 238 | 242 | ||
| 239 | ;;; *** Auxiliary functions *** | 243 | ;;; *** Auxiliary functions *** |
diff --git a/test/ChangeLog b/test/ChangeLog index 5c037eb2b79..33a70436b2d 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2014-05-21 Michal Nazarewicz <mina86@mina86.com> | ||
| 2 | |||
| 3 | * automated/tildify-tests.el: New file. | ||
| 4 | |||
| 1 | 2014-05-27 Stefan Monnier <monnier@iro.umontreal.ca> | 5 | 2014-05-27 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 6 | ||
| 3 | * indent/ruby.rb: Add one more test. | 7 | * indent/ruby.rb: Add one more test. |
diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el new file mode 100644 index 00000000000..4223029f626 --- /dev/null +++ b/test/automated/tildify-tests.el | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | ;;; tildify-test.el --- ERT tests for teldify.el | ||
| 2 | |||
| 3 | ;; Copyright (C) 2014 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Michal Nazarewicz <mina86@mina86.com> | ||
| 6 | ;; Version: 4.5 | ||
| 7 | ;; Keywords: text, TeX, SGML, wp | ||
| 8 | |||
| 9 | ;; This file is part of GNU Emacs. | ||
| 10 | |||
| 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 12 | ;; it under the terms of the GNU General Public License as published by | ||
| 13 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 14 | ;; (at your option) any later version. | ||
| 15 | |||
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ;; GNU General Public License for more details. | ||
| 20 | |||
| 21 | ;; You should have received a copy of the GNU General Public License | ||
| 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 23 | |||
| 24 | ;;; Commentary: | ||
| 25 | |||
| 26 | ;; This package defines regression tests for the tildify package. | ||
| 27 | |||
| 28 | ;;; Code: | ||
| 29 | |||
| 30 | (require 'ert) | ||
| 31 | (require 'tildify) | ||
| 32 | |||
| 33 | (defun tildify-test--example-sentence (space) | ||
| 34 | "Return an example sentence with SPACE where hard space is required." | ||
| 35 | (concat "Lorem ipsum v" space "dolor sit amet, a" space | ||
| 36 | "consectetur adipiscing elit.")) | ||
| 37 | |||
| 38 | |||
| 39 | (defun tildify-test--example-html (sentence &optional with-nbsp) | ||
| 40 | "Return an example HTML code. | ||
| 41 | SENTENCE is placed where spaces should not be replaced with hard spaces, and | ||
| 42 | WITH-NBSP is placed where spaces should be replaced with hard spaces. If the | ||
| 43 | latter is missing, SENTENCE will be used in all placeholder positions." | ||
| 44 | (let ((with-nbsp (or with-nbsp sentence))) | ||
| 45 | (concat "<p>" with-nbsp "</p>\n" | ||
| 46 | "<pre>" sentence "</pre>\n" | ||
| 47 | "<! -- " sentence " -- >\n" | ||
| 48 | "<p>" with-nbsp "</p>\n" | ||
| 49 | "<" sentence ">\n"))) | ||
| 50 | |||
| 51 | |||
| 52 | (defun tildify-test--test (modes input expected) | ||
| 53 | "Test tildify running in MODES. | ||
| 54 | INPUT is the initial content of the buffer and EXPECTED is expected result | ||
| 55 | after `tildify-buffer' is run." | ||
| 56 | (dolist (mode modes) | ||
| 57 | (with-temp-buffer | ||
| 58 | (funcall mode) | ||
| 59 | (let ((header (concat "Testing `tildify-buffer' in " | ||
| 60 | (symbol-name mode) "\n"))) | ||
| 61 | (insert header input) | ||
| 62 | (tildify-buffer t) | ||
| 63 | (should (string-equal (concat header expected) (buffer-string))))) | ||
| 64 | (with-temp-buffer | ||
| 65 | (funcall mode) | ||
| 66 | (let ((header (concat "Testing `tildify-region' in " | ||
| 67 | (symbol-name mode) "\n"))) | ||
| 68 | (insert header input) | ||
| 69 | (tildify-region (point-min) (point-max) t) | ||
| 70 | (should (string-equal (concat header expected) (buffer-string))))))) | ||
| 71 | |||
| 72 | (ert-deftest tildify-test-html () | ||
| 73 | "Tests tildification in an HTML document" | ||
| 74 | (let* ((sentence (tildify-test--example-sentence " ")) | ||
| 75 | (with-nbsp (tildify-test--example-sentence " "))) | ||
| 76 | (tildify-test--test '(html-mode sgml-mode) | ||
| 77 | (tildify-test--example-html sentence sentence) | ||
| 78 | (tildify-test--example-html sentence with-nbsp)))) | ||
| 79 | |||
| 80 | |||
| 81 | (defun tildify-test--example-tex (sentence &optional with-nbsp) | ||
| 82 | "Return an example (La)Tex code. | ||
| 83 | SENTENCE is placed where spaces should not be replaced with hard spaces, and | ||
| 84 | WITH-NBSP is placed where spaces should be replaced with hard spaces. If the | ||
| 85 | latter is missing, SENTENCE will be used in all placeholder positions." | ||
| 86 | (let ((with-nbsp (or with-nbsp sentence))) | ||
| 87 | (concat with-nbsp "\n" | ||
| 88 | "\\begin{verbatim}\n" sentence "\n\\end{verbatim}\n" | ||
| 89 | "\\verb#" sentence "#\n" | ||
| 90 | "$$" sentence "$$\n" | ||
| 91 | "$" sentence "$\n" | ||
| 92 | "\\[" sentence "\\]\n" | ||
| 93 | "\\v A % " sentence "\n" | ||
| 94 | with-nbsp "\n"))) | ||
| 95 | |||
| 96 | (ert-deftest tildify-test-tex () | ||
| 97 | "Tests tildification in a (La)TeX document" | ||
| 98 | (let* ((sentence (tildify-test--example-sentence " ")) | ||
| 99 | (with-nbsp (tildify-test--example-sentence "~"))) | ||
| 100 | (tildify-test--test '(tex-mode latex-mode plain-tex-mode) | ||
| 101 | (tildify-test--example-tex sentence sentence) | ||
| 102 | (tildify-test--example-tex sentence with-nbsp)))) | ||
| 103 | |||
| 104 | (provide 'tildify-tests) | ||
| 105 | |||
| 106 | ;;; tildify-tests.el ends here | ||