Created
March 10, 2018 21:10
-
-
Save sudharsans/1aacd723868315d30dd31543d6081c36 to your computer and use it in GitHub Desktop.
Sublime Plugin to convert frequent edits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sublime Plugin created for stackoverflow answer. | |
# https://stackoverflow.com/questions/49213489/sublime-text-and-python-plugin-how-to-incorporate-a-python-code-with-a-for-loop | |
import sublime, sublime_plugin, re, string #import the required modules | |
class ConvertCommand(sublime_plugin.TextCommand): #create Text Command | |
def run(self, edit): #implement run method | |
for region in self.view.sel(): #get user selection | |
if not region.empty(): #if selection not empty then | |
s = self.view.substr(region) #assign s variable the selected region | |
replace = '\n'.join([' '.join(para.splitlines()) for para in s.split('\n\n')]) | |
self.view.replace(edit, region, replace) #replace content in view | |
class UndoCommand(sublime_plugin.TextCommand): #create Text Command | |
def run(self, edit): #implement run method | |
for region in self.view.sel(): #get user selection | |
if not region.empty(): #if selection not empty then | |
s = self.view.substr(region) #assign s variable the selected region | |
replace = '\n'.split([' '.join(para.splitlines()) for para in s.split('\n\n')]) | |
self.view.replace(edit, region, replace) #replace content in view |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://i.stack.imgur.com/kzvIn.png | |
Just save it in ~/Library/Application Support/Sublime Text 3/Packages/User/convert.py. | |
menu should be saved as context.sublime-menu in the same path | |
Select the text to Convert: | |
Right Click -> Select "Convert" | |
Right Click -> Select "Undo" to Undo convert | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment