Sublime Forum

PHP Indentation Changes

#1

Does anyone know if the file Indentation Rules.tmPreferences in php is actually used? I don’t see a case statement in there and have a problem with the code within the case not being indented… ie

switch (variable) {
	case 'value':
	echo 'bb';
	break;
	default:
# code...
	break;
}[/code]

[code]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Indentation Rules</string>
	<key>scope</key>
	<string>source.php - comment</string>
	<key>settings</key>
	<dict>
		<key>decreaseIndentPattern</key>
		<string>(?x) ^ (.*\*/)? \s* \} .* $|&lt;\?(php)?\s+(else(if)?|end(if|for(each)?|while))</string>
		<key>indentNextLinePattern</key>
		<string>^(?!.*(#|//|\*/|&lt;\?))(?!.*};:]\s*(//|/\*.*\*/\s*$)).*^\s;:{}]\s*$|&lt;\?php.+?\b(if|else(?:if)?|for(?:each)?|while)\b.*:(?!.*end\1)</string>

		<key>bracketIndentNextLinePattern</key>
		<string>(?x)
		^ \s* \b(if|while|else|elseif|foreach)\b ^;]* $
		| ^ \s* \b(for)\b .* $
		</string>

	</dict>
	<key>uuid</key>
	<string>CA15DF69-E80D-46DA-BD45-E88C68E92117</string>
</dict>
</plist>
0 Likes

#2

can anyone help with this issue?

0 Likes

#3

I don’t know whether the indentation rules are used - I seem to recall someone mentioning that they are not. But if you replace, for example, ‘while’ with some other, random, word you’ll be able to check if they are.

If they are used then it might be possible to add switch/case to the rule(s) - but copy the file before experimenting with it.

There are snippets for ‘switch’ and ‘case’ which seem to align okay, but I assume you’re not using these.

Added: Actually, these rules are probably distinctly different to those for ‘switch’ so it might not be possible to just slip switch/case, etc., into this file. But I might be wrong :smile:

0 Likes

#4

Slightly off topic :smile: but I’d rather the switch and case snippets were like the following.

That is, I don’t want the apostrophe’s around the values; I always need at least two cases; and I don’t want a Tab position within the default. (When creating a switch I often haven’t decided on the default behaviour, and it’s often a repeat, or fall-through, of one of the cases anyway.)

<snippet> <content><![CDATA[switch (${1:variable}) { case ${2:value}: $0 break; case : # code.. break; default: break; }]]></content> <tabTrigger>switch</tabTrigger> <scope>source.php</scope> <description>switch …</description> </snippet>

<snippet> <content><![CDATA[case ${1:variable}: ${0:# code...} break;]]></content> <tabTrigger>case</tabTrigger> <scope>source.php</scope> <description>case …</description> </snippet>

Note: The indentation is correct in my snippet(s) but is distorted when pasted into this post.

0 Likes