idosela / sublime_new_from_selection Goto Github PK
View Code? Open in Web Editor NEWSublime Text 2 plugin for creating a new file from the current selection.
Sublime Text 2 plugin for creating a new file from the current selection.
I'm no good with Git, but there's a small feature I implemented for myself, that the name of the new file gets added from clipboard, so I'm posting it here. BTW, the plugin is compatible with Sublime Text 3, maybe you should push it to wbond so he could update the repository
"""A Sublime Text package that creates a new file from the current selection."""
import sublime, sublime_plugin
import os.path
from os.path import basename
def cap(s, l):
return s if len(s)<=l else s[0:l]
class NewFromSelection(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
# Generate the output file name from the file name currently in clipboard
fileName, fileExtension = os.path.splitext(view.file_name())
# output_filename.insert(1, " snippet")
output_filename = sublime.get_clipboard()
output_filename = cap(output_filename,250)
output_filename = output_filename + fileExtension
# Concatenate the current selections into a single string.
selected_text = ""
for region in view.sel():
selected_text = selected_text + view.substr(region)
# Create the new file.
output_view = view.window().new_file()
output_view.set_name("".join(output_filename))
output_view.insert(edit, 0, selected_text)
def is_enabled(self):
return not self.view.sel()[0].empty()
def description(self):
return "Creates a new file from the current selection."
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.