Skip to content

Brackets completion #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Nov 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4603a22
basic parentheses and quote closing on key events
samuelgregorovic Oct 6, 2021
594a468
basic pair deletion for common pairs
samuelgregorovic Oct 6, 2021
691def4
jump behind closing paren/quote on TAB
samuelgregorovic Oct 6, 2021
ee98f16
jump on tab even with content in parens
samuelgregorovic Oct 30, 2021
a59daed
move cursor on closing paren ovrwrite
samuelgregorovic Oct 30, 2021
9206403
removed quotes completion + fixed bad cursor bug
samuelgregorovic Oct 30, 2021
82a32e6
nested tabbing/ovewriting brackets working
samuelgregorovic Oct 30, 2021
e00f87b
fixed backspace event when cursor on closing paren
samuelgregorovic Oct 30, 2021
a902deb
added quote completion + autocomplete compatibility
samuelgregorovic Oct 30, 2021
c11b5fc
added cmd argument + update manpage help
samuelgregorovic Oct 30, 2021
a55830c
added config option + updated sample config
samuelgregorovic Oct 30, 2021
49c98df
obey config option + docstrings
samuelgregorovic Oct 30, 2021
aa321b1
update and document on_tab method
samuelgregorovic Oct 30, 2021
05dc36d
added comment
samuelgregorovic Oct 30, 2021
dc9d176
removed cmd argument
samuelgregorovic Oct 30, 2021
a34140a
removed unnecessary __class__ call + fix bad function call
samuelgregorovic Nov 2, 2021
5d302a5
removed unnecessary manpage entry
samuelgregorovic Nov 2, 2021
192663c
moved CHARACTER_PAIR_MAP to __init__ + 0 index fix
samuelgregorovic Nov 2, 2021
66c317b
moved cursor_on_closing_char_pair to line.py
samuelgregorovic Nov 2, 2021
a23843b
moved CHARACTER_PAIR_MAP to line.py
samuelgregorovic Nov 2, 2021
41750bf
fix overwriting quotes
samuelgregorovic Nov 2, 2021
6138b7a
fix autoclose quotes bug
samuelgregorovic Nov 2, 2021
8be9bbb
autocomplete enabled only before closing params or space
samuelgregorovic Nov 2, 2021
73782de
fix matching history entries
samuelgregorovic Nov 2, 2021
f3f03e2
basic tests without history
samuelgregorovic Nov 3, 2021
81bc622
added quote test
samuelgregorovic Nov 3, 2021
f33cf55
renamed add_to_search to narrow_search
samuelgregorovic Nov 3, 2021
66d34cf
changed default config value to False
samuelgregorovic Nov 3, 2021
d14207d
fixed test DRY problem with helper method
samuelgregorovic Nov 3, 2021
100735d
fixed insert_char_pair_start docstring
samuelgregorovic Nov 3, 2021
2c683fc
fix bad behavior of reverse-incremental search
samuelgregorovic Nov 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update and document on_tab method
  • Loading branch information
samuelgregorovic committed Oct 30, 2021
commit aa321b1dcde313a48ba314c8fe0af7bf47e0cd4a
39 changes: 23 additions & 16 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def process_key_event(self, e):
self.add_normal_character(e)

def insert_char_pair_start(self, e):
"""Accepts character which is a part of CHARACTER_PAIRS
"""Accepts character which is a part of PAIR_CHAR_MAP
like brackets and quotes, and appends it to the line with
an appropriate pair end

Expand All @@ -813,7 +813,7 @@ def insert_char_pair_start(self, e):
self.cursor_offset -= 1

def insert_char_pair_end(self, e):
"""Accepts character which is a part of CHARACTER_PAIRS
"""Accepts character which is a part of PAIR_CHAR_MAP
like brackets and quotes, and checks whether it should be
inserted to the line or overwritten

Expand Down Expand Up @@ -943,10 +943,12 @@ def only_whitespace_left_of_cursor():
if self.matches_iter.is_cseq():
cursor_and_line = self.matches_iter.substitute_cseq()
self._cursor_offset, self._current_line = cursor_and_line
if self.is_completion_callable(self._current_line):
self._current_line = self.append_closing_bracket(
self._current_line
)
if self.config.brackets_completion:
# appends closing char pair if completion is a callable
if self.is_completion_callable(self._current_line):
self._current_line = self.append_closing_bracket(
self._current_line
)
# using _current_line so we don't trigger a completion reset
if not self.matches_iter.matches:
self.list_win_visible = self.complete()
Expand All @@ -956,22 +958,27 @@ def only_whitespace_left_of_cursor():
)
cursor_and_line = self.matches_iter.cur_line()
self._cursor_offset, self._current_line = cursor_and_line
if self.is_completion_callable(self._current_line):
self._current_line = self.append_closing_bracket(
self._current_line
)
if self.config.brackets_completion:
# appends closing char pair if completion is a callable
if self.is_completion_callable(self._current_line):
self._current_line = self.append_closing_character(
self._current_line
)
# using _current_line so we don't trigger a completion reset
self.list_win_visible = True

def is_completion_callable(self, completion):
closing_char_map = {"(": ")", "{": "}", "[": "]", "'": "'", '"': '"'}
"""Checks whether given completion is callable (e.x. function)"""
completion_end = completion[-1]
return completion_end in closing_char_map
return completion_end in self.__class__.PAIR_CHAR_MAP

def append_closing_bracket(self, completion):
closing_char_map = {"(": ")", "{": "}", "[": "]", "'": "'", '"': '"'}
if completion[-1] in closing_char_map:
completion = f"{completion}{closing_char_map[completion[-1]]}"
def append_closing_character(self, completion):
"""Appends closing character/bracket to the completion"""
completion_end = completion[-1]
if completion_end in self.__class__.PAIR_CHAR_MAP:
completion = (
f"{completion}{self.__class__.PAIR_CHAR_MAP[completion_end]}"
)
return completion

def on_control_d(self):
Expand Down