This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Formatting issues with the Scala Emacs mode

9 replies
Alex Payne
Joined: 2009-01-12,
User offline. Last seen 3 years 8 weeks ago.

There is a bug in the Emacs mode that ships with the Scala
distribution (in misc/scala-tool-support/emacs). This bug is alluded
to in the FUTURE document in that directory, but I'm curious to know
what it's current status is.

The bug lies in the automatic indentation for multi-line expressions
within braces. An example:

example { foo =>
bar // this first line indents correctly
baz // but what happened here?
} // this isn't correct either

I've posted the above to http://gist.github.com/259333 as well, for reference.

If anyone plans on tackling this bug in the near future, that'd be
great to know. If nobody is available to look into it, I'll try to
learn enough Elisp to fix it. Thanks in advance for any information.

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Formatting issues with the Scala Emacs mode

On Fri, Dec 18, 2009 at 7:46 AM, Alex Payne wrote:
> There is a bug in the Emacs mode that ships with the Scala
> distribution (in misc/scala-tool-support/emacs). This bug is alluded
> to in the FUTURE document in that directory, but I'm curious to know
> what it's current status is.
>
> The bug lies in the automatic indentation for multi-line expressions
> within braces. An example:
>
> example { foo =>
>  bar  // this first line indents correctly
>         baz // but what happened here?
>       } // this isn't correct either
>
This one annoys me greatly as well. Anybody volunteering to fix this
would do a great service to the emacs scala user community!

Cheers

Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Formatting issues with the Scala Emacs mode
I'll take a swag at it this weekend if no one nails it today.  Currently I get something like this in my scala-mode.  Not sure why, but I do have some changes in there in other areas.
example { foo =>          bar           baz        }
bar/baz line up,  but indentation is not right. 
Ray
On Fri, Dec 18, 2009 at 9:32 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
On Fri, Dec 18, 2009 at 7:46 AM, Alex Payne <al3x [at] al3x [dot] net> wrote:
> There is a bug in the Emacs mode that ships with the Scala
> distribution (in misc/scala-tool-support/emacs). This bug is alluded
> to in the FUTURE document in that directory, but I'm curious to know
> what it's current status is.
>
> The bug lies in the automatic indentation for multi-line expressions
> within braces. An example:
>
> example { foo =>
>  bar  // this first line indents correctly
>         baz // but what happened here?
>       } // this isn't correct either
>
This one annoys me greatly as well. Anybody volunteering to fix this
would do a great service to the emacs scala user community!

