def exit_alias_expand(editor): """ Exit alias expansion. """ global aliases_editor_filename aliases_editor_filename = None editor.remove_all_slave_cursors() reset_overlay(editor) editor.remove_overlay( editor.aliases_background_overlay, editor.alias_begin_mark.location().beginning_of_line(), editor.alias_end_mark.location() ) editor.remove_overlay( editor.aliases_overlay_next, editor.alias_begin_mark.location().beginning_of_line(), editor.alias_end_mark.location() ) editor.current_alias_mark_index = None editor.alias_marks = [] editor.alias_end_mark = None editor.alias_begin_mark = None Hook("location_changed").remove(on_move) Hook("mdi_child_selected").remove(on_mdi_child_change)
def exit_alias_expand(editor): """ Exit alias expansion. """ editor.remove_all_slave_cursors() reset_overlay(editor) editor.remove_overlay( editor.aliases_background_overlay, editor.alias_begin_mark.location().beginning_of_line(), editor.alias_end_mark.location()) editor.remove_overlay(editor.aliases_background_overlay_1, editor.beginning_of_buffer(), editor.end_of_buffer()) editor.current_alias_mark_index = None editor.alias_marks = None editor.alias_end_mark = None editor.alias_begin_mark = None Hook("character_added").remove(on_edit) Hook("location_changed").remove(on_move)
def search_next(self, input, cursor_pos, redo_overlays): """Same as a on_changed, but doesn't change case sensitivity""" if redo_overlays: self.remove_overlays() Isearch.last_search = input # Special case for backward search: if the current location matches, # no need to do anything else. This is so that when the user keeps # adding characters to the pattern, we correctly highlight them at # the current location if self.backward: result = self.loc.search(input, regexp=self.regexp, case_sensitive=self.case_sensitive, dialog_on_failure=False, backward=False) if result and result[0] == self.loc: self.set_background(bg_color_pref.get()) (match_from, match_to) = result self.end_loc = match_to self.highlight_match() self.insert_overlays() return result = self.loc.search(input, regexp=self.regexp, case_sensitive=self.case_sensitive, dialog_on_failure=False, backward=self.backward) if result: self.set_background(bg_color_pref.get()) (self.loc, self.end_loc) = result self.highlight_match() if redo_overlays: self.insert_overlays() else: # If the last entry in the stack was a match, add a new one if self.stack != [] and self.stack[-1][3]: self.stack.append((self.loc, self.end_loc, self.read(), 0)) # Loop around, so that next search matches if self.backward: self.loc = self.loc.buffer().end_of_buffer() else: self.loc = self.loc.buffer().beginning_of_buffer() self.end_loc = self.loc self.set_background(bg_error_pref.get()) Hook('stop_macro_action_hook').run()
def register_module(hook): """Activate this local history module if RCS is found on the path""" if has_RCS_on_path(): Hook("file_saved").add(on_file_saved, last=True) Contextual("Local History/Revert to").create_dynamic( factory=contextual_factory, on_activate=on_revert, label="Local History//Revert to", filter=contextual_filter) Contextual("Local History/Diff").create_dynamic( factory=contextual_factory, on_activate=on_diff, label="Local History//Diff", filter=contextual_filter) Contextual("Local History/Show Patch").create_dynamic( factory=contextual_factory, on_activate=on_patch, label="Local History//Show Patch", filter=contextual_filter) Contextual("Local History View").create( on_activate=on_view_all, label="Local History//View", filter=contextual_filter)
def register_module(hook): """Activate this local history module if RCS is found on the path""" if has_RCS_on_path(): Hook("file_saved").add(on_file_saved, last=True) Contextual("Local History Revert to").create_dynamic( factory=contextual_factory, on_activate=on_revert, label="Local History/Revert To", filter=contextual_filter) Contextual("Local History Diff").create_dynamic( factory=contextual_factory, on_activate=on_diff, label="Local History/Diff", filter=contextual_filter) Contextual("Local History Patch").create_dynamic( factory=contextual_factory, on_activate=on_patch, label="Local History/Show Patch", filter=contextual_filter) gs_utils.make_interactive(callback=on_view_all, filter=contextual_filter, contextual='Local History/View')
def add_breakpoint_exception(): context = current_context() global autocont_br # Only consider base names of files, since the debugger does not always # show the full name in the "frame" command f = "%s:%s" % (os.path.basename( context.file().path), context.location().line()) if f in autocont_br: autocont_br.remove(f) else: autocont_br.add(f) if Preference("Plugins/debugger/save_autocont_br").get(): Project.root().set_property("autocont_br", "--".join(autocont_br), True) def on_project_view_changed(h): global autocont_br try: autocont_br = set( Project.root().get_property("autocont_br").split("--")) Console().write( "The debugger will not stop when an exception is raised at " + "\n".join(autocont_br)) except: autocont_br = set() Hook("debugger_process_stopped").add(on_debugger_stopped) Hook("project_view_changed").add(on_project_view_changed)
count = count - 1 @staticmethod def do_delete_line(arg, loc, maxloc): loc = loc.beginning_of_line() maxloc = maxloc.end_of_line() loc.buffer().delete(loc, maxloc) loc.buffer().current_view().goto(loc) @staticmethod def repeat_command(loc=None): """Repeat the last command that was executed, in Editor""" if not loc: loc = EditorBuffer.get().current_view().cursor() buffer = loc.buffer() (cmd, loc, maxloc) = CmdLine.get_scope(CmdLine.history[0], loc, buffer) with buffer.new_undo_group(): if cmd[0] == "s": CmdLine.do_replace(cmd[1:], loc, maxloc) elif cmd[0] == "d": CmdLine.do_delete_line(cmd[1:], loc, maxloc) def on_cancel(self, input): """The user has cancelled the search""" pass Hook("gps_started").add(on_gps_started)
def expand_alias(editor, alias, from_lsp=False): """ Expand given alias in the given editor buffer at the point where the cursor is. The given alias can be either a :class:`GPS.Alias` instance or a LSP completion snippet passed as a string (when `from_lsp` is True). """ # Remove the hook functions if any since we don't want to add them # several times when dealing with nested alias expansions. Hook("location_changed").remove(on_move) Hook("mdi_child_selected").remove(on_mdi_child_change) Hook("location_changed").add(on_move) Hook("mdi_child_selected").add(on_mdi_child_change) expansion = alias if from_lsp else alias.get_expanded() text_chunks = (lsp_subst_pattern.split(expansion) if from_lsp else subst_pattern.split(expansion)) # The pattern used to recognize where the last mark (i.e: final tab stop) # should be placed last_mark_pattern = "$0" if from_lsp else "%_" # Get the parameter substitutions via the appropriate regexp. # The "${<number>:" at the beginning and the '}' at the end # are removed from the LSP parameter substitutions # through the 's[4:-1] if not s[1:2].isalpha()' list comprehension # condition. if from_lsp: substs = [s[4:-1] if not s[1:2].isdigit() else s for s in lsp_subst_pattern.findall(expansion)] else: substs = subst_pattern.findall(expansion) # Don't do anything if we did not find any parameter substitutions # in the LSP snippet if from_lsp and not substs: return global aliases_editor_filename aliases_editor_filename = editor.file().path if not hasattr(editor, "alias_marks"): editor.alias_marks = [] editor.alias_begin_mark = None substs_offset_dict = OrderedDict() substs_marks_dict = OrderedDict() editor.aliases_overlay = editor.create_overlay("aliases_overlay") editor.aliases_overlay.set_property( "background", get_current_field_bg_color() ) color, color1 = get_paragraph_color() editor.aliases_background_overlay = editor.create_overlay( "aliases_background_overlay" ) editor.aliases_background_overlay.set_property( "paragraph-background", color ) editor.aliases_overlay_next = editor.create_overlay( "aliases_overlay_next" ) c1, c2 = get_comments_colors() editor.aliases_overlay_next.set_property("foreground", c1) if c2: editor.aliases_overlay_next.set_property("background", "#124") # Create a mark with right gravity so it will stay at the end of what we # have inserted, giving us the current insert point new_alias_begin_mark = editor.current_view().cursor().create_mark() new_alias_end_mark = editor.current_view().cursor().create_mark( left_gravity=False) new_last_alias_mark = None new_last_alias_mark_idx = -1 insert_mark = new_alias_end_mark insert_loc = insert_mark.location() text_to_insert = "" idx = 0 new_alias_marks = [] # Construct the text to insert by appending the text chunks and the # substitutions that have been found for text, subst in izip_longest(text_chunks, substs): text_to_insert += text # If we find final tab stop, get its index in the string to insert # to create the corresponding mark once the text is inserted if subst and subst == last_mark_pattern: new_last_alias_mark_idx = len(text_to_insert.decode("utf-8")) elif subst: default_value = ("" if from_lsp else alias.get_default_value(strip_alias(subst))) value = (default_value if default_value else strip_alias(subst, from_lsp)) subst_offset_start = len(text_to_insert) text_to_insert += value subst_offset_end = len(text_to_insert) if subst in substs_offset_dict: substs_offset_dict[subst].append( (subst_offset_start, subst_offset_end)) else: substs_offset_dict[subst] = [(subst_offset_start, subst_offset_end)] editor.insert(insert_loc, text_to_insert) if new_last_alias_mark_idx != -1: new_last_alias_mark = insert_loc.forward_char( new_last_alias_mark_idx).create_mark() for k in substs_offset_dict: substs_marks_dict[k] = [(insert_loc.forward_char(s).create_mark(), insert_loc.forward_char(e).create_mark( left_gravity=False)) for (s, e) in substs_offset_dict[k]] new_alias_marks = list(substs_marks_dict.values()) for marks_list in new_alias_marks: for mark_start, mark_end in marks_list: apply_overlay( editor, mark_start, mark_end, editor.aliases_overlay_next ) # If we are dealing with a nested alias expansions, append the new alias # marks to the existing ones and don't override the alias begin/end # marks. if len(editor.alias_marks) > 0: editor.alias_marks = new_alias_marks + \ editor.alias_marks[editor.current_alias_mark_index:] else: editor.alias_marks = new_alias_marks editor.last_alias_mark = new_last_alias_mark editor.alias_begin_mark = new_alias_begin_mark editor.alias_end_mark = new_alias_end_mark editor.current_alias_mark_index = 0 editor.alias_move_expected = True editor.alias_move_expected = False toggle_field(editor=editor, backward=False, first=True)
hist.view_all(context.revisions, context.revisions_menu) def register_module(hook): """Activate this local history module if RCS is found on the path""" if has_RCS_on_path(): Hook("file_saved").add(on_file_saved, last=True) Contextual("Local History/Revert to").create_dynamic( factory=contextual_factory, on_activate=on_revert, label="Local History//Revert to", filter=contextual_filter) Contextual("Local History/Diff").create_dynamic( factory=contextual_factory, on_activate=on_diff, label="Local History//Diff", filter=contextual_filter) Contextual("Local History/Show Patch").create_dynamic( factory=contextual_factory, on_activate=on_patch, label="Local History//Show Patch", filter=contextual_filter) Contextual("Local History View").create( on_activate=on_view_all, label="Local History//View", filter=contextual_filter) Hook("gps_started").add(register_module)
def expand_alias(editor, alias): """ Expand given alias in the given editor buffer at the point where the cursor is. """ text_chunks = subst_pattern.split(alias.expansion) substs = [ s[2:-1] if s != "%_" else s for s in subst_pattern.findall(alias.expansion) ] alias_labels = defaultdict(list) editor.aliases_overlay = editor.create_overlay("aliases_overlay") editor.aliases_overlay.set_property("background", get_current_field_bg_color()) color, color1 = get_paragraph_color() editor.aliases_background_overlay_1 = editor.create_overlay( "aliases_background_overlay_1") editor.aliases_background_overlay_1.set_property("paragraph-background", color1) editor.aliases_background_overlay = editor.create_overlay( "aliases_background_overlay") editor.aliases_background_overlay.set_property("paragraph-background", color) editor.aliases_overlay_next = editor.create_overlay("aliases_overlay_next") c1, c2 = get_comments_colors() editor.aliases_overlay_next.set_property("foreground", c1) if c2: editor.aliases_overlay_next.set_property("background", "#124") # Create a mark with right gravity so it will stay at the end of what we # have inserted, giving us the current insert point editor.alias_begin_mark = editor.current_view().cursor().create_mark() editor.alias_end_mark = editor.current_view().cursor().create_mark( left_gravity=False) insert_mark = editor.alias_end_mark for text, subst in izip_longest(text_chunks, substs): editor.insert(insert_mark.location(), text) if subst: alias_labels[subst].append(insert_mark.location().create_mark()) editor.alias_marks = [] substs_set = set() for subst in substs: if subst not in substs_set and subst != "%_": editor.alias_marks.append([ (m, m.location().create_mark(left_gravity=False)) for m in alias_labels[subst] ]) for m in alias_labels[subst]: editor.insert(m.location(), "<{0}>".format(subst)) substs_set.add(subst) for marks_list in editor.alias_marks: for mark_start, mark_end in marks_list: apply_overlay(editor, mark_start, mark_end, editor.aliases_overlay_next) if "%_" in alias_labels: editor.last_alias_mark = alias_labels["%_"][0] else: editor.last_alias_mark = None editor.current_alias_mark_index = 0 Hook("character_added").add(on_edit) Hook("location_changed").add(on_move) editor.indent(editor.alias_begin_mark.location(), editor.alias_end_mark.location()) toggle_next_field(editor)
def __init__(self): self.targets = [] Hook("compute_build_targets").add(self.on_compute_build_targets)
# This script changes the label of the project view and set it to the current # project file path. Upon a project changed, the title is properly updated. from GPS import Project, MDI, Timeout, Hook def update_project_view_title(t): new_name = Project.root().file().name() new_short_name = Project.root().name() view = MDI.get("Project View") if view is not None: view.rename(new_name, new_short_name) t.remove() def on_project_changed(h): Timeout(100, update_project_view_title) Hook("project_changed").add(on_project_changed)
def expand_alias(editor, alias, from_lsp=False): """ Expand given alias in the given editor buffer at the point where the cursor is. The given alias can be either a :class:`GPS.Alias` instance or a LSP completion snippet passed as a string (when `from_lsp` is True). """ expansion = alias if from_lsp else alias.get_expanded() text_chunks = (lsp_subst_pattern.split(expansion) if from_lsp else subst_pattern.split(expansion)) # Get the parameter substitutions via the appropriate regexp. # The "${<number>:" at the beginning and the '}' at the end # are removed from the LSP parameter substitutions # through the 's[4:-1] if not s[1:2].isalpha()' list comprehension # condition. if from_lsp: substs = [ s[4:-1] if not s[1:2].isdigit() else s for s in lsp_subst_pattern.findall(expansion) ] else: substs = [ s[2:-1] if s != "%_" else s for s in subst_pattern.findall(expansion) ] # Don't do anything if we did not find any parameter substitutions # in the LSP snippet if from_lsp and not substs: return alias_labels = defaultdict(list) editor.aliases_overlay = editor.create_overlay("aliases_overlay") editor.aliases_overlay.set_property("background", get_current_field_bg_color()) color, color1 = get_paragraph_color() editor.aliases_background_overlay_1 = editor.create_overlay( "aliases_background_overlay_1") editor.aliases_background_overlay_1.set_property("paragraph-background", color1) editor.aliases_background_overlay = editor.create_overlay( "aliases_background_overlay") editor.aliases_background_overlay.set_property("paragraph-background", color) editor.aliases_overlay_next = editor.create_overlay("aliases_overlay_next") c1, c2 = get_comments_colors() editor.aliases_overlay_next.set_property("foreground", c1) if c2: editor.aliases_overlay_next.set_property("background", "#124") # Create a mark with right gravity so it will stay at the end of what we # have inserted, giving us the current insert point editor.alias_begin_mark = editor.current_view().cursor().create_mark() editor.alias_end_mark = editor.current_view().cursor().create_mark( left_gravity=False) insert_mark = editor.alias_end_mark for text, subst in izip_longest(text_chunks, substs): editor.insert(insert_mark.location(), text) if subst: alias_labels[subst].append(insert_mark.location().create_mark()) editor.alias_marks = [] substs_set = set() for subst in substs: if subst not in substs_set and (subst != "%_" and subst != "$0"): editor.alias_marks.append([ (m, m.location().create_mark(left_gravity=False)) for m in alias_labels[subst] ]) default_value = "" if from_lsp else alias.get_default_value(subst) value = default_value if default_value else "<{0}>".format(subst) for m in alias_labels[subst]: editor.insert(m.location(), value) substs_set.add(subst) for marks_list in editor.alias_marks: for mark_start, mark_end in marks_list: apply_overlay(editor, mark_start, mark_end, editor.aliases_overlay_next) # Check for the final tab stop to set the last mark if from_lsp and "$0" in alias_labels: editor.last_alias_mark = alias_labels["$0"][0] elif "%_" in alias_labels: editor.last_alias_mark = alias_labels["%_"][0] else: editor.last_alias_mark = None editor.current_alias_mark_index = 0 Hook("character_added").add(on_edit) Hook("location_changed").add(on_move) editor.indent(editor.alias_begin_mark.location(), editor.alias_end_mark.location()) toggle_next_field(editor)
return # Query the Locations View for a list of visual differences for the source locations = Locations.list_locations("Visual differences", basename) prev = "" # Find out which is the "enclosing" program/package. loc = buffer.at(buffer.lines_count() - 1, 1) global_proc = loc.subprogram_name() i = 0 while i < len(locations) / 2: loc = buffer.at(locations[2 * i].line(), locations[2 * i].column()) prog = loc.subprogram_name() # If there are multiple changes within the same subprogram, display # the subprogram only once if (prog != prev) and (prog != global_proc): log.insert(log.end_of_buffer(), "(" + prog + "): \n") prev = prog i = i + 1 # Jump to the end of the first line log.current_view().goto(log.at(1, 1).end_of_line()) Hook("file_edited").add(on_file_edited)