From 5431ea062a463c5b3390a2691b3ec92f6c73a270 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Tue, 27 May 2014 17:18:54 -0700 Subject: [PATCH] Implement emacs-style join_lines --- Default.sublime-keymap | 1 + jove.py | 25 +++++++++++++++++++++++++ sbp.sublime-commands | 1 + 3 files changed, 27 insertions(+) diff --git a/Default.sublime-keymap b/Default.sublime-keymap index 8a0c1ac..6d455c3 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -40,6 +40,7 @@ {"keys": ["ctrl+l"], "command": "sbp_center_view"}, {"keys": ["ctrl+x", "g"], "command": "sbp_goto_line"}, {"keys": ["alt+g"], "command": "sbp_goto_line"}, + {"keys": ["super+shift+6"], "command": "sbp_join_lines"}, // Goto open file {"keys": ["ctrl+x", "ctrl+f"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} }, diff --git a/jove.py b/jove.py index ca7e4cf..8f45284 100644 --- a/jove.py +++ b/jove.py @@ -1319,6 +1319,31 @@ def run_cmd(self, util): view.insert(util.edit, point.b, "\n") view.run_command("move", {"by": "characters", "forward": False}) +class SbpJoinLinesCommand(SbpTextCommand): + def run_cmd(self, util): + if util.state.argument_supplied: + forward = True + else: + forward = False + view = self.view + + def join(cursor): + if not forward: + current_line = view.line(cursor) + view.run_command("move", {"by": "lines", "forward": False}) + cursor = view.sel()[0] + if view.line(cursor) == current_line: + # must be on the first line; do nothing + return None + else: + # Move to end-of-line + current_line = view.line(cursor) + cursor = sublime.Region(current_line.b, current_line.b) + view.run_command("join_lines") + return view.sel()[0] + + util.for_each_cursor(join) + class SbpKillRegionCommand(SbpTextCommand): is_kill_cmd = True def run_cmd(self, util, is_copy=False): diff --git a/sbp.sublime-commands b/sbp.sublime-commands index edd3c36..0799048 100644 --- a/sbp.sublime-commands +++ b/sbp.sublime-commands @@ -17,6 +17,7 @@ {"caption": "Sublemacs - Go to Line", "command": "sbp_goto_line"}, {"caption": "Sublemacs - Open line", "command": "sbp_open_line"}, + {"caption": "Sublemacs - Join Lines", "command": "sbp_join_lines"}, {"caption": "Sublemacs - Center View Around Point", "command": "sbp_center_view"}, //