Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Avoid migrating setting when already migrated
  Update default settings
  Update docs
  Refactor cleanup
  Fix gu, gU, and gq assigned modes
  Refactor goto line arg order
  Remove deprecated mixin get view method
  Refactor exceptions and other cs cleanup
  Remove stale TODO, FIXME, ...
  Refactor imports
  Refactor commands
  Refactor commands
  Refactor commands
  • Loading branch information
gerardroche committed Mar 5, 2019
2 parents d230e9b + c7811e9 commit 407d8a0
Show file tree
Hide file tree
Showing 38 changed files with 5,418 additions and 5,582 deletions.
646 changes: 0 additions & 646 deletions nv/cmds.py

This file was deleted.

2,470 changes: 0 additions & 2,470 deletions nv/cmds_vi_actions.py

This file was deleted.

2,347 changes: 0 additions & 2,347 deletions nv/cmds_vi_motions.py

This file was deleted.

5,348 changes: 5,348 additions & 0 deletions nv/commands.py

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions nv/ex_cmds.py
Expand Up @@ -1348,12 +1348,10 @@ def _do_write(window, view, file_name, forceit, line_range):
text = view.substr(region)
f.write(text)

# FIXME: Does this do what we think it does?
view.retarget(expanded_path)
window.run_command('save')

except IOError:
# TODO: Add logging.
return status_message("E212: Can't open file for writing: {}".format(fname))

return _do_write(window, view, file_name, forceit, line_range)
Expand Down Expand Up @@ -1396,7 +1394,7 @@ def _default_ex_cmd(window, view, line_range, **kwargs):
state = State(view)
enter_normal_mode(window, state.mode)
state.enter_normal_mode()
goto_line(view, line, state.mode)
goto_line(view, state.mode, line)


def _get_ex_cmd(name):
Expand Down
6 changes: 3 additions & 3 deletions nv/goto.py
Expand Up @@ -61,9 +61,9 @@ def goto_help(window):
do_ex_command(window, 'help', {'subject': subject})


def goto_line(view, line, mode):
line = line if line > 0 else 1
dest = view.text_point(line - 1, 0)
def goto_line(view, mode, line_number):
line_number = line_number if line_number > 0 else 1
dest = view.text_point(line_number - 1, 0)

def f(view, s):
if mode == NORMAL:
Expand Down
3 changes: 1 addition & 2 deletions nv/state.py
Expand Up @@ -670,7 +670,7 @@ def set_command(self, command):
# ValueError: If too many motions.
# ValueError: If too many actions.
# ValueError: Unexpected command type.
assert isinstance(command, ViCommandDefBase), 'ViCommandDefBase expected, got {}'.format(type(command)) # FIXME # noqa: E501
assert isinstance(command, ViCommandDefBase), 'ViCommandDefBase expected, got {}'.format(type(command))

is_runnable = self.runnable()

Expand Down Expand Up @@ -906,7 +906,6 @@ def init_state(view):
#
# Args:
# :view (sublime.View):

if not is_view(view):
# Abort if we got a console, widget, panel...
try:
Expand Down
9 changes: 3 additions & 6 deletions nv/vi/cmd_defs.py
Expand Up @@ -33,8 +33,8 @@
from NeoVintageous.nv.vim import VISUAL_LINE


_MODES_MOTION = (NORMAL, OPERATOR_PENDING, VISUAL, VISUAL_LINE, VISUAL_BLOCK)
_MODES_ACTION = (NORMAL, VISUAL, VISUAL_LINE, VISUAL_BLOCK)
_MODES_MOTION = (NORMAL, OPERATOR_PENDING, VISUAL, VISUAL_LINE, VISUAL_BLOCK)


@keys.assign(seq=seqs.D, modes=_MODES_ACTION)
Expand Down Expand Up @@ -677,7 +677,6 @@ def translate(self, state):
}


# FIXME: Doesn't work.
@keys.assign(seq=seqs.G_BIG_J, modes=_MODES_ACTION)
class ViJoinLinesNoSeparator(ViOperatorDef):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -3065,10 +3064,8 @@ def translate(self, state):
# Non-standard modes:
@keys.assign(seq=seqs.CTRL_DOT, modes=_MODES_MOTION)
@keys.assign(seq=seqs.CTRL_SHIFT_DOT, modes=_MODES_MOTION)
# XXX: This is called a 'submode' in the vim docs:
@keys.assign(seq=seqs.CTRL_X, modes=(INSERT,))
# TODO This should not be a motion.
class ViOpenNameSpace(ViMotionDef):
@keys.assign(seq=seqs.CTRL_X, modes=(INSERT,)) # This is called a 'submode' in the vim docs.
class ViOpenNameSpace(ViMotionDef): # TODO This should not be a motion.
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
22 changes: 4 additions & 18 deletions nv/vi/core.py
Expand Up @@ -22,35 +22,21 @@

