Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update to work with Python 3/Sublime Text 3 #6

Merged
merged 1 commit into from

3 participants

@JohnArcher

Updates the file for Python 3, so it runs with Sublime Text 3.

Not sure whether there is a better way than explicitly converting all_before and all_after to lists ...!? But that works.

@JohnArcher JohnArcher Update for Python 3 syntax
Updates the file for Python 3, so it runs with Sublime Text 3.

Not sure whether there is a better way than explicitly converting all_before and all_after to lists ...!? But that works.
7503757
@mattfordham

This worked great for me. Thanks!

@JohnArcher

Great to read! Your welcome!

@kek kek merged commit b555c07 into kek:master
@kek
Owner
kek commented

Thanks! I had tried to do a conversion of the code to be Python 3-compatible, but not commited it yet. But your way is better. The way I did it was to replace map and filter with loops and indexes because I didn't really understand how they changed those functions. Seems that in Python 3 map/filter return iterators where in Python 2 they just returned lists?

I also commited a small change that seems to make the same code work with Sublime Text 2.

@JohnArcher

Thanks, @kek ! Well, yeah, they return iterators. But to be honest, I am no Python dev, I simply googled for the error message that was shown in Sublime console, and did the fix. :-)

Glad that you (hopefully) found a way to support v2 und v3 at the same time. Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 22, 2013
  1. @JohnArcher

    Update for Python 3 syntax

    JohnArcher authored
    Updates the file for Python 3, so it runs with Sublime Text 3.
    
    Not sure whether there is a better way than explicitly converting all_before and all_after to lists ...!? But that works.
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 2 deletions.
  1. +5 −2 ExpandSelectionToQuotes.py
View
7 ExpandSelectionToQuotes.py
@@ -15,8 +15,8 @@
class ExpandSelectionToQuotesCommand(sublime_plugin.TextCommand):
def run(self, edit):
- d_quotes = map(lambda x: x.begin(), self.view.find_all('"'))
- s_quotes = map(lambda x: x.begin(), self.view.find_all("'"))
+ [*d_quotes] = map(lambda x: x.begin(), self.view.find_all('"'))
+ [*s_quotes] = map(lambda x: x.begin(), self.view.find_all("'"))
for sel in self.view.sel():
def search_for_quotes(q_type, quotes):
@@ -25,6 +25,9 @@ def search_for_quotes(q_type, quotes):
if len(quotes) - self.view.substr(sel).count('"') >= 2:
all_before = filter(lambda x: x < sel.begin(), quotes)
all_after = filter(lambda x: x >= sel.end(), quotes)
+
+ all_before = list(all_before)
+ all_after = list(all_after)
if all_before: before = all_before[-1]
if all_after: after = all_after[0]
Something went wrong with that request. Please try again.