NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Entering single quote


Joined: 26 May 2009
Posts: 10
Location: Poland
Reply with quote
I've got following line:
Code:
 
$output .= $buttons;

Put the cursor before $buttons
Press: "

It's typing double quote, why?:
Code:

$output .= ""$buttons;

I'm trying to delete one by pressing Backspace, it deleting both of them.

Any way to put single quote before this variable?
It's a bug or feature?

It should put double-quote if there is some string after that (especially variable), eventually apart when there is a dot.
View user's profileFind all posts by kenorbSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
Put the cursor before $buttons
Press: "

It's typing double quote, why?


This feature is known as auto-balancing the quotes.

Quote:
Any way to put single quote before this variable?


Yep, turn off auto-quotes.

Quote:
It should put double-quote if there is some string after that (especially variable), eventually apart when there is a dot.


I'm not sure why it should. Could you please explain your idea in more details?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 06 Jun 2007
Posts: 289
Location: Vancouver, Canada
Reply with quote
Kenorb, by wanting to put a single quote character before the variable, I assume that the variable will eventually be enclosed by quotes. If so, you may like the following feature of PhpED: Select the variable first (using either the mouse or keyboard), and then enter the quote. Doing so will enclose the variable in quotes.


Last edited by anno on Tue May 26, 2009 5:34 pm; edited 1 time in total

_________________
Smile
View user's profileFind all posts by annoSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
Kenorb, by wanting to put a single quote character before the variable


Hi Anno, it's clear. What I wanted to understand is logic behind auto-balancing for quotes he would like to get from the editor. One-quote before the variable is probably just one case. I'd like to see all the others. He started talking about dot and didn't finish, yet.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 26 May 2009
Posts: 10
Location: Poland
Reply with quote
hmm, it's weird, because I've activated now 'Auto-close quotes', and behaviour is different than I had before.
Pasted this code:
Code:
$output .= $buttons;

Pressed double quote, and it's like 'Auto-close quotes' option is not activated:
Code:

$output .= "$buttons;

But now I'm pressing End (to go to the end of line) and Arrow Left to go before semicolon and add ending ending double-quote
Now double-quote show up twice:)
Code:

$output .= "$buttons"";

As standard normally I'm switching off this option, but I want to go forward and understand how is working this feature.

This feature that anno posted is very nice: "Select the variable first (using either the mouse or keyboard), and then enter the quote"
But it doesn't work properly when double clicking on arrays $foo['foo'], objects ($foo->foo), referenced variables (&), etc.
So for me it will be useless, because mostly I'm using double clicks to select some phrases.

Expected behaviour:
- if you have already started quote and you have no any separator before the cursor (like dot, comma, etc.), probably user want to finish what he started, it should not add additional double-quote (especially when it's started already, even in previous lines before semicolon)
- if you have any of separator (. or + or ,), then probably user want to start another quoted phrase
View user's profileFind all posts by kenorbSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
You're right, auto-closing is not very handy when used for quoting existing code. In this case, you need to follow Anno's suggestion. Select code first, then enter quote.
Otherwise, with a new code you're typing, try to use this simple techniquie:
Enter 1 quote, you'll see it complemented with pair and cursor placed in-between, so you can type your code between the quotes. After you have it done, press Right Arrow to leave quoted area. If you typed a quote by mistake, just press Backspace and both (the quote you entered and its pair) will be deleted at once.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 27 Feb 2004
Posts: 33
Location: Netherlands / France
Reply with quote
Actually, auto-balancing should do what the word says: auto balance.

However, as Dmitri has pointed out, its not very handy when changing existing code, unless of course you get the hang of it.

So what IS the hang of it?

I think the basic rule to follow is this:

Whenever a quote is entered auto balancing will provide a second one if this will not break PHP code.

Now there are of course complications to this simple rule, because as one types new code, in general the lines are only syntactically correct upon entering the closing semicolon, and as such auto balancing would never see any reason to add the closing quote.

So we need to reformulate our previous rule, which leads to this set:
- Auto balancing quotes will not break previously correct PHP code
- Auto balancing quotes will always balance if the initial line was not valid PHP code.

OK, we're almost there.
Now there are a couple of situations in which auto balancing is not required or even appreciated. Dmitri usually refers to the "Pet's name" example. This issue can be understood as a second order problem, which could be dealt with by defining auto balancing be switched off in strings.

However, this last rule does NOT apply to PHP-blocks within strings, i.e. array variables in double quoted strings, like "My name is {$_SESSION['Name']}";

Currently, PhpEd follows these rules quite well, the only problem is on multi-dimensional arrays, as a modified version of the last example will demonstrate:

"My name is {$_SESSION['User']['Name]}";

The second index will currenlty NOT be auto balanced, which I consider a bug.
View user's profileFind all posts by dinoSend private messageVisit poster's website


Joined: 09 Jul 2009
Posts: 13
Reply with quote
It also auto balances quotes inside of comments, which I find decidedly annoying most of the time.

I often don't put quoted strings in comments, and usually I just need one ' as follows:
Code:
// This is my comment's text here


Auto balancing puts a complimenting ' in the string and then we have to delete it after the text is done. As follows:
Code:
// This is my comment's text here'


I think the auto balancing for the quotes, parenthesis and curly braces should just happen inside code blocks and variable expansions in strings. If I went into it more, I could probably give more places where it could be used, but that's all that comes to mind right now.
View user's profileFind all posts by killermonkSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Quote:
If I went into it more, I could probably give more places where it could be used

yes please, conduct a simple investigation where this could be useful and let us know.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Entering single quote
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic