+8

api to access a project's .sublime-project and .sublime-workspace files

popavo vor 12 Jahren aktualisiert von Jeremy White vor 11 Jahren 3
There's currently no way for a plugin to easily access a project's .sublime-project and .sublime-workspace files.

I'd like to see something like project_file() and project_workspace() added to the sublime.Window class
I'm trying to access settings in the .sublime-project file, so far I have to walk down the directory tree searching for ".*\.sublime-project" then load that file as json and manually read the settings. There must be an easier way...

This is a must have, bc .sublime-project can be stored in anywhere on the file system (outside of project folder list)

+4

You currently have to use the following steps to implement this:

  1. Get the current packages directory using sublime.packages_path()
  2. Format this to get current session settings as: "{0}{1}..{1}Settings{1}Auto Save Session.sublime_session".format(packages_path, os.sep)
  3. Read in the json using json.loads(open(mysessionpath).read(),strict=False)
  4. Create a hash for each window in mysessionjson["windows"], where the mapping is window["window_id"] => window["workspace_name"]
  5. Call window.id() to get your current window's id
  6. Use the workspace_name entry that matches your current window
I am planning on implementing a package that provides access to this via a View setting... at least, that sounds like a good idea.
Does anyone mind if I have it be view.settings().get("workspace_name") which returns a full path to the workspace? I guess I'd also need to hookup something to watch for changes to the current window's settings... because windows would start out without a actual workspace at first.