Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
:author: Gustavo Rezende <nsigustavo@gmail.com>
:author: Gustavo Rezende <nsigustavo@gmail.com>, Patryk Zawadzki <patrys@pld-linux.org>

Gedit Pyflakes Plugins
Gedit Pyflakes Plugin
======================

Geditpyflakes plugin allow users to run Pyflakes inside Gedit and show found pyflakes's error messages.
gedit-pyflakes-plugin allows users to run Pyflakes inside Gedit and show found pyflakes' error messages.


Get and install
Download and install
===============

You can download geditpyflakes::
You can download gedit-pyflakes-plugin::

$ wget http://github.com/nsigustavo/geditpyflakes/tarball/master
$ tar -xzvf nsigustavo-geditpyflakes*.tar.gz
$ wget -O gedit-pyflakes-plugin.tar.gz http://github.com/patrys/gedit-pyflakes-plugin/tarball/master
$ tar -xzvf gedit-pyflakes-plugin.tar.gz

Put the geditpyflakes.gedit-plugin file and the whole content directory into ~/.gnome2/gedit/plugins::
Put the geditpyflakes.plugin file and the whole content directory into ~/.local/share/gedit/plugins::

$ cd nsigustavo-geditpyflakes*
$ mkdir ~/.gnome2/gedit/plugins
$ cp -rf * ~/.gnome2/gedit/plugins
$ cd patrys-gedit-pyflakes-plugin*
$ mkdir ~/.local/share/gedit/plugins
$ cp -rf * ~/.local/share/gedit/plugins

Install dependences: pynotify and pyflakes
Install dependences: pyflakes

In gedit main menu go to: Edit -> Preferences

In Preferences dialog go to Plugins tab
In Preferences dialog go to Plugins tab.

Find 'Gedit Pyflakes Plugins' in plugin list and check it
Find 'Gedit Pyflakes Plugin' in plugin list and enable it. Done.



Getting involved !
Getting involved!
==================

Gedit Pyflakes Plugins is development may be viewed and followed on github::
Gedit Pyflakes Plugins is in development state. It may be viewed and followed on github::

http://github.com/nsigustavo/geditpyflakes
http://github.com/patrys/gedit-pyflakes-plugin


Retrieve the source code using git::

$ git clone git://github.com/nsigustavo/geditpyflakes.git
$ git clone git@github.com:patrys/gedit-pyflakes-plugin.git

9 changes: 0 additions & 9 deletions geditpyflakes.gedit-plugin

This file was deleted.

8 changes: 8 additions & 0 deletions geditpyflakes.plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Plugin]
Loader=python
Module=geditpyflakes
IAge=3
Name=Gedit Pyflakes Plugin, version 3.0.0
Description=It is focused on identifying common errors quickly without executing Python code.
Authors=Gustavo Rezende <nsigustavo@gmail.com>, Patryk Zawadzki <patrys@pld-linux.org>
Website=https://github.com/patrys/gedit-pyflakes-plugin
121 changes: 109 additions & 12 deletions geditpyflakes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,114 @@
from gedit import Plugin
from geditpyflakes.plugin import PyflakesPlugin
import ast
from gi.repository import GObject, Gedit, Pango
from operator import attrgetter
from pyflakes import checker, messages
import sys

class BlackHole(object):
write = flush = lambda *args, **kwargs: None

def __enter__(self):
self.stderr, sys.stderr = sys.stderr, self

def __exit__(self, *args, **kwargs):
sys.stderr = self.stderr


class PyLocation(object):
def __init__(self, lineno, col=None):
self.lineno = lineno
self.col_offset = col


class PySyntaxError(messages.Message):
message = 'syntax error in line %d: %s'

def __init__(self, filename, lineno, col, message):
super(PySyntaxError, self).__init__(filename, lineno)
self.message_args = (col, message)


class PyflakesPlugin(GObject.Object, Gedit.ViewActivatable):
__gtype_name__ = 'PyflakesPlugin'
view = GObject.property(type=Gedit.View)
document = GObject.property(type=Gedit.Document)

class Geditpyflakes(Plugin):
def __init__(self):
Plugin.__init__(self)
self._instances = {}
GObject.Object.__init__(self)

def do_activate(self):
self.document = self.view.get_buffer()
self.err_tag = self.document.create_tag(None,
underline_set=True,
underline=Pango.Underline.ERROR)
self.warn_tag = self.document.create_tag(None,
underline_set=True,
underline=Pango.Underline.ERROR,
foreground_set=True,
foreground='orange')
self.handler = self.document.connect('highlight-updated', self.recheck)

def do_deactivate(self):
self.document.disconnect(self.handler)

def recheck(self, document, *args):
self.hide_errors(document)
language = document.get_language()
if language and language.get_name() == 'Python':
self.show_errors(document)

def hide_errors(self, document):
bounds = document.get_bounds()
self.document.remove_tag(self.err_tag, *bounds)
self.document.remove_tag(self.warn_tag, *bounds)

def activate(self, window):
self._instances[window] = PyflakesPlugin(window)
def show_errors(self, document):
for problem in self.check(document):
line = problem.lineno - 1
line_start = document.get_iter_at_line(line)
line_end = document.get_iter_at_line(line)
line_end.forward_to_line_end()
keyword = None
tag_start, tag_end = line_start, line_end
if isinstance(problem, (messages.UnusedImport,
messages.RedefinedWhileUnused,
messages.ImportShadowedByLoopVar,
messages.UndefinedName,
messages.UndefinedExport,
messages.UndefinedLocal,
messages.DuplicateArgument,
messages.RedefinedFunction,
messages.LateFutureImport,
messages.UnusedVariable)):
keyword = problem.message_args[0]
elif isinstance(problem, messages.ImportStarUsed):
keyword = '*'
if keyword:
offset = line_start
while offset.in_range(line_start, line_end):
tag_start, tag_end = offset.forward_search(keyword, 0,
line_end)
if not tag_start or not tag_end:
tag_start, tag_end = line_start, line_end
break
if tag_start.starts_word() and tag_end.ends_word():
break
offset.forward_word_end()

def deactivate(self, window):
self._instances[window].deactivate()
del self._instances[window]
tag_type = (self.err_tag if isinstance(problem, PySyntaxError)
else self.warn_tag)
document.apply_tag(tag_type, tag_start, tag_end)

def update_ui(self, window):
self._instances[window].update_ui()
def check(self, document):
filename = document.get_short_name_for_display()
start, end = document.get_bounds()
text = document.get_text(start, end, True)
try:
with BlackHole():
tree = ast.parse(text, filename)
except SyntaxError, e:
return [PySyntaxError(filename, e.lineno, e.offset, e.text)]
else:
w = checker.Checker(tree, filename)
w.messages.sort(key=attrgetter('lineno'))
return w.messages
31 changes: 0 additions & 31 deletions geditpyflakes/geditpyflakes.dt

This file was deleted.

62 changes: 0 additions & 62 deletions geditpyflakes/plugin.py

This file was deleted.

9 changes: 0 additions & 9 deletions geditpyflakes/redirect_out.dt

This file was deleted.