Home Download Buy Blog Forum Support

Rename a file you have open

Rename a file you have open

Postby toothrot on Tue Feb 16, 2010 1:08 am

I think it might be useful to be able to rename the file being worked on from inside the editor, maybe adding rename to the tab context menu, or ctrl+click on the tab?

I know you can rename the buffer, and then save the file, and then delete the other file...heh

Any other quick way to rename a file and keep it open?

- toothrot
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Rename a file you have open

Postby EJ12N on Tue Feb 16, 2010 5:35 pm

Not that I know of but very possible with a plugin :)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Rename a file you have open

Postby toothrot on Tue Feb 16, 2010 6:06 pm

EJ12N wrote:Not that I know of but very possible with a plugin :)


You're right, I know there's an openInCurrentTab, however, I will lose my undo history because it's actually a new view...

Also, I can't get it to work.

This is what I'm trying without success in the console:

view.window().runCommand('openInCurrentTab', [r'c:\somefile.txt'])

(if I use the 'open' command instead, it opens the file correctly, in a new tab of course.)

It prompts me for a filename. Can anyone point me in the right direction?

Anyhow, plugin aside, I just thought it would be useful to be able to rename from the tab and keep the undo history.


-toothrot
Last edited by toothrot on Wed Feb 17, 2010 1:00 am, edited 1 time in total.
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Rename a file you have open

Postby EJ12N on Tue Feb 16, 2010 9:16 pm

Ok here's the plugin for all of you, enjoy it :)

Code: Select all
import sublime, sublimeplugin, os, functools

class renameCurrentTab(sublimeplugin.WindowCommand):
   def run(self, window, args):
      view = window.activeView()
      current_name = os.path.basename(view.fileName())
      current_dir = os.path.dirname(view.fileName())
      window.showInputPanel("New Tab Name:", current_name,
            functools.partial(self.doRename, window, current_name, current_dir), None, None)

   def doRename(self, window, current_name, current_dir, new_name):
      old_name_path = os.path.join(current_dir, current_name)
      new_name_path = os.path.join(current_dir, new_name)
      os.rename(old_name_path, new_name_path)
      window.runCommand('close')
      window.openFile(new_name_path.replace('\\','/'))


To add it to your context menu or tab context menu read this:
viewtopic.php?p=4151#p4151

NOTE TO JON: Apparently openInCurrentTab is BUGGY! it does NOT accept any arguments, it will always ask you for a file to open :(
beta 20100201
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Rename a file you have open

Postby toothrot on Tue Feb 16, 2010 10:35 pm

Thanks for that, it's not all that different from what I'm already using..

Hopefully the powers that be might think renaming while preserving undo history is useful enough to spend a little time on...

At the very least a fixed openinCurrentTab will improve things a bit
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Rename a file you have open

Postby EJ12N on Thu Feb 18, 2010 4:00 pm

toothrot wrote:Thanks for that, it's not all that different from what I'm already using..

Hopefully the powers that be might think renaming while preserving undo history is useful enough to spend a little time on...

At the very least a fixed openinCurrentTab will improve things a bit

Agree.
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Rename a file you have open

Postby GreyWyvern on Sat Feb 20, 2010 5:02 pm

EJ12N, would you be able to extend that plugin so that it can also make a backup? One of the things I find myself doing often is wanting to make big changes to a file I have open, but I want to save a backup first, so first I would Save As... with a new filename, then I would close it and reopen the file I was originally editing. This also removes the undo history :|

It would be nice if there was a "Save backup" command that would save the current file but tack on a ".bak" extension, while keeping the current file open.
GreyWyvern
 
Posts: 106
Joined: Fri Oct 23, 2009 7:08 pm
Location: Canadia

Re: Rename a file you have open

Postby gpfsmurf on Sun Feb 21, 2010 9:19 pm

Did you try the "Automatic Backups" plugin?
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: Rename a file you have open

Postby toothrot on Sun Feb 21, 2010 11:11 pm

+1 for "Save As Copy.." if that's what you mean Grey Wyvern
toothrot
 
Posts: 28
Joined: Sun Dec 13, 2009 8:20 am

Re: Rename a file you have open

Postby GreyWyvern on Mon Feb 22, 2010 2:55 pm

gpfsmurf wrote:Did you try the "Automatic Backups" plugin?


I don't want to make automatic backups. Every now and then I am working on a file that is part of a larger framework, like a website or a source repository, so I want to keep editing the file using the same filename; but I also want to save a version of it before I start doing the edits, in case it messes up everything, so I can easily restore it.

toothrot wrote:+1 for "Save As Copy.." if that's what you mean Grey Wyvern


Yup, exactly. It's just Save As... except the current view sticks with the previous file rather than moving to the new one.
GreyWyvern
 
Posts: 106
Joined: Fri Oct 23, 2009 7:08 pm
Location: Canadia

Next

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: Yahoo [Bot] and 10 guests