Commit d46b9eac authored by Johannes Schmid's avatar Johannes Schmid

language-support-python: Initial import

parent e509112a
......@@ -867,9 +867,6 @@ plugins/project-wizard/templates/sdl/Makefile
plugins/project-wizard/templates/sdl/src/Makefile
plugins/project-wizard/templates/sdl/po/Makefile
plugins/project-wizard/templates/licenses/Makefile
plugins/project-wizard/templates/gnome-applet/Makefile
plugins/project-wizard/templates/gnome-applet/src/Makefile
plugins/project-wizard/templates/gnome-applet/po/Makefile
plugins/project-wizard/templates/library/Makefile
plugins/project-wizard/templates/library/src/Makefile
plugins/project-wizard/templates/library/po/Makefile
......@@ -882,6 +879,7 @@ plugins/run-program/Makefile
plugins/starter/Makefile
plugins/language-support-js/Makefile
plugins/language-support-vala/Makefile
plugins/language-support-python/Makefile
anjuta.desktop.in
manuals/Makefile
manuals/reference/Makefile
......
......@@ -36,6 +36,7 @@ SUBDIRS = . \
starter \
js-debugger \
language-support-js \
language-support-vala
language-support-vala \
language-support-python
-include $(top_srcdir)/git.mk
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# Plugin UI files
python_plugin_uidir = $(anjuta_ui_dir)
python_plugin_ui_DATA = python-plugin.xml
# Plugin Glade file
python_plugin_gladedir = $(anjuta_glade_dir)
python_plugin_glade_DATA = python-plugin-properties.ui
# Plugin Icon file
python_plugin_pixmapsdir = $(anjuta_image_dir)
python_plugin_pixmaps_DATA = python_plugin.png
# Plugin Python Scripts
scriptsdir = $(anjuta_plugin_dir)
scripts_SCRIPTS = anjuta-python-autocomplete.py
# Plugin description file
plugin_in_files = python-plugin.plugin.in
%.plugin: %.plugin.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
python_plugin_plugindir = $(anjuta_plugin_dir)
python_plugin_plugin_DATA = $(plugin_in_files:.plugin.in=.plugin)
AM_CPPFLAGS = \
$(LIBXML_CFLAGS) \
$(LIBANJUTA_CFLAGS) \
-DSCRIPTS_DIR=\"$(scriptsdir)\"
# Where to install the plugin
plugindir = $(anjuta_plugin_dir)
# The plugin
plugin_LTLIBRARIES = libpython_plugin.la
# Plugin sources
libpython_plugin_la_SOURCES = plugin.c plugin.h python-assist.c python-assist.h python-utils.c python-utils.h
# Plugin dependencies
libpython_plugin_la_LIBADD = \
$(LIBANJUTA_LIBS)
EXTRA_DIST = \
$(plugin_in_files) \
$(python_plugin_plugin_DATA) \
$(python_plugin_ui_DATA) \
$(python_plugin_glade_DATA) \
$(python_plugin_pixmaps_DATA)
import getopt
import sys
from rope.base.project import Project
from rope.contrib import codeassist
from rope.contrib import autoimport
import os
def pathsplit(p, rest=[]):
(h,t) = os.path.split(p)
if len(h) < 1: return [t]+rest
if len(t) < 1: return [h]+rest
return pathsplit(h,[t]+rest)
def commonpath(l1, l2, common=[]):
if len(l1) < 1: return (common, l1, l2)
if len(l2) < 1: return (common, l1, l2)
if l1[0] != l2[0]: return (common, l1, l2)
return commonpath(l1[1:], l2[1:], common+[l1[0]])
def relpath(p1, p2):
(common,l1,l2) = commonpath(pathsplit(p1), pathsplit(p2))
p = []
if len(l1) > 0:
p = [ '../' * len(l1) ]
p = p + l2
return os.path.join( *p )
options, remainder = getopt.getopt(sys.argv[1:], 'o:p:s:r:f:')
for opt, arg in options:
if opt in ('-o', '--option'):
option_arg = arg
elif opt in ('-p', '--project'):
project_arg = arg
elif opt == '-s':
source_code_arg = arg
elif opt == '-r':
res_arg = arg
elif opt == '-f':
offset_arg = arg
option = option_arg;
projectpath = project_arg
if projectpath.startswith("file://"):
projectpath = projectpath.replace("file://", "")
proj = Project(projectpath)
proj.pycore._init_python_files()
input = open(source_code_arg, 'r')
source_code = input.read()
respath = relpath(projectpath, res_arg)
res = proj.get_resource(respath)
position = int(offset_arg)
if option == "autocomplete":
proposals = codeassist.code_assist(proj, source_code, position, resource=res, maxfixes=10)
proposals = codeassist.sorted_proposals(proposals)
for proposal in proposals:
print proposal
elif option == "calltip":
proposals = codeassist.get_doc(proj, source_code, position, resource=res, maxfixes=10)
print proposals
proj.close()
This diff is collapsed.
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* plugin.h
* Copyright (C) Ishan Chattopadhyaya 2009 <ichattopadhyaya@gmail.com>
*
* plugin.h is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* plugin.h is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with plugin.h. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#ifndef _PYTHON_PLUGIN_H_
#define _PYTHON_PLUGIN_H_
#include <libanjuta/anjuta-plugin.h>
#include <libanjuta/interfaces/ianjuta-editor.h>
#include <libanjuta/interfaces/ianjuta-symbol-manager.h>
#include <libanjuta/interfaces/ianjuta-file-manager.h>
#include <libanjuta/interfaces/ianjuta-project-manager.h>
#include <libanjuta/interfaces/ianjuta-file.h>
#include <libanjuta/anjuta-shell.h>
#include "python-assist.h"
extern GType python_plugin_get_type (GTypeModule *module);
#define ANJUTA_TYPE_PLUGIN_PYTHON (python_plugin_get_type (NULL))
#define ANJUTA_PLUGIN_PYTHON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ANJUTA_TYPE_PLUGIN_PYTHON, PythonPlugin))
#define ANJUTA_PLUGIN_PYTHON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), ANJUTA_TYPE_PLUGIN_PYTHON, PythonPluginClass))
#define ANJUTA_IS_PLUGIN_PYTHON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ANJUTA_TYPE_PLUGIN_PYTHON))
#define ANJUTA_IS_PLUGIN_PYTHON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_PLUGIN_PYTHON))
#define ANJUTA_PLUGIN_PYTHON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ANJUTA_TYPE_PLUGIN_PYTHON, PythonPluginClass))
typedef struct _PythonPlugin PythonPlugin;
typedef struct _PythonPluginClass PythonPluginClass;
struct _PythonPlugin{
AnjutaPlugin parent;
GtkWidget *widget;
gint uiid;
GtkActionGroup *action_group;
AnjutaPreferences *prefs;
GObject *current_editor;
gboolean support_installed;
const gchar *current_language;
gchar *project_root_directory;
gchar *current_editor_filename;
gchar *current_fm_filename;
/* Watches */
gint project_root_watch_id;
gint editor_watch_id;
gint fm_watch_id;
/* Adaptive indentation parameters */
gint param_tab_size;
gint param_use_spaces;
gint param_statement_indentation;
gint param_brace_indentation;
gint param_case_indentation;
gint param_label_indentation;
/* Assist */
PythonAssist *assist;
};
struct _PythonPluginClass{
AnjutaPluginClass parent_class;
};
#endif
This diff is collapsed.
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* python-assist.h
* Copyright (C) Ishan Chattopadhyaya 2009 <ichattopadhyaya@gmail.com>
*
* anjuta is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* anjuta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with anjuta. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#ifndef _PYTHON_ASSIST_H_
#define _PYTHON_ASSIST_H_
#include <glib-object.h>
#include <libanjuta/anjuta-preferences.h>
#include <libanjuta/interfaces/ianjuta-editor-assist.h>
#include <libanjuta/interfaces/ianjuta-symbol-manager.h>
#include <libanjuta/interfaces/ianjuta-project-manager.h>
G_BEGIN_DECLS
#define TYPE_PYTHON_ASSIST (python_assist_get_type ())
#define PYTHON_ASSIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PYTHON_ASSIST, PythonAssist))
#define PYTHON_ASSIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PYTHON_ASSIST, PythonAssistClass))
#define IS_PYTHON_ASSIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PYTHON_ASSIST))
#define IS_PYTHON_ASSIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PYTHON_ASSIST))
#define PYTHON_ASSIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PYTHON_ASSIST, PythonAssistClass))
typedef struct _PythonAssistClass PythonAssistClass;
typedef struct _PythonAssist PythonAssist;
typedef struct _PythonAssistContext PythonAssistContext;
typedef struct _PythonAssistPriv PythonAssistPriv;
struct _PythonAssistContext {
GCompletion* completion;
GList* tips;
gint position;
};
struct _PythonAssistClass
{
GObjectClass parent_class;
};
struct _PythonAssist
{
GObject parent_instance;
PythonAssistPriv *priv;
};
GType python_assist_get_type (void) G_GNUC_CONST;
PythonAssist *python_assist_new (IAnjutaEditorAssist *assist,
IAnjutaSymbolManager *isymbol_manager,
IAnjutaDocumentManager *idocument_manager,
AnjutaPreferences *preferences,
const gchar *editor_filename,
const gchar *project_root);
void python_assist_check (PythonAssist *assist, gboolean autocomplete,
gboolean calltips, gboolean backspace);
gboolean
python_assist_create_word_completion_cache (PythonAssist *assist);
void
python_assist_update_autocomplete (PythonAssist *assist);
G_END_DECLS
#endif /* _PYTHON_ASSIST_H_ */
This diff is collapsed.
[Anjuta Plugin]
Location=python_plugin:PythonPlugin
Icon=python_plugin.png
Name=Python support Plugin
Description=Python support plugin for code completion, auto indentation etc.
<!--*- xml -*-->
<ui>
<menubar name="MenuMain">
<menu name="MenuFile" action="ActionMenuFile">
<placeholder name="PlaceholderFileMenus">
<menuitem name="SampleAction" action="ActionFileSample" />
</placeholder>
</menu>
</menubar>
<menubar name="MenuMain">
<menu name="MenuEdit" action="ActionMenuEdit">
<placeholder name="PlaceholderOperationMenus">
<separator name="separator1"/>
<menuitem name="Autocomplete" action="ActionEditAutocomplete" />
<menuitem name="AutoindentAction" action="ActionEditAutoindent" />
</placeholder>
</menu>
</menubar>
<popup name="PopupDocumentManager">
<separator name="separator1"/>
<menuitem name="Swap" action="ActionFileSwap" />
<separator name="separator2"/>
</popup>
</ui>
/*-*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
cpp-java-utils.c
Copyright (C) 2000 Naba Kumar <naba@gnome.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <libanjuta/interfaces/ianjuta-editor-cell.h>
#include "python-utils.h"
#define LEFT_BRACE(ch) (ch == ')'? '(' : (ch == '}'? '{' : (ch == ']'? '[' : ch)))
gboolean
python_util_jump_to_matching_brace (IAnjutaIterable *iter, gchar brace, gint limit)
{
gchar point_ch = brace;
gint cur_iteration = 0;
gboolean use_limit = (limit > 0);
GString *braces_stack = g_string_new ("");
g_return_val_if_fail (point_ch == ')' || point_ch == ']' ||
point_ch == '}', FALSE);
/* DEBUG_PRINT ("%s", "Matching brace being"); */
/* Push brace */
g_string_prepend_c (braces_stack, point_ch);
while (ianjuta_iterable_previous (iter, NULL))
{
/* Check limit */
cur_iteration++;
if (use_limit && cur_iteration > limit)
break;
/* Skip comments and strings */
IAnjutaEditorAttribute attrib =
ianjuta_editor_cell_get_attribute (IANJUTA_EDITOR_CELL (iter), NULL);
if (attrib == IANJUTA_EDITOR_COMMENT || attrib == IANJUTA_EDITOR_STRING)
continue;
/* DEBUG_PRINT ("%s", "point ch = %c", point_ch); */
point_ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter), 0,
NULL);
if (point_ch == ')' || point_ch == ']' || point_ch == '}')
{
/* Push brace */
g_string_prepend_c (braces_stack, point_ch);
continue;
}
if (point_ch == LEFT_BRACE (braces_stack->str[0]))
{
/* Pop brace */
g_string_erase (braces_stack, 0, 1);
}
/* Bail out if there is no more in stack */
if (braces_stack->str[0] == '\0')
{
/* DEBUG_PRINT ("%s", "Matching brace end -- found"); */
return TRUE;
}
}
/* DEBUG_PRINT ("%s", "Matching brace end -- not found"); */
return FALSE;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
cpp-java-utils.h
Copyright (C) 2000 Naba Kumar <naba@gnome.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _CPP_JAVA_UTILS_H_
#define _CPP_JAVA_UTILS_H_
#include <libanjuta/interfaces/ianjuta-iterable.h>
gboolean python_util_jump_to_matching_brace (IAnjutaIterable *iter,
gchar brace, gint limit);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment