aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichal Nazarewicz <[email protected]>2014-06-05 16:39:18 +0200
committerMichal Nazarewicz <[email protected]>2014-06-05 16:39:18 +0200
commit9342feecdd92b769b1f45a6feea8ad34985c5049 (patch)
tree5be0d974eccfc0bb98effbe6735cb29271f13d69 /lisp
parentaf9a3b28c0ca250ed245bd54c8737792916fe4c6 (diff)
tildify.el: Fix matched group indexes in end-regex building
* lisp/textmodes/tildifi.el (tildify-find-env): When looking for a start of an ignore-environment, the regex is built by concatenating regexes of all the environments configured in `tildify-ignored-environments-alist'. So for example, the following list could be used to match TeX's \verb and \verb* commands: (("\\\\verb\\(.\\)" . (1)) ("\\\\verb\\*\\(.\\)" . (1))) This would result in the following regex being used to find the start of any of the variants of the \verb command: \\\\verb\\(.\\)\\|\\\\verb\\*\\(.\\) But now, if “\\\\verb\\*\\(.\\)” matches, the first capture group won't match anything, and thus (match-string 1) will be nil, which will cause building of the end-matching regex to fail. Fix this by using capture groups from the time when the opening regexes are matched individually. * tests/automated/tildify-tests.el (tildify-test-find-env-group-index-bug): New test validating fix to the above bug.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog23
-rw-r--r--lisp/textmodes/tildify.el30
2 files changed, 38 insertions, 15 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7bbaf642d3..936ae225a8 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,28 @@
2014-06-05 Michal Nazarewicz <[email protected]>
+ * textmodes/tildify.el (tildify-find-env): Fix matched group
+ indexes in end-regex building
+
+ When looking for a start of an ignore-environment, the regex is built
+ by concatenating regexes of all the environments configured in
+ `tildify-ignored-environments-alist'. So for example, the following
+ list could be used to match TeX's \verb and \verb* commands:
+
+ (("\\\\verb\\(.\\)" . (1))
+ ("\\\\verb\\*\\(.\\)" . (1)))
+
+ This would result in the following regex being used to find the start
+ of any of the variants of the \verb command:
+
+ \\\\verb\\(.\\)\\|\\\\verb\\*\\(.\\)
+
+ But now, if “\\\\verb\\*\\(.\\)” matches, the first capture group
+ won't match anything, and thus (match-string 1) will be nil, which
+ will cause building of the end-matching regex to fail.
+
+ Fix this by using capture groups from the time when the opening
+ regexes are matched individually.
+
* textmodes/tildify.el (tildify-find-env): Fix end-regex building
in `tildify-find-env'
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index 7e4b39b615..7aa338ef20 100644
--- a/lisp/textmodes/tildify.el
+++ b/lisp/textmodes/tildify.el
@@ -271,22 +271,22 @@ Return regexp for the end of the environment or nil if no environment was
found."
;; Find environment
(when (re-search-forward regexp nil t)
- ;; Build end-env regexp
- (let ((match (match-string 0))
- (alist (tildify-mode-alist tildify-ignored-environments-alist)))
- (save-match-data
+ (save-match-data
+ ;; Build end-env regexp
+ (let ((match (match-string 0))
+ (alist (tildify-mode-alist tildify-ignored-environments-alist)))
(while (not (eq (string-match (caar alist) match) 0))
- (setq alist (cdr alist))))
- (let ((expression (cdar alist)))
- (if (stringp expression)
- expression
- (mapconcat
- (lambda (expr)
- (if (stringp expr)
- expr
- (regexp-quote (match-string expr))))
- expression
- ""))))))
+ (setq alist (cdr alist)))
+ (let ((expression (cdar alist)))
+ (if (stringp expression)
+ expression
+ (mapconcat
+ (lambda (expr)
+ (if (stringp expr)
+ expr
+ (regexp-quote (match-string expr match))))
+ expression
+ "")))))))
(defun tildify-tildify (beg end ask)
"Add tilde characters in the region between BEG and END.