diff options
author | Magnus Henoch <[email protected]> | 2010-09-15 15:24:52 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-09-30 14:23:18 +0200 |
commit | b81b6106f9feda8f3bce9eca3173560778c336fb (patch) | |
tree | 3aaebff395b1c61f32500bbe24b21d0bcbc0521f | |
parent | c9a40f46a37bd0891779d9204244a86ffb34a683 (diff) | |
download | otp-b81b6106f9feda8f3bce9eca3173560778c336fb.tar.gz otp-b81b6106f9feda8f3bce9eca3173560778c336fb.tar.bz2 otp-b81b6106f9feda8f3bce9eca3173560778c336fb.zip |
Emacs erlang-mode: fix syntax highlighting of $ in two cases
A string whose last character is a dollar sign used to make the syntax
highlighter believe that the string never ends, breaking highlighting
of following code:
-vsn("$Revision: 42 $").
And the double quote as a character constant with a (superfluous)
backslash used to make the syntax highlighter believe that a new
string started:
foo() ->
$\".
This change fixes both problems by adding two regexps to
font-lock-syntactic-keywords in erlang-font-lock-init.
One case that is still broken is when a multi-line string ends with a
dollar sign:
bar() ->
"This multi-line string
ends with a $".
baz() ->
this_gets_incorrectly_highlighted.
-rw-r--r-- | lib/tools/emacs/erlang.el | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index 91acfdf2b6..ed825a298f 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -1481,7 +1481,23 @@ Other commands: erlang-font-lock-keywords-3 erlang-font-lock-keywords-4) nil nil ((?_ . "w")) erlang-beginning-of-clause - (font-lock-mark-block-function . erlang-mark-clause)))) + (font-lock-mark-block-function . erlang-mark-clause) + (font-lock-syntactic-keywords + ;; A dollar sign right before the double quote that ends a + ;; string is not a character escape. + ;; + ;; And a "string" has with a double quote not escaped by a + ;; dollar sign, any number of non-backslash non-newline + ;; characters or escaped backslashes, a dollar sign + ;; (otherwise we wouldn't care) and a double quote. This + ;; doesn't match multi-line strings, but this is probably + ;; the best we can get, since while font-locking we don't + ;; know whether matching started inside a string: limiting + ;; search to a single line keeps things sane. + . (("\\(?:^\\|[^$]\\)\"\\(?:[^\"\n]\\|\\\\\"\\)*\\(\\$\\)\"" 1 "w") + ;; And the dollar sign in $\" escapes two characters, not + ;; just one. + ("\\(\\$\\)\\\\\\\"" 1 "'")))))) |