class ViCommandMixin:

# DEPRECATED
def _get_view(self):
view = None
try:
view = self.view
except AttributeError:
try:
view = self.window.active_view()
except AttributeError:
raise AttributeError(
'ViCommandMixin must be used with a TextCommand or a WindowCommand class')
return view

@property
def state(self):
return State(self._get_view())
return State(self.view)

def save_sel(self):
self.old_sel = tuple(self._get_view().sel())
self.old_sel = tuple(self.view.sel())

def _is_equal_to_old_sel(self, new_sel):
try:
return (tuple((s.a, s.b) for s in self.old_sel) ==
tuple((s.a, s.b) for s in tuple(self._get_view().sel())))
return (tuple((s.a, s.b) for s in self.old_sel) == tuple((s.a, s.b) for s in tuple(self.view.sel())))
except AttributeError:
raise AttributeError('have you forgotten to call .save_sel()?')

def has_sel_changed(self):
return not self._is_equal_to_old_sel(self._get_view().sel())
return not self._is_equal_to_old_sel(self.view.sel())


class IrreversibleTextCommand(sublime_plugin.TextCommand):
Expand Down
1 change: 0 additions & 1 deletion nv/vi/keys.py
Expand Up @@ -147,7 +147,6 @@ class key_names:
max_len = len('<leader>')


# TODO: detect counts, registers, marks...
class KeySequenceTokenizer(object):
"""Takes in a sequence of key names and tokenizes it."""

Expand Down
6 changes: 2 additions & 4 deletions nv/vi/macros.py
Expand Up @@ -25,13 +25,11 @@ def __init__(self, *args, **kwargs):
def __setitem__(self, key, value):
if key in ('%', '#'):
raise ValueError('invalid register key: %s' % key)
# TODO further restrict valid register names.
# TODO implement a vs A register.

super().__setitem__(key.lower(), value)

def __getitem__(self, key):
if key in ('%', '#'):
raise ValueError('unsupported key: %s' % key)
# TODO further restrict valid register names.
# TODO implement a vs A register.

return super().__getitem__(key.lower())
5 changes: 2 additions & 3 deletions nv/vi/text_objects.py
Expand Up @@ -662,13 +662,13 @@ def find_indent_text_object(view, s, inclusive=True):
break_on_empty_lines = True

if pattern:
pattern = re.compile(pattern)
compiled_pattern = re.compile(pattern)

def should_break_on_line(line_content):
if break_on_empty_lines and not line_content.strip():
return True

return "pattern_match" if pattern.match(line_content) else False
return "pattern_match" if compiled_pattern.match(line_content) else False
else:
def should_break_on_line(line_content):
return not line_content.strip()
Expand Down Expand Up @@ -707,7 +707,6 @@ def should_break_on_line(line_content):


def find_line_text_object(view, s):
"""Implement the line object."""
line = view.line(s)
line_content = view.substr(line)

Expand Down
4 changes: 1 addition & 3 deletions nv/vi/units.py
Expand Up @@ -17,13 +17,13 @@

import re

from sublime import Region
from sublime import CLASS_LINE_END
from sublime import CLASS_LINE_START
from sublime import CLASS_PUNCTUATION_END
from sublime import CLASS_PUNCTUATION_START
from sublime import CLASS_WORD_END
from sublime import CLASS_WORD_START
from sublime import Region

from NeoVintageous.nv.vi.utils import last_row
from NeoVintageous.nv.vi.utils import next_non_white_space_char
Expand All @@ -45,7 +45,6 @@ def at_eol(view, pt):


def at_punctuation(view, pt):
# FIXME Not very reliable?
is_at_eol = at_eol(view, pt)
is_at_word = at_word(view, pt)
is_white_space = view.substr(pt).isspace()
Expand Down Expand Up @@ -184,7 +183,6 @@ def word_ends(view, start, count=1, big=False):
else:
pt = next_word_end(view, pt)

# FIXME We should return the actual word end and not pt - 1 ??
return pt


Expand Down
49 changes: 20 additions & 29 deletions nv/vi/utils.py
Expand Up @@ -29,20 +29,16 @@ def has_dirty_buffers(window):
return False


# Useful for external plugins to disable NeoVintageous for specific views.
def is_ignored(view):
# type: (...) -> bool

# Useful for external plugins to disable NeoVintageous for specific views.

return view.settings().get('__vi_external_disable', False)


