If necessary, another indent object (Emacs)

I use Emacs for some obj-c programming and it is very hard for me to work with the standard indentation scheme. I don’t know enough list or emacs lisp to fix it myself, but hopefully someone here can help.

Here is an example of how I want my code to be indented:

void someFunc() { NSBitmapImageRep* repout = [ [NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: width pixelsHigh: height bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: width*4 bitsPerPixel: 32 ]; } 

But here's what the indentation area of ​​Mx is doing at the moment, it's pretty awful:

 void someFunc() { NSBitmapImageRep* repout = [ [NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: width pixelsHigh: height bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: width*4 bitsPerPixel: 32 ]; } 

I don’t really care about things lining up for the colon, since I have them lining up in the first letters. In addition, it explicitly casts the argument list too far. Finally, he closes the "];" one level of deepening is too deep.

Many thanks in advance to any emacs configuration hacker who can send responses.

-Patrick

+4
source share
1 answer

You can indent various syntax elements by calling c-set-offset . If you call it interactively, emacs will tell you the value of the "indent variable" that you want to change, and ask you to get the value.

Programmatically, this will do something close to what you want in the example you mentioned, but you can have many other use cases where you want different behavior:

 (c-set-offset 'arglist-intro '+) (c-set-offset 'arglist-close 0) (c-set-offset 'objc-method-call-cont 'c-lineup-argcont) 
0
source

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


All Articles