diff options
| author | Michal Nazarewicz | 2014-06-05 16:37:45 +0200 |
|---|---|---|
| committer | Michal Nazarewicz | 2014-06-05 16:37:45 +0200 |
| commit | af9a3b28c0ca250ed245bd54c8737792916fe4c6 (patch) | |
| tree | e6547ebc6b75c57699cde2c3a8e07066ab73d110 /lisp | |
| parent | a1d799c25e4ad96dd2303ef2daa6cb51b5a0fe01 (diff) | |
| download | emacs-af9a3b28c0ca250ed245bd54c8737792916fe4c6.tar.gz emacs-af9a3b28c0ca250ed245bd54c8737792916fe4c6.zip | |
tildify.el: Fix end-regex building in `tildify-find-env'
* lisp/textmodes/tildify.el (tildify-find-env): The
`tildify-ignored-environments-alist' allows the end-regex
to be provided not as a static string but mix of strings and
indexes of groups matched the begin-regex. For example, the
“\verb!…!” TeX-command (where “!” is an arbitrary character)
is handled using:
("\\\\verb\\*?\\(.\\)" . (1))
In the same way, the following should be supported as well:
("open-\\(.\\)" . ("end-" 1))
However the tildify-find-env function fails at
(concat result
(if (stringp (setq aux (car expression)))
expression ; BUG: expression is a list
(regexp-quote (match-string aux))))
where the string part is handled incorrectly.
The most trivial fix would be to replace `expression'
in the true-part of the if-statement with `aux', but
instead, this commit optimises `tildify-find-env' by
changing it to use `mapconcat' rather than open-coded
while-loop.
* tests/automated/tildify-tests.el (tildify-test-find-env-end-re-bug):
New test validating fix to the above bug.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 31 | ||||
| -rw-r--r-- | lisp/textmodes/tildify.el | 40 |
2 files changed, 49 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f5273a66659..7bbaf642d3c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,34 @@ | |||
| 1 | 2014-06-05 Michal Nazarewicz <mina86@mina86.com> | ||
| 2 | |||
| 3 | * textmodes/tildify.el (tildify-find-env): Fix end-regex building | ||
| 4 | in `tildify-find-env' | ||
| 5 | |||
| 6 | The `tildify-ignored-environments-alist' allows the end-regex to | ||
| 7 | be provided not as a static string but mix of strings and indexes | ||
| 8 | of groups matched the begin-regex. For example, the “\verb!…!” | ||
| 9 | TeX-command (where “!” is an arbitrary character) is handled | ||
| 10 | using: | ||
| 11 | |||
| 12 | ("\\\\verb\\*?\\(.\\)" . (1)) | ||
| 13 | |||
| 14 | In the same way, the following should be supported as well: | ||
| 15 | |||
| 16 | ("open-\\(.\\)" . ("end-" 1)) | ||
| 17 | |||
| 18 | However the tildify-find-env function fails at | ||
| 19 | |||
| 20 | (concat result | ||
| 21 | (if (stringp (setq aux (car expression))) | ||
| 22 | expression ; BUG: expression is a list | ||
| 23 | (regexp-quote (match-string aux)))) | ||
| 24 | |||
| 25 | where the string part is handled incorrectly. | ||
| 26 | |||
| 27 | The most trivial fix would be to replace `expression' in the | ||
| 28 | true-part of the if-statement with `aux', but instead, this commit | ||
| 29 | optimises `tildify-find-env' by changing it to use `mapconcat' | ||
| 30 | rather than open-coded while-loop. | ||
| 31 | |||
| 1 | 2014-06-05 Mario Lang <mlang@delysid.org> | 32 | 2014-06-05 Mario Lang <mlang@delysid.org> |
| 2 | 33 | ||
| 3 | * woman.el (woman-mapcan): Remove. | 34 | * woman.el (woman-mapcan): Remove. |
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el index 339f9006cf2..7e4b39b615a 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.1 | 6 | ;; Version: 4.5.2 |
| 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. |
| @@ -270,27 +270,23 @@ won't be prompted for confirmation of each substitution." | |||
| 270 | Return regexp for the end of the environment or nil if no environment was | 270 | Return regexp for the end of the environment or nil if no environment was |
| 271 | found." | 271 | found." |
| 272 | ;; Find environment | 272 | ;; Find environment |
| 273 | (if (re-search-forward regexp nil t) | 273 | (when (re-search-forward regexp nil t) |
| 274 | ;; Build end-env regexp | 274 | ;; Build end-env regexp |
| 275 | (let ((match (match-string 0)) | 275 | (let ((match (match-string 0)) |
| 276 | (alist (tildify-mode-alist tildify-ignored-environments-alist)) | 276 | (alist (tildify-mode-alist tildify-ignored-environments-alist))) |
| 277 | expression) | 277 | (save-match-data |
| 278 | (save-match-data | 278 | (while (not (eq (string-match (caar alist) match) 0)) |
| 279 | (while (not (eq (string-match (caar alist) match) 0)) | 279 | (setq alist (cdr alist)))) |
| 280 | (setq alist (cdr alist)))) | 280 | (let ((expression (cdar alist))) |
| 281 | (if (stringp (setq expression (cdar alist))) | 281 | (if (stringp expression) |
| 282 | expression | 282 | expression |
| 283 | (let ((result "") | 283 | (mapconcat |
| 284 | aux) | 284 | (lambda (expr) |
| 285 | (while expression | 285 | (if (stringp expr) |
| 286 | (setq result (concat result | 286 | expr |
| 287 | (if (stringp (setq aux (car expression))) | 287 | (regexp-quote (match-string expr)))) |
| 288 | expression | 288 | expression |
| 289 | (regexp-quote (match-string aux))))) | 289 | "")))))) |
| 290 | (setq expression (cdr expression))) | ||
| 291 | result))) | ||
| 292 | ;; Return nil if not found | ||
| 293 | nil)) | ||
| 294 | 290 | ||
| 295 | (defun tildify-tildify (beg end ask) | 291 | (defun tildify-tildify (beg end ask) |
| 296 | "Add tilde characters in the region between BEG and END. | 292 | "Add tilde characters in the region between BEG and END. |