[gedit-plugins] Added 'all' arguments to all format functions
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins] Added 'all' arguments to all format functions
- Date: Sun, 21 Mar 2010 21:54:12 +0000 (UTC)
commit 06131a7580951e998297039541ca9ab64b8545f9
Author: Jesse van den Kieboom <jesse icecrew nl>
Date: Sun Mar 21 22:53:06 2010 +0100
Added 'all' arguments to all format functions
plugins/commander/modules/format.py | 74 ++++++++++++++++++++---------------
1 files changed, 42 insertions(+), 32 deletions(-)
---
diff --git a/plugins/commander/modules/format.py b/plugins/commander/modules/format.py
index 8a500fa..0f9bf89 100644
--- a/plugins/commander/modules/format.py
+++ b/plugins/commander/modules/format.py
@@ -2,13 +2,15 @@ import commander.commands as commands
__commander_module__ = True
-def remove_trailing_spaces(view, removeall=False):
- """Remove trailing spaces: format.remove-trailing-spaces
+def remove_trailing_spaces(view, all=False):
+ """Remove trailing spaces: format.remove-trailing-spaces [<all>]
Remove trailing spaces in the selection. If there is no selection, trailing
-spaces are removed from the whole document."""
-
- if removeall:
+spaces are removed from the whole document. When the optional argument
+<all> is specified, trailing spaces will be removed from all
+the open documents."""
+
+ if all:
buffers = view.get_toplevel().get_documents()
else:
buffers = [view.get_buffer()]
@@ -58,43 +60,51 @@ spaces are removed from the whole document."""
return commands.result.HIDE
-def _transform(view, how):
- buf = view.get_buffer()
- bounds = buf.get_selection_bounds()
+def _transform(view, how, all):
+ if all:
+ buffers = view.get_toplevel().get_documents()
+ else:
+ buffers = [view.get_buffer()]
- if not bounds:
- start = buf.get_iter_at_mark(buf.get_insert())
- end = start.copy()
+ for buf in buffers:
+ bounds = buf.get_selection_bounds()
- if not end.ends_line():
- end.forward_to_line_end()
+ if not bounds:
+ start = buf.get_iter_at_mark(buf.get_insert())
+ end = start.copy()
- bounds = [start, end]
+ if not end.ends_line():
+ end.forward_to_line_end()
- if not bounds[0].equal(bounds[1]):
- text = how(bounds[0].get_text(bounds[1]))
+ bounds = [start, end]
- buf.begin_user_action()
- buf.delete(bounds[0], bounds[1])
- buf.insert(bounds[0], text)
- buf.end_user_action()
+ if not bounds[0].equal(bounds[1]):
+ text = how(bounds[0].get_text(bounds[1]))
+
+ buf.begin_user_action()
+ buf.delete(bounds[0], bounds[1])
+ buf.insert(bounds[0], text)
+ buf.end_user_action()
return commands.result.HIDE
-def upper(view):
- """Make upper case: format.upper
+def upper(view, all=False):
+ """Make upper case: format.upper [<all>]
-Transform text in selection to upper case."""
- return _transform(view, lambda x: x.upper())
+Transform text in selection to upper case. If the optional argument <all>
+is specified, text in all the open documents will be transformed."""
+ return _transform(view, lambda x: x.upper(), all)
-def lower(view):
- """Make lower case: format.lower
+def lower(view, all=False):
+ """Make lower case: format.lower [<all>]
-Transform text in selection to lower case."""
- return _transform(view, lambda x: x.lower())
+Transform text in selection to lower case. If the optional argument <all>
+is specified, text in all the open documents will be transformed."""
+ return _transform(view, lambda x: x.lower(), all)
-def title(view):
- """Make title case: format.title
+def title(view, all=False):
+ """Make title case: format.title [<all>]
-Transform text in selection to title case."""
- return _transform(view, lambda x: x.title()).replace('_', '')
+Transform text in selection to title case. If the optional argument <all>
+is specified, text in all the open documents will be transformed."""
+ return _transform(view, lambda x: x.title().replace('_', ''), all)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]