Commit 9e3b1f0c authored by Dominik Haumann's avatar Dominik Haumann

Merge branch 'master' into frameworks

parents 43c74da0 ddf061a4
This diff is collapsed.
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
......@@ -16,7 +16,7 @@ Name[de]=Bedingtes Schließen
Name[el]=Κλείσιμο Except/Like
Name[es]=Cerrar excepto/como
Name[fi]=Sulje samanlaiset kuin / muut kuin
Name[fr]=Fermer les exclusions / inclusions
Name[fr]=Fermer les exclusions / inclusions
Name[gl]=Pechar agás/como
Name[hu]=Kivétel/Like bezárása
Name[ia]=Claude Excepte/Simile
......@@ -72,7 +72,7 @@ Comment[es]=Buscar definiciones/declaraciones con CTags
Comment[et]=Definitsiooni/deklaratsiooni otsimine CTagsiga
Comment[eu]=Bilatu CTags duten definizioak/deklarazioak
Comment[fi]=Hyppää määrittelyihin/esittelyihin käyttäen CTagsia
Comment[fr]=Cherche des définitions / déclarations avec CTags
Comment[fr]=Cherche des définitions / déclarations avec CTags
Comment[ga]=Cuardaigh sainmhínithe/fógraí le CTags
Comment[gl]=Busca de definicións/declaracións con CTags
Comment[he]=חפש הגדרות של משתנים בעזרת CTags
......@@ -72,7 +72,7 @@ Comment[es]=Abre el correspondiente archivo .h/[.cpp|.c]
Comment[et]=Vastava .h/[.cpp|.c] faili avamine
Comment[eu]=Dagokion .h/[.cpp|.c] fitxategia irekitzen du
Comment[fi]=Avaa vastaavan .h/[.cpp|.c]-tiedoston
Comment[fr]=Ouvre le fichier .h / [.cpp |.c] correspondant
Comment[fr]=Ouvre le fichier .h / [.cpp |.c] correspondant
Comment[ga]=Oscail an comhad .h/[.cpp|.c] a fhreagraíonn leis an gceann seo
Comment[gl]=Abre o ficheiro .h/[.cpp|.c] correspondente
Comment[he]=פותח את הקובץ המתאים (file.h, file.cpp)
......@@ -809,7 +809,14 @@ void Pate::Engine::unloadModule(int idx)
py.functionCall("_pluginUnloading", Python::PATE_ENGINE, args);
// This will just decrement a reference count for module instance
PyDict_DelItemString(plugins, PQ(plugin.pythonModuleName()));
// Remove the module also from 'sys.modules' dict to really unload it,
// so if reloaded all @init actions will work again!
PyObject* sys_modules = py.itemString("modules", "sys");
Q_ASSERT("Sanity check" && sys_modules);
PyDict_DelItemString(sys_modules, PQ(plugin.pythonModuleName()));
// kate: space-indent on; indent-width 4;
......@@ -7,6 +7,7 @@ Comment[cs]=Moduly Pythonu pro Kate
Comment[de]=Python-Modul für Kate
Comment[es]=Complementos de Python para Kate
Comment[fi]=Katen Python-liitännäinen
Comment[fr]=Module externe Python de Kate
Comment[gl]=Complementos de Python para Kate
Comment[ia]=Plugins de Python pro Kate
Comment[kk]=Kate Python плагині
# Copyright (C) 2012, 2013 Shaheed Haque <>
# Copyright (C) 2013 Alex Turbov <>
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
......@@ -89,7 +90,7 @@ install_pate_plugin(xml_pretty)
install_pate_plugin(js_utils PATTERNS "*.json" "*.js")
install_pate_plugin(js_utils PATTERNS "*.json")
install_pate_plugin(expand PATTERNS "*.expand" "templates/*.tpl")
......@@ -7,6 +7,7 @@ Name[cs]=Nástroje CMake
Name[es]=Utilidades CMake
Name[fr]=Utilitaires CMake
Name[ia]=Utilitates de CMake
Name[kk]=CMake утилиталары
......@@ -27,7 +28,9 @@ Name[zh_TW]=CMake 工具
Comment=Code completer, cache and help browser
Comment[cs]=Doplňování kódu, mezipaměť a prohlížeč nápovědy
Comment[de]=Quelltext-Vervollständigung, Zwischenspeicher und Hilfe-Browser
Comment[es]=Completador de código, caché y navegador de la ayuda
Comment[fi]=Koodintäydennys sekä välimuistin ja ohjeiden selain
Comment[fr]=Compléteur de code, cache et explorateur d'aide
Comment[gl]=Varias accións para axudar na edición de código
Comment[ia]=Completator de codice, cache e navigator de adjuta
Comment[kk]=Код толтырғышы, кэш пен көмек шолғышы
......@@ -71,14 +71,13 @@ public:
from PyKDE4.kdecore import i18nc
from .udf import *
from libkatepate.autocomplete import AbstractCodeCompletionModel
def getHelpOnExpandAtCursorAction():
__expands_completion_model = None
......@@ -100,23 +99,33 @@ class ExpandsCompletionModel(AbstractCodeCompletionModel):
expansions = getExpansionsFor(view.document().mimeType())
for exp, fn_tuple in expansions.items():
# Try to get a function description (very first line)
d = fn_tuple[0].__doc__
if d is not None:
lines = d.splitlines()
d = lines[0].strip().replace('<br/>', '')
if hasattr(fn_tuple[0], '__description__'):
description = fn_tuple[0].__description__.strip()
description = None
if hasattr(fn_tuple[0], '__details__'):
details_text = fn_tuple[0].__details__.strip()
details_text = None
# Get function parameters
fp = inspect.getargspec(fn_tuple[0])
args = fp[0]
if len(args) != 0:
params = ", ".join(args)
params = ', '.join(args)
if fp[1] is not None:
if len(params):
params += ', '
params += '['+fp[1]+']'
params += '[{}]'.format(fp[1])
# Append to result completions list
self.createItemAutoComplete(text=exp, description=d, args='('+params+')')
, description=description
, details = details_text
, args='({})'.format(params)
def reset(self):
......@@ -124,19 +133,42 @@ class ExpandsCompletionModel(AbstractCodeCompletionModel):
def _reset(*args, **kwargs):
global __expands_completion_model
if __expands_completion_model is not None:
def on_load():
global __expands_completion_model
assert(__expands_completion_model is None)
__expands_completion_model = ExpandsCompletionModel(kate.application)
# Set completion model for all already existed views
# (cuz the plugin can be loaded in the middle of editing session)
for doc in kate.documentManager.documents():
for view in doc.views():
cci = view.codeCompletionInterface()
def on_unoad():
global __expands_completion_model
assert(__expands_completion_model is not None)
for doc in kate.documentManager.documents():
for view in doc.views():
cci = view.codeCompletionInterface()
__expands_completion_model = None
def createSignalAutocompleteExpands(view=None, *args, **kwargs):
view = view or kate.activeView()
def createSignalAutocompleteExpands(view):
global __expands_completion_model
if view:
cci = view.codeCompletionInterface()
expands_completation_model = ExpandsCompletionModel(kate.application)
def jinja(template):
......@@ -157,3 +189,17 @@ def postprocess(func):
func.use_template_iface = True
return func
def description(text):
def _decorator(func):
setattr(func, '__description__', text)
return func
return _decorator
def details(text):
def _decorator(func):
setattr(func, '__details__', text)
return func
return _decorator
......@@ -51,6 +51,10 @@ def try_expand_params_seq(arg):
return result
def sum_arg_lengths(args):
return sum(len(s) for s in args)
def looks_like_false(arg):
return arg in _FUSSY_FALSE_VALUES
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kpartgui>
<gui name="expand"
......@@ -10,8 +10,7 @@
<Menu name="pate"><text>&amp;Pate</text>
<Separator />
<Action name="expandAtCursorAction" text="Expand" shortcut="Ctrl+E" group="bottom_tools_operations" />
<Action name="getHelpOnExpandAtCursorAction" text="Expand Usage" shortcut="Shift+Ctrl+E" group="bottom_tools_operations" />
<!-- kate: indent-width 4; -->
......@@ -5,6 +5,7 @@ X-KDE-Library=expand
Name=User defined text expansions
Name[de]=Benutzerdefinierte Texterweiterungen
Name[es]=Expansiones de texto definidas por el usuario
Name[fr]=Expansions de texte définies par l'utilisateur
Name[gl]=Expansións de texto definidas polo usuario
Name[ia]=Expansiones de texto definite per le usator
Name[kk]=Пайдаланушы анықтаған мәтін кеңейтулері
......@@ -25,6 +26,7 @@ Name[zh_TW]=使用預定義的文字擴展
Comment=Execute expansion function and insert output into a document
Comment[de]=Führt die Erweiterungsfunktion aus und fügt die Ausgabe in ein Dokument ein
Comment[es]=Ejecutar la función de expansión e insertar la salida en un documento
Comment[fr]=Exécuter la fonction d'expansion et insérer la sortie dans un document
Comment[gl]=Executa funcións de expansión e insire a saída nun documento
Comment[ia]=Executa function de expansion e inserta exito in un documento
Comment[kk]=Кеңейту функциясын орындап, шығысын құжатқа енгізу
/*%- if namespaces -%*/
/*% for ns in namespaces %*//*% if not loop.first %*/ /*% endif %*/namespace /*< ns >*/ {/*% endfor %*/
/*< close_braces >*//*< padding >*/// namespace
/*%- for ns in namespaces | reverse -%*/
/*%- if loop.first %*/ /*% else %*/, /*% endif %*//*< ns >*/
/*%- endfor -%*/
/*%- else -%*/
namespace {
} // anonymous namespace
/*%- endif -%*/
//# kate: hl C++11
/*%- if template_params -%*/
template </*% for tp in template_params %*//*% if not loop.first %*/, /*% endif %*/typename /*<tp | editable >*//*% endfor %*/>
/*%- else -%*/
template <${tparams:typename T}>
/*%- endif -%*/
//# kate: hl C++11
......@@ -50,7 +50,7 @@ class ParseError(Exception):
def wordAndArgumentAtCursorRanges(document, cursor):
def _wordAndArgumentAtCursorRanges(document, cursor):
line = document.line(cursor.line())
argument_range = None
......@@ -59,7 +59,7 @@ def wordAndArgumentAtCursorRanges(document, cursor):
if cursor.column() < len(line) and line[cursor.column()] == ')':
# special case: cursor just right before a closing brace
argument_end = KTextEditor.Cursor(cursor.line(), cursor.column())
argument_start = matchingParenthesisPosition(document, argument_end, opening=')')
argument_start = _matchingParenthesisPosition(document, argument_end, opening=')')
argument_end.setColumn(argument_end.column() + 1)
argument_range = KTextEditor.Range(argument_start, argument_end)
cursor = argument_start # NOTE Reassign
......@@ -67,7 +67,7 @@ def wordAndArgumentAtCursorRanges(document, cursor):
if line[cursor.column() - 1] == ')':
# one more special case: cursor past end of arguments
argument_end = KTextEditor.Cursor(cursor.line(), cursor.column() - 1)
argument_start = matchingParenthesisPosition(document, argument_end, opening=')')
argument_start = _matchingParenthesisPosition(document, argument_end, opening=')')
argument_end.setColumn(argument_end.column() + 1)
argument_range = KTextEditor.Range(argument_start, argument_end)
cursor = argument_start # NOTE Reassign
......@@ -84,13 +84,13 @@ def wordAndArgumentAtCursorRanges(document, cursor):
# ruddy lack of attribute type access from the KTextEditor
# interfaces.
argument_start = KTextEditor.Cursor(cursor.line(), end)
argument_end = matchingParenthesisPosition(document, argument_start, opening='(')
argument_end = _matchingParenthesisPosition(document, argument_start, opening='(')
argument_range = KTextEditor.Range(argument_start, argument_end)
return word_range, argument_range
# TODO Generalize this and move to `common' package
def matchingParenthesisPosition(document, position, opening='('):
def _matchingParenthesisPosition(document, position, opening='('):
closing = ')' if opening == '(' else '('
delta = 1 if opening == '(' else -1
# take a copy, Cursors are mutable
......@@ -136,7 +136,7 @@ def matchingParenthesisPosition(document, position, opening='('):
return position
def loadExpansionsFromFile(path):
def _loadExpansionsFromFile(path):
kate.kDebug('Loading expansions from {}'.format(path))
name = os.path.basename(path).split('.')[0]
module = imp.load_source(name, path)
......@@ -155,7 +155,7 @@ def loadExpansionsFromFile(path):
return expansions
def mergeExpansions(left, right):
def _mergeExpansions(left, right):
assert(isinstance(left, dict) and isinstance(right, dict))
result = left
for exp_key, exp_tuple in right.items():
......@@ -168,15 +168,15 @@ def mergeExpansions(left, right):
return result
def _getExpansionsFor(mime):
def _collectExpansionsForType(mime):
expansions = {}
# TODO What about other (prohibited in filesystem) symbols?
mime_filename = mime.replace('/', '_') + _EXPANDS_EXT
for directory in kate.applicationDirectories(_EXPANDS_BASE_DIR):
if os.path.exists(os.path.join(directory, mime_filename)):
expansions = mergeExpansions(
expansions = _mergeExpansions(
, loadExpansionsFromFile(os.path.join(directory, mime_filename))
, _loadExpansionsFromFile(os.path.join(directory, mime_filename))
return expansions
......@@ -184,7 +184,7 @@ def _getExpansionsFor(mime):
def getExpansionsFor(mime):
kate.kDebug('Collecting expansions for MIME {}'.format(mime))
result = mergeExpansions(_getExpansionsFor(mime), _getExpansionsFor('all'))
result = _mergeExpansions(_collectExpansionsForType(mime), _collectExpansionsForType('all'))
kate.kDebug('Got {} expansions at the end'.format(len(result)))
return result
......@@ -206,44 +206,41 @@ def _is_int(s):
return isinstance(s,int)
def jinja_environment_configurator(func):
ATTENTION Be aware that functions marked w/ jinja_environment_configurator
decorator should have two leading underscores in their name!
Otherwise, they will be available as ordinal expand functions, which is
definitely UB. This made to keep `expand` code simple...
if not hasattr(jinja_environment_configurator, 'registered_configurators'):
setattr(jinja_environment_configurator, 'registered_configurators', dict())
mimeType = kate.activeDocument().mimeType()
jinja_environment_configurator.registered_configurators[mimeType] = func
kate.kDebug('Set jinja2 environment configurator for {} to {}'.format(mimeType, func.__name__))
return func
def getJinjaEnvironment(baseDir):
def _getJinjaEnvironment(baseDir):
kate.kDebug('Make a templates loader for a base dir: {}'.format(baseDir))
env = jinja2.Environment(loader=jinja2.FileSystemLoader(baseDir))
#env.trim_blocks = True
#env.lstrip_blocks = True
env.block_start_string = '/*%'
env.block_end_string = '%*/'
env.variable_start_string = '/*<'
env.variable_end_string = '>*/'
env.line_statement_prefix = '//%'
env.line_comment_prefix = '//#'
env.filters['editable'] = _makeEditableField
env.tests['boolean'] = _is_bool
env.tests['integer'] = _is_int
return env
if hasattr(jinja_environment_configurator, 'registered_configurators'):
mimeType = kate.activeDocument().mimeType()
configurator = jinja_environment_configurator.registered_configurators[mimeType]
kate.kDebug('Setup jinja2 environment for {} [{}]'.format(mimeType, configurator.__name__))
env = configurator(env)
return env
def getHelpOnExpandAtCursor():
document = kate.activeDocument()
view = document.activeView()
word_range, argument_range = wordAndArgumentAtCursorRanges(document, view.cursorPosition())
except ParseError as e:
kate.ui.popup(i18nc('@title:window', 'Parse error'), e, 'dialog-warning')
word = document.text(word_range)
expansions = getExpansionsFor(document.mimeType())
if word in expansions:
func = expansions[word][0]
cursor_pos = view.cursorPositionCoordinates()
tooltip_text = '\n'.join([
line[8:] if line.startswith(' ' * 8) else line for line in func.__doc__.splitlines()
kate.kDebug('Expand: help on {}: {}'.format(word, tooltip_text))
QToolTip.showText(cursor_pos, tooltip_text)
kate.kDebug('WARNING: undefined expansion `{}`'.format(word))
def expandAtCursor():
......@@ -252,11 +249,13 @@ def expandAtCursor():
The expansions available are based firstly on the mimetype of the
document, for example "text_x-c++src.expand" for "text/x-c++src", and
secondly on "all.expand".
TODO Split this function!
document = kate.activeDocument()
view = document.activeView()
word_range, argument_range = wordAndArgumentAtCursorRanges(document, view.cursorPosition())
word_range, argument_range = _wordAndArgumentAtCursorRanges(document, view.cursorPosition())
except ParseError as e:
kate.ui.popup(i18nc('@title:window', 'Parse error'), e, 'dialog-warning')
......@@ -350,10 +349,9 @@ def expandAtCursor():
assert(base_dir_pos != -1)
basedir = filename[:base_dir_pos + len(_JINJA_TEMPLATES_BASE_DIR)]
filename = filename[base_dir_pos + len(_JINJA_TEMPLATES_BASE_DIR) + 1:]
env = getJinjaEnvironment(basedir)
env = _getJinjaEnvironment(basedir)
kate.kDebug('basedir={}, template_rel={}'.format(basedir, filename))
kate.kDebug('Using jinja template file: {0}'.format(filename))
tpl = env.get_template(filename)
kate.kDebug('data dict={}'.format(replacement))
replacement = tpl.render(replacement)
......@@ -5,6 +5,8 @@ X-KDE-Library=gid
Name=GNU idutils plugin
Name[cs]=Modul GNU idutils
Name[de]=„GNU Idutils“-Modul
Name[es]=Complemento GNU idutils
Name[fr]=Module externe GNU idutils de Kate
Name[gl]=Complemento das GNU idutils
Name[ia]=Plug-in de GNU idutils
Name[kk]=GNU idutils плагині
......@@ -24,6 +26,8 @@ Name[x-test]=xxGNU idutils pluginxx
Name[zh_TW]=GNU idutils 外掛程式
Comment=Browse the tokens in a GNU idutils ID file
Comment[de]=Durchsuchen Sie die Token in einer ID-Datei von „GNU-Idutils“
Comment[es]=Mostrar los identificadores en un archivo GNU idutils de ID
Comment[fr]=Explorer les jetons dans un fichier d'identification GNU idutils
Comment[gl]=Examina os tokens dun ficheiro de identificadores de GNU idutils
Comment[ia]=Explora indicios in un file de GNU idutils ID
Comment[kk]=GNU idutils ID файлдағы өрнектерді шолу
This diff is collapsed.
from PyQt4.QtScript import QScriptEngine, QScriptValue, QScriptValueIterator
import re
from import Mapping, Iterable
except ImportError:
......@@ -51,7 +52,11 @@ class JSModule:
self.engine = engine
with open(filepath) as s:
code = fix_js(
if self.engine.hasUncaughtException():
raise ValueError('file can’t be evaluated', self.engine.uncaughtException().toVariant())
self.obj = self.engine.globalObject().property(objname)
......@@ -65,6 +70,34 @@ class JSModule:
return self.engine.js_call(value)
return value.toVariant()
# some ECMAScript ReservedWords which can be used as object property names.
_keywords = 'continue|break|function|var|delete|if|then|else' # extend as appropriate
_keyword_in_okey = re.compile(r'\b({})\s*:'.format(_keywords))
_keyword_in_attr = re.compile(r'\.({})\b'.format(_keywords))
def fix_js(code):
"""Fixes JS so that Qt’s engine can digest it.
The problem is that unquoted object keys like `{key: 'value'}`,
as well as member accessors like `object.member` may be IdentifierNames,
while Qt’s implementation expects them not to be ReservedWords.
>>> fix_js('var foo = { function: function() {} }')
'{ "function": function() {} }'
>>> fix_js('foo.function()')