MCPcopy Index your code
hub / github.com/bpython/bpython / insert_char_pair_start

Method insert_char_pair_start

bpython/curtsiesfrontend/repl.py:833–860  ·  view source on GitHub ↗

Accepts character which is a part of CHARACTER_PAIR_MAP like brackets and quotes, and appends it to the line with an appropriate character pair ending. Closing character can only be inserted when the next character is either a closing character or a space e.x. if you

(self, e)

Source from the content-addressed store, hash-verified

831 )
832
833 def insert_char_pair_start(self, e):
834 """Accepts character which is a part of CHARACTER_PAIR_MAP
835 like brackets and quotes, and appends it to the line with
836 an appropriate character pair ending. Closing character can only be inserted
837 when the next character is either a closing character or a space
838
839 e.x. if you type "(" (lparen) , this will insert "()"
840 into the line
841 """
842 self.add_normal_character(e)
843 if self.config.brackets_completion:
844 start_of_line = len(self._current_line) == 1
845 end_of_line = len(self._current_line) == self._cursor_offset
846 can_lookup_next = len(self._current_line) > self._cursor_offset
847 next_char = (
848 None
849 if not can_lookup_next
850 else self._current_line[self._cursor_offset]
851 )
852 if (
853 start_of_line
854 or end_of_line
855 or (next_char is not None and next_char in "})] ")
856 ):
857 self.add_normal_character(
858 CHARACTER_PAIR_MAP[e], narrow_search=False
859 )
860 self._cursor_offset -= 1
861
862 def insert_char_pair_end(self, e):
863 """Accepts character which is a part of CHARACTER_PAIR_MAP

Callers 1

process_key_eventMethod · 0.95

Calls 1

add_normal_characterMethod · 0.95

Tested by

no test coverage detected