def should_escape(context): """ Filter for the 'smart escape' action """ editor = GPS.EditorBuffer.get(force=False, open=False) if editor: if GPS.Action("Cancel completion").can_execute(): return True if aliases.is_in_alias_expansion(editor): return True if editor.has_slave_cursors(): return True current_view = GPS.MDI.current() if current_view and current_view.is_floating(): try: window = current_view.get_child().pywidget().get_toplevel() focus_widget = window.get_focus() # Don't perform smart escape when the focus is on the preferences # editor's search bar. return focus_widget.get_name() != "preferences_editor_search" except Exception: return False return False
def do_something(): """ React to the Esc key, and return True iff something was done. """ editor = GPS.EditorBuffer.get(force=False, open=False) if editor: if aliases.is_in_alias_expansion(editor): aliases.exit_alias_expand(editor) return True if editor.has_slave_cursors(): editor.remove_all_slave_cursors() return True if GPS.Action("Cancel completion").execute_if_possible(): return True c = [c for c in GPS.MDI.children() if (c.is_floating() and c.get_child().__class__ == GPS.GUI)] if c: # Do this rather than c[0].close() to give the toplevel window # a chance to react to delete_event. c[0].get_child().pywidget().get_toplevel().close() return True
def do_something(): """ React to the Esc key, and return True if something was done. """ editor = GPS.EditorBuffer.get(force=False, open=False) if editor: if GPS.Action("Cancel completion").execute_if_possible(): return True if aliases.is_in_alias_expansion(editor): aliases.exit_alias_expand(editor) return True if editor.has_slave_cursors(): editor.remove_all_slave_cursors() return True current_view = GPS.MDI.current() if current_view and current_view.is_floating(): try: window = current_view.get_child().pywidget().get_toplevel() if window.get_transient_for(): current_view.close() else: GPS.MDI.present_main_window() except Exception: return False return True return False
def do_something(): """ React to the Esc key, and return True iff something was done. """ editor = GPS.EditorBuffer.get(force=False, open=False) if editor: if aliases.is_in_alias_expansion(editor): aliases.exit_alias_expand(editor) return True if editor.has_slave_cursors(): editor.remove_all_slave_cursors() return True if GPS.Action("Cancel completion").execute_if_possible(): return True c = [ c for c in GPS.MDI.children() if (c.is_floating() and c.get_child().__class__ == GPS.GUI) ] if c: c[0].close() return True
def smart_tab(): """ This action is the default binding for the tab key, and will apply different behaviors depending on the current context. When expanding aliases, <tab> will move to the next field. Otherwise, when multiple lines are selected it will try to align special sequences like ":", "=>", "use" and ":=". Finally, it will automatically indent the selected lines. """ editor = GPS.EditorBuffer.get() # When expanding aliases, <tab> should move to the next field if aliases.is_in_alias_expansion(editor): aliases.toggle_next_field(editor) return # If multiple lines are selected, perform various alignments if not GPS.Logger("PREVENT_ALIGN_ON_TAB").active: if tabs_align_selection.get(): start = editor.selection_start() end = editor.selection_end() if abs(start.line() - end.line()) >= 1: align.align_colons() align.align_arrows() align.align_use_clauses() align.align_assignments() # if it's a python code, do it in python way if editor.file().language() == "python": d = python_tab_indent(editor, editor.selection_start(), editor.selection_end()) # Otherwise, reformat the current selection else: action = GPS.Action("Autoindent selection") if not action.execute_if_possible(): editor.insert(editor.current_view().cursor(), "\t")
def smart_tab(): """ This action is the default binding for the tab key, and will apply different behaviors depending on the current context. When expanding aliases, <tab> will move to the next field. Otherwise, when multiple lines are selected it will try to align special sequences like ":", "=>", "use" and ":=". Finally, it will automatically indent the selected lines. """ editor = GPS.EditorBuffer.get() # When expanding aliases, <tab> should move to the next field if aliases.is_in_alias_expansion(editor): aliases.toggle_next_field(editor) return # If multiple lines are selected, perform various alignments if not GPS.Logger("GPS.INTERNAL.PREVENT_ALIGN_ON_TAB").active: if tabs_align_selection.get(): start = editor.selection_start() end = editor.selection_end() if abs(start.line() - end.line()) >= 1: align.align_colons() align.align_arrows() align.align_use_clauses() align.align_assignments() # if it's a python code, do it in python way if editor.file().language() == "python": python_tab_indent(editor, editor.selection_start(), editor.selection_end()) # Otherwise, reformat the current selection else: action = GPS.Action("Autoindent selection") if not action.execute_if_possible(): editor.insert(editor.current_view().cursor(), "\t")
def should_escape(context): """ Filter for the 'smart escape' action """ editor = GPS.EditorBuffer.get(force=False, open=False) if editor: if aliases.is_in_alias_expansion(editor): return True if editor.has_slave_cursors(): return True if GPS.Action("Cancel completion").can_execute(): return True if [c for c in GPS.MDI.children() if (c.is_floating() and c.get_child().__class__ == GPS.GUI)]: return True return False
def should_escape(context): """ Filter for the 'smart escape' action """ editor = GPS.EditorBuffer.get(force=False, open=False) if editor: if aliases.is_in_alias_expansion(editor): return True if editor.has_slave_cursors(): return True if GPS.Action("Cancel completion").can_execute(): return True current_view = GPS.MDI.current() if current_view and current_view.is_floating(): return True return False
def smart_tab(): """ This action is the default binding for the tab key, and will apply different behaviors depending on the current context. When expanding aliases, <tab> will move to the next field. Otherwise: - if there is a multi-line selection, the selection will be reformatted; - otherwise, the current line will be reformatted """ editor = GPS.EditorBuffer.get() # When expanding aliases, <tab> will be handled by the aliases package if aliases.is_in_alias_expansion(editor): return # If multiple lines are selected, perform various alignments if not GPS.Logger("GPS.INTERNAL.PREVENT_ALIGN_ON_TAB").active: if tabs_align_selection.get(): start = editor.selection_start() end = editor.selection_end() if abs(start.line() - end.line()) >= 1: align.align_colons() align.align_arrows() align.align_use_clauses() align.align_assignments() # if it's a python code, do it in python way if editor.file().language() == "python": python_tab_indent(editor, editor.selection_start(), editor.selection_end()) # Otherwise, reformat the current selection else: action = GPS.Action("format selection") if not action.execute_if_possible(): editor.insert(editor.current_view().cursor(), "\t")
def should_escape(context): """ Filter for the 'smart escape' action """ editor = GPS.EditorBuffer.get(force=False, open=False) if editor: if aliases.is_in_alias_expansion(editor): return True if editor.has_slave_cursors(): return True if GPS.Action("Cancel completion").can_execute(): return True if [ c for c in GPS.MDI.children() if (c.is_floating() and c.get_child().__class__ == GPS.GUI) ]: return True return False