Xcode block (NSMallocBlock) indent (automatically starts on a new line)

I want to open blocks with curly braces starting from a new line.

Deviate from a philosophical discussion of whether this is a good decision or not - regardless of 'where' and 'when', 'how' remains absolute.

So the problem is described below:

enter image description here

Is there any way to achieve this?


I looked around for a long time, but I did not find any solutions.

I already know about things like:

  • Snippet Edit - This small program will allow you to edit the default code fragments of Xcode. This way you can open curly braces from a new line in if , for , while , etc. However, this does not allow you to indent the block.

  • Uncrustify - this may solve my problem, but it does not seem like you are easily configured. And it only formats the code after it is already written, instead of formatting 'on the go' . Moreover, even if I installed uncrustify , it will still be rather slow - it takes 4 clicks to format the block, which takes a lot of time.

Does anyone know of any other solutions?

EDIT:

To be more specific, I want the block to be indented as soon as I press ENTER in this step:

enter image description here

+5
source share
3 answers

The easiest solution I have found is:

Download Karabiner and change your private.xml (you can also view the documentation here )

Your private.xml might look like this:

 <?xml version="1.0"?> <root> <item> <name>Command+Enter to complete single block</name> <identifier>private.swap_cmnd+Enter_to_complete__single_block</identifier> <autogen> __KeyToKey__ KeyCode::RETURN, ModifierFlag::COMMAND_L | ModifierFlag::NONE, KeyCode::RETURN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::DELETE, ModifierFlag::COMMAND_L, KeyCode::BRACKET_RIGHT, ModifierFlag::SHIFT_L, KeyCode::BRACKET_RIGHT, KeyCode::SEMICOLON, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::CURSOR_LEFT, KeyCode::RETURN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::I, ModifierFlag::CONTROL_L, KeyCode::CURSOR_RIGHT, KeyCode::CURSOR_UP, KeyCode::CURSOR_LEFT, ModifierFlag::SHIFT_L, KeyCode::TAB, </autogen> </item> <item> <name>Option+Enter to complete double block</name> <identifier>private.swap_Option+Enter_to_complete_double_block</identifier> <autogen> __KeyToKey__ KeyCode::RETURN, ModifierFlag::OPTION_L | ModifierFlag::NONE, KeyCode::CURSOR_RIGHT, KeyCode::RETURN, KeyCode::CURSOR_UP, KeyCode::CURSOR_LEFT, ModifierFlag::COMMAND_L, KeyCode::TAB, KeyCode::RETURN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_LEFT, ModifierFlag::COMMAND_L, KeyCode::TAB, KeyCode::RETURN, KeyCode::DELETE, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::DELETE, ModifierFlag::COMMAND_L, KeyCode::BRACKET_RIGHT, ModifierFlag::SHIFT_L, KeyCode::BRACKET_RIGHT, KeyCode::SEMICOLON, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::CURSOR_LEFT, KeyCode::RETURN, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::CURSOR_LEFT, KeyCode::RETURN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_DOWN, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::CURSOR_UP, ModifierFlag::SHIFT_L, KeyCode::I, ModifierFlag::CONTROL_L, KeyCode::CURSOR_RIGHT, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_UP, KeyCode::CURSOR_LEFT, ModifierFlag::COMMAND_L, KeyCode::TAB, </autogen> </item> </root> 

After that, you can open the block by pressing ⌘ + ENTER ( instead ) press ENTER , when opening the block press ⌘ + ENTER ). Here's a preview (slowdown so you can see the details).

The above only works with single blocks. If you want to open two blocks at once, you can press ALT + ENTER . Here's a preview (slowdown so you can see the details).

Here is a preview with actual speed:

Demo CountPages alpha

0
source

Just manually add the beginning of the bracket to a new line, then your indent should be good.

-1
source

I don’t think there is a way to do this automatically after pressing ENTER .

What you can do is press ENTER to fill in this passage, then go to { and press ENTER again. After that, Xcode formats it the way you like.

-2
source

Source: https://habr.com/ru/post/1241953/


All Articles