smallseo.info

brackets

An open source code editor for the web, written in JavaScript, HTML and CSS.

How to prevent Sublime Text 2 from swallowing closing brackets, quotes and parentheses?

Sublime has this behaviour which is really annoying sometimes when you have to type in constructions with lots of brackets. When you type ( it adds () and puts the cursor in the middle, all fine, if you however will type ) it will silently swallow the closing bracket.

This is really annoying when typing long regexps because the brackets gets unbalanced pretty quick and this is driving me crazy. So you end up with constructions like (([a-z]).

So the question is - is there a way to disable this? If I type a closing bracket I want it to stay, not be swallowed.

I have checked through Sublime configs, googled, but nobody seems to mind this behaviour. Am I using it wrong?

Update

You might want to check out Sublime: Jump out of matching brackets shortcut as well.

Full version that allows you to type through with () but will not swallow the closing symbol if you have entered any text:

  { "keys": ["\""], "command": "insert", "args": {"characters": "\""}, "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 },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[^\"]$", "match_all": true }
      ]
  },
  { "keys": [")"], "command": "insert", "args": {"characters": ")"}, "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 },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[^(]$", "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 },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
      ]
  },
  { "keys": ["'"], "command": "insert", "args": {"characters": "'"}, "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 },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "'$", "match_all": true }
      ]
  },
  { "keys": ["]"],"command": "insert", "args": {"characters": "]"}, "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 },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[$", "match_all": true }
      ]
  },
  { "keys": ["}"], "command": "insert", "args": {"characters": "}"}, "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 },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "{$", "match_all": true }

      ]
  }

Source: (StackOverflow)

Regex pattern to return text from within parenthesis

I am looking for a regex pattern that will return me the contents of the first set of parenthesis in a string.

For example,

text text text text (hello) text (hello2) (hello3) text

will return "hello"

Does anyone know what the pattern looks like for c#?


Source: (StackOverflow)

Is there a way for NetBeans to automatically create brackets in a seperate line? [details inside]

When I create a new class for instance, I get this:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloworld;

/**
 *
 * @author Sergio
 */
public class WordManipulations{        
}

I hate it when brackets are placed this way. Is there a way to make it create things like this:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloworld;

/**
 *
 * @author Sergio
 */
public class WordManipulations 
{

}

Source: (StackOverflow)

Codeigniter - brackets with activerecord?

How to have round brackets symbol in Codeigniter's active record SQL queries? e.g. how to accomplish

SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18'

Source: (StackOverflow)

PHP conditionals, brackets needed?

I was just browsing a forum and someone asked about a PHP file they had found on the web. It has several spots like this in the code:

if ($REMOTE_ADDR == "") $ip = "no ip"; else $ip = getHostByAddr($REMOTE_ADDR);

I have always thought brackets are needed to enclose what you want to do if the condition is true. Is there some other alternative, such as if it is on the same line you don't?

