Giter VIP home page Giter VIP logo

sublime-expand-region's Introduction

Build Status

ExpandRegion for Sublime Text

Like "Expand Selection to Scope". But better!

ExpandRegion works a bit like the build in "Expand Selection to Scope", however it does not depend on Scopes (Scopes are used by ST to "understand" code, i.e. for syntax highlighting). Therefore selection expansion can be more granular and customizable.

It works similar to ExpandRegion for Emacs and "Structural Selection" (Control-W) in the JetBrains IDE's (i.e. IntelliJ IDEA).

Prereleases

Pre-releases help us to test new features and improve the stability of releases. You can benefit the newest features and help us testing them. Just open Preferences > Package Settings > Package Control > Settings - User and insert at a reasonable (correct JSON syntax) position:

    "install_prereleases": ["ExpandRegion"],

If you also use pre-releases of other packages just add them comma separated into the list.

Example

JavaScript (should also work for other c'ish languages like Java).

  1. Expand selection to word
  2. Expand selection to quotes (content only)
  3. Expand selection to quotes (with quotes)
  4. Expand selection to square braces
  5. Expand selection to expression
  6. Expand selection to content of braces (all arguments in this case)
  7. Expand selection to line
  8. Expand selection to function body (w/o curly brace)
  9. Expand selection to function body (with curly brace)

and so on...

Python

Behaves similar to JavaScript, but also depends on indentation:

  1. Expand selection to word
  2. Expand selection to parentheses (content only)
  3. Expand selection to parentheses (with parentheses)
  4. Expand selection to function call
  5. Expand selection to line (w/o indent)
  6. Expand selection to indentation
  7. Expand selection to block start before indentation
  8. Expand selection to indentation
  9. Expand selection to block start before indentation
  10. Expand selection to indentation
  11. Expand selection to block start before indentation

and so on...

HTML

  1. Expand selection to word
  2. Expand selection to quotes (content only)
  3. Expand selection to quotes (with quotes)
  4. Expand selection to complete self closing tag
  5. Expand selection to parent node content
  6. Expand selection to complete node
  7. Expand selection to parent node content

and so on...

LaTeX (thx r-stein)

  1. Expand selection to word
  2. Expand selection to command
  3. Expand selection to command arguments
  4. Expand selection to brackets (content only)
  5. Expand selection to brackets (with brackets)
  6. Expand selection to surrounding command
  7. Expand selection to surrounding environment (content only)
  8. Expand selection to surrounding environment (whole)
  9. Expand selection to surrounding environment (content only)
  10. Expand selection to surrounding environment (whole)

and so on...

Installing

With the Package Control plugin: The easiest way to install ExpandRegion is through Package Control, which can be found at this site: http://wbond.net/sublime_packages/package_control

Once you install Package Control, restart ST and bring up the Command Palette (Command+Shift+P on OS X, Control+Shift+P on Linux/Windows). Select "Package Control: Install Package", wait while Package Control fetches the latest package list, then select ExpandRegion when the list appears. The advantage of using this method is that Package Control will automatically keep ExpandRegion up to date with the latest version.

Without Git: Download the latest source from GitHub and copy the ExpandRegion folder to your Sublime Text "Packages" directory.

With Git: Clone the repository in your Sublime Text "Packages" directory:

git clone https://github.com/aronwoost/sublime-expand-region.git ExpandRegion

The "Packages" directory is located at:

  • OS X:

      ~/Library/Application Support/Sublime Text 2/Packages/
    
  • Linux:

      ~/.config/sublime-text-2/Packages/
    
  • Windows:

      %APPDATA%/Sublime Text 2/Packages/
    

Using

  • Set a shortcut. Open "Key Bindings - User" and add to following line:
{ "keys": ["super+shift+space"], "command": "expand_region" },
{
  "keys": ["super+u"],
  "command": "expand_region",
  "args": {"undo": true},
  "context": [{ "key": "expand_region_soft_undo" }]
},

Note: third party plugins can not properly hook into the history. So soft-undo in basically only a undo expand selection. Soft-redo will not work.

Develop

Background

This plugin is inspired by the amazing expand-region for Emacs.

Here a video showing this feature (in Emacs):

Read more:
Extend Selection by Semantic Unit

License

MIT

sublime-expand-region's People

Contributors

aronwoost avatar davidlinse avatar evandrocoan avatar krosti avatar r-stein avatar vladrassokhin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublime-expand-region's Issues

Python support

Hi! Love the plugin, but unfortunately it doesn't seem to support expansion on Python. It's harder to parse for various reasons (hangs head) but it'd be nice to have it anyway... do you think you can add it?

De-expand command

Hello,
I really enjoy this module but as a previous user of this function under Emacs, one thing is still missing in this SublimeText implementation : the possibility to undo one level of expansion.

Example
expand > select word
expand > select enclosing quotes
expand > select enclosing parenthesis
we want to come back to quotes
de-expand > select enclosed quotes :: missing feature here

Antoine

Support for PHP

This plugin is great and is indeed way better than expand to scope, however it'd be nice to use it inside PHP and the HMTL & javascript code inside a PHP file.

another bug.

i found another bug ,b4 the last updates the selection was expanding section by section till it selects everything ,now it will stop @ the double quotes , or @ the end of the tag

test with the below code

<div id="main">
    <h2>Photographs</h2>
    <table class="bordered">
        <tr>
            <th>Image</th>
            <th>Filename</th>
            <th>Caption</th>
            <th>Size</th>
            <th>Type</th>
            <th>Delete</th>
        </tr>
    </table>
    <br />
    <a href="photo-upload.php">Upload New</a>
    <a href="../photo-big.php">show public</a>
</div>

Multiple cursor support

This is a plugin I've been looking for for a loooong time. Thanks a lot!

I am wondering if you could add the multiple cursor support. It shouldn't be that hard. In ExpandRegionCommand class, instead of doing region = self.view.sel()[0], just add a for loop for region in self.view.sel(): and execute the same code.

If this is not clear enough, I am more than happy to do it and submit a pull request.

Thanks again for this plugin!

add preferences to menu

Hey, when you install this from package control, there's no easy way to see the readme or edit the preferences... I'm not sure how it's done, but it'd be great to add these to the Sublime preferences window (AdvancedNewFile, another plugin, does this really well.)

Expand to $ and $$ in Latex

Was there a reason expanding to inline math symbols $ and $$ was left out or can it be added in easily? This I think would be a very useful expansion for the latex plugin.

Stop inside of ruby string interpolation

When I have "some ruby string #{variable}" with my cursor inside the #{...} and expand, it immediately includes the beginning #{ and ending } in the selection.

It would be better for there to be an extra non-inclusive selection (from right after the #{ to right before the }) that only selects the contents of the interpolation.

Why is expand-to-line disabled?

I was trying to figure out why the selection doesn't expand to the full line, and tracked it down to this commit: eab9e3d. Why was that commented out, and would you be open to re-enabling it?

Structural Selection (more of a request, than an Issue)

Hi aron, Just tried out sublime-expand-region, its great, its what sublime expand selection to scope (the default in ST3) should have been. Thanks for package.
I understand that the functionality is based of emacs, I wanted to know if you have tried IntelliJ IDEA Rubymine - Structural Selection, because it is the best implementation of the concept.
http://blog.jetbrains.com/idea/files/2013/05/editor_structural_selection.gif
http://paulhammant.com/2014/02/07/jetbrains-ides-their-best-feature-is-control-w/
http://sublimetext.userecho.com/topic/94850-expand-selection-like-in-intellij-idea/
Structural selection allows you to select expressions based on grammar. Press Ctrl+W to select the word where the caret is currently located. Pressing Ctrl+W successively to extend selection to the next containing node (for example, an expression, a paired tag, an entire conditional block, a method body, a class, a group of variables, arguments, etc.)
sublime-expand-region is the closest in functionality to having structural selection on sublime text. I hope you check out structural selection and keep it in mind whenever you decide to update / work on sublime-expand-region next. thanks again.

Support for expanding inside backticks

Continuing with what @wilkystyle has asked: it would be good too have support for expanding to a text inside backticks "`". Probably will be useful for anybody who deals with and reads often Markdown and copies a lot of code strings from there.

windows sublime2 can not work

hi, i have installed your plugin and add the command in the sublime, but nothing happens.
What else i have to do?
My system is windows 10 plus sublime text 2

thanks~!

Error when working with the files

Traceback (most recent call last):
File "C:\tools\Sublime Text Build 3061 x64\sublime_plugin.py", line 549, in run_
return self.run(edit)
File "ExpandRegion in C:\tools\Sublime Text Build 3061 x64\Data\Installed Packages\ExpandRegion.sublime-package", line 11, in run
File "./ntpath.py", line 301, in splitext
File "./genericpath.py", line 92, in _splitext
AttributeError: 'NoneType' object has no attribute 'rfind'

win 8.1 x64

Expansion not working for generic typing

Hello,

first - thanks for this awesome plugin!

I encountered an issue with things like

map<Int, String> myMap;

When selecting myMap and using ExpandRegion, it only expands to the comma, e.g.
map<Int, String> myMap;

instead of
map<Int, String> myMap;

Is this an issue or working as designed?

Thanks,
Michael

overrides the "close tab" keyboard shortcut

I'm using on the mac and to my surprise this extension seems to override the ⌘w keyboard shortcut which is the default shortcut for closing a tab. I can map it to a key combination I like but it seems to hold onto this mapping and i'm not sure how to block that.

Please help, really like the functionality.

Add support for subwords

It would be nice for expand-region to expand first to select a subword before selecting the whole word.

Golang doesn't do a select line

Hi,

Testing this extension with golang I found an issue:

func Example() {
  a := 123
  b := 456
}

Expanding the region from any of the numbers selects the whole number first (this is expected) but the next time it selects the whole function content, from right after { to right before }.
I expect it to select the line before the function content.

Cyrillic in PHP

Hey! Unfortunately this glorious plugin doesn't select cyrillic inside html tags in .php file. But cyrillic in html works fine! That's pretty stange. Is there any solution to fix this?

Expansion stopping at non-ascii characters

Writing some text in french language, which use characters like "é", "à", "ù", "è" or apostrophe, like in l'expansion, I noticed that the expand-region command stops at them. For example when in the word
élevée, with the cursor placed like this: éle|vée, the expand-region command selects only selects "lev" instead of the whole word. The same happens with a sentence like this one:
"il se rendit compte à l'instant suivant que son voisin l'avait devancé" with the cursor placed like this
"il se rendit compte à l'instant |suivant que son voisin l'avait devancé", expand-region two times in a row selects the folowing region in brackets, stopping at apostrophes ( ' ):
"il se rendit compte à l'[instant suivant que son voisin l]'avait devancé"
I also tried with ü, ï and ë, but in those cases it works fine.

I think the problem could be solved including accented characters (é,à,ù,ç,...) and apostrophes ( ' ) like word characters. Or at least accented characters as apostrophes could also be used around character strings in programming languages, and it would break this good behavior.

I haven't look at the code but I think the author of the code could fix the problem easily.

Cheers!

Antoine

What default shortcut?

Ok, there need to be a default shortcut. I really think that "super+shift+space" is the best.

However, that would override the build in "Expand Selection to Scope". I'm not sure, if this is proper behavior...

Strange selection of ruby hashes

Given the following code:

def test
  a(:test => "hi")
end

starting the Expand Region from the "hi", it expands until selecting > "hi. After this, it selects the hash.
I think after selecting the string should expand the selection to the whole hash without that strange step in between.

Error on loading

On loading the plugin in SublimeText3 Build 3061 I get the following error:

reloading plugin ExpandRegion.test
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "./importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 671, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "test in C:\Program Files\Sublime Text 3\Data\Installed Packages\ExpandRegion.sublime-package", line 2, in <module>
ImportError: No module named 'expand_region_handler'

Bug: tag selection not working properly in HTML (.php)

When trying to select the tag with ExpandRegion, the selection doesn't select the tag but instead selects either the next attribute, the next bracket or the end tag.

Test case 1:
Region expansion (selection shown as [], cursor in test):

  1. <div class="[test]"></div>
  2. <div class=["test"]></div>
  3. <div class=["test"></div>]
  4. End

Test case 2:

  1. <div class="[test]" id="test"></div>
  2. ...
  3. <div class=["test" id]="test"></div>
  4. End

Test case 3:

<div class="[test]">
</div>
2)
<div class=["test"]>
</div>
3)
<div class=["test">]
</div>
4) End

PS: Shouldn't it select the entire attribute first, before selecting the tag?
Like: <div [class="test]"></div>

EDIT: It just isn't working in *.php files, that's why. Don't know if this can be aided?

expand_region in json bug.

i found another bug

  • Ex
    <string>punctuation.de|finition.comment</string>

when using expand_region the plugin select the word the caret is positioned at "definition" ,
now if i used the cmnd again it will select the whole line where it should select the other words within the tag "punctuation.definition.comment" and on a 3rd run it should select the whole line ,exactly as it does in the html.

Expand before quotes

 ': '

Expansion from {start: 0, end: 0} and {start: 1, end: 1} leads to very strange result.

Support for pairs of backticks/angle brackets

When editing HTML, I'd like to be able to expand within the angle brackets, for example, if the cursor is where the "href=" text is...

<a href="http://google.com">Go to Google.com</a>

... I'd like to be able to expand up to the quotes, including the quotes, and finally, the full text inside the angle brackets: a href="http://google.com"

Also, when writing markdown or bash scripts, it would be very helpful to have expansion within a pair of backticks:

docker rm `docker ps -aq`

Maybe there could even be a way for the user to specify their own custom matching pairs of symbols/characters?

Remove the threshold.

is there away to extend the selection threshold or even remove the limit all together ?

i use expand_region cmnd to visualize where is the start & end of the scope ,the problem is that sometimes i have a brackets with like 300 lines ,if i moved the cursor too deep like to line #200 nothing gets selected because the plugin cant see pass the line # 195.

Support ruby blocks

Support Ruby blocks, such as if, while, begin, do and the corresponding end.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.