Home Download Buy Blog Forum Support

Request: Don't prompt to save empty "untitled" tabs.

Request: Don't prompt to save empty "untitled" tabs.

Postby GreyWyvern on Wed Feb 24, 2010 8:02 pm

Sometimes I use ST as a go-between for modifying some text from one application in order to paste it into another application. When I do this, I create a New "untitled" and empty document, use ST's handy tools to modify the text, then Ctrl+A and Ctrl+X to clear the buffer and put everything into the clipboard.

After I do this and try to close the "untitled*" tab, ST thinks it has been modified and asks me if I would like to save it. Of course it has been modified, but it is also empty. What use could I possibly have to name it and keep it if I had not already done so?

My previous editor, Metapad, would only prompt to save the untitled file if it contained text, otherwise it would just close the window. I don't know how other editors behave regarding this, but I grew very fond of this behaviour :)
GreyWyvern
 
Posts: 106
Joined: Fri Oct 23, 2009 7:08 pm
Location: Canadia

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby EJ12N on Thu Feb 25, 2010 3:46 pm

Interesting. makes sense :)
Personally I still like it to ask me because I use a lot of untitled windows for notes and stuff like that and if I accidentally close them I would be very sad lol
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby gpfsmurf on Thu Feb 25, 2010 7:20 pm

But he's talking about empty untitled tabs, so you wouldn't lose your work anyways. I think it makes sense
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby PinnacleWebDesign on Fri Feb 26, 2010 8:43 am

It's a +1 from me for this functionality for empty documents

Notepad++ also exhibits this behaviour

Cheers,
Mick
PinnacleWebDesign
 
Posts: 33
Joined: Sun Aug 09, 2009 6:43 pm
Location: UK

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby EJ12N on Thu Mar 04, 2010 4:23 pm

gpfsmurf wrote:But he's talking about empty untitled tabs, so you wouldn't lose your work anyways. I think it makes sense

true, I *think* it could be done with a plugin hooking in presave and check if the view is empty then just close the damn thing...

EDIT: I mean onClose oops :P; anyways tinkering around with onClose was total fail because the prompt to save is triggered before onClose hook gets called. So to do what you want I guess we would have to get a lil clever and just hook onModified and check if the view is empty then make it a scratch (which won't ever ask to save) if it's not empty then just do normal prompt before closing. So if your view has any non-whitespace character it will ask to save else close that damn thing.



Code: Select all
import sublime, sublimeplugin
class noEmptyTabs(sublimeplugin.Plugin):
   def onModified(self, view):
#we only check empty tabs...
      if(view.fileName() == None):
         view_has_content = view.findAll('\S')
         if(len(view_has_content) <= 0):
            view.setScratch(True)
         else:
            view.setScratch(False)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby GreyWyvern on Thu Mar 04, 2010 7:07 pm

Thanks very much! Works great so far :) Will let you know if I run into any troubles.
GreyWyvern
 
Posts: 106
Joined: Fri Oct 23, 2009 7:08 pm
Location: Canadia

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby gpfsmurf on Thu Mar 04, 2010 8:23 pm

The problem is that if you have a genuine scratch buffer, the plugin will remove its scratch flag.

I think using view.name() instead of view.fileName() will fix this, as long as scratch buffers are named.
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby GreyWyvern on Fri Mar 05, 2010 7:18 pm

Here's another request related to this...

If I don't have any tabs open in Sublime, and I have text in the clipboard, if I hit CTRL+V, a new untitled tab should open, and the contents of the clipboard should be pasted into it.

I tried seeing if I could make this into a keybinding, but there doesn't seem to be a context for "noViewsOpen" nor the ability to string two commands (new + paste) into one binding. I guess a plugin could help here? Sorry for being such a bother, but my specialties are Javascript and PHP, not Python. :oops:

As an aside... It would be good if there were a lot more key contexts available to use (such as noViewsOpen), as well as allowing multiple commands in a single keybinding, perhaps separated with a pipe (|). Opera, for instance, has two types of separators for custom keyboard shortcuts, ampersand (&) and pipe (|). Commands separated with ampersand are sent immediately one after the other, while the pipe separator indicates that the program should wait until all actions associated with the first command are done, then execute the second command. It is a useful system, I think :)
GreyWyvern
 
Posts: 106
Joined: Fri Oct 23, 2009 7:08 pm
Location: Canadia

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby EJ12N on Fri Mar 05, 2010 11:47 pm

gpfsmurf wrote:The problem is that if you have a genuine scratch buffer, the plugin will remove its scratch flag.

I think using view.name() instead of view.fileName() will fix this, as long as scratch buffers are named.


True good find :D didn't think of that. I personally barely use scratch buffers and if I do I would name them too.

If I don't have any tabs open in Sublime, and I have text in the clipboard, if I hit CTRL+V, a new untitled tab should open, and the contents of the clipboard should be pasted into it.


Code: Select all
class newPaste(sublimeplugin.WindowCommand):
   def run(self, window, args):
      if(len(window.views()) == 0 and sublime.getClipboard() != ''):
         window.newFile()
         view = window.activeView()
         view.insert(view.size(), sublime.getClipboard())
      else:
         window.runCommand('paste')


bind this to ctrl+v it wont interfere with normal paste functionality.

BTW, You can do your own "contexts" with view.options().set() but if you have no views open at all the whole context="option" in keymap files is useless since from what it seems it only works when there's actually view(s) open.
Also only way to run multiple commands with one command is to do a custom command (plugin) and in your code to runCommand("blah"); or call in a function which does that. In your case, runCommand('paste') but we also have sublime.getClipboard() which is more efficient *IMO*
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Request: Don't prompt to save empty "untitled" tabs.

Postby gpfsmurf on Mon Mar 08, 2010 7:33 am

EJ12N wrote:Also only way to run multiple commands with one command is to do a custom command (plugin)

You can also use the "sequence" command, or create a macro
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 6 guests

cron