Stupid question: indentation


#1

Hi

I have select a bunch of lines in a function (in Lisp) and I would like to indent them automagically.

I tried several commands, but I cannot figure out how to get the indentation done.

Is there some obvious thing I should try?

All the best

Marco


#2

The command is called “Editor: Auto Indent”. You can find it in the Command Palette.


#3

Thanks for the reply, but what is “Editor: Auto Indent” in the Command Palette supposed to do?

I select a function (i.e., a full code snippet) and then?

Please bear with me.

Thanks

Marco


#4

It is supposed to automatically indent the code according to the rules of the currently selected grammar.


#5

I don’t see that happening. Neither in Lisp nor in C, nor Java. The code remains unchanged and if I try to edit ii non indentation to speak of is performed.

Marco


#6

“edit it, no indentation to speak of…”

Sorry. Typing too fast :slight_smile:


#7

Can you describe what exactly you do, what you expect to happen and what actually happens? Steps to reproduce your problem will be a big help in diagnosing what is going wrong rather than me trying to guess out of the myriad things it could be :grinning:


#8

Here is a code snippet in Java

if (foo == 42) { return "Don't panic!" }

If I hit a return right after the open bracket I get

if (foo == 42) {
return "Don't panic!" }

This with and without the Editor: Auto Indent and with or without the Window: Toggle auto indent.

Not even selecting the code and selecting Edit -> Lines -> Autoindent seem to work.

What I expect is to see is

if (foo == 42) {
    return "Don't panic"; }

Is there a way to achieve this? At a minimum with a command based on a selection. While typing would be better.

Thanks
Marco


#9

Is the grammar set to Java?


#10

Yes it is. As it is for the Lisp example and for the C one. I am on a Mac, just in case.

Marco


#11

I can’t reproduce the behavior you’re describing using Atom v1.12.7 on Mac OS X 10.12.2. I tried your described repro steps using both the built-in C and Java grammars. I don’t have a Lisp grammar installed and I don’t think your example applies to Lisp anyway :slight_smile:

Do you have the “Auto Indent” setting turned on?


#12

I have the Atomic Soft Tabs set and the Auto Indent set. I can get some behavior improvement for Java and C by making sure I have bracket enclosed blocks. Expression indentation does not seem to work though. The Lisp grammar seems insensitive to the settings.

Marco


#13

Just to clarify. This is an expression I’d like to indent.

System.out.println(">>> " + x[0] + "! = " + 42);

What I expect is to hit return before the ‘+’ signs and get the following:

System.out.println(">>> "
		   + x[0]
		   + "! = "
		   + 42);

This is the standard GNU Coding Style -like indentation.

All the best

Marco


#14

Atom doesn’t support that kind of indentation out of the box. There may be some packages that offer that though.


#15

Ok. Thanks.

Do you have any suggestion about which packages may provide that?

Happy Holidays

Marco