Emacs style code formatting #10

Open
horkhe opened this Issue Jul 26, 2012 · 18 comments

Comments

Projects
None yet
9 participants
@horkhe
Contributor

horkhe commented Jul 26, 2012

Emacs code formatter is both de facto and de jure the industry standard. I believe that people will be more eager to move to your IDE if it formats the code the way they used to.

@ignatov

This comment has been minimized.

Show comment Hide comment
@ignatov

ignatov Jul 26, 2012

Owner

Seems, the good idea is a provide path to emacs and after that we can
use emacs formatter like:
http://erlang.org/pipermail/erlang-questions/2009-February/041720.html

And leave the standard formatter as well.

Owner

ignatov commented Jul 26, 2012

Seems, the good idea is a provide path to emacs and after that we can
use emacs formatter like:
http://erlang.org/pipermail/erlang-questions/2009-February/041720.html

And leave the standard formatter as well.

@horkhe

This comment has been minimized.

Show comment Hide comment
@horkhe

horkhe Jul 27, 2012

Contributor

That would be a perfect quick hack to do the job while a native formatter is being adjusted. But IMHO it is not acceptable as a permanent solution for several reasons:

  • Emacs needs to be installed to do as simple thing as formatting which definitely prevent your plugin from being good out-of-the-box;
  • The default formatter as it is produces unsatisfactory result. It does not recognize type specifications, very bad with tuple and record formating; and indention from some of my functions was removed altogether. The default formatter should be something that is used but the majority of developers and that is not what we have now;
  • Performance might become a problem since Emacs is not a light-weight thing;
  • I have a filling that Formatter and Auto-Indentation are somewhat dependent features. Auto-indentation needs to insert indentation based on the effective formatter.
Contributor

horkhe commented Jul 27, 2012

That would be a perfect quick hack to do the job while a native formatter is being adjusted. But IMHO it is not acceptable as a permanent solution for several reasons:

  • Emacs needs to be installed to do as simple thing as formatting which definitely prevent your plugin from being good out-of-the-box;
  • The default formatter as it is produces unsatisfactory result. It does not recognize type specifications, very bad with tuple and record formating; and indention from some of my functions was removed altogether. The default formatter should be something that is used but the majority of developers and that is not what we have now;
  • Performance might become a problem since Emacs is not a light-weight thing;
  • I have a filling that Formatter and Auto-Indentation are somewhat dependent features. Auto-indentation needs to insert indentation based on the effective formatter.

@ghost ghost assigned ignatov Jul 29, 2012

@vladimirk

This comment has been minimized.

Show comment Hide comment
@vladimirk

vladimirk Aug 7, 2012

Contributor

It is better to make formatter adjustable like in other intellij ides, and maybe provide emacs-style config for people who need this. Because whether emacs style is de-facto "standard" it is a) usually violated (and there are good reasons for it) and b) have too much "variants" for style of the similar code like C-c C-a.

Contributor

vladimirk commented Aug 7, 2012

It is better to make formatter adjustable like in other intellij ides, and maybe provide emacs-style config for people who need this. Because whether emacs style is de-facto "standard" it is a) usually violated (and there are good reasons for it) and b) have too much "variants" for style of the similar code like C-c C-a.

@ignatov

This comment has been minimized.

Show comment Hide comment
@ignatov

ignatov Aug 7, 2012

Owner

Ok, guys, you are both right. I'll add settings page for formatter. But it will take some time.

Owner

ignatov commented Aug 7, 2012

Ok, guys, you are both right. I'll add settings page for formatter. But it will take some time.

@yzh44yzh

This comment has been minimized.

Show comment Hide comment
@yzh44yzh

yzh44yzh Oct 16, 2012

We can use emacs formatter in early versions of plugin. I am sure all erlang developers have emacs installed :)

We can use emacs formatter in early versions of plugin. I am sure all erlang developers have emacs installed :)

@yzh44yzh

This comment has been minimized.

Show comment Hide comment
@yzh44yzh

yzh44yzh Oct 16, 2012

Code Style -> Erlang -> Tabs and Indents
Tab size and indent should be 8 chars long by default.

See screenshots and explanation here https://plus.google.com/u/0/111796213623287288776/posts/BiuFW8qatsM

Code Style -> Erlang -> Tabs and Indents
Tab size and indent should be 8 chars long by default.

See screenshots and explanation here https://plus.google.com/u/0/111796213623287288776/posts/BiuFW8qatsM

@yzh44yzh

This comment has been minimized.

Show comment Hide comment
@yzh44yzh

yzh44yzh Oct 16, 2012

Emacs compatibility is absolutely needed, so we can use it

exec '!emacs --eval "(progn (find-file \"' . expand('%:p') . '\")' .
   \ '(erlang-indent-current-buffer) (save-buffer) '.
   \ '(save-buffers-kill-emacs))"'

as temporary solution. Till we found a better way.

Emacs compatibility is absolutely needed, so we can use it

exec '!emacs --eval "(progn (find-file \"' . expand('%:p') . '\")' .
   \ '(erlang-indent-current-buffer) (save-buffer) '.
   \ '(save-buffers-kill-emacs))"'