There is also another line like this: if ($action != ""): mail("$adminaddress","Visitor Comment from YOUR SITE",

My instinct is to say this wouldn't work, but I also don't know if it is an outdated PHP file and it used to work?


Source: (StackOverflow)

Autocomplete Method Brackets

Using: Visual Studio Pro 2013

Previous research: [1], [2], [3]

I'm used to working in Java with Eclipse.

My usual flow is: object. CTRL+SPACE + ENTER which autocompletes the method and places the correct curly brackets & method inputs in there:

object.myMethod();
or
object.myMethod(input1,input2);

I'm trying to get the same behaviour with VS in C#. I can get the method, but it doesn't want to include the final brackets for some reason.

I get:

object.myMethod

Is there a way to enable this?


Source: (StackOverflow)

Python: What does the use of [] mean here?

What is the difference in these two statements in python?

var = foo.bar

and

var = [foo.bar]

I think it is making var into a list containing foo.bar but I am unsure. Also if this is the behavior and foo.bar is already a list what do you get in each case?

For example: if foo.bar = [1, 2] would I get this?

var = foo.bar #[1, 2]

and

var = [foo.bar] #[[1,2]] where [1,2] is the first element in a multidimensional list

Source: (StackOverflow)

regular expressions with escaping round brackets

I am trying to write the expresion that will accep fallowing phone numbers format:

508 736 756
505050505
+48 505 505 505
(+48) 505 505 505
++48 505 505 505
(++48) 505 505 505
(23)692 36 99
23 692 36 99

I have wrote the fallowing expresion

^(([+]{0,2}?)?([+]{0,2}?)?([0-9 ]+)?)$

How ever this expresion covers only the format listed below:

508 736 756
505050505
+48 505 505 505
++48 505 505 505
23 692 36 99

I have issue with escaping the round brackets characters ( , ) that is why i cant cover the fallowing formats

(+48) 505 505 505
(++48) 505 505 505
(23)692 36 99

I have tried escaping them with backslash but it wouldn't work for some reason.

...[(]?[+]{0,2}[)]?...

DEMO: https://regex101.com/r/hY5tG4/2


Source: (StackOverflow)

Special uses of this syntax in PHP? (Triple 'Angle Brackets')

Given the following code:

$myString = <<<script
   .
   .
   .
 script;

Thanks to the answers on the original version of this question, I understand <<< to be heredoc syntax, treated as double quotes without the need for escaping quotes.

Taking this a step further, how is this best exploited? Specifically, should this ease the strain of dealing with mixed quote strings containing code syntax?

i,e..

attribute="name-like string" attribute="property: 'value("value")';"

The thought is this may be useful (if implemented the way I am now guessing) especially when dealing with greater complexity and/or looking out for code injection. Again, looking for any scenarios where the heredoc for is particularly useful or exploitable.


Source: (StackOverflow)

What is the difference between square brackets and single quotes for aliasing in SQL Server?

I have seen some people alias column names using single quotes eg:

select orderID 'Order No' from orders

and others use square brackets eg:

select orderID [Order No] from orders

I tend to use square brackets. Is there any preference/difference?


Source: (StackOverflow)

round brackets in xaml syntax

when I'm using ColorAnimation to change Background of control i'm using following syntax:

<ColorAnimation Duration="0:0:0.5" 
 Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" 
 To="Black" />

I'm very happy it works but I couldn't find any information about round braces in xaml syntax reference ...

So could you please explain where does this syntax come from and what does the round brace actually mean?

It would be very helpful. Thanks


Source: (StackOverflow)

Visual studio 2010 + resharper bracket indentation problem

I'm using VS 2010 + resharper, and i'm tired reformatting bracket indentation in code as i want it. As example if i have code like:

operators.Keys
    .ToList()
    .ForEach(k => filters
        .AddRange(CustomHtmlHelpers.GetIdAndValueListByPrefix(queryString, k)
            .Select(t => new QueryFilter()
            {
                Operation = operators[k],
                PropertyName = t.Item1,
                Value = t.Item2
            })))

And if i put ; in the end VS (or resharper) 'fixes' bracket indentation so code becomes like:

operators.Keys
    .ToList()
    .ForEach(k => filters
                        .AddRange(CustomHtmlHelpers.GetIdAndValueListByPrefix(queryString, k)
                                    .Select(t => new QueryFilter()
                                    {
                                        Operation = operators[k],
                                        PropertyName = t.Item1,
                                        Value = t.Item2
                                    })));

Same happens if i use resharper's code cleanup. I probably could turn off automatic code reformatting on ; but i need it in other situations. I tried changing code formating options both in VS and resharper setting but never got indentation as i want it.

How could i configure vs or resharper so that it would not do more than one tab formating? Or maybe there is other plugin i can use (together with r#) specificly for this purpose?

EDIT: for anyone interested in this problem here is same question in r# forum http://devnet.jetbrains.net/thread/304794 anyone who would like to see better nested code indentation from r# are welcome to vote for it here http://youtrack.jetbrains.net/issue/RSRP-88220


Source: (StackOverflow)

consecutive operators and brackets

I'm just trying to learn a bit of Perl and have come across this:

foreach $element (@{$records})
{
    do something;
}

To my newbie eyes, this reads: "for each element in an array named @{$records}, do something" but, since that seems an unlikely name for an array (with "@{$" altogether), I imagine it isn't that simple?

I've also come across "%$" used together. I know % signifies a hash and $ signifies a scalar but don't know what they mean together.

Can anyone shed any light on these?


Source: (StackOverflow)

Regular Expressions (Normal OR Nested Brackets)

So I'm completely new to the overwhelming world of Regex. Basically, I'm using the Gedit API to create a new custom language specification (derived from C#) for syntax-highlighting (for DM from Byond). In escaped characters in DM, you have to use [variable] as an escaping syntax, which is simple enough. However, it could also be nested, such as [array/list[index]] for instance. (It could be nested infinitely.) I've looked through the other questions, and when they ask about nested brackets they only mean exclusively nested, whereas in this case it could be either/or.

Several attempts I've tried:

  • \[.*\] produces the result "Test [Test[Test] Test]Test[Test] Test"
  • \[.*?\] produces the result "Test [Test[Test] Test]Test [Test] Test"
  • \[(?:.*)\] produces the result "Test [Test[Test] Test]Test[Test] Test"
  • \[(?:(?!\[|\]).)*\] produces the result "Test [Test[Test] Test]Test[Test] Test". This is derived from http://stackoverflow.com/a/9580978/2303154 but like mentioned above, that only matches if there are no brackets inside.

Obviously I've no real idea what I'm doing here in more complex matching, but at least I understand more of the basic operations from other sources.


Source: (StackOverflow)

int([x[, base]]). Square brackets in functions in Python documentation? [duplicate]

This question already has an answer here:

What is the meaning of the square brackets inside the round brackets of a function in the Python documentation?

E.g.:

help([object])

or

int([x[, base]])


Source: (StackOverflow)