【问题标题】:A visual studio macro to format code comma first首先格式化代码逗号的视觉工作室宏
【发布时间】:2016-10-03 14:53:37
【问题描述】:

我正在尝试使用 Visual Studio 宏编辑器

https://visualstudiogallery.msdn.microsoft.com/d3fbf133-e51b-41a2-b86f-9560a96ff62b

它允许用户在 javascript 中编写宏来驱动 IDE。我想做的是编写一个格式化文本的宏

public void Foo(
int i,
int b,
int c)

public void Foo
( int i
, int b
, int c
)   

如果我只知道执行以下操作的命令,这应该很简单。

(1) Move the cursor to the next matching character, and detect if it is not found
(2) Insert a carriage return
(3) Join lines together

我已经做到了

dte.ExecuteCommand("Edit.Find");
dte.Find.FindWhat = ",";

但希望有人比我更了解他们的 DTE 命令。

【问题讨论】:

    标签: visual-studio macros


    【解决方案1】:

    (1) 将光标移动到下一个匹配的字符处,检测是否找不到:

    DTE.Find.FindWhat = ",";
    DTE.Find.Target = EnvDTE.vsFindTarget.vsFindTargetCurrentDocument;
    if (DTE.Find.Execute() == EnvDTE.vsFindResult.vsFindResultNotFound)
    {
    // not found
    }
    

    (2)插入回车:

    DTE.ExecuteCommand("Edit.BreakLine");
    

    (3) 将线条连接在一起:

    Edit.DeleteBackwardsEdit.Delete 可以在从行首或行尾调用时删除换行符。

    (注意:这是来自我的 Visual Commander 扩展的语法,但也适用于 Visual Studio 宏编辑器。)

    【讨论】:

      猜你喜欢
      • 2020-06-14
      • 2018-07-05
      • 2015-07-10
      • 1970-01-01
      • 2017-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多