Per project file associations

I have some projects where .html files are vanilla HTML, and others (Meteor projects) where .html files are spacebars (essentially mustache) templates. It would be fabulous if I could override file associations on a per-project basis, instead of having to set individual file properties for every new .html file I encounter.

I’ve done quite a bit of searching, even through the codebase on Github, but haven’t found a solution for this. Any suggestions?

I don’t think Komodo has the ability to do this :frowning:

@mitchell Thanks for the quick reply. I was hoping there was something in the API that could allow me to accomplish this with a macro. I figured if it’s possible to override file associations at the file-level, then maybe it could be done for all files in a project. No chance?

Thanks,
David

First some background (forgive me if I’m stating the obvious):

Disclaimer: I am a bit fuzzy on the details below, but I think this is how it works.

When determining which language to “guess” for a particular file, among other heuristics, Komodo has a single lookup table for file extensions mapped to languages. If an extension is recognized, the file’s language is “set”, and that setting becomes a property of that file. If you change the language, you are just changing the language property, not an association (the setting contains no memory of how it came to be – by extension, manual setting, etc.).

Therefore, I think the only way to script “per-project” file associations would be to ask for the current project’s path and use your own lookup table to manually set the language for a file. How exactly to do this (or even if it’s possible), I’m not familiar enough with Komodo to say.

Thanks for the background—fuzzy or no, you know way more than I about Komodo. :smile: That was enough of a possibility to get me rooting around the API this evening. This is what I came up with, in case it helps anyone else:

####Create a macro, triggered on file open: “Identify Spacebars files in Meteor projects”

var project = ko.projects.manager._currentProject;
var koDoc = ko.views.manager.currentView.koDoc;
if(koDoc.baseName.match(/\.html/) && project.name.match(/\.meteor/)) {
  koDoc.language = 'Mustache';
}

Adding a ‘.meteor’ keyword to my project name worked dandy for my purposes, but I had a couple other ideas on how to handle this without a hard-coded lookup table—Curious if anyone more familiar with Komodo’s internals would recommend any in particular:

  • Scan the project directory (ko.projects.manager._currentProject.liveDirectory) for a .meteor directory (which would always be present in these projects)?
  • Set an environment variable in the project settings and look for it? (Not sure how to access this)

Cheers,
David

Nice job! I’m delighted that you were able to get it to work :smile:

Project-specific environment variables are in a project preference called “userEnvironmentStartupOverride” in this format (including newlines):

key1=value1
key2=value2

You can see for yourself by manually adding some env variables to your project preferences, close Komodo, and take a peek at your .komodoproject file.

I’m not exactly sure how to access project preferences via the API, but I’m sure you’ll find it :smile: