简体   繁体   English

在 Ruby 中编程 TextMate。 TextMate.go_to 的问题

[英]Programming TextMate in Ruby. Problem with TextMate.go_to

I'm modding a TextMate bundle even though I'm a complete beginner at Ruby.即使我是 Ruby 的初学者,我也在修改 TextMate 包。 The problem I'm trying to solve is the issue of moving the caret to a certain positition after the command has made its output.我要解决的问题是在命令使其 output 之后将插入符号移动到某个位置的问题。

Basically what happens is this: I hit a key combo which triggers a command to filter through the document and inserts text at the relevant places, then exits with replacing the document with the new filtered text.基本上发生的事情是这样的:我点击了一个组合键,它触发了一个命令来过滤文档并在相关位置插入文本,然后用新的过滤文本替换文档退出。

What I want to happen next is for the caret to move back to where it originally was.我接下来想要发生的事情是让插入符号移回原来的位置。 I was pretty happy when I found the TextMate.go_to function, but I can only get it partly to work.当我找到 TextMate.go_to function 时,我非常高兴,但我只能让它部分工作。 The function: function:

positionY = ENV['TM_LINE_NUMBER']
positionX = ENV['TM_LINE_INDEX']
...
TextMate.go_to :line => positionY, :column => positionX; #column no worky

I can get the caret to the right line, but the column parameter isn't working.我可以将插入符号移到正确的行,但 column 参数不起作用。 I've tried shifting them about and even doing the function with just the column param, but no luck.我试过改变它们,甚至只用列参数做 function,但没有运气。 I've also tried with a hard coded integer, but the positionX param prints the correct line index, so I doubt there's anything there.我也尝试过使用硬编码的 integer,但是 positionX 参数打印了正确的行索引,所以我怀疑那里有什么东西。

This is the only documentation I've found on this method, but I took a look in the textmate.rb and to my untrained eyes it seems I'm using it properly. 是我在此方法上找到的唯一文档,但我查看了 textmate.rb 并且在我未经训练的眼睛看来,我正在正确使用它。

I know this can be achieved by macros, but I want to avoid that if possible.我知道这可以通过宏来实现,但我想尽可能避免这种情况。 I also know that you can use markers if you choose "Insert as snippet" but then I'd have to clear the document first, and I haven't really figured out how to do this either without using the "Replace document" option.我也知道,如果您选择“插入为片段”,则可以使用标记,但是我必须先清除文档,而且我还没有真正弄清楚如何在不使用“替换文档”选项的情况下执行此操作。 Anyone?任何人?

Let's look at the source code of the bindings:让我们看一下绑定的源代码:

def go_to(options = {})
  default_line = options.has_key?(:file) ? 1 : ENV['TM_LINE_NUMBER']
  options = {:file => ENV['TM_FILEPATH'], :line => default_line, :column => 1}.merge(options)
  if options[:file]
    `open "txmt://open?url=file://#{e_url options[:file]}&line=#{options[:line]}&column=#{options[:column]}"`
  else
    `open "txmt://open?line=#{options[:line]}&column=#{options[:column]}"`
  end
end

Rather hackishly, the binding sets up a txmt:// URL and calls open on it in the shell.相当骇人听闻的是,绑定设置了一个 txmt://URL 并在 shell 中调用 open 。

So the first thing to do would be constructing an open URL and typing it into Terminal/your browser to see if TextMate is respecting the column parameter.因此,首先要做的是构建一个开放的 URL 并将其输入终端/浏览器以查看 TextMate 是否尊重列参数。 If that works then perhaps there is a bug in your version's implementation of Textmate.go_to.如果这样可行,那么您的版本的 Textmate.go_to 实现中可能存在错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM