Skip to content

Commit

Permalink
Add Visual bell styles #502
Browse files Browse the repository at this point in the history
Close #502
  • Loading branch information
gerardroche committed Apr 17, 2019
1 parent 1ea6047 commit 82ded30
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 100 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt

### Added

* Added [#502](https://github.com/NeoVintageous/NeoVintageous/issues/502): Visual bell styles
* Added [#500](https://github.com/NeoVintageous/NeoVintageous/issues/500): `-` in Visual line mode
* Added [#492](https://github.com/NeoVintageous/NeoVintageous/issues/492): `(` and `)` in Visual line mode
* Added [#499](https://github.com/NeoVintageous/NeoVintageous/issues/499): `<CR>` in Visual line mode
Expand Down
7 changes: 6 additions & 1 deletion Preferences.sublime-settings
Expand Up @@ -107,5 +107,10 @@

// Propagate copy actions to the system clipboard.
// {not in Vim}
"vintageous_use_sys_clipboard": false
"vintageous_use_sys_clipboard": false,

// Visual bell type.
// Valid values are: blink, view, or views.
// {not in Vim}
"vintageous_bell": "blink"
}
78 changes: 39 additions & 39 deletions nv/commands.py
Expand Up @@ -56,7 +56,7 @@
from NeoVintageous.nv.mappings import mappings_resolve
from NeoVintageous.nv.state import init_state
from NeoVintageous.nv.state import State
from NeoVintageous.nv.ui import ui_blink
from NeoVintageous.nv.ui import ui_bell
from NeoVintageous.nv.ui import ui_cmdline_prompt
from NeoVintageous.nv.ui import ui_highlight_yank
from NeoVintageous.nv.ui import ui_highlight_yank_clear
Expand Down Expand Up @@ -387,20 +387,20 @@ def _next_history(self, edit, backwards):
if count == 0:
_nv_cmdline_feed_key.LAST_HISTORY_ITEM_INDEX = None

return ui_blink()
return ui_bell()

if abs(_nv_cmdline_feed_key.LAST_HISTORY_ITEM_INDEX) > count:
_nv_cmdline_feed_key.LAST_HISTORY_ITEM_INDEX = -count

return ui_blink()
return ui_bell()

if _nv_cmdline_feed_key.LAST_HISTORY_ITEM_INDEX >= 0:
_nv_cmdline_feed_key.LAST_HISTORY_ITEM_INDEX = 0

if self.view.size() > 1:
return self.view.erase(edit, Region(1, self.view.size()))
else:
return ui_blink()
return ui_bell()

if self.view.size() > 1:
self.view.erase(edit, Region(1, self.view.size()))
Expand Down Expand Up @@ -627,7 +627,7 @@ def _handle_missing_command(self, state, command):
state.mode = NORMAL

state.reset_command_data()
ui_blink()
ui_bell()

return True

Expand Down Expand Up @@ -741,7 +741,7 @@ def run(self, keys, repeat_count=None, check_user_mappings=True):

if motion_data is None:
state.reset_command_data()
ui_blink()
ui_bell()
return

self.window.run_command(motion_data['motion'], motion_data['motion_args'])
Expand Down Expand Up @@ -773,7 +773,7 @@ def collect_input(self):

except IndexError:
_log.debug('could not find a command to collect more user input')
ui_blink()
ui_bell()
finally:
self.state.non_interactive = False

Expand Down Expand Up @@ -915,7 +915,7 @@ def f(view, s):
if self.has_sel_changed():
regions_transformer(self.view, f)
else:
ui_blink()
ui_bell()
else:
regions_transformer(self.view, f)

Expand All @@ -940,7 +940,7 @@ def f(view, s):
if self.has_sel_changed():
regions_transformer(self.view, f)
else:
ui_blink()
ui_bell()
else:
regions_transformer(self.view, f)

Expand Down Expand Up @@ -997,7 +997,7 @@ def shrink(view, s):
for s in self.old_sel:
self.view.sel().add(s.begin())
else:
ui_blink()
ui_bell()

enter_normal_mode(self.view, mode)

Expand Down Expand Up @@ -1029,7 +1029,7 @@ def run(self, count=1, **kwargs):
self.view.run_command('redo')

if self.view.change_count() == change_count_before:
return ui_blink()
return ui_bell()

# Fix EOL issue.
# See https://github.com/SublimeTextIssues/Core/issues/2121.
Expand Down Expand Up @@ -1357,7 +1357,7 @@ def f(view, s):
return Region(s.a, s.b)
else:
if s.empty() and (s.b == self.view.size()):
ui_blink()
ui_bell()

return s

Expand Down Expand Up @@ -1396,7 +1396,7 @@ def run(self, edit, mode=None, force=False):

# Abort if we are at EOF -- no newline char to hold on to.
if any(s.b == self.view.size() for s in self.view.sel()):
return ui_blink()
return ui_bell()

self.view.run_command('_enter_visual_line_mode_impl', {'mode': mode})
state.enter_visual_line_mode()
Expand Down Expand Up @@ -1450,7 +1450,7 @@ def run(self, mode=None, count=None, repeat_data=None):
state.mode = NORMAL

if repeat_data is None:
ui_blink()
ui_bell()
return

# TODO: Find out if the user actually meant '1'.
Expand All @@ -1464,9 +1464,9 @@ def run(self, mode=None, count=None, repeat_data=None):
state.restore_visual_data(visual_data)
elif not visual_data and (mode == VISUAL):
# Can't repeat normal mode commands in visual mode.
return ui_blink()
return ui_bell()
elif mode not in (VISUAL, VISUAL_LINE, NORMAL, INTERNAL_NORMAL, INSERT):
return ui_blink()
return ui_bell()

if type_ == 'vi':
self.window.run_command('_nv_process_notation', {'keys': seq_or_cmd, 'repeat_count': count})
Expand Down Expand Up @@ -1580,7 +1580,7 @@ def restore():

if mode not in (INTERNAL_NORMAL, VISUAL):
enter_normal_mode(self.view, mode)
ui_blink()
ui_bell()
return

self.save_sel()
Expand Down Expand Up @@ -1637,12 +1637,12 @@ def run(self, edit, count=1, mode=None, motion=None, register=None):

if not self.has_sel_changed():
enter_normal_mode(self.view, mode)
ui_blink()
ui_bell()
return

if all(s.empty() for s in self.view.sel()):
enter_normal_mode(self.view, mode)
ui_blink()
ui_bell()
return

self.state.registers.op_delete(register=register, linewise=(mode == VISUAL_LINE))
Expand Down Expand Up @@ -1934,7 +1934,7 @@ def select(view, s):

if mode not in (VISUAL, VISUAL_LINE, VISUAL_BLOCK, INTERNAL_NORMAL):
enter_normal_mode(self.view, mode)
ui_blink()
ui_bell()
return

self.save_sel()
Expand All @@ -1960,7 +1960,7 @@ def select(view, s):

if mode not in (VISUAL, VISUAL_LINE, VISUAL_BLOCK, INTERNAL_NORMAL):
enter_normal_mode(self.view, mode)
ui_blink()
ui_bell()
return

if mode == INTERNAL_NORMAL and all(self.view.line(s.b).empty() for s in self.view.sel()):
Expand Down Expand Up @@ -2111,7 +2111,7 @@ def indent_from_begin(view, s, level=1):
if motion:
self.view.run_command(motion['motion'], motion['motion_args'])
elif mode not in (VISUAL, VISUAL_LINE):
return ui_blink()
return ui_bell()

for i in range(count):
self.view.run_command('indent')
Expand All @@ -2134,7 +2134,7 @@ def f(view, s):
if motion:
self.view.run_command(motion['motion'], motion['motion_args'])
elif mode not in (VISUAL, VISUAL_LINE):
return ui_blink()
return ui_bell()

for i in range(count):
self.view.run_command('unindent')
Expand All @@ -2152,7 +2152,7 @@ def f(view, s):
if motion:
self.view.run_command(motion['motion'], motion['motion_args'])
elif mode not in (VISUAL, VISUAL_LINE):
return ui_blink()
return ui_bell()

self.view.run_command('reindent', {'force_indent': False})

Expand Down Expand Up @@ -2589,7 +2589,7 @@ def run(self, edit, count=1, mode=None, subtract=False):
pts = self.find_next_num(regs)

if not pts:
return ui_blink()
return ui_bell()

end_sels = []
count = count if not subtract else -count
Expand Down Expand Up @@ -2828,14 +2828,14 @@ def run(self, name=None, mode=None, count=1):
return

if name not in tuple('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"'):
return ui_blink("E354: Invalid register name: '" + name + "'")
return ui_bell("E354: Invalid register name: '" + name + "'")

state.start_recording()
self.__class__._current = name
except (AttributeError, ValueError):
state.stop_recording()
self.__class__._current = None
ui_blink()
ui_bell()


class _vi_at(IrreversibleTextCommand):
Expand All @@ -2844,20 +2844,20 @@ class _vi_at(IrreversibleTextCommand):

def run(self, name, mode=None, count=1):
if name not in tuple('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".=*+@'):
return ui_blink("E354: Invalid register name: '" + name + "'")
return ui_bell("E354: Invalid register name: '" + name + "'")

if name == '@':
name = self._last_used
if not name:
return ui_blink('E748: No previously used register')
return ui_bell('E748: No previously used register')

try:
cmds = State.macro_registers[name]
except (KeyError, ValueError):
return ui_blink()
return ui_bell()

if not cmds:
ui_blink()
ui_bell()
return

self.__class__._last_used = name
Expand Down Expand Up @@ -2899,7 +2899,7 @@ def f(view, s):

if self.view.line(first.end() - 1).empty():
enter_normal_mode(self.view, mode)
ui_blink()
ui_bell()
return

self.view.sel().clear()
Expand Down Expand Up @@ -3015,7 +3015,7 @@ def f(view, s):
self.view.run_command(motion['motion'], motion['motion_args'])

if not self.has_sel_changed():
ui_blink()
ui_bell()
enter_normal_mode(self.view, mode)
return

Expand Down Expand Up @@ -3119,7 +3119,7 @@ def run(self, mode=None, count=1):
self.state.display_status()
return

ui_blink()
ui_bell()
status_message('no available search matches')
self.state.reset_command_data()

Expand Down Expand Up @@ -3147,7 +3147,7 @@ def run(self, edit, mode=None, register='"'):
raise ValueError('wrong mode')

if (len(self.view.sel()) > 1 or not self.view.sel()[0].empty()):
return ui_blink()
return ui_bell()

s = self.view.sel()[0]
line_begin = self.view.text_point(row_at(self.view, s.b), 0)
Expand All @@ -3160,7 +3160,7 @@ def run(self, edit, mode=None, register='"'):
state.reset_command_data()
return

ui_blink()
ui_bell()

def show_matches(self, items):
self.view.window().show_quick_panel(items, self.replace, MONOSPACE_FONT)
Expand Down Expand Up @@ -4575,7 +4575,7 @@ def f(view, s):
number_of_scroll_lines = count if count >= 1 else get_option_scroll(self.view)
scroll_target_pt = get_scroll_up_target_pt(self.view, number_of_scroll_lines)
if scroll_target_pt is None:
return ui_blink()
return ui_bell()

regions_transformer(self.view, f)
if not self.view.visible_region().contains(0):
Expand All @@ -4600,7 +4600,7 @@ def f(view, s):
number_of_scroll_lines = count if count >= 1 else get_option_scroll(self.view)
scroll_target_pt = get_scroll_down_target_pt(self.view, number_of_scroll_lines)
if scroll_target_pt is None:
return ui_blink()
return ui_bell()

regions_transformer(self.view, f)
if not self.view.visible_region().contains(self.view.size()):
Expand Down Expand Up @@ -5102,7 +5102,7 @@ def advance(view, s):
return Region(min(row_start + mid_pt, line.b - 1))

if mode != NORMAL:
return ui_blink()
return ui_bell()

regions_transformer(self.view, advance)

Expand Down
12 changes: 6 additions & 6 deletions nv/ex_cmds.py
Expand Up @@ -46,7 +46,7 @@
from NeoVintageous.nv.mappings import mappings_add
from NeoVintageous.nv.mappings import mappings_remove
from NeoVintageous.nv.state import State
from NeoVintageous.nv.ui import ui_blink
from NeoVintageous.nv.ui import ui_bell
from NeoVintageous.nv.vi.search import find_all_in_range
from NeoVintageous.nv.vi.settings import get_cmdline_cwd
from NeoVintageous.nv.vi.settings import set_cmdline_cwd
Expand Down Expand Up @@ -1232,12 +1232,12 @@ def ex_wq(window, view, forceit=False, **kwargs):

def ex_wqall(window, **kwargs):
if not all(view.file_name() for view in window.views()):
ui_blink()
ui_bell()

return status_message("E32: No file name")

if any(view.is_read_only() for view in window.views()):
ui_blink()
ui_bell()

return status_message("E45: 'readonly' option is set (add ! to override)")

Expand Down Expand Up @@ -1334,12 +1334,12 @@ def _do_write(window, view, file_name, forceit, line_range):

if not forceit:
if os.path.exists(fname):
ui_blink()
ui_bell()

return status_message("E13: File exists (add ! to override)")

if _check_is_readonly(fname):
ui_blink()
ui_bell()

return status_message("E45: 'readonly' option is set (add ! to override)")

Expand Down Expand Up @@ -1373,7 +1373,7 @@ def _do_write(window, view, file_name, forceit, line_range):
read_only = (_check_is_readonly(view.file_name()) or view.is_read_only())

if read_only and not forceit:
ui_blink()
ui_bell()

return status_message("E45: 'readonly' option is set (add ! to override)")

Expand Down

0 comments on commit 82ded30

Please sign in to comment.