Sublime Forum

How would I make a menu to edit compiled package files?

#1

Hey there, I’ve been working on a language package for a small modding community. We use the Pawn language and compiler and I am wondering how to allow users of my package to easily set their compiler directory.

The Pawn compiler isn’t generally “installed” so it rarely has a default location or a PATH variable so the “sublime-build” file has to specify the absolute path to the compiler executable.

My package is set up on Package Control for community members to easily install, however I’m a bit stuck at making an easy way for users to alter their compiler path. I have set up a menu that successfully opens “${packages}/Pawn syntax/PAWN-stable.sublime-build” but it seems impossible to edit. I assumed it’s because this file is inside a “.sublime-package” zip file.

Here’s my menu code:


  {
    "caption": "Preferences",
    "mnemonic": "n",
    "id": "preferences",
    "children":
    
      {
        "caption": "Package Settings",
        "mnemonic": "P",
        "id": "package-settings",
        "children":
        
          {
            "caption": "Pawn Compiler Settings",
            "mnemonic": "P",
            "children":
            
              {
                "caption": "Build Settings",
                "command": "open_file",
                "args": { "file": "${packages}/Pawn syntax/PAWN-stable.sublime-build" }
              }
            ]
          }
        ]
      }
    ]
  }
]

And here’s the contents of the sublime-build file if it helps:

{
	"cmd": "pawncc.exe", "$file", "-o$file_path\\\\$file_base_name", "-;+", "-(+", "-d3"],
	"file_regex": "(.*?)(]([0-9]*))]",
	"working_dir": "E:/Games/Projects/SA-MP/pawnostable"
}

(The “working_dir” property is what needs to be changed, the value there is my path which is also the default one on the repository).

I think it would be nice if users could just type in their path into a panel at the bottom (like when you rename a file) without even opening the sublime-build file but I’m not sure how difficult that would be and can imagine it would involve some Python.

Anyway, I’d love a solution to this problem, thanks in advance!

0 Likes

#2

Not sure if bumps are allowed here but I’m still stuck on this problem.

Installing my package is a pain since people can’t use Package Control unless they mess around unzipping the zipped package just to edit the .sublime-build file.

Placing a .sublime-build file in the User packages folder seems to be the best workaround I have right now but I’d love to give users a way to just set their build path from inside a Sublime menu.

0 Likes

#3

common technique is to specify default options and user options as an override (exactly like sublime itself does) this is the code i use in my colorcoder plugin

{ "id": "preferences", "children": { "id": "package-settings", "children": { "id": "Colorcoder-set", "caption": "Colorcoder", "children": { "caption": "Settings – Default", "command": "open_file", "args": {"file": "${packages}/Colorcoder/colorcoder.sublime-settings"} },{ "caption": "Settings – User", "command": "open_file", "args": {"file": "${packages}/User/colorcoder.sublime-settings"} }] }] }] }

i am not sure if one can use a global setting in an build system, so i would make the detour about a plugin which would be triggered by the build system, read the setting and issue the compile command

0 Likes

#4

I’m not much of an expert on the build system, so take this as you will.

First, as a little tip, you can prevent Package Control from zipping your package by including a file called “.no-sublime-package”.

A problem with letting users edit the build script in your package is that as soon as the package updates it will overwrite any changes they make.

AFAIK, the build system does not provide any mechanisms to access configuration variables. Generally it is intended that the user will update the PATH environment variable to include the compiler.

Writing something to work with the build system might not be too difficult. You can see the code in exec.py of the Default package. Perhaps something along the lines of:

window.run_command('exec', {'cmd': 'pawncc.exe', 'path': my_settings.get('pawncc_path')})

However, I would just encourage you to explain to people how to update their PATH instead, since that is the normal route.

0 Likes