Skip to content

Commit 3233844

Browse files
committed
Implement Kill Paredit command #9
1 parent 3529212 commit 3233844

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

paredit.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,19 @@ def comment_dwim(view, edit):
327327
line = view.line(region.begin())
328328
n = view.insert(edit, line.end(), ' ; ')
329329
sel.append(line.end() + n)
330+
331+
332+
def kill(view, edit):
333+
for region, _ in iterate(view):
334+
# What should kill do with a non-empty selection?
335+
point = region.begin()
336+
337+
innermost = sexp.innermost(view, point, edge=True)
338+
339+
# Cursive only deletes until newline, we delete the contents of the sexp regardless of
340+
# newlines. Not sure which is right, but this is easier to implement and makes more sense
341+
# to me.
342+
if point == innermost.open.begin() or point == innermost.close.end():
343+
view.erase(edit, innermost.extent())
344+
elif point == innermost.open.end() or point == innermost.close.begin():
345+
view.erase(edit, sublime.Region(innermost.open.end(), innermost.close.begin()))

tests/test_paredit.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,30 @@ def test_comment_dwim(self):
511511
self.set_selections((4, 4))
512512
self.view.run_command('tutkain_paredit_comment_dwim')
513513
self.assertEquals('(a b ; \n c)', self.view_content())
514+
515+
def test_kill(self):
516+
self.set_view_content('(a b c)')
517+
self.set_selections((0, 0))
518+
self.view.run_command('tutkain_paredit_kill')
519+
self.assertEquals('', self.view_content())
520+
521+
self.set_view_content('(a b c)')
522+
self.set_selections((1, 1))
523+
self.view.run_command('tutkain_paredit_kill')
524+
self.assertEquals('()', self.view_content())
525+
526+
self.set_view_content('(a b c)')
527+
self.set_selections((7, 7))
528+
self.view.run_command('tutkain_paredit_kill')
529+
self.assertEquals('', self.view_content())
530+
531+
self.set_view_content('(foo "bar baz" quux)')
532+
self.set_selections((6, 6))
533+
self.view.run_command('tutkain_paredit_kill')
534+
self.assertEquals('(foo "" quux)', self.view_content())
535+
536+
self.set_view_content('(a b c) (d e f)')
537+
self.set_selections((1, 1), (9, 9))
538+
self.view.run_command('tutkain_paredit_kill')
539+
self.assertEquals('() ()', self.view_content())
540+
self.assertEquals([(1, 1), (4, 4)], self.selections())

tutkain.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@ def run(self, edit):
603603
paredit.comment_dwim(self.view, edit)
604604

605605

606+
class TutkainPareditKillCommand(sublime_plugin.TextCommand):
607+
def run(self, edit):
608+
paredit.kill(self.view, edit)
609+
610+
606611
class TutkainCycleCollectionTypeCommand(sublime_plugin.TextCommand):
607612
def run(self, edit):
608613
sexp.cycle_collection_type(self.view, edit)

0 commit comments

Comments
 (0)