as temporary solution. Till we found a better way.

@ignatov

This comment has been minimized.

Show comment Hide comment
@sergeyevstifeev

This comment has been minimized.

Show comment Hide comment
@sergeyevstifeev

sergeyevstifeev Jun 25, 2013

It would be great if the formatter could pay attention to file-specific emacs-configs, like this footer:

%%% Local Variables:
%%% erlang-indent-level: 2
%%% End:

or this header:

%% -*- erlang-indent-level: 2 -*-

Different files within one project may have different indentation level specified (usually some have 2 spaces, some have 4 spaces).

It would be great if the formatter could pay attention to file-specific emacs-configs, like this footer:

%%% Local Variables:
%%% erlang-indent-level: 2
%%% End:

or this header:

%% -*- erlang-indent-level: 2 -*-

Different files within one project may have different indentation level specified (usually some have 2 spaces, some have 4 spaces).

@ignatov

This comment has been minimized.

Show comment Hide comment
@ignatov

ignatov Jun 26, 2013

Owner
@artburkart

This comment has been minimized.

Show comment Hide comment
@artburkart

artburkart Aug 11, 2015

Does this still use emacs? I'm trying to take a stab at a formatter, but it's not as simple as I'd hoped.

Does this still use emacs? I'm trying to take a stab at a formatter, but it's not as simple as I'd hoped.

@deadok22

This comment has been minimized.

Show comment Hide comment
@deadok22

deadok22 Aug 11, 2015

Collaborator

Yes, we have an action for formatting with emacs, as well as our own formatter.

Collaborator

deadok22 commented Aug 11, 2015

Yes, we have an action for formatting with emacs, as well as our own formatter.

@amir343

This comment has been minimized.

Show comment Hide comment
@amir343

amir343 Mar 14, 2016

Hi,

It might be a stupid mistake by me but when I try "Reformat code with Emacs", the whole code is indented with 4 spaces. I even tried to set indent level. Any idea?

amir343 commented Mar 14, 2016

Hi,

It might be a stupid mistake by me but when I try "Reformat code with Emacs", the whole code is indented with 4 spaces. I even tried to set indent level. Any idea?

@ignatov

This comment has been minimized.

Show comment Hide comment
@ignatov

ignatov Mar 14, 2016

Owner

Please see (erlang-indent-current-buffer) in (erlang-mode).

Owner

ignatov commented Mar 14, 2016

Please see (erlang-indent-current-buffer) in (erlang-mode).

@amir343

This comment has been minimized.

Show comment Hide comment
@amir343

amir343 Mar 14, 2016

I mean in IntelliJ IDEA, when I use Code -> "Reformat Code with Emacs", the indentation is with 4 spaces. Do you mean that I need to fix it in Emacs itself?

amir343 commented Mar 14, 2016

I mean in IntelliJ IDEA, when I use Code -> "Reformat Code with Emacs", the indentation is with 4 spaces. Do you mean that I need to fix it in Emacs itself?

@NobbZ

This comment has been minimized.

Show comment Hide comment
@NobbZ

NobbZ Mar 14, 2016

Yes, because it runs in an hidden emacs. It's called indend WITH emacs, not
LIKE emacs.

αmir μoulavi notifications@github.com schrieb am Mo., 14. März 2016 21:45:

I mean in IntelliJ IDEA, when I use Code -> "Reformat Code with Emacs",
the indentation is with 4 spaces. Do you mean that I need to fix it in
Emacs itself?


Reply to this email directly or view it on GitHub
#10 (comment)
.

NobbZ commented Mar 14, 2016

Yes, because it runs in an hidden emacs. It's called indend WITH emacs, not
LIKE emacs.

αmir μoulavi notifications@github.com schrieb am Mo., 14. März 2016 21:45:

I mean in IntelliJ IDEA, when I use Code -> "Reformat Code with Emacs",
the indentation is with 4 spaces. Do you mean that I need to fix it in
Emacs itself?


Reply to this email directly or view it on GitHub
#10 (comment)
.

@amir343

This comment has been minimized.

Show comment Hide comment
@amir343

amir343 Mar 14, 2016

Ok, I set erlang-indent-level in my .emacs file and I tested to see if the erlang-indent-current-buffer works and it did. However the IntelliJ still format the code differently. What am I doing wrong here?

amir343 commented Mar 14, 2016

Ok, I set erlang-indent-level in my .emacs file and I tested to see if the erlang-indent-current-buffer works and it did. However the IntelliJ still format the code differently. What am I doing wrong here?

@amir343

This comment has been minimized.

Show comment Hide comment
@amir343

amir343 Mar 15, 2016

I was reading the code in "src/org/intellij/erlang/actions/ErlangEmacsFormatAction.java" and I was wondering the way java handles processes, does it read .emacs file from home directory?

amir343 commented Mar 15, 2016

I was reading the code in "src/org/intellij/erlang/actions/ErlangEmacsFormatAction.java" and I was wondering the way java handles processes, does it read .emacs file from home directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment