Sublime Forum

PHP if indent

#1

Hey there,

when I press enter in PHP syntax after typing, while my cursor (the “|”) is here:

if (condition) {|}

I get:

if (condition) { _ _| }
(tow tabs)

instead of:

if (condition) { _ | }
(one tab).

I searched the whole web and this forum, but I could not clearly find a solution I did understand.

So is there a way to adjust how many tabs will be indented in this auto indent behaviour?

Thanks for the help!

Manu

0 Likes

#2

I tried this in a clean, uncustomized copy of ST build 3157, and only one indentation level is added. Perhaps you have a plugin installed that is causing this behavior?

0 Likes

#3

Hey, thanks for the reply. I am on ST3 build 3143 (which seems to be the official recent version … I am a bit unsure if it would be a good idea to work with dev builds …hm?).

I tried to disable some plugins though - there are quite a lot already active by sublime itself, right? The package control showed me plenty of plugins to disable - most seem to be sytax related. I tried to disable the plugins I know I installed after a clean sublime install. And then after only disabling PHP with the package control, I got only one indent atfer pressing enter … no syntax highlighting though, of course. Is the build-in PHP broken in version 3143?

Thanks for the help and sorry to bother!

0 Likes

#4

I think I might found the problem. I seem to have a tweaked “Add Line in Braces.sublime-macro”, which I once made to mdofiy the smart indentation or similar. If I disable this tweak PHP indentation work fine again, but Python is not as I want it. But I will figure it out. Thanks for the help! :slight_smile:

0 Likes

#5

I now found out a solution that works in PHP and Python and probably every other syntax. I replace the “enter” key binding like this:

{ "keys": ["enter"], "command": "insert_snippet", "args": { "contents": "\n\t$0\n" }, "context":
	    [
	        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
	        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
	        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{|\\(|\\[$", "match_all": true },
			{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}|\\)|\\]", "match_all": true }
	    ]
	},

This way I get the indention I expect. I searched quite long in the web to find this. I thought I post it here and hopefully it will help someone else in the future. :wink:

0 Likes