Coder Social home page Coder Social logo

sublime_new_from_selection's People

Contributors

idosela avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dkarter

sublime_new_from_selection's Issues

Add file name from clipboard

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."

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.