Cheers

Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Formatting issues with the Scala Emacs mode
I have a partial fix for the most common annoying case .  I'm also out the door to catch Avatar (IMax, 3D no less).  I haven't finished checking for unintended consequences yet but will later this evening.  The fix is predicated on the fact that a block is opened which "may" have a "=>"  on the same line.  The below handles the posted situation.  It doesn't quite work yet for one situation in the gist below and I need to do a tweak for nesting.   But I'm interested in knowing of other situations other than the posted "{ ... =>" 
http://gist.github.com/260103
Are there any other cases of that need to handled ?? 
foo { stuff_without_a_=>_in_it  bar   ...}
I hesitate, but for the impatient I'll slap up a the changed function in scala-mode-indent.el if anyone wants to play pre-Alpha tester.   I'll do a proper patch tonight.  After I've actually tested it. :)
(defun scala-block-indentation ()   (let ((block-start-eol (scala-point-after (end-of-line)))        (block-after-spc (scala-point-after (scala-forward-spaces))))     (if (> block-after-spc block-start-eol) (progn               ;; deals with first def/val/var afters a multiline arg class  (beginning-of-line)  (when (search-forward ")" block-start-eol t) ;; class ( ...,    // across lines.    (scala-forward-spaces)                     ;;       ^ ...): T // seeks to '('    (backward-sexp))  (+ (current-indentation) scala-mode-indent:step))       (if (search-forward "=>" block-start-eol t)  (+ (current-indentation) scala-mode-indent:step) (progn  (scala-forward-spaces)  (current-column))))))

On Fri, Dec 18, 2009 at 9:32 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
On Fri, Dec 18, 2009 at 7:46 AM, Alex Payne <al3x [at] al3x [dot] net> wrote:
> There is a bug in the Emacs mode that ships with the Scala
> distribution (in misc/scala-tool-support/emacs). This bug is alluded
> to in the FUTURE document in that directory, but I'm curious to know
> what it's current status is.
>
> The bug lies in the automatic indentation for multi-line expressions
> within braces. An example:
>
> example { foo =>
>  bar  // this first line indents correctly
>         baz // but what happened here?
>       } // this isn't correct either
>
This one annoys me greatly as well. Anybody volunteering to fix this
would do a great service to the emacs scala user community!

Cheers

Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Formatting issues with the Scala Emacs mode
Progress was made.  Due to scope creep fixed some things with multiline templates: class,object,trait formating with early initializers etc.  Last hang up is dealing with bracketless case blocks.  Trying to avoid throwing endless heuristics at the formating rules.  Almost there.
Meanwhile the quick fix work-around below should deal with the initial posted case.
Ray

On Sat, Dec 19, 2009 at 12:09 PM, Ray Racine <ray [dot] racine [at] gmail [dot] com> wrote:
I have a partial fix for the most common annoying case .  I'm also out the door to catch Avatar (IMax, 3D no less).  I haven't finished checking for unintended consequences yet but will later this evening.  The fix is predicated on the fact that a block is opened which "may" have a "=>"  on the same line.  The below handles the posted situation.  It doesn't quite work yet for one situation in the gist below and I need to do a tweak for nesting.   But I'm interested in knowing of other situations other than the posted "{ ... =>" 
http://gist.github.com/260103
Are there any other cases of that need to handled ?? 
foo { stuff_without_a_=>_in_it  bar   ...}
I hesitate, but for the impatient I'll slap up a the changed function in scala-mode-indent.el if anyone wants to play pre-Alpha tester.   I'll do a proper patch tonight.  After I've actually tested it. :)
(defun scala-block-indentation ()   (let ((block-start-eol (scala-point-after (end-of-line)))        (block-after-spc (scala-point-after (scala-forward-spaces))))     (if (> block-after-spc block-start-eol) (progn               ;; deals with first def/val/var afters a multiline arg class  (beginning-of-line)  (when (search-forward ")" block-start-eol t) ;; class ( ...,    // across lines.    (scala-forward-spaces)                     ;;       ^ ...): T // seeks to '('    (backward-sexp))  (+ (current-indentation) scala-mode-indent:step))       (if (search-forward "=>" block-start-eol t)  (+ (current-indentation) scala-mode-indent:step) (progn  (scala-forward-spaces)  (current-column))))))

On Fri, Dec 18, 2009 at 9:32 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
On Fri, Dec 18, 2009 at 7:46 AM, Alex Payne <al3x [at] al3x [dot] net> wrote:
> There is a bug in the Emacs mode that ships with the Scala
> distribution (in misc/scala-tool-support/emacs). This bug is alluded
> to in the FUTURE document in that directory, but I'm curious to know
> what it's current status is.
>
> The bug lies in the automatic indentation for multi-line expressions
> within braces. An example:
>
> example { foo =>
>  bar  // this first line indents correctly
>         baz // but what happened here?
>       } // this isn't correct either
>
This one annoys me greatly as well. Anybody volunteering to fix this
would do a great service to the emacs scala user community!

Cheers

Alex Payne
Joined: 2009-01-12,
User offline. Last seen 3 years 8 weeks ago.
Re: Formatting issues with the Scala Emacs mode

Thanks much for following up, Ray! Much appreciated.

On Mon, Dec 21, 2009 at 09:23, Ray Racine wrote:
> Progress was made.  Due to scope creep fixed some things with multiline
> templates: class,object,trait formating with early initializers etc.  Last
> hang up is dealing with bracketless case blocks.  Trying to avoid throwing
> endless heuristics at the formating rules.  Almost there.
> Meanwhile the quick fix work-around below should deal with the initial
> posted case.
> Ray
>
> On Sat, Dec 19, 2009 at 12:09 PM, Ray Racine wrote:
>>
>> I have a partial fix for the most common annoying case .  I'm also out the
>> door to catch Avatar (IMax, 3D no less).  I haven't finished checking for
>> unintended consequences yet but will later this evening.  The fix is
>> predicated on the fact that a block is opened which "may" have a "=>"  on
>> the same line.  The below handles the posted situation.  It doesn't quite
>> work yet for one situation in the gist below and I need to do a tweak for
>> nesting.   But I'm interested in knowing of other situations other than the
>> posted "{ ... =>"
>> http://gist.github.com/260103
>> Are there any other cases of that need to handled ??
>> foo { stuff_without_a_=>_in_it
>>   bar
>>   ...
>> }
>> I hesitate, but for the impatient I'll slap up a the changed function in
>> scala-mode-indent.el if anyone wants to play pre-Alpha tester.   I'll do a
>> proper patch tonight.  After I've actually tested it. :)
>> (defun scala-block-indentation ()
>>   (let ((block-start-eol (scala-point-after (end-of-line)))
>>         (block-after-spc (scala-point-after (scala-forward-spaces))))
>>     (if (> block-after-spc block-start-eol)
>> (progn               ;; deals with first def/val/var afters a multiline
>> arg class
>>  (beginning-of-line)
>>  (when (search-forward ")" block-start-eol t) ;; class ( ...,    // across
>> lines.
>>    (scala-forward-spaces)                     ;;       ^ ...): T // seeks
>> to '('
>>    (backward-sexp))
>>  (+ (current-indentation) scala-mode-indent:step))
>>       (if (search-forward "=>" block-start-eol t)
>>  (+ (current-indentation) scala-mode-indent:step)
>> (progn
>>  (scala-forward-spaces)
>>  (current-column))))))
>>
>> On Fri, Dec 18, 2009 at 9:32 AM, martin odersky
>> wrote:
>>>
>>> On Fri, Dec 18, 2009 at 7:46 AM, Alex Payne wrote:
>>> > There is a bug in the Emacs mode that ships with the Scala
>>> > distribution (in misc/scala-tool-support/emacs). This bug is alluded
>>> > to in the FUTURE document in that directory, but I'm curious to know
>>> > what it's current status is.
>>> >
>>> > The bug lies in the automatic indentation for multi-line expressions
>>> > within braces. An example:
>>> >
>>> > example { foo =>
>>> >  bar  // this first line indents correctly
>>> >         baz // but what happened here?
>>> >       } // this isn't correct either
>>> >
>>> This one annoys me greatly as well. Anybody volunteering to fix this
>>> would do a great service to the emacs scala user community!
>>>
>>> Cheers
>>>
>>>  -- Martin
>>
>>
>>
>> --
>> The object of life is not to be on the side of the majority, but to escape
>> finding oneself in the ranks of the insane. - Marcus Aurelius
>
>
>
> --
> The object of life is not to be on the side of the majority, but to escape
> finding oneself in the ranks of the insane. - Marcus Aurelius
>

Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Formatting issues with the Scala Emacs mode
EMACS Indentations Fixes(?)
I have attempted to fix a number of corner case issues with the scala-mode-indent.el file.  All to often an indent fix for one situation broke indentation in a number of other places.  It's very much like playing Whack-A-Mole at a carnival.   At this point I'm not sure if I've even improved anything or just made it worse. :0
http://github.com/RayRacine/Scamacs/tree/master/src/elisp/scala
I'd love to have some testers give it a whirl and offer feedback.  All of my testing was for my (pretty standard) Scala "style".  Depending on individual circumstances some may see a regression in lieu of an improvement.  I'll attempt to fix any reported indenting problems.  
I also addressed a number of emacs byte compile warnings as well.
If all tests well, I'll submit a patch.
Happy Holidays,
Ray

On Mon, Dec 21, 2009 at 7:09 PM, Alex Payne <al3x [at] al3x [dot] net> wrote:
Thanks much for following up, Ray! Much appreciated.

On Mon, Dec 21, 2009 at 09:23, Ray Racine <ray [dot] racine [at] gmail [dot] com> wrote:
> Progress was made.  Due to scope creep fixed some things with multiline
> templates: class,object,trait formating with early initializers etc.  Last
> hang up is dealing with bracketless case blocks.  Trying to avoid throwing
> endless heuristics at the formating rules.  Almost there.
> Meanwhile the quick fix work-around below should deal with the initial
> posted case.
> Ray
>
> On Sat, Dec 19, 2009 at 12:09 PM, Ray Racine <ray [dot] racine [at] gmail [dot] com> wrote:
>>
>> I have a partial fix for the most common annoying case .  I'm also out the
>> door to catch Avatar (IMax, 3D no less).  I haven't finished checking for
>> unintended consequences yet but will later this evening.  The fix is
>> predicated on the fact that a block is opened which "may" have a "=>"  on
>> the same line.  The below handles the posted situation.  It doesn't quite
>> work yet for one situation in the gist below and I need to do a tweak for
>> nesting.   But I'm interested in knowing of other situations other than the
>> posted "{ ... =>"
>> http://gist.github.com/260103
>> Are there any other cases of that need to handled ??
>> foo { stuff_without_a_=>_in_it
>>   bar
>>   ...
>> }
>> I hesitate, but for the impatient I'll slap up a the changed function in
>> scala-mode-indent.el if anyone wants to play pre-Alpha tester.   I'll do a
>> proper patch tonight.  After I've actually tested it. :)
>> (defun scala-block-indentation ()
>>   (let ((block-start-eol (scala-point-after (end-of-line)))
>>         (block-after-spc (scala-point-after (scala-forward-spaces))))
>>     (if (> block-after-spc block-start-eol)
>> (progn               ;; deals with first def/val/var afters a multiline
>> arg class
>>  (beginning-of-line)
>>  (when (search-forward ")" block-start-eol t) ;; class ( ...,    // across
>> lines.
>>    (scala-forward-spaces)                     ;;       ^ ...): T // seeks
>> to '('
>>    (backward-sexp))
>>  (+ (current-indentation) scala-mode-indent:step))
>>       (if (search-forward "=>" block-start-eol t)
>>  (+ (current-indentation) scala-mode-indent:step)
>> (progn
>>  (scala-forward-spaces)
>>  (current-column))))))
>>
>> On Fri, Dec 18, 2009 at 9:32 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch>
>> wrote:
>>>
>>> On Fri, Dec 18, 2009 at 7:46 AM, Alex Payne <al3x [at] al3x [dot] net> wrote:
>>> > There is a bug in the Emacs mode that ships with the Scala
>>> > distribution (in misc/scala-tool-support/emacs). This bug is alluded
>>> > to in the FUTURE document in that directory, but I'm curious to know
>>> > what it's current status is.
>>> >
>>> > The bug lies in the automatic indentation for multi-line expressions
>>> > within braces. An example:
>>> >
>>> > example { foo =>
>>> >  bar  // this first line indents correctly
>>> >         baz // but what happened here?
>>> >       } // this isn't correct either
>>> >
>>> This one annoys me greatly as well. Anybody volunteering to fix this
>>> would do a great service to the emacs scala user community!
>>>
>>> Cheers
>>>
>>>  -- Martin
>>
>>
>>
>> --
>> The object of life is not to be on the side of the majority, but to escape
>> finding oneself in the ranks of the insane. - Marcus Aurelius
>
>
>
> --
> The object of life is not to be on the side of the majority, but to escape
> finding oneself in the ranks of the insane. - Marcus Aurelius
>



--
Alex Payne
http://twitter.com/al3x



--
The object of life is not to be on the side of the majority, but to escape finding oneself in the ranks of the insane. - Marcus Aurelius
Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Formatting issues with the Scala Emacs mode
I have a trial of several indentation fixes in scala-mode-indent.el  for the Emacs Scala mode.  The goal is to have a C-x h followed by a C-M-\ just work and format code correctly.
http://github.com/RayRacine/Scamacs/tree/master/src/elisp/scala
The following indentation issues were addressed. - Proper indentation of the first line after the opening of a template for object, class, trait.  Works for mulitline definitions with alignment of the multiline args as well as 2.8 early initializers.
class C (val x: Int,


 - Indentation of    example { foo =>   bar      baz  } - Indentation for bracketless case ... =>  for match, react, receive and catch.   Pretty sure this can be done generically and I'll take a look at that this weekend.  - Fixed up a few byte-compiler warnings.

Only known issue current is for simple unit methods with incorrectly indent the following def.  Will fix this weekend.
def f (): Unit = ()   def h(): Unit = ...

On Fri, Dec 18, 2009 at 9:32 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
On Fri, Dec 18, 2009 at 7:46 AM, Alex Payne <al3x [at] al3x [dot] net> wrote:
> There is a bug in the Emacs mode that ships with the Scala
> distribution (in misc/scala-tool-support/emacs). This bug is alluded
> to in the FUTURE document in that directory, but I'm curious to know
> what it's current status is.
>
> The bug lies in the automatic indentation for multi-line expressions
> within braces. An example:
>
> example { foo =>
>  bar  // this first line indents correctly
>         baz // but what happened here?
>       } // this isn't correct either
>
This one annoys me greatly as well. Anybody volunteering to fix this
would do a great service to the emacs scala user community!

Cheers

Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Formatting issues with the Scala Emacs mode
I have a trial of several indentation fixes for scala-mode-indent.el  for the Emacs Scala mode.  The goal is to have a C-x h followed by a C-M-\ just work and format code correctly.
http://github.com/RayRacine/Scamacs/tree/master/src/elisp/scala
The following indentation issues were addressed. - Proper indentation of the first line after the opening of a template for object, class, trait.  Works for mulitline definitions with alignment of the multiline args as well as 2.8 early initializers.
class C (val x: Int,         val y: Int) extends {  x = 3 } with B (...) {  ...}
 - Indentation of    example { foo =>   bar     baz   }
 - Indentation for bracketless case ... =>  for match, react, receive and catch.   This can be done generically and I'll take a look at that this weekend. ... match|react|receive|catch {  case ... =>      ...    ...  case ... =>     ...    ...}
 - Fixed up a few deprecated byte-compiler warnings.
Only known issue currently is for simple unit methods with incorrectly indent the following def.  Will fix this weekend.
def f (): Unit = ()   def h (): AType = ...

Looking for testers to try it for a bit before cleaning it up and submitting a patch.
Thanks,
Ray

On Fri, Dec 18, 2009 at 1:46 AM, Alex Payne <al3x [at] al3x [dot] net> wrote:
There is a bug in the Emacs mode that ships with the Scala
distribution (in misc/scala-tool-support/emacs). This bug is alluded
to in the FUTURE document in that directory, but I'm curious to know
what it's current status is.

The bug lies in the automatic indentation for multi-line expressions
within braces. An example:

example { foo =>
 bar  // this first line indents correctly
        baz // but what happened here?
      } // this isn't correct either

I've posted the above to http://gist.github.com/259333 as well, for reference.

If anyone plans on tackling this bug in the near future, that'd be
great to know. If nobody is available to look into it, I'll try to
learn enough Elisp to fix it. Thanks in advance for any information.

--
Alex Payne
http://twitter.com/al3x



--
The object of life is not to be on the side of the majority, but to escape finding oneself in the ranks of the insane. - Marcus Aurelius
Grey
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Formatting issues with the Scala Emacs mode
The below indentation issue has been fixed.  At this point I don't know of any gross emacs/scala indentation issues.   Feedback welcome.  I'll give it a week to burn in and then clean it up and offer a patch.
http://github.com/RayRacine/Scamacs
Ray 
Only known issue currently is for simple unit methods with incorrectly indent the following def.  Will fix this weekend.
def f (): Unit = ()   def h (): AType = ...

Looking for testers to try it for a bit before cleaning it up and submitting a patch.
Thanks,
Ray

On Fri, Dec 18, 2009 at 1:46 AM, Alex Payne <al3x [at] al3x [dot] net> wrote:
There is a bug in the Emacs mode that ships with the Scala
distribution (in misc/scala-tool-support/emacs). This bug is alluded
to in the FUTURE document in that directory, but I'm curious to know
what it's current status is.

The bug lies in the automatic indentation for multi-line expressions
within braces. An example:

example { foo =>
 bar  // this first line indents correctly
        baz // but what happened here?
      } // this isn't correct either

I've posted the above to http://gist.github.com/259333 as well, for reference.

If anyone plans on tackling this bug in the near future, that'd be
great to know. If nobody is available to look into it, I'll try to
learn enough Elisp to fix it. Thanks in advance for any information.

--
Alex Payne
http://twitter.com/al3x



--
The object of life is not to be on the side of the majority, but to escape finding oneself in the ranks of the insane. - Marcus Aurelius



--
The object of life is not to be on the side of the majority, but to escape finding oneself in the ranks of the insane. - Marcus Aurelius

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland