Skip to content

Commit 6f78e56

Browse files
committed
Initial commit
0 parents  commit 6f78e56

27 files changed

+2031
-0
lines changed

Conscript

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/local/bin/perl
2+
# Copyright (c) 2010 ActiveState Software Inc.
3+
# See the file LICENSE.txt for licensing information.
4+
5+
Import(
6+
'cons',
7+
'platform',
8+
'productType',
9+
'buildFlavour',
10+
'sdkDir',
11+
'idlExportDir',
12+
'build',
13+
'mozBin',
14+
'unsiloedPythonExe',
15+
'mozVersion',
16+
'mozExtensionDir',
17+
'mozIdlIncludePath',
18+
);
19+
20+
$cons->KoExt("koinstall");
21+
22+
# For quick development, comment out the "KoExt" call above and
23+
# use the following. The first time this is run, it will setup the
24+
# appropriate extension link. Then you need to *manually* do
25+
# a local "koext" dev build via:
26+
# python ../../sdk/bin/koext.py build --dev
27+
# You need to re-run "koext build --dev" every time you change or add
28+
# files that are built, e.g.: preprocessed files, idl files. However for
29+
# files that are not built -- e.g. XUL, CSS, JS, Python -- you don't
30+
# need to build at all, just re-start Komodo.
31+
#
32+
#$cons->KoExtSourceDevInstall();

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Adds [.editorconfig](http://editorconfig.org/) support for Komodo IDE and Edit.
2+
3+
Simply drag the XPI on Komodo to install the addon, then restart Komodo.
4+
5+
Your .editorconfig is applied whenever you open a file. It does not pick up changes
6+
to your .editorconfig while a file is opened, you would have to reopen the file
7+
to apply your .editorconfig changes.
8+
9+
Aside from the native .editorconfig properties you can also use any Komodo preference
10+
names. Mind you that this has not been thoroughly tested yet, so take caution.
11+
12+
If you mess up your file Preferences in some way you can reset them by deleting
13+
the [doc-state.xmlc file from your profile folder](https://community.activestate.com/faq/komodo-profile-structure).
14+
Note that Komodo should not be running when you do this.
15+
16+
This feature will be built-in to Komodo as of version 9.2, so please ensure you
17+
uninstall the addon when updating.

chrome.p.manifest

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
manifest components/component.manifest
2+
3+
# #if MODE == "dev"
4+
content editorconfig content/
5+
# #else
6+
content editorconfig jar:editorconfig.jar!/content/
7+
# #endif
8+
9+
overlay chrome://komodo/content/komodo.xul chrome://editorconfig/content/overlay.xul

components/component.manifest

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
component {2cf77db4-c923-4a37-bfea-91764163ff84} koEditorConfig.py
2+
contract @activestate.com/editorconfig/koEditorConfig;1 {2cf77db4-c923-4a37-bfea-91764163ff84}

components/koEditorConfig.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!python
2+
# Copyright (c) 2014-2014 ActiveState Software Inc.
3+
# See the file LICENSE.txt for licensing information.
4+
5+
"""The main PyXPCOM module for .editorconfig"""
6+
7+
from xpcom.components import interfaces as Ci
8+
from xpcom.components import classes as Cc
9+
from editorconfig import get_properties, EditorConfigError
10+
11+
import logging
12+
import json
13+
14+
log = logging.getLogger("editorconfig")
15+
log.setLevel(10)
16+
17+
class koEditorConfig:
18+
19+
_com_interfaces_ = [Ci.koIEditorConfig]
20+
_reg_desc_ = "EditorConfig"
21+
_reg_clsid_ = "{2cf77db4-c923-4a37-bfea-91764163ff84}"
22+
_reg_contractid_ = "@activestate.com/editorconfig/koEditorConfig;1"
23+
24+
def get_properties(self, filename, interpret = True):
25+
try:
26+
options = get_properties(filename)
27+
except exceptions.ParsingError:
28+
log.warning("Error parsing an .editorconfig file")
29+
return ""
30+
except exceptions.PathError:
31+
log.error("Invalid filename specified")
32+
return ""
33+
except exceptions.EditorConfigError:
34+
log.error("An unknown EditorConfig error occurred")
35+
return ""
36+
37+
if interpret:
38+
items = {}
39+
for key, value in options.iteritems():
40+
if value.isdigit():
41+
value = int(value)
42+
elif value == "true" or value == "false":
43+
value = value == "true"
44+
45+
if key == "indent_style":
46+
items["useTabs"] = value == "tab"
47+
elif key == "indent_size":
48+
if value != "tab":
49+
items["indentWidth"] = value
50+
elif key == "tab_width":
51+
items["tabWidth"] = value
52+
elif key == "end_of_line":
53+
items["endOfLine"] = value.upper()
54+
elif key == "charset":
55+
items["encodingDefault"] = value
56+
elif key == "trim_trailing_whitespace":
57+
items["cleanLineEnds"] = value
58+
elif key == "insert_final_newline":
59+
items["ensureFinalEOL"] = value
60+
elif key == "max_line_length":
61+
# not exactly the same, we're just setting the guide line
62+
items["editAutoWrapColumn"] = value
63+
else:
64+
items[key] = value
65+
else:
66+
items = options.items();
67+
68+
return json.dumps(items)

components/koIEditorConfig.idl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* Copyright (c) 2015 ActiveState Software Inc.
2+
See the file LICENSE.txt for licensing information. */
3+
4+
#include "nsISupports.idl"
5+
interface koIAsyncCallback;
6+
7+
[scriptable, uuid(2cf77db4-c923-4a37-bfea-91764163ff84)]
8+
interface koIEditorConfig: nsISupports {
9+
10+
AString get_properties(in AString filepath);
11+
12+
};

content/editorconfig.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
(function() {
2+
3+
var viewChanged = function()
4+
{
5+
var log = require("ko/logging").getLogger("editorconfig");
6+
//log.setLevel(10);
7+
8+
var currentView = ko.views.manager.currentView;
9+
if ( ! currentView || ! currentView.koDoc ||
10+
! currentView.koDoc.file || currentView.editorConfigProcessed)
11+
return;
12+
13+
currentView.editorConfigProcessed = true;
14+
15+
var ec = Cc["@activestate.com/editorconfig/koEditorConfig;1"]
16+
.getService(Ci.koIEditorConfig);
17+
var prefs = currentView.koDoc.prefs;
18+
var filepath = currentView.koDoc.file.path;
19+
20+
try
21+
{
22+
var items = ec.get_properties(filepath);
23+
log.debug("Setting editorconfig: " + items);
24+
items = JSON.parse(items);
25+
}
26+
catch (e)
27+
{
28+
log.exception(e, "Exception while parsing editorconfig");
29+
return;
30+
}
31+
32+
for (let k in items)
33+
{
34+
switch (typeof items[k])
35+
{
36+
case 'string':
37+
prefs.setStringPref(k, items[k]);
38+
break;
39+
case 'boolean':
40+
prefs.setBooleanPref(k, items[k]);
41+
break;
42+
case 'number':
43+
prefs.setLongPref(k, items[k]);
44+
break;
45+
default:
46+
log.warn("Invalid pref type for: " + k);
47+
break;
48+
}
49+
}
50+
}
51+
52+
// Use setTimeout because the view manager is lagging behind
53+
window.addEventListener('current_view_changed',
54+
function() { setTimeout(viewChanged, 10); });
55+
56+
})();

content/overlay.xul

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<!-- Copyright (c) 2000-2015 ActiveState Software Inc. -->
3+
<!-- See the file LICENSE.txt for licensing information. -->
4+
<!DOCTYPE overlay PUBLIC "-//MOZILLA//DTD XUL V1.0//EN" "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
5+
6+
<overlay id="editorConfigOverlay"
7+
xmlns:html="http://www.w3.org/1999/xhtml"
8+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
9+
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
10+
11+
<script src="chrome://editorconfig/content/editorconfig.js" />
12+
13+
</overlay>

install.rdf

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
3+
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
4+
<Description about="urn:mozilla:install-manifest">
5+
<em:id>[email protected]</em:id>
6+
<em:name>.editorconfig Support</em:name>
7+
<em:version>1.0</em:version>
8+
<em:description></em:description>
9+
<em:creator>Nathan Rijksen</em:creator>
10+
<em:homepageURL>http://www.activestate.com/komodo-ide</em:homepageURL>
11+
<em:iconURL>chrome://editorconfig/content/icon.png</em:iconURL>
12+
<em:type>2</em:type> <!-- type=extension -->
13+
14+
<em:targetApplication>
15+
<Description>
16+
<!-- Komodo IDE's uuid -->
17+
<em:id>{36E66FA0-F259-11D9-850E-000D935D3368}</em:id>
18+
<em:minVersion>8.*</em:minVersion> <!-- Workaround for alphanumeric versions - NOT tested on 8.* -->
19+
<em:maxVersion>9.1.*</em:maxVersion>
20+
</Description>
21+
</em:targetApplication>
22+
<em:targetApplication>
23+
<Description>
24+
<!-- Komodo Edit's uuid -->
25+
<em:id>{b1042fb5-9e9c-11db-b107-000d935d3368}</em:id>
26+
<em:minVersion>8.*</em:minVersion> <!-- Workaround for alphanumeric versions - NOT tested on 8.* -->
27+
<em:maxVersion>9.1.*</em:maxVersion>
28+
</Description>
29+
</em:targetApplication>
30+
</Description>
31+
</RDF>

0 commit comments

Comments
 (0)