eye.helpers.quote_surround module

Module for surrounding selected text with quotes or other chars.

When enabled, in an editor, if some text is selected and a quote character is typed, the selected text will be surrounded with the quote character instead of being replaced by the character. It can also surround with parentheses and other characters.

Using the raw trySurroundSelectionEvent and trySurroundSelection helpers, it’s possible to implement different surrounding mappings depending on the edited file type.

eye.helpers.quote_surround.BASE_SURROUND_MAPPING = {'"': '"%s"', "'": "'%s'", '(': '(%s)', '<': '<%s>', '[': '[%s]', '`': '`%s`', '{': '{%s}'}

Default surround mapping.

A surround mapping should have the same format: a dict mapping characters to a template string using ‘%’-formatting. If a char is not present in such a table, no surrounding will be performed and it will simply replace the selected text.

eye.helpers.quote_surround.auto_surround_selection(editor, event)[source]

Event-filter performing default char surrounding.

Calls try_surround_selection_event and uses BASE_SURROUND_MAPPING as mapping table. If surrounding was performed, the event is filtered so it’s not caught by the editor widget.

This handler is disabled by default.

This handler is registered as event filter for categories ['editor'] with event types [<Mock object at 0x7f3088166ed0>].

eye.helpers.quote_surround.set_enabled(b)[source]

Enables auto_surround_selection.

eye.helpers.quote_surround.try_surround_selection(editor, char, map_table)[source]

Try to do char-surrounding using a mapping table.

Will not do any surrounding if a keyboard modifier key (e.g. Ctrl) is in pressed state. If the editor has multiple selections, each selection will be surrounded separately.

Parameters:
  • editor (eye.widgets.editor.Editor) – editor where to try to do surrounding

  • char (str) – the character to do the surrounding

  • map_table (dict[str, str]) – mapping table listing chars and their replacement

Returns:

True if a char surrounding was performed, else False. The value can be used for returning from an event filter function.

Return type:

bool

eye.helpers.quote_surround.try_surround_selection_event(editor, event, map_table)[source]

Try to do char-surrounding using a mapping table.

Will not do any surrounding if a keyboard modifier key (e.g. Ctrl) is in pressed state. If the editor has multiple selections, each selection will be surrounded separately. Calls trySurroundSelection.

Parameters:
  • editor (eye.widgets.editor.Editor) – editor where to try to do surrounding

  • event (QKeyEvent) – typing event containing the char to do the surrounding

  • map_table (dict[str, str]) – mapping table listing chars and their replacement

Returns:

True if a char surrounding was performed, else False. The value can be used for returning from an event filter function.

Return type:

bool