首页 > 解决方案 > 崇高文本中的循环和测试

问题描述

我习惯于在 Ultraedit 中创建宏以将注释组织在某个列中,例如第 90 列。为此,我创建了一个宏来搜索行尾,如果存在则清除结尾空格并将空格添加到行尾直到它到达第 90 列。我找不到 Sublime 文本的任何参考:如何检查光标位置,
如何检查光标位置上的字符,如何创建循环。这个想法是创建一个宏做类似的事情

go to the end of line
while the column is not the first {
  return one character
  if the character under cursor is space or tab {
    delete the character
  }
  else {
    break
  }
}
if column is before or on column 90 { 
  while the column is before 90 {
    insert space 
  } 
  insert "//" 
}

标签: loopsconditional-statementssublimetext3

解决方案


这种逻辑在使用Sublime API编写的Python插件中可用。特别是,您将子类化. Package Control中有数千个包,其中许多是插件,您可以查看这些包作为示例。前面的文档链接也很有帮助。您可以在此处、Sublime Text 论坛Discord 服务器上获得有关特定问题的帮助。Youtube 上也有很多视频 -特别是OdatNurd 的频道很棒。sublime_plugin.TextCommand


推荐阅读