# Useful for third party plugins to disable vim emulation for specific views.
# Differs from is_ignored() in that only keys should be disabled.
def is_ignored_but_command_mode(view):
# type: (...) -> bool

# Useful for third party plugins to disable vim emulation for specific
# views. Differs from is_ignored() in that only keys should be disabled.

return view.settings().get('__vi_external_disable_keys', False)


Expand Down Expand Up @@ -109,54 +105,47 @@ def regions_transformer_reversed(view, f):
_regions_transformer(sels, view, f, False)


# Return the insertion point closest to region.b for a visual region. For
# non-visual regions, the insertion point is always any of the region's ends, so
# using this function is pointless.
def resolve_insertion_point_at_b(region):
# type: (Region) -> int

# Return the insertion point closest to region.b for a visual region. For
# non-visual regions, the insertion point is always any of the region's
# ends, so using this function is pointless.

if region.a < region.b:
return (region.b - 1)

return region.b


# Return the actual insertion point closest to region.a for a visual region. For
# non-visual regions, the insertion point is always any of the region's ends, so
# using this function is pointless.
def resolve_insertion_point_at_a(region):
# type: (Region) -> int

# Return the actual insertion point closest to region.a for a visual region.
# For non-visual regions, the insertion point is always any of the region's
# ends, so using this function is pointless.

if region.size() == 0:
raise TypeError('not a visual region')

if region.a < region.b:
return region.a
elif region.b < region.a:
return region.a - 1
else:
raise TypeError('not a visual region')


# TODO [review] this function looks unused; it was refactored from an obsolete module.
@contextmanager
def restoring_sels(view):
old_sels = list(view.sel())

yield

# TODO REVIEW Possible race-condition? If the buffer has changed.
view.sel().clear()
for s in old_sels:

# TODO [review] Race-condition? If the buffer has changed in the
# meantime, this won't work well.

view.sel().add(s)


# Save selection. Used, for example, by the gv command.
# Save selection, but only if it's not empty.
def save_previous_selection(view, mode):
# type: (...) -> None
if view.has_non_empty_selection_region():
# Only save a selection if it's not empty.
view.add_regions('visual_sel', list(view.sel()))
view.settings().set('_nv_visual_sel_mode', mode)

Expand All @@ -173,11 +162,9 @@ def show_if_not_visible(view):
view.show(pt)


# Create a region that includes the char at a or b depending on orientation.
def new_inclusive_region(a, b):
# type: (int, int) -> Region

# Create a region that includes the char at a or b depending on orientation.

if a <= b:
return Region(a, b + 1)
else:
Expand All @@ -202,7 +189,9 @@ def row_to_pt(view, row, col=0):
def gluing_undo_groups(view, state):
state.processing_notation = True
view.run_command('mark_undo_groups_for_gluing')

yield

view.run_command('glue_marked_undo_groups')
state.processing_notation = False

Expand Down Expand Up @@ -379,5 +368,7 @@ def resize_visual_region(r, b):
@contextmanager
def adding_regions(view, name, regions, scope_name):
view.add_regions(name, regions, scope_name)

yield

view.erase_regions(name)
16 changes: 12 additions & 4 deletions plugin.py
Expand Up @@ -62,10 +62,7 @@
_startup_exception = None

# Commands.
# TODO Organise all commands into a single module (i.e. .nv.cmds).
from NeoVintageous.nv.cmds import * # noqa: F401,F403
from NeoVintageous.nv.cmds_vi_actions import * # noqa: F401,F403
from NeoVintageous.nv.cmds_vi_motions import * # noqa: F401,F403
from NeoVintageous.nv.commands import * # noqa: F401,F403

# Plugins.
from NeoVintageous.nv.plugin_abolish import * # noqa: F401,F403
Expand Down Expand Up @@ -120,6 +117,17 @@ def plugin_loaded():
sublime.log_input(True)
sublime.log_commands(True)

# Some setting defaults are changing! To avoid impacting users in a later
# update, this patch sets the current value to whatever is currently used.
# See Roadmap: https://github.com/NeoVintageous/NeoVintageous/issues/404.
preferences = sublime.load_settings('Preferences.sublime-settings')
build_version = preferences.get('neovintageous_build_version', 0) # type: int
if not build_version or int(build_version) < 11000:
preferences.set('neovintageous_build_version', 11000)
preferences.set('vintageous_use_ctrl_keys', preferences.get('vintageous_use_ctrl_keys'))
preferences.set('vintageous_use_super_keys', preferences.get('vintageous_use_super_keys'))
sublime.save_settings('Preferences.sublime-settings')

loading_exeption = None

pc_event = None
Expand Down

0 comments on commit 407d8a0

Please sign in to comment.