Home Download Buy Blog Forum Support

Autopair quotes inside anything autopaired

Autopair quotes inside anything autopaired

Postby gonzab on Tue Oct 06, 2009 3:31 am

First of all, what and impressive editor, its really superb, im trying it for one week and im really astonished.

I dont know if im missing something, or this is normal behaviour, but when i type a quote " the autopair funcionality works fine and automatically the second quote appears "".

But if im writing the quote inside anything autopaired (like, for example, parenthesis) the quote autopair never appears. To be more concrete:
Code: Select all
$foo = "bar";


the second quote will appear automatically, but if i do
Code: Select all
if ($foo == "bar") {


i'd to write the second quote manually.
This is normal behavior?

Thanks in advance,
Gonzalo

ps: sorry if this was talked in another topic, i did a search and i cannot find anything related it.
gonzab
 
Posts: 7
Joined: Tue Oct 06, 2009 3:25 am

Re: Autopair quotes inside anything autopaired

Postby jps on Tue Oct 06, 2009 4:44 am

The auto-inserting of quotes only happens if there's whitespace to the right of the cursor, otherwise it can get a bit annoying. You can change this though: if you add the following key binding to your user key bindings (Preferences/User Key Bindings):

Code: Select all
<binding key="&quot;" command="insertSnippet 'Packages/Default/Quote.sublime-snippet'">
   <context name="option" value="autoMatchEnabled"/>
   <context name="allSelectionsEmpty" value="true"/>
</binding>


...then it will always add in the paired quote, irrespective of the text around the cursor. For reference, the original key binding is:

Code: Select all
<binding key="&quot;" command="insertSnippet 'Packages/Default/Quote.sublime-snippet'">
   <context name="option" value="autoMatchEnabled"/>
   <context name="allSelectionsEmpty" value="true"/>
   <context name="allFollowingText" value="^(\t| |$)"/>
   <context name="noPrecedingText" value="[&quot;a-zA-Z0-9_]$"/>
</binding>


This differs from the above binding by having two extra contexts that inhibit the paring if there's something other that whitespace to the right of the cursor, or alpha-numeric characters to the left. If you do find the always-auto-pairing annoying, you may want to consider just modifying the 'allFollowingText' context to have value="^(\t| |\)|$)", i.e., it'll also insert the quote if there's a close bracket to the right.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Re: Autopair quotes inside anything autopaired

Postby gonzab on Tue Oct 06, 2009 12:04 pm

Thanks jon!! Excellent to know, i love the fact that everything is configurable in Sublime.

Thanks again,
gonzalo
gonzab
 
Posts: 7
Joined: Tue Oct 06, 2009 3:25 am


Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 17 guests