Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file name from clipboard #1

Open
certainlyakey opened this issue Feb 9, 2014 · 0 comments
Open

Add file name from clipboard #1

certainlyakey opened this issue Feb 9, 2014 · 0 comments

Comments

@certainlyakey
Copy link

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."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant