AutoHotkey Community

It is currently May 27th, 2012, 8:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: February 9th, 2012, 1:00 am 
Offline

Joined: February 8th, 2012, 7:15 pm
Posts: 2
I use AutoHotkey text replacements for a number of snippets for web development. My text editor (Sublime Text, highly recommended) automatically does some formatting of the text. For example, when you use a curly brace, it automatically indents your next line another tab and when you do a closing brace it automatically moves it back a tab. Anyway, I had to spend a while writing a function that would anticipate this and edit the text being sent accordingly. So in my script I can paste text in a new hotstring like below:

Code:
:*?:__hotstring::
Var =
(
if(this)
{
    that
}
)
snippet(Var)
Return


And when I enter the hotstring, it will automatically format that string so it isn't messed up by sublime text. (Otherwise the line with the tab and each successive line would be indented too far since Sublime text automatically indents after a Curly Brace)

Anyway, all of that is basically to explain how it works. The problem I'm encountering is that I have some snippets I want to use where I have some relatively complex nested ifs. I have always done complex nested ifs like so, because it is the quickest for me to make sense of:

Code:
if(
    x > y &&
    (
        z == a ||
        b >= c
    )
){
    that
}


The problem is that the continuation section is started by a ( by itself on a line and closed with a ) by itself on a line. Is there anyway to change what character is delimiting the continuation section? If I tried to use the if above in my usual snippet function, Var would only contain:

Code:
if(
    x > y &&
    (
        z == a ||
        b >= c


So what I'm wanting is to be able to use code similar to this:

Code:
Var =
(
if(
    x > y &&
    (
        z == a ||
        b >= c
    )
){
    that
}
)


That will allow me to store that full block of code into the Variable. This could be achieved by using different delimiters for the continuation section, but I couldn't figure out if that's possible. Anyone know if it is? Or know of a workaround that might be functionally similar? I know I could just change my formatting, but it's hard to break habits and I like the way I do the ifs.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2012, 4:44 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
Code:
Var = ; Use a `backtick` to escape a literal ")" at the beginning of a line in a continuation section
(
if(
    x > y &&
    (
        z == a ||
        b >= c
    `)
`){
    that
}
)

msgbox % var
:?:

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks
PostPosted: February 9th, 2012, 6:07 am 
Offline

Joined: February 8th, 2012, 7:15 pm
Posts: 2
That works, thanks. I tried escaping the opening parenthesis and it didn't fix it, so I assumed you couldn't escape the parenthesis. After your code worked, I did a bit more searching and this is the information I needed:

Opening parenthesis are OK in any location in continuation sections, but if a closing parenthesis begins the non-whitespace content of a line in a continuation section, that closing parenthesis must be escaped.

I still would prefer that I didn't have to edit the code, but I was planning on making a hotkey and gui to add a new snippet that would append it to the file. This just gives me one more reason to do it, because I could programatically escape those ( as needed. Thanks for the post!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Google Feedfetcher, immunity, sjc1000 and 72 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group