Discussion:
[erlang-patches] [erlang-bugs] erlang.el mis-indents whole-buffer selection
unknown
2014-06-29 14:10:15 UTC
Permalink
Previously it was just a certain[1] function in rebar.erl which got
mis-indented when you did a whole-buffer indent, but now there's also
a second[2] function which gets mis-indented.
In both cases indenting the function itself separately works, and the
bug happens if you select the whole buffer and indent that with
erlang.el (C-x C-q).
I'm using Emacs 24.3.1 with latest erlang.el from maint.
Is it possible to fix this in the existing indenter?
[1] https://github.com/rebar/rebar/blob/620c4b01c/src/rebar.erl#L318-L365
[2] https://github.com/rebar/rebar/blob/620c4b01c/src/rebar_erlc_compiler.erl#L92-L112
It seems like this happens when the code being indented has not yet been
made visible, and thus lazy syntax highlighting has not yet happened.
The syntax table for erlang-mode is unable to handle some combinations
of characters; in particular, when a string ends with a dollar sign (as
in "foo$"), the dollar sign plus the double quote would be treated as a
character constant were it not for some magic regexps in
font-lock-syntactic-keywords. Manually scrolling through the buffer
before reindenting seems to make the problem go away.
This is less than satisfactory, of course. Looking up online help for
This variable is obsolete since 24.1;
use `syntax-propertize-function' instead.
*** New variable `syntax-propertize-function'.
This replaces `font-lock-syntactic-keywords' which is now obsolete.
just call syntax-propertize to make sure the text is propertized.
Together with this new variable come a new hook
syntax-propertize-via-font-lock to reuse old font-lock-syntactic-keywords
as-is; and syntax-propertize-rules which provides a new way to specify
syntactic rules.
This sounds like the right way to solve the problem, though of course
you won't know until you try...
While playing with the code, I realised that there's a much simpler
solution: explicitly run syntax highlighting before indenting; that way
all syntax properties will be set.

git fetch git://github.com/legoscia/otp.git fontify-before-indentation

https://github.com/legoscia/otp/compare/fontify-before-indentation

Regards,
Magnus
unknown
2014-06-29 16:47:19 UTC
Permalink
Post by unknown
Previously it was just a certain[1] function in rebar.erl which
got mis-indented when you did a whole-buffer indent, but now
there's also a second[2] function which gets mis-indented.
In both cases indenting the function itself separately works,
and the bug happens if you select the whole buffer and indent
that with erlang.el (C-x C-q).
I'm using Emacs 24.3.1 with latest erlang.el from maint.
Is it possible to fix this in the existing indenter?
[1] https://github.com/rebar/rebar/blob/620c4b01c/src/rebar.erl#L318-L365
[2] https://github.com/rebar/rebar/blob/620c4b01c/src/rebar_erlc_compiler.erl#L92-L112
It seems like this happens when the code being indented has not
yet been made visible, and thus lazy syntax highlighting has not
yet happened. The syntax table for erlang-mode is unable to handle
some combinations of characters; in particular, when a string ends
with a dollar sign (as in "foo$"), the dollar sign plus the double
quote would be treated as a character constant were it not for
some magic regexps in font-lock-syntactic-keywords. Manually
scrolling through the buffer before reindenting seems to make the
problem go away.
This is less than satisfactory, of course. Looking up online help
This variable is obsolete since 24.1;
use `syntax-propertize-function' instead.
*** New variable `syntax-propertize-function'.
This replaces `font-lock-syntactic-keywords' which is now
obsolete. This allows syntax-table properties to be set
independently from font-lock: just call syntax-propertize to
make sure the text is propertized. Together with this new
variable come a new hook
syntax-propertize-extend-region-functions, as well as two helper
functions: syntax-propertize-via-font-lock to reuse old
font-lock-syntactic-keywords as-is; and syntax-propertize-rules
which provides a new way to specify syntactic rules.
This sounds like the right way to solve the problem, though of
course you won't know until you try...
While playing with the code, I realised that there's a much simpler
solution: explicitly run syntax highlighting before indenting; that
way all syntax properties will be set.
git fetch git://github.com/legoscia/otp.git fontify-before-indentation
https://github.com/legoscia/otp/compare/fontify-before-indentation
Nice, thanks Magnus!

Does the patch allow me to set (global-font-lock-mode 0) without
breaking erlang-mode?
unknown
2014-06-29 18:10:13 UTC
Permalink
Post by unknown
Post by unknown
While playing with the code, I realised that there's a much simpler
solution: explicitly run syntax highlighting before indenting; that
way all syntax properties will be set.
git fetch git://github.com/legoscia/otp.git fontify-before-indentation
https://github.com/legoscia/otp/compare/fontify-before-indentation
Nice, thanks Magnus!
Does the patch allow me to set (global-font-lock-mode 0) without
breaking erlang-mode?
I tried your branch, and I still see the same behavior:

* rebar_erlc_compiler:clean is mis-indented only when I set
(global-font-lock-mode 0)

* the multi-line <<"string">> in rebar.erl is mis-indented with and
without (global-font-lock-mode 0)

Loading...