Sublime Forum

Automatic Indentation with Ruby?

#1

I like what I’ve seen so far of Sublime, and I want to like it more, but I can’t do that until I can find a way to get Ruby autoindent working. It’s highly probable I’m simply missing something since I know Sublime can do what I want as it works out of the box with Python. If I type:

5.times do |x| puts x end
I would very much like for Sublime to automatically indent the “puts x” line for me, and then automatically deindent the “end” line, when I type them.

What am I doing wrong that this doesn’t simply happen? Thanks in advance!

0 Likes

#2

Sublime Text’s autoindent won’t handle this yet - it’s not configurable. I’ve added it to the list of things to fix.

0 Likes

#3

jon, do you intend to support textmate Indentation Rules (tmPreferences)?

0 Likes

#4

That’s the plan at this stage, yes.

0 Likes

#5

Hi Jps, do you know when this feature might be released?

0 Likes

#6

I do a lot of Ruby and Lua currently. This feature should work similarly for these languages. When will this be available?

0 Likes

#7

Hey, just wanted to ask if there is auto-indentation in Ruby, now that 1.4 has rolled out.
I’m pretty sure there was auto-indentation yesterday, but today there is none. Not in ANY language. Which is kinda strange.
I’ve searched the forum but didn’t find anything useful. I also can’t see anything wrong with my configuration. Is there something I’m missing? Thanks in advance.

Here is my config file:

[code]# While you can edit this file, it’s generally best to put your changes in

User File Type.sublime options, which overrides the settings in here.

Settings may also be placed in file type specific options files, for example,

in Packages/Python/Python.sublime-options for python files.

Sets the colors used within the text area

colorscheme Packages/user/Sublimey.tmTheme

The menu that pops up when you right click

contextMenu Packages/Default/Context.sublime-menu

Font to draw with. To override the system antialiasing settings, append

:noantialias to the end of the line.

font Consolas 11

What characters are considered to separate words when using ctrl+arrows etc

wordSeparators ./\()"’-:,.;<>~!@#$%^&*|+=]{}`~?

Set to false to prevent line numbers being drawn in the gutter

lineNumbers true

Set to false to hide the gutter altogether

gutter true

Columns in which to display vertical rulers, space separated

rulers

Set to true to turn spell checking on by default

spellCheck false

The number of spaces a tab is considered equal to

tabSize 2

Set to true to insert spaces when tab is pressed

translateTabsToSpaces true

If translateTabsToSpaces is true, useTabStops will make tab and backspace to

insert/delete up to the next tabstop

useTabStops true

Set to false to disable automatic indentation

autoIndent true

Set to false to not trim whitespace added by autoIndent

trimAutomaticWhitespace true

Set to false for horizontal scrolling

wordWrap true

Set to a value other than 0 to force wrapping at that column rather than the

window width

wrapWidth 0

Set to false to prevent word wrapped lines from being indented to the same

level

indentSubsequentLines true

Set to true to draw text centered in the window rather than left aligned

drawCentered false

Set to false to stop auto pairing quotes, brackets etc

autoMatchEnabled true

Word list to use for spell checking

dictionary Packages/Language - English/en_US.dic

Set to true to never prompt to reload when a file is changed on disk

ignoreChanged false

Set to true to always reload changed files on disk, instead of prompting

autoReloadChanged true

Set to false to disable highlighting any line with a cursor

highlightLine true

Set to false to disable underlining the brackets surrounding the cursor

matchBrackets true

Set to false if you’d rather only highlight the brackets when the cursor is

next to one

matchBracketsContent true

Set to false to not highlight square brackets. This only takes effect if

matchBrackets is true

matchBracketsSquare true

Set to false to not highlight curly brackets. This only takes effect if

matchBrackets is true

matchBracketsBraces true

Set to false to not highlight angle brackets. This only takes effect if

matchBrackets is true

matchBracketsAngle false

Set to false to disable detection of tabs vs. spaces on load

detectIndentation true

Additional spacing at the top of each line, in pixels

linePaddingTop 0

Additional spacing at the bottom of each line, in pixels

linePaddingBottom 0

What should happen when the minimap is clicked outside of the view rectangle.

Valid values are ‘none’, ‘position’ or ‘text’.

clickToScroll text

Set to false to hide the vertical and horizontal scroll bars

wantVerticalScrollBar true
wantHorizontalScrollBar true

Set to false to disable scrolling past the end of the buffer

scrollPastEnd true

Set to ‘none’ to turn off drawing whitespace, ‘selection’ to draw only the

whitespace within the selection, and ‘all’ to draw all whitespace

drawWhiteSpace selection

Set to true to removing trailing whitespace on save

trimTrailingWhiteSpaceOnSave false

The encoding to use when the encoding can’t be determined automatically.

ASCII, UTF-8 and UTF-16 encodings will be automatically detected.

fallbackEncoding Western (Windows 1252)

Determines what character(s) are used to terminate each line in new files.

Valid values are ‘system’ (whatever the OS uses), ‘windows’ (CRLF) and

‘unix’ (LF only).

defaultLineEnding system

Set to true to copy the selection to the clipboard whenever text is selected

with the mouse

copyOnMouseSelect false
[/code]

0 Likes

#8

There is automatic indentation for Ruby, and it should be working fine out of the box with 1.4.

To see if auto indent is turned on for you in Ruby files, open one, and in the console, enter:

view.options().get('autoIndent')
0 Likes

#9

[quote=“jps”]There is automatic indentation for Ruby, and it should be working fine out of the box with 1.4.

To see if auto indent is turned on for you in Ruby files, open one, and in the console, enter:

view.options().get('autoIndent') [/quote]

It comes out ‘True’. But still no auto-indent. And not just in .rb files. Everywhere. As I said, I’m pretty sure I had auto-indentation when I installed. I guess I’ll reinstall the app. Hope that fixes it.

0 Likes

#10

Perhaps you have a key binding that’s taking effect on enter, and thus overriding the auto indent.

To reset to a vanilla installation, close Sublime Text and delete the %APPDATA%/Sublime Text directory, all settings and customizations are stored within there - a reinstall alone won’t reset them.

0 Likes

#11

[quote=“jps”]Perhaps you have a key binding that’s taking effect on enter, and thus overriding the auto indent.

To reset to a vanilla installation, close Sublime Text and delete the %APPDATA%/Sublime Text directory, all settings and customizations are stored within there - a reinstall alone won’t reset them.[/quote]

Actually, I may have overridden a key binding, but I noticed that when I type ‘end’ it doesn’t automatically dedent it. Anyway, when I deleted the %APPDATA% folder everything seems to work fine. I noticed re-install doesn’t work, because it loaded all the previously open files :smile:

Anyhow, thank for the help! It’s working perfectly now.

0 Likes