From 6d2315c9e80c569e7d8bd29fa08f9fd7b7e694c7 Mon Sep 17 00:00:00 2001 From: Moises Trovo Date: Fri, 23 Sep 2011 15:47:03 -0300 Subject: [PATCH 1/6] changed base support for gedit3, now the plugin is incompatible with gedit2 --- install.sh | 8 +- zencoding.gedit-plugin | 4 +- zencoding/__init__.py | 413 +++++++++++++++++++++------------------- zencoding/zen_dialog.py | 26 ++- zencoding/zen_editor.py | 20 +- 5 files changed, 243 insertions(+), 228 deletions(-) diff --git a/install.sh b/install.sh index db226a4..96df073 100755 --- a/install.sh +++ b/install.sh @@ -1,11 +1,11 @@ #!/bin/bash # -# Zen Coding for GEdit installation +# Zen Coding for GEdit3 installation # sudo cp zencoding.png /usr/share/icons/hicolor/16x16/apps sudo gtk-update-icon-cache /usr/share/icons/hicolor > /dev/null 2>&1 -mkdir -p ~/.gnome2/gedit/plugins -cp zencoding.gedit-plugin ~/.gnome2/gedit/plugins -cp -r zencoding ~/.gnome2/gedit/plugins +mkdir -p ~/.local/share/gedit/plugins/ +cp zencoding.gedit-plugin ~/.local/share/gedit/plugins/ +cp -r zencoding ~/.local/share/gedit/plugins/ diff --git a/zencoding.gedit-plugin b/zencoding.gedit-plugin index 8490a19..d68901a 100644 --- a/zencoding.gedit-plugin +++ b/zencoding.gedit-plugin @@ -1,7 +1,7 @@ -[Gedit Plugin] +[Plugin] Loader=python Module=zencoding -IAge=2 +IAge=3 Name=Zen Coding Description=Expand expressions similar to CSS selectors into HTML, CSS or XSLT code Description[fr]=Développe des expressions similaires à des sélecteurs CSS en code HTML, CSS ou XSLT diff --git a/zencoding/__init__.py b/zencoding/__init__.py index c084806..ffa3c53 100644 --- a/zencoding/__init__.py +++ b/zencoding/__init__.py @@ -15,232 +15,245 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import gedit, gtk, os +#FIXME debug line remove +#import pydevd; pydevd.settrace() + + +from gi.repository import GObject, Gedit, Gtk, Gio + +import os from zen_editor import ZenEditor zencoding_ui_str = """ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ class ZenCodingWindowHelper(): - def __init__(self, window): - - # window - self.window = window - - # menu items - actions = [ - ('ZenCodingMenuAction', None, '_Zen Coding', None, "Zen Coding tools", None), - ('ZenCodingExpandAction', None, '_Expand abbreviation', 'E', "Expand abbreviation to raw HTML/CSS", self.expand_abbreviation), - ('ZenCodingExpandWAction', None, 'E_xpand with abbreviation...', 'E', "Type in an abbreviation to expand", self.expand_with_abbreviation), - ('ZenCodingWrapAction', None, '_Wrap with abbreviation...', 'E', "Wrap with code expanded from abbreviation", self.wrap_with_abbreviation), - ('ZenCodingZenifyAction', None, '_Zenify', None, "Reduce to abbreviation", None), - ('ZenCodingZenify0Action', None, '_Tag names', 'Z', "Reduce to tag names only", self.zenify0), - ('ZenCodingZenify1Action', None, ' + _Ids and classes', None, "Reduce with ids and classes", self.zenify1), - ('ZenCodingZenify2Action', None, ' + All other _attributes', None, "Reduce with all attributes", self.zenify2), - ('ZenCodingZenify3Action', None, ' + _Values', None, "Reduce with all attributes and values", self.zenify3), - ('LoremIpsumAction', None, '_Lorem ipsum...', 'X', "Insert a lorem ipsum string", self.lorem_ipsum), - ('ZenCodingInwardAction', None, 'Select _inward', 'I', "Select inner tag's content", self.match_pair_inward), - ('ZenCodingOutwardAction', None, 'Select _outward', 'O', "Select outer tag's content", self.match_pair_outward), - ('ZenCodingPTagAction', None, 'Previous tag', 'Up', "Select the previous tag in HTML code", self.prev_tag), - ('ZenCodingNTagAction', None, 'Next tag', 'Down', "Select the next tag in HTML code", self.next_tag), - ('ZenCodingPNodeAction', None, 'Previous node', 'Left', "Select the previous HTML node", self.prev_node), - ('ZenCodingNNodeAction', None, 'Next node', 'Right', "Select the next HTML node", self.next_node), - ('ZenCodingPrevAction', None, '_Previous edit point', 'Left', "Place the cursor at the previous edit point", self.prev_edit_point), - ('ZenCodingNextAction', None, '_Next edit point', 'Right', "Place the cursor at the next edit point", self.next_edit_point), - ('ZenCodingSizeAction', None, 'Update image _size', 'S', "Update image size tag from file", self.update_image_size), - ('ZenCodingDataAction', None, 'Toggle image url/da_ta', 'A', "Toggle between image url and data", self.encode_decode_base64), - ('ZenCodingMergeAction', None, '_Merge lines', 'M', "Merge all lines of the current selection", self.merge_lines), - ('ZenCodingRemoveAction', None, '_Remove tag', 'R', "Remove a tag", self.remove_tag), - ('ZenCodingSplitAction', None, 'Split or _join tag', 'J', "Toggle between single and double tag", self.split_join_tag), - ('ZenCodingCommentAction', None, 'Toggle _comment', 'C', "Toggle an XML or HTML comment", self.toggle_comment), - ('ZenCodingSettingsAction', None, 'E_dit settings...', None, "Customize snippets and abbreviations", self.edit_settings) - ] - windowdata = dict() - self.window.set_data("ZenCodingPluginDataKey", windowdata) - windowdata["action_group"] = gtk.ActionGroup("GeditZenCodingPluginActions") - windowdata["action_group"].add_actions(actions) - manager = self.window.get_ui_manager() - manager.insert_action_group(windowdata["action_group"], -1) - windowdata["ui_id"] = manager.add_ui_from_string(zencoding_ui_str) - self.window.set_data("ZenCodingPluginInfo", windowdata) - - # zen coding - self.modified = None - self.editor = ZenEditor(self.window) - - def deactivate(self): - - # zen coding - self.editor = None - - # menu items - windowdata = self.window.get_data("ZenCodingPluginDataKey") - manager = self.window.get_ui_manager() - manager.remove_ui(windowdata["ui_id"]) - manager.remove_action_group(windowdata["action_group"]) - - # window - self.window = None - - def update_ui(self): - - # disabled if not editable - view = self.window.get_active_view() - windowdata = self.window.get_data("ZenCodingPluginDataKey") - windowdata["action_group"].set_sensitive(bool(view and view.get_editable())) - - # user settings - modified = os.path.getmtime(os.path.join(os.path.dirname(__file__), 'my_zen_settings.py')) - if modified != self.modified: - try: - import my_zen_settings - reload(my_zen_settings) - except Exception as error: - md = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, - gtk.BUTTONS_CLOSE, "An error occured in user settings:") - message = "{0} on line {1} at character {2}\n\nUser settings will not be available." - md.set_title("Zen Coding error") - md.format_secondary_text(message.format(error.msg, error.lineno, error.offset)) - md.run() - md.destroy() - else: - globals()['zen_core'].zen_settings = globals()['stparser'].get_settings(my_zen_settings.my_zen_settings) - self.modified = modified - - # the content changed - self.editor.set_context(view) - - # Menu handlers - - def expand_abbreviation(self, action): - self.editor.expand_abbreviation() - - def expand_with_abbreviation(self, action): - self.editor.expand_with_abbreviation() - - def wrap_with_abbreviation(self, action): - self.editor.wrap_with_abbreviation() - - def zenify0(self, action): - self.editor.zenify(0) - - def zenify1(self, action): - self.editor.zenify(1) - - def zenify2(self, action): - self.editor.zenify(2) - - def zenify3(self, action): - self.editor.zenify(3) - - def lorem_ipsum(self, action): - self.editor.lorem_ipsum() - - def match_pair_inward(self, action): - self.editor.match_pair_inward() - - def match_pair_outward(self, action): - self.editor.match_pair_outward() - - def prev_tag(self, action): - self.editor.prev_tag() - - def next_tag(self, action): - self.editor.next_tag() - - def prev_node(self, action): - self.editor.prev_node() + def __init__(self, window): + + # window + self.window = window + + # menu items + actions = [ + ('ZenCodingMenuAction', None, '_Zen Coding', None, "Zen Coding tools", None), + ('ZenCodingExpandAction', None, '_Expand abbreviation', 'E', "Expand abbreviation to raw HTML/CSS", self.expand_abbreviation), + ('ZenCodingExpandWAction', None, 'E_xpand with abbreviation...', 'E', "Type in an abbreviation to expand", self.expand_with_abbreviation), + ('ZenCodingWrapAction', None, '_Wrap with abbreviation...', 'E', "Wrap with code expanded from abbreviation", self.wrap_with_abbreviation), + ('ZenCodingZenifyAction', None, '_Zenify', None, "Reduce to abbreviation", None), + ('ZenCodingZenify0Action', None, '_Tag names', 'Z', "Reduce to tag names only", self.zenify0), + ('ZenCodingZenify1Action', None, ' + _Ids and classes', None, "Reduce with ids and classes", self.zenify1), + ('ZenCodingZenify2Action', None, ' + All other _attributes', None, "Reduce with all attributes", self.zenify2), + ('ZenCodingZenify3Action', None, ' + _Values', None, "Reduce with all attributes and values", self.zenify3), + ('LoremIpsumAction', None, '_Lorem ipsum...', 'X', "Insert a lorem ipsum string", self.lorem_ipsum), + ('ZenCodingInwardAction', None, 'Select _inward', 'I', "Select inner tag's content", self.match_pair_inward), + ('ZenCodingOutwardAction', None, 'Select _outward', 'O', "Select outer tag's content", self.match_pair_outward), + ('ZenCodingPTagAction', None, 'Previous tag', 'Up', "Select the previous tag in HTML code", self.prev_tag), + ('ZenCodingNTagAction', None, 'Next tag', 'Down', "Select the next tag in HTML code", self.next_tag), + ('ZenCodingPNodeAction', None, 'Previous node', 'Left', "Select the previous HTML node", self.prev_node), + ('ZenCodingNNodeAction', None, 'Next node', 'Right', "Select the next HTML node", self.next_node), + ('ZenCodingPrevAction', None, '_Previous edit point', 'Left', "Place the cursor at the previous edit point", self.prev_edit_point), + ('ZenCodingNextAction', None, '_Next edit point', 'Right', "Place the cursor at the next edit point", self.next_edit_point), + ('ZenCodingSizeAction', None, 'Update image _size', 'S', "Update image size tag from file", self.update_image_size), + ('ZenCodingDataAction', None, 'Toggle image url/da_ta', 'A', "Toggle between image url and data", self.encode_decode_base64), + ('ZenCodingMergeAction', None, '_Merge lines', 'M', "Merge all lines of the current selection", self.merge_lines), + ('ZenCodingRemoveAction', None, '_Remove tag', 'R', "Remove a tag", self.remove_tag), + ('ZenCodingSplitAction', None, 'Split or _join tag', 'J', "Toggle between single and double tag", self.split_join_tag), + ('ZenCodingCommentAction', None, 'Toggle _comment', 'C', "Toggle an XML or HTML comment", self.toggle_comment), + ('ZenCodingSettingsAction', None, 'E_dit settings...', None, "Customize snippets and abbreviations", self.edit_settings) + ] + windowdata = dict() + self.window.set_data("ZenCodingPluginDataKey", windowdata) + windowdata["action_group"] = Gtk.ActionGroup("GeditZenCodingPluginActions") + windowdata["action_group"].add_actions(actions) + manager = self.window.get_ui_manager() + manager.insert_action_group(windowdata["action_group"], -1) + windowdata["ui_id"] = manager.add_ui_from_string(zencoding_ui_str) + self.window.set_data("ZenCodingPluginInfo", windowdata) + + # zen coding + self.modified = None + self.editor = ZenEditor(self.window) + + def deactivate(self): + + # zen coding + self.editor = None + + # menu items + windowdata = self.window.get_data("ZenCodingPluginDataKey") + manager = self.window.get_ui_manager() + manager.remove_ui(windowdata["ui_id"]) + manager.remove_action_group(windowdata["action_group"]) + + # window + self.window = None + + def update_ui(self): + + # disabled if not editable + view = self.window.get_active_view() + windowdata = self.window.get_data("ZenCodingPluginDataKey") + windowdata["action_group"].set_sensitive(bool(view and view.get_editable())) + + # user settings + modified = os.path.getmtime(os.path.join(os.path.dirname(__file__), 'my_zen_settings.py')) + if modified != self.modified: + try: + import my_zen_settings + reload(my_zen_settings) + except Exception as error: + md = Gtk.MessageDialog(self.window, Gtk.DIALOG_MODAL, Gtk.MESSAGE_ERROR, + Gtk.BUTTONS_CLOSE, "An error occured in user settings:") + message = "{0} on line {1} at character {2}\n\nUser settings will not be available." + md.set_title("Zen Coding error") + md.format_secondary_text(message.format(error.msg, error.lineno, error.offset)) + md.run() + md.destroy() + else: + globals()['zen_core'].zen_settings = globals()['stparser'].get_settings(my_zen_settings.my_zen_settings) + self.modified = modified + + # the content changed + self.editor.set_context(view) + + # Menu handlers + + def expand_abbreviation(self, action): + self.editor.expand_abbreviation() + + def expand_with_abbreviation(self, action): + self.editor.expand_with_abbreviation() + + def wrap_with_abbreviation(self, action): + self.editor.wrap_with_abbreviation() + + def zenify0(self, action): + self.editor.zenify(0) + + def zenify1(self, action): + self.editor.zenify(1) + + def zenify2(self, action): + self.editor.zenify(2) + + def zenify3(self, action): + self.editor.zenify(3) + + def lorem_ipsum(self, action): + self.editor.lorem_ipsum() + + def match_pair_inward(self, action): + self.editor.match_pair_inward() + + def match_pair_outward(self, action): + self.editor.match_pair_outward() + + def prev_tag(self, action): + self.editor.prev_tag() + + def next_tag(self, action): + self.editor.next_tag() + + def prev_node(self, action): + self.editor.prev_node() - def next_node(self, action): - self.editor.next_node() + def next_node(self, action): + self.editor.next_node() - def prev_edit_point(self, action): - self.editor.prev_edit_point() + def prev_edit_point(self, action): + self.editor.prev_edit_point() - def next_edit_point(self, action): - self.editor.next_edit_point() + def next_edit_point(self, action): + self.editor.next_edit_point() - def update_image_size(self, action): - self.editor.update_image_size() + def update_image_size(self, action): + self.editor.update_image_size() - def encode_decode_base64(self, action): - self.editor.encode_decode_base64() + def encode_decode_base64(self, action): + self.editor.encode_decode_base64() - def merge_lines(self, action): - self.editor.merge_lines() + def merge_lines(self, action): + self.editor.merge_lines() - def remove_tag(self, action): - self.editor.remove_tag() + def remove_tag(self, action): + self.editor.remove_tag() - def split_join_tag(self, action): - self.editor.split_join_tag() + def split_join_tag(self, action): + self.editor.split_join_tag() - def toggle_comment(self, action): - self.editor.toggle_comment() + def toggle_comment(self, action): + self.editor.toggle_comment() - def edit_settings(self, action): - name = 'file://' + os.path.join(os.path.dirname(__file__), 'my_zen_settings.py') - self.window.create_tab_from_uri(name, None, 0, True, True) + def edit_settings(self, action): + uri = 'file://' + os.path.join(os.path.dirname(__file__), 'my_zen_settings.py') + self.window.create_tab_from_location(Gio.file_new_for_uri(uri), None, 0, 0, True, True) -class ZenCodingPlugin(gedit.Plugin): +class ZenCodingPlugin(GObject.Object, Gedit.WindowActivatable): - def __init__(self): - gedit.Plugin.__init__(self) - self.instances = {} + __gtype_name__ = "ZenCodingPlugin" + window = GObject.property(type=Gedit.Window) - def activate(self, window): - self.instances[window] = ZenCodingWindowHelper(window) + def __init__(self): + GObject.Object.__init__(self) + self.instances = {} def deactivate(self, window): self.instances[window].deactivate() del self.instances[window] - def update_ui(self, window): - self.instances[window].update_ui() + def do_activate(self): + self.instances[self.window] = ZenCodingWindowHelper(self.window) + + def do_deactivate(self): + self.instances[self.window].deactivate() + del self.instances[self.window] + + def do_update_state(self): + self.instances[self.window].update_ui() diff --git a/zencoding/zen_dialog.py b/zencoding/zen_dialog.py index 342063c..4188741 100644 --- a/zencoding/zen_dialog.py +++ b/zencoding/zen_dialog.py @@ -15,9 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import pygtk -pygtk.require('2.0') -import gtk +from gi.repository import Gtk class ZenDialog(): @@ -30,7 +28,7 @@ def __init__(self, editor, x, y, callback, text, last): self.callback = callback self.last = last - self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) + self.window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL) self.window.set_decorated(False) self.window.connect("destroy", self.quit) self.window.connect("focus-out-event", self.focus_lost) @@ -38,18 +36,18 @@ def __init__(self, editor, x, y, callback, text, last): self.window.set_resizable(False) self.window.move(x - 15, y - 35) - self.frame = gtk.Frame() + self.frame = Gtk.Frame() self.window.add(self.frame) self.frame.show() - self.box = gtk.HBox() + self.box = Gtk.HBox() self.frame.add(self.box) self.box.show() - self.entry = gtk.Entry() + self.entry = Gtk.Entry() self.entry.connect("changed", self.update) self.entry.set_text(text) - self.entry.set_icon_from_icon_name(gtk.ENTRY_ICON_PRIMARY, 'zencoding') + self.entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, 'zencoding') self.entry.set_width_chars(48) self.box.pack_start(self.entry, True, True, 4) self.entry.show() @@ -87,23 +85,23 @@ def update(self, entry): def quit(self, widget=None, event=None): self.window.hide() self.window.destroy() - gtk.main_quit() + Gtk.main_quit() def main(self): - gtk.main() + Gtk.main() def main(editor, window, callback, text = "", last = False): # ensure the caret is hidden editor.view.set_cursor_visible(False) - + # get coordinates of the cursor offset_start, offset_end = editor.get_selection_range() insert = editor.buffer.get_iter_at_offset(offset_start) location = editor.view.get_iter_location(insert) - window = editor.view.get_window(gtk.TEXT_WINDOW_TEXT) - xo, yo = window.get_origin() - xb, yb = editor.view.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT, location.x + location.width, location.y) + window = editor.view.get_window(Gtk.TextWindowType.TEXT) + xo, yo, zo = window.get_origin() + xb, yb = editor.view.buffer_to_window_coords(Gtk.TextWindowType.TEXT, location.x + location.width, location.y) # open dialog at coordinates with eventual text my_zen_dialog = ZenDialog(editor, xo + xb, yo + yb, callback, text, last) diff --git a/zencoding/zen_editor.py b/zencoding/zen_editor.py index 97dda6c..e434785 100644 --- a/zencoding/zen_editor.py +++ b/zencoding/zen_editor.py @@ -25,12 +25,15 @@ from lorem_ipsum import lorem_ipsum try: - sys.path.append('/usr/lib/gedit-2/plugins') - from snippets.Document import Document as SnippetDocument - USE_SNIPPETS = True + sys.path.append('/usr/lib/gedit/plugins/') + from snippets import Document as SnippetDocument + USE_SNIPPETS = True except: + print 'failed importing snippets' USE_SNIPPETS = False + + class ZenSnippet(): def __init__(self, abbreviation, content): @@ -112,7 +115,8 @@ def set_context(self, view): if USE_SNIPPETS: if not (self.view in self.snippet_document): - self.snippet_document[self.view] = SnippetDocument(None, self.view) + self.snippet_document[self.view] = SnippetDocument() + self.snippet_document[self.view].view = self.view else: self.snippet_document[self.view] = None @@ -162,7 +166,7 @@ def get_current_line(self): offset_start, offset_end = self.get_current_line_range() iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_end) - return self.buffer.get_text(iter_start, iter_end).decode('UTF-8') + return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') def replace_content(self, value, offset_start=None, offset_end=None): @@ -191,7 +195,7 @@ def replace_content(self, value, offset_start=None, offset_end=None): def get_content(self): iter_start = self.buffer.get_iter_at_offset(0) iter_end = self.get_end_iter() - return self.buffer.get_text(iter_start, iter_end).decode('UTF-8') + return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') def get_syntax(self): lang = self.window.get_active_document().get_language() @@ -214,7 +218,7 @@ def get_selection(self): offset_start, offset_end = self.get_selection_range() iter_start = self.buffer.get_iter_at_offset(offset_start) iter_end = self.buffer.get_iter_at_offset(offset_end) - return self.buffer.get_text(iter_start, iter_end).decode('UTF-8') + return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') def get_file_path(self): return re.sub('^file://', '', self.document.get_uri()) @@ -514,7 +518,7 @@ def new_node(self, direction, with_spaces = True): iter_start = self.buffer.get_iter_at_offset(node.start) iter_end = self.buffer.get_iter_at_offset(node.end) - found = self.buffer.get_text(iter_start, iter_end).decode('UTF-8') + found = self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') if not with_spaces and found.isspace() and found.find('\n') != -1: offset_start = node.start offset_end = node.end From ee08a3e382c9a18e0df91da66dba685063d4b577 Mon Sep 17 00:00:00 2001 From: Moises Trovo Date: Fri, 23 Sep 2011 15:48:20 -0300 Subject: [PATCH 2/6] added kudos --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0713033..be13351 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Credits - Zen Coding is written by [Sergey Chikuyonok](http://chikuyonok.ru/) - Zen Coding for Gedit is written by [Franck Marcia](http://github.com/fmarcia) +- Zen Coding for Gedit3 is written by [Moises Trovo](http://github.com/mtrovo) License ------- From 0b1f322be3d98dea1a3a2c4538ae62f0112f3fa2 Mon Sep 17 00:00:00 2001 From: Moises Trovo Date: Sat, 24 Sep 2011 17:05:54 -0300 Subject: [PATCH 3/6] fixed a tab space bug --- zencoding/zen_editor.py | 847 ++++++++++++++++++++-------------------- 1 file changed, 423 insertions(+), 424 deletions(-) diff --git a/zencoding/zen_editor.py b/zencoding/zen_editor.py index e434785..3a9e98f 100644 --- a/zencoding/zen_editor.py +++ b/zencoding/zen_editor.py @@ -30,559 +30,558 @@ USE_SNIPPETS = True except: print 'failed importing snippets' - USE_SNIPPETS = False - + USE_SNIPPETS = False class ZenSnippet(): - def __init__(self, abbreviation, content): - self.valid = True - self.properties = { - 'text': content, - 'drop-targets': '', - 'tag': abbreviation, - 'description': 'zencoding', - 'accelerator': '' - } + def __init__(self, abbreviation, content): + self.valid = True + self.properties = { + 'text': content, + 'drop-targets': '', + 'tag': abbreviation, + 'description': 'zencoding', + 'accelerator': ''} - def __getitem__(self, prop): - return self.properties[prop] + def __getitem__(self, prop): + return self.properties[prop] placeholder_count = 0 + def placeholder_feed(m): - global placeholder_count - placeholder_count += 1 - - skip = len(zen_core.get_caret_placeholder()) + 1 - - if m and m.group(1): - if m.group(1).startswith('{{'): - return '${' + repr(placeholder_count) - elif m.group(1).startswith('>'): - return '>${' + repr(placeholder_count) + ':' + m.group(1)[skip:-1] + '}<' - else: - return '$' + repr(placeholder_count) - else: - return '' + global placeholder_count + placeholder_count += 1 + + skip = len(zen_core.get_caret_placeholder()) + 1 + + if m and m.group(1): + if m.group(1).startswith('{{'): + return '${' + repr(placeholder_count) + elif m.group(1).startswith('>'): + return '>${' + repr(placeholder_count) + ':' + m.group(1)[skip:-1] + '}<' + else: + return '$' + repr(placeholder_count) + else: + return '' + class ZenEditor(): - def __init__(self, window): + def __init__(self, window): + + self.window = window + + self.last_wrap = '' + self.last_expand = '' + self.last_lorem_ipsum = 'list 5*5' + + self.placeholder = zen_core.get_caret_placeholder() + zen_core.set_caret_placeholder('') + + self.html_navigation = None + self.snippet_document = {} + + # --- Original interface --------------------------------------------------- + def set_context(self, view): + + default_locale = locale.getdefaultlocale()[0] + if default_locale: + lang = re.sub(r'_[^_]+$', '', default_locale) + if lang != default_locale: + zen_core.set_variable('lang', lang) + zen_core.set_variable('locale', default_locale.replace('_', '-')) + else: + zen_core.set_variable('lang', default_locale) + zen_core.set_variable('locale', default_locale) + + self.document = self.window.get_active_document() + if self.document: + zen_core.set_variable('charset', self.document.get_encoding().get_charset()) + + self.view = view + if self.view: + self.buffer = self.view.get_buffer() + if self.view.get_insert_spaces_instead_of_tabs(): + zen_core.set_variable('indentation', " " * self.view.get_tab_width()) + else: + zen_core.set_variable('indentation', "\t") + + #zen_core.set_newline(???) + + if USE_SNIPPETS: + if not (self.view in self.snippet_document): + self.snippet_document[self.view] = SnippetDocument() + self.snippet_document[self.view].view = self.view + else: + self.snippet_document[self.view] = None + + def get_selection_range(self): + + offset_start = self.get_insert_offset() + offset_end = self.get_selection_bound_offset() + + if offset_start < offset_end: + return offset_start, offset_end + + return offset_end, offset_start + + def create_selection(self, offset_start, offset_end=None): + + if offset_end is None: + iter_start = self.buffer.get_iter_at_offset(offset_start) + self.buffer.place_cursor(iter_start) + + else: + iter_start = self.buffer.get_iter_at_offset(offset_start) + iter_end = self.buffer.get_iter_at_offset(offset_end) + self.buffer.select_range(iter_start, iter_end) + + def get_current_line_range(self): + + iter_start = self.get_insert_iter() + iter_start.set_line_offset(0) + iter_end = iter_start.copy() + + if iter_end.forward_visible_line(): + iter_end.backward_char() + + else: + iter_end = self.buffer.get_end_iter() + + return iter_start.get_offset(), iter_end.get_offset() + + def get_caret_pos(self): + return self.get_insert_offset() + + def set_caret_pos(self, pos): + self.buffer.place_cursor(self.buffer.get_iter_at_offset(pos)) + + def get_current_line(self): + + offset_start, offset_end = self.get_current_line_range() + iter_start = self.buffer.get_iter_at_offset(offset_start) + iter_end = self.buffer.get_iter_at_offset(offset_end) + return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') + + def replace_content(self, value, offset_start=None, offset_end=None): + + if offset_start is None and offset_end is None: + iter_start = self.buffer.get_iter_at_offset(0) + iter_end = self.get_end_iter() + + elif offset_end is None: + iter_start = self.buffer.get_iter_at_offset(offset_start) + iter_end = self.buffer.get_iter_at_offset(offset_start) + + else: + iter_start = self.buffer.get_iter_at_offset(offset_start) + iter_end = self.buffer.get_iter_at_offset(offset_end) + + self.buffer.delete(iter_start, iter_end) + self.set_caret_pos(offset_start) + self.insertion_start = self.get_insert_offset() + + padding = zen_actions.get_current_line_padding(self) + padding = re.sub('[\r\n]', '', padding) + self.buffer.insert_at_cursor(zen_core.pad_string(value, padding)) - self.window = window + self.insertion_end = self.get_insert_offset() - self.last_wrap = '' - self.last_expand = '' - self.last_lorem_ipsum = 'list 5*5' + def get_content(self): + iter_start = self.buffer.get_iter_at_offset(0) + iter_end = self.get_end_iter() + return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') - self.placeholder = zen_core.get_caret_placeholder() - zen_core.set_caret_placeholder('') + def get_syntax(self): + lang = self.window.get_active_document().get_language() + lang = lang and lang.get_name() + if lang == 'CSS': lang = 'css' + elif lang == 'XSLT': lang = 'xsl' + else: lang = 'html' + return lang - self.html_navigation = None - self.snippet_document = {} + def get_profile_name(self): + return 'xhtml' - # --- Original interface --------------------------------------------------- + def prompt(self, title): + done, result = zen_dialog.main(self, self.window, None, title) + if done: + return result + return '' - def set_context(self, view): + def get_selection(self): + offset_start, offset_end = self.get_selection_range() + iter_start = self.buffer.get_iter_at_offset(offset_start) + iter_end = self.buffer.get_iter_at_offset(offset_end) + return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') - default_locale = locale.getdefaultlocale()[0] - if default_locale: - lang = re.sub(r'_[^_]+$', '', default_locale) - if lang != default_locale: - zen_core.set_variable('lang', lang) - zen_core.set_variable('locale', default_locale.replace('_', '-')) - else: - zen_core.set_variable('lang', default_locale) - zen_core.set_variable('locale', default_locale) - - self.document = self.window.get_active_document() - if self.document: - zen_core.set_variable('charset', self.document.get_encoding().get_charset()) - - self.view = view - if self.view: - self.buffer = self.view.get_buffer() - if self.view.get_insert_spaces_instead_of_tabs(): - zen_core.set_variable('indentation', " " * self.view.get_tab_width()) - else: - zen_core.set_variable('indentation', "\t") - - #zen_core.set_newline(???) - - if USE_SNIPPETS: - if not (self.view in self.snippet_document): - self.snippet_document[self.view] = SnippetDocument() - self.snippet_document[self.view].view = self.view - else: - self.snippet_document[self.view] = None - - def get_selection_range(self): - - offset_start = self.get_insert_offset() - offset_end = self.get_selection_bound_offset() + def get_file_path(self): + return re.sub('^file://', '', self.document.get_uri()) - if offset_start < offset_end: - return offset_start, offset_end - - return offset_end, offset_start - - def create_selection(self, offset_start, offset_end=None): - - if offset_end is None: - iter_start = self.buffer.get_iter_at_offset(offset_start) - self.buffer.place_cursor(iter_start) - - else: - iter_start = self.buffer.get_iter_at_offset(offset_start) - iter_end = self.buffer.get_iter_at_offset(offset_end) - self.buffer.select_range(iter_start, iter_end) + # --- Iter and offset oneliners -------------------------------------------- - def get_current_line_range(self): + def get_insert_iter(self): + return self.buffer.get_iter_at_mark(self.buffer.get_insert()) - iter_start = self.get_insert_iter() - iter_start.set_line_offset(0) - iter_end = iter_start.copy() + def get_insert_offset(self): + return self.get_insert_iter().get_offset() - if iter_end.forward_visible_line(): - iter_end.backward_char() - - else: - iter_end = self.buffer.get_end_iter() - - return iter_start.get_offset(), iter_end.get_offset() - - def get_caret_pos(self): - return self.get_insert_offset() - - def set_caret_pos(self, pos): - self.buffer.place_cursor(self.buffer.get_iter_at_offset(pos)) - - def get_current_line(self): - - offset_start, offset_end = self.get_current_line_range() - iter_start = self.buffer.get_iter_at_offset(offset_start) - iter_end = self.buffer.get_iter_at_offset(offset_end) - return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') - - def replace_content(self, value, offset_start=None, offset_end=None): - - if offset_start is None and offset_end is None: - iter_start = self.buffer.get_iter_at_offset(0) - iter_end = self.get_end_iter() - - elif offset_end is None: - iter_start = self.buffer.get_iter_at_offset(offset_start) - iter_end = self.buffer.get_iter_at_offset(offset_start) - - else: - iter_start = self.buffer.get_iter_at_offset(offset_start) - iter_end = self.buffer.get_iter_at_offset(offset_end) - - self.buffer.delete(iter_start, iter_end) - self.set_caret_pos(offset_start) - self.insertion_start = self.get_insert_offset() - - padding = zen_actions.get_current_line_padding(self) - padding = re.sub('[\r\n]', '', padding) - self.buffer.insert_at_cursor(zen_core.pad_string(value, padding)) - - self.insertion_end = self.get_insert_offset() - - def get_content(self): - iter_start = self.buffer.get_iter_at_offset(0) - iter_end = self.get_end_iter() - return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') - - def get_syntax(self): - lang = self.window.get_active_document().get_language() - lang = lang and lang.get_name() - if lang == 'CSS': lang = 'css' - elif lang == 'XSLT': lang = 'xsl' - else: lang = 'html' - return lang - - def get_profile_name(self): - return 'xhtml' + def get_selection_bound_iter(self): + return self.buffer.get_iter_at_mark(self.buffer.get_selection_bound()) - def prompt(self, title): - done, result = zen_dialog.main(self, self.window, None, title) - if done: - return result - return '' + def get_selection_bound_offset(self): + return self.get_selection_bound_iter().get_offset() - def get_selection(self): - offset_start, offset_end = self.get_selection_range() - iter_start = self.buffer.get_iter_at_offset(offset_start) - iter_end = self.buffer.get_iter_at_offset(offset_end) - return self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') + def get_end_iter(self): + return self.buffer.get_iter_at_offset(self.buffer.get_char_count()) - def get_file_path(self): - return re.sub('^file://', '', self.document.get_uri()) + def get_end_offset(self): + return self.get_end_iter().get_offset() - # --- Iter and offset oneliners -------------------------------------------- + #--- Miscellaneous stuff --------------------------------------------------- - def get_insert_iter(self): - return self.buffer.get_iter_at_mark(self.buffer.get_insert()) - - def get_insert_offset(self): - return self.get_insert_iter().get_offset() + def start_edit(self): + # bug when the cursor is at the very beginning + if self.insertion_start == 0: + self.insertion_start = 1 + self.set_caret_pos(self.insertion_start) + if not self.next_edit_point() or (self.get_insert_offset() > self.insertion_end): + self.set_caret_pos(self.insertion_end) - def get_selection_bound_iter(self): - return self.buffer.get_iter_at_mark(self.buffer.get_selection_bound()) + def show_caret(self): + self.view.scroll_mark_onscreen(self.buffer.get_insert()) - def get_selection_bound_offset(self): - return self.get_selection_bound_iter().get_offset() + def get_user_settings_error(self): + return zen_core.get_variable('user_settings_error') - def get_end_iter(self): - return self.buffer.get_iter_at_offset(self.buffer.get_char_count()) + def save_selection(self): + self.save_offset_insert = self.get_insert_offset() + self.save_offset_selection_bound = self.get_selection_bound_offset() - def get_end_offset(self): - return self.get_end_iter().get_offset() + def restore_selection(self): + iter_insert = self.buffer.get_iter_at_offset(self.save_offset_insert) + iter_selection_bound = self.buffer.get_iter_at_offset(self.save_offset_selection_bound) + self.buffer.select_range(iter_insert, iter_selection_bound) - #--- Miscellaneous stuff --------------------------------------------------- + def prepare_nav(self): + offset_start, offset_end = self.get_selection_range() + content = self.get_content() + if not self.html_navigation: + self.html_navigation = HtmlNavigation(content) + return offset_start, offset_end, content - def start_edit(self): - # bug when the cursor is at the very beginning - if self.insertion_start == 0: - self.insertion_start = 1 - self.set_caret_pos(self.insertion_start) - if not self.next_edit_point() or (self.get_insert_offset() > self.insertion_end): - self.set_caret_pos(self.insertion_end) - - def show_caret(self): - self.view.scroll_mark_onscreen(self.buffer.get_insert()) + #--- Snippet hook ---------------------------------------------------------- - def get_user_settings_error(self): - return zen_core.get_variable('user_settings_error') + def expand_with_snippet(self, abbr, mode = 0): + # mode_names = { 0: 'expand abbr', 1: 'expand with abbr', 2: 'wrap with abbr' } - def save_selection(self): - self.save_offset_insert = self.get_insert_offset() - self.save_offset_selection_bound = self.get_selection_bound_offset() + if mode < 2: + content = zen_core.expand_abbreviation(abbr, self.get_syntax(), self.get_profile_name()) + else: + content = self.core_wrap_with_abbreviation(abbr) - def restore_selection(self): - iter_insert = self.buffer.get_iter_at_offset(self.save_offset_insert) - iter_selection_bound = self.buffer.get_iter_at_offset(self.save_offset_selection_bound) - self.buffer.select_range(iter_insert, iter_selection_bound) + if content: - def prepare_nav(self): - offset_start, offset_end = self.get_selection_range() - content = self.get_content() - if not self.html_navigation: - self.html_navigation = HtmlNavigation(content) - return offset_start, offset_end, content + global placeholder_count + placeholder_count = 0 + search_string = '(' + self.placeholder + '|\{' + self.placeholder + '|>' + self.placeholder + '[^<]+<' + ')' + content = re.sub(search_string, placeholder_feed, content) - #--- Snippet hook ---------------------------------------------------------- - - def expand_with_snippet(self, abbr, mode = 0): - # mode_names = { 0: 'expand abbr', 1: 'expand with abbr', 2: 'wrap with abbr' } + offset_start, offset_end = self.get_selection_range() + if offset_start == offset_end and mode == 0: + offset_start -= len(abbr) - if mode < 2: - content = zen_core.expand_abbreviation(abbr, self.get_syntax(), self.get_profile_name()) - else: - content = self.core_wrap_with_abbreviation(abbr) + snippet = ZenSnippet(abbr, content) + iter_start = self.buffer.get_iter_at_offset(offset_start) + iter_end = self.buffer.get_iter_at_offset(offset_end) - if content: + self.snippet_document[self.view].apply_snippet(snippet, iter_start, iter_end) - global placeholder_count - placeholder_count = 0 - search_string = '(' + self.placeholder + '|\{' + self.placeholder + '|>' + self.placeholder + '[^<]+<' + ')' - content = re.sub(search_string, placeholder_feed, content) + return content - offset_start, offset_end = self.get_selection_range() - if offset_start == offset_end and mode == 0: - offset_start -= len(abbr) + #--- Expand abbreviation --------------------------------------------------- - snippet = ZenSnippet(abbr, content) - iter_start = self.buffer.get_iter_at_offset(offset_start) - iter_end = self.buffer.get_iter_at_offset(offset_end) + def expand_abbreviation(self): - self.snippet_document[self.view].apply_snippet(snippet, iter_start, iter_end) - - return content + zen_core.set_caret_placeholder(self.placeholder) - #--- Expand abbreviation --------------------------------------------------- + abbr = zen_actions.find_abbreviation(self) - def expand_abbreviation(self): + if abbr: - zen_core.set_caret_placeholder(self.placeholder) - - abbr = zen_actions.find_abbreviation(self) + if self.snippet_document[self.view]: + self.expand_with_snippet(abbr) - if abbr: + else: + self.buffer.begin_user_action() + content = zen_core.expand_abbreviation(abbr, self.get_syntax(), self.get_profile_name()) + if content: + content = content.replace(self.placeholder, '') + content = re.sub('\$\d+|\$\{\d+:[^\}]*\}', '', content) + unused, offset_end = self.get_selection_range() + self.replace_content(content, offset_end - len(abbr), offset_end) + self.start_edit() + self.buffer.end_user_action() - if self.snippet_document[self.view]: - self.expand_with_snippet(abbr) + zen_core.set_caret_placeholder('') - else: - self.buffer.begin_user_action() - content = zen_core.expand_abbreviation(abbr, self.get_syntax(), self.get_profile_name()) - if content: - content = content.replace(self.placeholder, '') - content = re.sub('\$\d+|\$\{\d+:[^\}]*\}', '', content) - unused, offset_end = self.get_selection_range() - self.replace_content(content, offset_end - len(abbr), offset_end) - self.start_edit() - self.buffer.end_user_action() + #--- Expand with abbreviation ---------------------------------------------- - zen_core.set_caret_placeholder('') + def callback_expand_with_abbreviation(self, done, abbr, last = False): - #--- Expand with abbreviation ---------------------------------------------- + self.buffer.begin_user_action() - def callback_expand_with_abbreviation(self, done, abbr, last = False): + if done: + self.buffer.undo() + self.restore_selection() - self.buffer.begin_user_action() + if last and self.snippet_document[self.view]: + content = self.expand_with_snippet(abbr, 1) - if done: - self.buffer.undo() - self.restore_selection() + else: - if last and self.snippet_document[self.view]: - content = self.expand_with_snippet(abbr, 1) + content = zen_core.expand_abbreviation(abbr, self.get_syntax(), self.get_profile_name()) - else: + if content: + content = content.replace(self.placeholder, '') + content = re.sub('\$\d+|\$\{\d+:[^\}]*\}', '', content) + self.replace_content(content, self.get_insert_offset()) - content = zen_core.expand_abbreviation(abbr, self.get_syntax(), self.get_profile_name()) + self.buffer.end_user_action() - if content: - content = content.replace(self.placeholder, '') - content = re.sub('\$\d+|\$\{\d+:[^\}]*\}', '', content) - self.replace_content(content, self.get_insert_offset()) + return not not content - self.buffer.end_user_action() + def expand_with_abbreviation(self): - return not not content + zen_core.set_caret_placeholder(self.placeholder) + self.save_selection() - def expand_with_abbreviation(self): + done, self.last_expand = zen_dialog.main(self, self.window, self.callback_expand_with_abbreviation, self.last_expand, True) - zen_core.set_caret_placeholder(self.placeholder) - self.save_selection() + if done and not self.snippet_document[self.view]: + self.start_edit() - done, self.last_expand = zen_dialog.main(self, self.window, self.callback_expand_with_abbreviation, self.last_expand, True) + zen_core.set_caret_placeholder('') - if done and not self.snippet_document[self.view]: - self.start_edit() + #--- Wrap with abbreviation ------------------------------------------------ - zen_core.set_caret_placeholder('') + def core_wrap_with_abbreviation(self, abbr): - #--- Wrap with abbreviation ------------------------------------------------ + if not abbr: + return None - def core_wrap_with_abbreviation(self, abbr): - - if not abbr: - return None + syntax = self.get_syntax() + profile_name = self.get_profile_name() - syntax = self.get_syntax() - profile_name = self.get_profile_name() + start_offset, end_offset = self.get_selection_range() + content = self.get_content() - start_offset, end_offset = self.get_selection_range() - content = self.get_content() + if start_offset == end_offset: + rng = html_matcher.match(content, start_offset, profile_name) + if rng[0] is None: + return None + else: + start_offset, end_offset = rng - if start_offset == end_offset: - rng = html_matcher.match(content, start_offset, profile_name) - if rng[0] is None: - return None - else: - start_offset, end_offset = rng + start_offset, end_offset = zen_actions.narrow_to_non_space(content, start_offset, end_offset) + line_bounds = zen_actions.get_line_bounds(content, start_offset) + padding = zen_actions.get_line_padding(content[line_bounds[0]:line_bounds[1]]) - start_offset, end_offset = zen_actions.narrow_to_non_space(content, start_offset, end_offset) - line_bounds = zen_actions.get_line_bounds(content, start_offset) - padding = zen_actions.get_line_padding(content[line_bounds[0]:line_bounds[1]]) + new_content = content[start_offset:end_offset] + return zen_core.wrap_with_abbreviation(abbr, zen_actions.unindent_text(new_content, padding), syntax, profile_name) - new_content = content[start_offset:end_offset] - return zen_core.wrap_with_abbreviation(abbr, zen_actions.unindent_text(new_content, padding), syntax, profile_name) + def callback_wrap_with_abbreviation(self, done, abbr, last = False): - def callback_wrap_with_abbreviation(self, done, abbr, last = False): + self.buffer.begin_user_action() - self.buffer.begin_user_action() + if done: + self.buffer.undo() + self.restore_selection() - if done: - self.buffer.undo() - self.restore_selection() + if last and self.snippet_document[self.view]: + content = self.expand_with_snippet(abbr, 2) - if last and self.snippet_document[self.view]: - content = self.expand_with_snippet(abbr, 2) + else: - else: + content = self.core_wrap_with_abbreviation(abbr) - content = self.core_wrap_with_abbreviation(abbr) + if content: + content = content.replace(self.placeholder, '') + content = re.sub('\$\d+|\$\{\d+:[^\}]*\}', '', content) + offset_start, offset_end = self.get_selection_range() + self.replace_content(content, offset_start, offset_end) - if content: - content = content.replace(self.placeholder, '') - content = re.sub('\$\d+|\$\{\d+:[^\}]*\}', '', content) - offset_start, offset_end = self.get_selection_range() - self.replace_content(content, offset_start, offset_end) + self.buffer.end_user_action() - self.buffer.end_user_action() + return not not content - return not not content + def wrap_with_abbreviation(self): - def wrap_with_abbreviation(self): + zen_core.set_caret_placeholder(self.placeholder) + self.save_selection() - zen_core.set_caret_placeholder(self.placeholder) - self.save_selection() + done, self.last_wrap = zen_dialog.main(self, self.window, self.callback_wrap_with_abbreviation, self.last_wrap, True) - done, self.last_wrap = zen_dialog.main(self, self.window, self.callback_wrap_with_abbreviation, self.last_wrap, True) + if done and not self.snippet_document[self.view]: + self.start_edit() - if done and not self.snippet_document[self.view]: - self.start_edit() + zen_core.set_caret_placeholder('') - zen_core.set_caret_placeholder('') + #--- Zenify ---------------------------------------------------------------- - #--- Zenify ---------------------------------------------------------------- + def zenify(self, mode): - def zenify(self, mode): + offset_start, offset_end, content = self.prepare_nav() + result = self.html_navigation.zenify(offset_start, offset_end, content, mode) - offset_start, offset_end, content = self.prepare_nav() - result = self.html_navigation.zenify(offset_start, offset_end, content, mode) + if result: + self.save_selection() + self.prompt(result) + self.restore_selection() - if result: - self.save_selection() - self.prompt(result) - self.restore_selection() + #--- Lorem ipsum ----------------------------------------------------------- - #--- Lorem ipsum ----------------------------------------------------------- + def callback_lorem_ipsum(self, done, cmd, last = False): + self.buffer.begin_user_action() + if done: + self.buffer.undo() + self.restore_selection() + content = lorem_ipsum(cmd) + if content: + self.replace_content(content, self.get_insert_offset()) + self.buffer.end_user_action() + return not not content - def callback_lorem_ipsum(self, done, cmd, last = False): - self.buffer.begin_user_action() - if done: - self.buffer.undo() - self.restore_selection() - content = lorem_ipsum(cmd) - if content: - self.replace_content(content, self.get_insert_offset()) - self.buffer.end_user_action() - return not not content + def lorem_ipsum(self): + self.save_selection() + done, self.last_lorem_ipsum = zen_dialog.main(self, self.window, self.callback_lorem_ipsum, self.last_lorem_ipsum, False) - def lorem_ipsum(self): - self.save_selection() - done, self.last_lorem_ipsum = zen_dialog.main(self, self.window, self.callback_lorem_ipsum, self.last_lorem_ipsum, False) + #--- Select inward or outward ---------------------------------------------- - #--- Select inward or outward ---------------------------------------------- + def match_pair_inward(self): + offset_start, offset_end, content = self.prepare_nav() + offset_start, offset_end = self.html_navigation.inner_bounds(offset_start, offset_end, content) + if not (offset_start is None or offset_end is None): + self.create_selection(offset_start, offset_end) - def match_pair_inward(self): - offset_start, offset_end, content = self.prepare_nav() - offset_start, offset_end = self.html_navigation.inner_bounds(offset_start, offset_end, content) - if not (offset_start is None or offset_end is None): - self.create_selection(offset_start, offset_end) + def match_pair_outward(self): + offset_start, offset_end, content = self.prepare_nav() + offset_start, offset_end = self.html_navigation.outer_bounds(offset_start, offset_end, content) + if not (offset_start is None or offset_end is None): + self.create_selection(offset_start, offset_end) - def match_pair_outward(self): - offset_start, offset_end, content = self.prepare_nav() - offset_start, offset_end = self.html_navigation.outer_bounds(offset_start, offset_end, content) - if not (offset_start is None or offset_end is None): - self.create_selection(offset_start, offset_end) + #--- Tag jumps ------------------------------------------------------------- - #--- Tag jumps ------------------------------------------------------------- - - def new_tag(self, direction): + def new_tag(self, direction): - offset_start, offset_end, content = self.prepare_nav() + offset_start, offset_end, content = self.prepare_nav() - if direction == 'next': - node = self.html_navigation.next_tag(offset_start, offset_end, content) + if direction == 'next': + node = self.html_navigation.next_tag(offset_start, offset_end, content) - else: - node = self.html_navigation.previous_tag(offset_start, offset_end, content) + else: + node = self.html_navigation.previous_tag(offset_start, offset_end, content) - if node: - iter_start = self.buffer.get_iter_at_offset(node.start) - iter_end = self.buffer.get_iter_at_offset(node.end) - self.create_selection(node.start, node.end) - self.show_caret() + if node: + iter_start = self.buffer.get_iter_at_offset(node.start) + iter_end = self.buffer.get_iter_at_offset(node.end) + self.create_selection(node.start, node.end) + self.show_caret() - def prev_tag(self): - self.new_tag('previous') + def prev_tag(self): + self.new_tag('previous') - def next_tag(self): - self.new_tag('next') + def next_tag(self): + self.new_tag('next') - #--- Node jumps ------------------------------------------------------------ + #--- Node jumps ------------------------------------------------------------ - def new_node(self, direction, with_spaces = True): + def new_node(self, direction, with_spaces = True): - offset_start, offset_end, content = self.prepare_nav() + offset_start, offset_end, content = self.prepare_nav() - while True: + while True: - if direction == 'next': - node = self.html_navigation.next_node(offset_start, offset_end, content) + if direction == 'next': + node = self.html_navigation.next_node(offset_start, offset_end, content) - else: - node = self.html_navigation.previous_node(offset_start, offset_end, content) + else: + node = self.html_navigation.previous_node(offset_start, offset_end, content) - if node: + if node: - iter_start = self.buffer.get_iter_at_offset(node.start) - iter_end = self.buffer.get_iter_at_offset(node.end) + iter_start = self.buffer.get_iter_at_offset(node.start) + iter_end = self.buffer.get_iter_at_offset(node.end) - found = self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') - if not with_spaces and found.isspace() and found.find('\n') != -1: - offset_start = node.start - offset_end = node.end + found = self.buffer.get_text(iter_start, iter_end, True).decode('UTF-8') + if not with_spaces and found.isspace() and found.find('\n') != -1: + offset_start = node.start + offset_end = node.end - else: - self.create_selection(node.start, node.end) - break + else: + self.create_selection(node.start, node.end) + break - else: - break + else: + break - self.show_caret() + self.show_caret() - def prev_node(self): - self.new_node('previous') + def prev_node(self): + self.new_node('previous') - def next_node(self): - self.new_node('next') + def next_node(self): + self.new_node('next') - #--- Edit points jumps ----------------------------------------------------- + #--- Edit points jumps ----------------------------------------------------- - def prev_edit_point(self): - result = zen_actions.prev_edit_point(self) - self.show_caret() - return result + def prev_edit_point(self): + result = zen_actions.prev_edit_point(self) + self.show_caret() + return result - def next_edit_point(self): - result = zen_actions.next_edit_point(self) - self.show_caret() - return result + def next_edit_point(self): + result = zen_actions.next_edit_point(self) + self.show_caret() + return result - #--- Image actions --------------------------------------------------------- + #--- Image actions --------------------------------------------------------- - def update_image_size(self): - self.buffer.begin_user_action() - update_image_size(self) - self.buffer.end_user_action() + def update_image_size(self): + self.buffer.begin_user_action() + update_image_size(self) + self.buffer.end_user_action() - def encode_decode_base64(self): - self.buffer.begin_user_action() - try: - zen_actions.encode_decode_base64(self) - except: - pass - self.buffer.end_user_action() + def encode_decode_base64(self): + self.buffer.begin_user_action() + try: + zen_actions.encode_decode_base64(self) + except: + pass + self.buffer.end_user_action() - #--- Other edition actions ------------------------------------------------- + #--- Other edition actions ------------------------------------------------- - def merge_lines(self): - self.buffer.begin_user_action() - zen_actions.merge_lines(self) - self.buffer.end_user_action() + def merge_lines(self): + self.buffer.begin_user_action() + zen_actions.merge_lines(self) + self.buffer.end_user_action() - def remove_tag(self): - self.buffer.begin_user_action() - zen_actions.remove_tag(self) - self.buffer.end_user_action() + def remove_tag(self): + self.buffer.begin_user_action() + zen_actions.remove_tag(self) + self.buffer.end_user_action() - def split_join_tag(self): - self.buffer.begin_user_action() - zen_actions.split_join_tag(self) - self.buffer.end_user_action() + def split_join_tag(self): + self.buffer.begin_user_action() + zen_actions.split_join_tag(self) + self.buffer.end_user_action() - def toggle_comment(self): - self.buffer.begin_user_action() - zen_actions.toggle_comment(self) - self.buffer.end_user_action() + def toggle_comment(self): + self.buffer.begin_user_action() + zen_actions.toggle_comment(self) + self.buffer.end_user_action() From cd5d0fe96dcfbd94f78c52b9a1ec3f42047afcab Mon Sep 17 00:00:00 2001 From: Moises Trovo Date: Sun, 25 Sep 2011 17:07:53 -0300 Subject: [PATCH 4/6] fixed plugin not being listed --- install.sh | 2 +- zencoding.gedit-plugin => zencoding.plugin | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename zencoding.gedit-plugin => zencoding.plugin (100%) diff --git a/install.sh b/install.sh index 96df073..3cd6f48 100755 --- a/install.sh +++ b/install.sh @@ -6,6 +6,6 @@ sudo cp zencoding.png /usr/share/icons/hicolor/16x16/apps sudo gtk-update-icon-cache /usr/share/icons/hicolor > /dev/null 2>&1 mkdir -p ~/.local/share/gedit/plugins/ -cp zencoding.gedit-plugin ~/.local/share/gedit/plugins/ +cp zencoding.plugin ~/.local/share/gedit/plugins/ cp -r zencoding ~/.local/share/gedit/plugins/ diff --git a/zencoding.gedit-plugin b/zencoding.plugin similarity index 100% rename from zencoding.gedit-plugin rename to zencoding.plugin From 09b4be9371d5c3805afbbd0433ce0841caf0366c Mon Sep 17 00:00:00 2001 From: Moises Trovo Date: Sat, 5 Nov 2011 20:32:46 -0200 Subject: [PATCH 5/6] =Updated installation instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be13351..08be360 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This plugin fully integrates [Zen Coding](http://code.google.com/p/zen-coding/) Installation ------------ -1. Download [zip](http://github.com/fmarcia/zen-coding-gedit/zipball/master) or [tar](http://github.com/fmarcia/zen-coding-gedit/tarball/master) source +1. Download [zip](http://github.com/mtrovo/zen-coding-gedit3/zipball/master) or [tar](http://github.com/mtrovo/zen-coding-gedit3/tarball/master) source 2. Unpack it 3. Run `./install.sh` 4. In Gedit, go to Edit > Preferences > Plugins and enable the plugin From cc4b6a3f6e9ecc442c565731fb9256eff4277c09 Mon Sep 17 00:00:00 2001 From: Alexander Blomen Date: Tue, 28 May 2013 11:57:36 +0300 Subject: [PATCH 6/6] Fix for ubuntu 13.04 (gedit 3.6.2 & phyton 2.7.4) Old version threw "RuntimeError: Data access methods are unsupported. Use normal Python attributes instead" errors --- zencoding/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zencoding/__init__.py b/zencoding/__init__.py index ffa3c53..6ce69f5 100644 --- a/zencoding/__init__.py +++ b/zencoding/__init__.py @@ -107,13 +107,13 @@ def __init__(self, window): ('ZenCodingSettingsAction', None, 'E_dit settings...', None, "Customize snippets and abbreviations", self.edit_settings) ] windowdata = dict() - self.window.set_data("ZenCodingPluginDataKey", windowdata) + self.window.ZenCodingPluginDataKey = windowdata windowdata["action_group"] = Gtk.ActionGroup("GeditZenCodingPluginActions") windowdata["action_group"].add_actions(actions) manager = self.window.get_ui_manager() manager.insert_action_group(windowdata["action_group"], -1) windowdata["ui_id"] = manager.add_ui_from_string(zencoding_ui_str) - self.window.set_data("ZenCodingPluginInfo", windowdata) + self.window.ZenCodingPluginInfo = windowdata # zen coding self.modified = None @@ -125,7 +125,7 @@ def deactivate(self): self.editor = None # menu items - windowdata = self.window.get_data("ZenCodingPluginDataKey") + windowdata = self.window.ZenCodingPluginDataKey manager = self.window.get_ui_manager() manager.remove_ui(windowdata["ui_id"]) manager.remove_action_group(windowdata["action_group"]) @@ -137,7 +137,7 @@ def update_ui(self): # disabled if not editable view = self.window.get_active_view() - windowdata = self.window.get_data("ZenCodingPluginDataKey") + windowdata = self.window.ZenCodingPluginDataKey windowdata["action_group"].set_sensitive(bool(view and view.get_editable())) # user settings