Re: [gedit-list] visible tabs, spaces, newlines?
- From: Steve Frécinaux <nudrema gmail com>
- To: John Pye <john pye student unsw edu au>
- Cc: gedit-list gnome org
- Subject: Re: [gedit-list] visible tabs, spaces, newlines?
- Date: Tue, 15 Aug 2006 14:02:41 +0200
John Pye wrote:
Hi all
Is there any way to make tabs, spaces, newlines, etc visible in gedit?
In some other editors, you can switch on a view that gives you little
dots for spaces, little arrows for tabs, and backwards arrows for
newlines. This would be or great use when attempting to fixed up badly
indented code, or when dealing with tables of tab delimited data.
Perhaps there's a plugin for this?
There is an embryonic one I'm attaching to this e-mail. I think it's
available somewhere on the net too but I'm too lazy ;-)
Feel free to enhance it and get it back to us.
Cheers,
--
Steve
[Gedit Plugin]
Loader=python
Module=drawspaces
IAge=2
Name=Draw Spaces
Description=Draw Spaces and Tabs
Authors=Paolo Borelli
Copyright=Copyright © 2006 Paolo Borelli
Website=http://www.gedit.org
import gtk
import gedit
def draw_tab_at_iter(view, event, iter):
rect = view.get_iter_location(iter)
x, y = view.buffer_to_window_coords (gtk.TEXT_WINDOW_TEXT, rect.x, rect.y + rect.height - 4)
event.window.draw_line(view.style.text_gc[gtk.STATE_NORMAL], x, y, x + 4, y)
def draw_tabs(view, event, start, end):
i = start.copy();
while i.compare(end) < 0:
if i.get_char() == '\t':
draw_tab_at_iter (view, event, i);
if not i.forward_char():
break
class DrawSpacesViewHelper(object):
pass
class DrawSpacesPlugin(gedit.Plugin):
def __init__(self):
gedit.Plugin.__init__(self)
def activate(self, window):
for view in window.get_views():
self.connect_expose_handler(view)
tab_added_id = window.connect("tab_added",
lambda w, t: self.connect_expose_handler(t.get_view()))
window.set_data("DrawSpacesPluginHandlerId", tab_added_id)
def deactivate(self, window):
tab_added_id = window.get_data("DrawSpacesPluginHandlerId")
window.disconnect(tab_added_id)
window.set_data("DrawSpacesPluginHandlerId", None)
for view in window.get_views():
self.disconnect_expose_handler(view)
def update_ui(self, window):
pass
def connect_expose_handler(self, view):
view.connect('expose-event', self.expose_cb)
def disconnect_expose_handler(self, view):
#todo
pass
def expose_cb(self, view, event):
if event.window == view.get_window(gtk.TEXT_WINDOW_TEXT):
y = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, event.area.x, event.area.y)[1]
s = view.get_line_at_y(y)[0]
e = view.get_line_at_y(y + event.area.height)[0]
draw_tabs(view, event, s, e)
# ex:ts=4:et:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]