Home Download Buy Blog Forum Support

auto complete php tag

auto complete php tag

Postby elygen on Wed Jan 30, 2013 4:19 pm

Is there a plugin that will append (php) when you type <?
That would just make my day :)
elygen
 
Posts: 1
Joined: Wed Jan 30, 2013 4:17 pm

Re: auto complete php tag

Postby dotzecker on Wed Jan 30, 2013 6:33 pm

It goes to the technical support!

But you could create a snippet

Code: Select all
<snippet>
    <content><![CDATA[
<?php
]]></content>
    <tabTrigger><?</tabTrigger>
    <scope>source.php</scope>
</snippet>

dotzecker
 
Posts: 1
Joined: Wed Jan 30, 2013 6:30 pm

Re: auto complete php tag

Postby britalb on Thu Jan 31, 2013 12:37 am

Hi All,

Seemed like an excellent suggestion, so I tried it, only to get an XML parsing error.

I found the following after a Google search:
http://sublimetext.userecho.com/topic/9 ... -a-period/

and emended the snippet to the following:
Code: Select all
<snippet>
   <content><![CDATA[
<?php ${1} ?>
]]></content>
   <tabTrigger>&lt;?</tabTrigger>
   <scope>source.php</scope>
</snippet>


As always, give it a name like "phptag.sublime-snippet," and save it to your Packages/User directory (or a subfolder - i.e. "/php").

Hope this saves someone some time! Thanks again for the great suggestion.

Brit
britalb
 
Posts: 2
Joined: Thu Jan 31, 2013 12:31 am

Re: auto complete php tag

Postby bozdoz on Wed Mar 12, 2014 8:42 pm

Made a couple auto-complete settings that auto complete PHP tags. It also auto completes the less-than sign, which also comes in handy with HTML tags. Hope it helps.

Code: Select all
// Auto-pair less than
   { "keys": ["<"], "command": "insert_snippet", "args": {"contents": "<$0>"}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
         { "key": "preceding_text", "operator": "not_regex_contains", "operand": "[<a-zA-Z0-9_]$", "match_all": true },
         { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "match_all": true }
      ]
   },
   { "keys": ["<"], "command": "insert_snippet", "args": {"contents": "<${0:$SELECTION}>"}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
      ]
   },
   { "keys": ["<"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^<", "match_all": true }
      ]
   },
   { "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
      [
         { "key": "setting.auto_match_enabled", "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 }
      ]
   },

   // Auto-pair PHP percent
   { "keys": ["?"], "command": "insert_snippet", "args": {"contents": "?php $0 ?"}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
         { "key": "preceding_text", "operator": "regex_contains", "operand": "<$", "match_all": true },
         { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "match_all": true }
      ]
   },
   { "keys": ["?"], "command": "insert_snippet", "args": {"contents": "?php ${0:$SELECTION} ?"}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
      ]
   },
   { "keys": ["?"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^//?", "match_all": true }
      ]
   },
   { "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
      [
         { "key": "setting.auto_match_enabled", "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 }
      ]
bozdoz
 
Posts: 1
Joined: Wed Mar 12, 2014 8:31 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 17 guests