Skip to content

Commit

Permalink
Merge pull request sublimehq#63 from misfo/linewise-changes-reindent
Browse files Browse the repository at this point in the history
Linewise changes reindent if 'auto_indent' is set
  • Loading branch information
Sublime HQ Pty Ltd committed Feb 18, 2012
2 parents 0913362 + 20ec6b2 commit ed9ccff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,8 @@
// Motions to allow double press to mean entire line

{ "keys": ["c"], "command": "set_motion", "args": {
"motion": "expand_selection",
"motion_args": {"to": "line_without_eol" }},
"motion": "vi_dont_move",
"linewise": true},
"context":
[
{"key": "setting.command_mode"},
Expand Down Expand Up @@ -778,8 +778,8 @@
{ "keys": ["S"], "command": "set_action_motion", "args": {
"action": "enter_insert_mode",
"action_args": {"insert_command": "vi_delete"},
"motion": "expand_selection",
"motion_args": {"to": "line_without_eol" }},
"motion": "vi_dont_move",
"motion_linewise": true},
"context": [{"key": "setting.command_mode"}]
},

Expand Down
11 changes: 9 additions & 2 deletions vintage.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def run_(self, args):
return self.run(**args)

def run(self, motion, action, motion_args = {}, motion_clip_to_line = False,
motion_inclusive = False, action_args = {}):
motion_inclusive = False, motion_linewise = False, action_args = {}):

global g_input_state

Expand All @@ -326,6 +326,8 @@ def run(self, motion, action, motion_args = {}, motion_clip_to_line = False,
g_input_state.motion_clip_to_line = motion_clip_to_line
g_input_state.action_command = action
g_input_state.action_command_args = action_args
if motion_linewise:
g_input_state.motion_mode = MOTION_MODE_LINE

eval_input(self.view)

Expand Down Expand Up @@ -593,6 +595,8 @@ def run(self, edit, action_command, action_args,
if motion_mode != MOTION_MODE_LINE and action_command and motion_clip_to_line:
transform_selection_regions(self.view, lambda r: self.view.split_by_newlines(r)[0])

reindent = False

if motion_mode == MOTION_MODE_LINE:
expand_to_full_line(self.view, visual_mode)
if action_command == "enter_insert_mode":
Expand All @@ -601,10 +605,13 @@ def run(self, edit, action_command, action_args,
# newline out of the selection to allow for this.
transform_selection_regions(self.view,
lambda r: sublime.Region(r.begin(), r.end() - 1))
reindent = True

if action_command:
# Apply the action to the selection
self.view.run_command(action_command, action_args)
if reindent and self.view.settings().get('auto_indent'):
self.view.run_command('reindent')

if not visual_mode:
# Shrink the selection down to a point
Expand Down Expand Up @@ -907,7 +914,7 @@ def run(self, edit, character):
self.view.sel().add(s)

if created_new_line and self.view.settings().get('auto_indent'):
self.view.window().run_command('reindent')
self.view.run_command('reindent')

class CenterOnCursor(sublime_plugin.TextCommand):
def run(self, edit):
Expand Down
4 changes: 4 additions & 0 deletions vintage_motions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from vintage import transform_selection
from vintage import transform_selection_regions

class ViDontMove(sublime_plugin.TextCommand):
def run(self, edit):
pass

class ViMoveByCharactersInLine(sublime_plugin.TextCommand):
def run(self, edit, forward = True, extend = False, visual = False):
delta = 1 if forward else -1
Expand Down

0 comments on commit ed9ccff

Please sign in to comment.