Home Download Buy Blog Forum Support

Temporary file generator

Temporary file generator

Postby S0und on Fri Mar 23, 2012 6:58 pm

To be honest and straight, i'm looking for someone who can help me to finish my plugin.

So what i planed to do, is:

1. create a new file with a random name
2. send some text into the new file
3. if i close the file (on_close(view) ?) delete the file from the drive


I managed to do 1) and 3). Anyone can help me out with 2) ?

Code: Select all
import sublime, sublime_plugin, random, os, re

class TempfileCommand(sublime_plugin.WindowCommand):
   def run(self):
      rand = random.randrange(1,1000000)
      path = "N:/ahk work/" + str(rand) + ".ahk"
      v = self.window.open_file(path)

class TempfileEvent(sublime_plugin.EventListener):
   def on_close(self, view):
      fullpath = view.file_name()
      match = re.match('.+\\d+.ahk$', fullpath)
      if match:
Last edited by S0und on Mon Mar 26, 2012 5:58 pm, edited 3 times in total.
Posts: 68
Joined: Wed Oct 28, 2009 4:12 pm

Re: Temporary file generator

Postby weslly on Fri Mar 23, 2012 7:04 pm

Maybe you'll want to use the tempfile module from python's standart library:

Posts: 231
Joined: Sun Aug 28, 2011 3:57 am
Location: Brazil

Re: Temporary file generator

Postby fatboy on Sat Mar 24, 2012 3:07 am

It sounds like you want a temporary view where you can stick some text and not be asked about saving it on closing. Is that right?
If so then maybe you'd be better off with a scratch view, like the find results.
Posts: 12
Joined: Mon Jan 16, 2012 11:41 pm

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests