Skip to content

Instantly share code, notes, and snippets.

@rexzj266
Forked from finscn/NewFile.py
Created October 29, 2015 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexzj266/4afa1b70dc9215db8112 to your computer and use it in GitHub Desktop.
Save rexzj266/4afa1b70dc9215db8112 to your computer and use it in GitHub Desktop.
A plugin of SublimeText 3 : Let the FOLDER of a new untitled file be as same as the folder of current activated file.
# NewFileAtCurrentFolder
import sublime_plugin
import os.path
class NewFileListener(sublime_plugin.EventListener):
def on_new_async(self, view):
if not view.window().active_view():
print("NF: no view")
return
newView = view.window().active_view()
index = view.window().views().index(newView)
lastView = view.window().views()[index - 1]
if not lastView:
print("NF: no lastView")
return
fileName = lastView.file_name()
if not fileName:
print("NF: no fileName")
return
basePath = os.path.dirname(fileName)
if not basePath:
print("NF: no basePath")
return
print("NF: "+basePath)
newView.settings().set('default_dir', basePath)
@rexzj266
Copy link
Author

How to use this plugin

  1. Create a folder with name "NewFileAtCurrentFolder" in the Packages folder
  2. Put this plugin NewFile.py file into this folder.
  3. OK to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment