[TxMt] Re: Emulating keyboard activity with commands

Steven Arnold thoth_amon at mac.com
Wed Oct 3 02:59:07 UTC 2012


Here is my hackish way of deleting a line from a file.  It seems like overkill.  Anyone got a better approach?

#!/usr/bin/env ruby -wKU
linenum = ENV['TM_LINE_NUMBER'].to_i
lines = STDIN.readlines
output = []
lines.each_with_index do |line, idx|
  if idx+1 != linenum
    output << line
  end
end
print output.join

You have to select the document as input, replace document as output, and use line interpolation as caret placement.  It only works if there is no selection.

steven

On Oct 2, 2012, at 9:20 PM, Steven Arnold <thoth_amon at mac.com> wrote:

> Hi Tim,
> 
> On Oct 2, 2012, at 7:56 PM, Timothy Bates <timothy.c.bates at gmail.com> wrote:
> 
>> If the \n preceding a line is in the selection, then a command setting the selection to "" will erase the newline.
> 
> This is a clever idea, but I am not sure how to increase the selection from the current line to the current line plus one character.  Do you have a code sample for that, or can you point me toward some resources that might document how that sort of thing can be done?
> 
>> Macro recording will be great when it comes (I'm actually waiting till TMs internal states like dynamic selections can be played with in bundle commands and snippets).
> 
> Definitely.  Editors like jEdit translate macros into a program.  I like that idea.  Everything that can be done in a macro is essentially translatable to a series of commands.
> 
>> If the example really is simply "do what backspace does when a line and the preceeding feed are selected", then that comes built-in and bound to backspace :-)
> 
> But I don't know how to make that happen in an automated way.  Are you saying just hit the backspace key manually each time?  I grant that's not much work, but it's annoying.
> 
> Regards,
> steven



More information about the textmate mailing list