Skip to content

Commit

Permalink
Merge pull request #12 from drahnr/master
Browse files Browse the repository at this point in the history
Fixes to make it work with current gnome and cinnamon.
  • Loading branch information
Bernhard Schuster committed Dec 1, 2013
2 parents cbe7bb1 + 170065b commit 2644c1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
**I am no longer maintaining this project. Please contact me if you'd like to take over.**

Gedit Trailsave
---------------

A plugin for Gedit 3 to strip trailing whitespace on save.

This will not work on Gedit 2. You can download the Gedit 2 version here: http://users.tkk.fi/~otsaloma/gedit/
This will not work on Gedit 2.

* Authors:
* Osmo Salomaa wrote original Gedit 2 plugin
* Jon Leighton ported to Gedit 3
* Version: 3.1.2
* Bernhard Schuster maintainance & fixes
* Version: 3.3.0

Installation
------------
Expand All @@ -21,9 +20,16 @@ Installation
4. Activate the plugin in 'Edit > Preferences'
5. Now, whenever a document is saved, trailing whitepace will be removed

Issues
------

Report issues to the [bug tracker on github](https://github.com/jonleighton/gedit-trailsave/issues)


License
-------

Copyright (C) 2013 Bernhard Schuster
Copyright (C) 2006-2011 Osmo Salomaa & Jon Leighton

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.
Expand Down
4 changes: 2 additions & 2 deletions trailsave.plugin
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[Plugin]
Loader=python
Loader=python3
Module=trailsave
IAge=3
Name=Trailsave
Description=Strip trailing whitespace on save
Authors=Osmo Salomaa <[email protected]>, Jon Leighton <[email protected]>
Copyright=Copyright (C) 2006-2011 Osmo Salomaa & Jon Leighton
Website=http://github.com/jonleighton/gedit-trailsave
Version=3.1.2
Version=3.3.0
5 changes: 3 additions & 2 deletions trailsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ def strip_trailing_spaces(self):
"""

text = self.doc.get_text(self.doc.get_start_iter(), self.doc.get_end_iter(), False)
text = unicode(text, 'utf-8')

compiledpattern = re.compile('.*?([ \t]+)$', flags=re.MULTILINE)

start_iter = self.doc.get_start_iter()
end_iter = self.doc.get_start_iter()

line_no = 0 # Last matched line no
last_match_pos = 0 # Last matched position in the string

for match in re.finditer('.*?([ \t]+)$', text, flags=re.MULTILINE):
for match in re.finditer(compiledpattern, text):
# Count the newlines since the last match
line_no += text.count('\n', last_match_pos, match.start())

Expand Down

0 comments on commit 2644c1d

Please sign in to comment.