Sublime Forum

Whitesmiths Indentation Style?

#1

Is there a way to specify indentation rules regarding actual position of braces?

I know it’s uncommon, but years ago I somehow picked up Whitesmiths style indentation and it would be nice if I was able to specify that braces are to be both indented.

Is there any way to do this through the application settings?

Whitesmiths Style:

function zoink()
	{
	// yadda
	}
0 Likes

#2

WITCH! BURN HIM AT THE STAKE!!

But seriously, this isn’t native to Sublime, however there are plugins which control indentation for variables etc, so I don’t see why this wouldn’t be impossible to implement as a plugin.

0 Likes

#3

+1

:laughing:

0 Likes

#4

[quote=“jbrooksuk”]

indentation and it would be nice if I was able to specify that braces are to be both indented.
WITCH! BURN HIM AT THE STAKE!!

But seriously, this isn’t native to Sublime, however there are plugins which control indentation for variables etc, so I don’t see why this wouldn’t be impossible to implement as a plugin.[/quote]

+2

0 Likes

#5

Believe me, it is my great shame. I even had someone refuse to work with me on a project unless I stopped.

I find it to be rather helpful. To me, the braces provide a clear representation of the current indentation level like saying >>here is the current scope<<

Anyway, thanks for the info that it’s not a built-in feature, and I shall look into some of these plugins

0 Likes

#6

I’m late to the game but I share your shame and use that indentation style all the time on a large commercial product! (I started it).
I need a solution too as fixing the braces manually is annoying.

0 Likes

#7

Anyone find a solution to this? Whitesmith is a standard where I work unfortunately.

0 Likes

#8

I have been using the Whitesmith syntax without even knowing it for many years.

I started using it back in the days of Microsoft C for DOS and then nearly all coding examples I saw used this format.

I too find this notation easy on the eyes and easy to pick out the level of the code and blocks of similar code. The code is logically seperated and clean to read. My brain, limited as it is, does not have to think about matching braces or counting braces. Visually for me the code looks right and my brain can concentrate on the content.

I also would be very interested in Sublime supporting this syntax style.

Thanks
OW

0 Likes

#9

I vote for Whitesmiths indentation style too for the same reasons as those above. Used it since before MS-DOS days and for any C-braces style language such as PHP and Javascript too.

I am fairly new to sublime and might do a plugin. Is there any documentation on that or is it mostly learned by example?

0 Likes

#10

Using a whole extra line for an opening brace? I have never been able to understand why anyone would waste the space and not use One True Brace Style. If there is a reason, please enlighten me. The beginning of a block can always be located because the “for” / “while” / “if” / “else” keyword should be highlighted - so then what is the reason.

More lines for the same code means more scrolling and less methods shown at screen at one time --> takes longer to navigate around in your code.

0 Likes

#11

This is probably not the place for yet another brace placement war.

The fact is that some people or code will use a brace style that you dislike for whatever reason (they might just like it, or they might hate it but are forced to use it because of some requirement). Some people might even dislike the brace style that you prefer, even if as far as you can tell there’s absolutely no defect in it.

Whitesmiths is common enough that ST should support it.

0 Likes

#12

So, people have said that it is possible to do this with a plugin, but I haven’t seen anyone point to how exactly to do it. Can someone please give some guidance on how one would go about writing a plugin that formats code this way?

0 Likes

#13

[quote=“robertcollier4”]Using a whole extra line for an opening brace? I have never been able to understand why anyone would waste the space and not use One True Brace Style. If there is a reason, please enlighten me. The beginning of a block can always be located because the “for” / “while” / “if” / “else” keyword should be highlighted - so then what is the reason.

More lines for the same code means more scrolling and less methods shown at screen at one time --> takes longer to navigate around in your code.[/quote]

I’m with you!

0 Likes

#14

Still no news on this? Sadly, whitesmith is the coding style the company I work for uses and without support for it I can’t really imagine using ST as my main editor at work.

Edit: I created a userecho feature request for this. Please add your support: sublimetext.userecho.com/topic/213818-/

0 Likes

#15

@chlab: you may want to post something up on the sublime github issue tracker as well, since it seems that userecho is falling on deaf ears these days :frowning:

For anyone else interested in whitesmith indenting, it does look as though this could be done with a plugin. I found this plugin for customised lisp/clojure indent behaviour which should serve as a useful starting point for writing a custom autoindent, whitesmith style. I’m not interested in whitesmith myself so I’ll bow out here - but I did take a look at the plugin code and upon cursory glance it seems to have all of the needed elements.

:smile:

0 Likes

#16

Thanks for the heads up. Here’s the feature request for those interested: github.com/SublimeText/Issues/issues/112
I’ll have a look at that plugin, thanks.

0 Likes

#17

Don’t be ashamed of using Whitesmiths notation. It’s a sign of maturity.

Whitesmiths was around long before the current K&R/Linux/Windows way of doing it was invented. In fact, the history of K&R goes back to a 1990’s book on programming for Windows. For those of us who have been programming since the 70’s and managed to avoid Windows, we’ve not been infected with K&R formatting.

And I add my voice to those who would like to see Whitesmiths in SublimeText. It’s pretty much the only reason I stick with my current IDE and don’t switch to Sublime.

0 Likes

#18

Wait wait wait. Time out. I’m not gonna get into the brace wars, but:

In fact, the history of K&R goes back to a 1990’s book on programming for Windows.

“K&R” are Kernighan and Ritchie, the authors of the book The C Programming Language (and of course, they’re also the authors of, well, the C programming language). I don’t know what programming book you’re thinking of, but I assure you that the K&R brace style predates that book. And, for that matter, predates Windows.

(Ironically, while the Whitesmiths style also predates Windows, Wikipedia suggests that it was popularized largely by… early books on programming for Windows.)

0 Likes

#19

There’s clang-format and a “clang format” plugin on package control; you can indent braces themselves with that (:fearful:) if you write in something that looks like C.

0 Likes

#20

this Whitesmiths indentation style is highly incompatible with the TextMate Indentation Rules - for example, I imagine you would want it so that when pressing { on an otherwise blank line, it would indent the brace. There is no way to do this using the indentation rules. However, you could write a keybinding to insert a tab (which would get converted to your preferred number of spaces if you don’t use tabs) followed by the { character. I think this is probably your best option. If you wanted, you could prevent the reindent command from moving those braces, but there wouldn’t be an easy way to get it to indent the braces for you.

Again, for } you would probably want a keybinding to insert the }, followed by a new line and to adjust the indentation one level backwards on the new line. Because there is no way using the indentation rules to say, dedent the next line after a } on the previous/current line.

In terms of having snippets and completions pre-formatted in Whitesmiths style, this is possible. Take a look at https://github.com/sublimehq/Packages/issues/131

2 Likes