Eclipse C++编辑CDT插件, 不再使用Alt+/快捷键补全


安装好**Eclipse C++**后, 需要按alt+/按钮才能显示自动补全的下拉框,很不方便.所以有了这篇文章的产生, 本篇章适合C/C++工程, java工程就不需要这么麻烦了.

第一步:下载安装CDT插件

依次点击菜单:Help->Install New Software,在弹出的窗口中点击如下下拉框,选择CDT-http…,然后点击Next进行安装.
在这里插入图片描述
在这里插入图片描述

第二步:下载安装plugin-ins插件

与第一步类似,点击菜单点击菜单:Help->Install New Software,在弹出的对话框中做如下选择.
在这里插入图片描述

第三步:导入CDT插件源码

打开 window->show view,选择others。然后选择plug-in Development 下的plug-ins,再点击Open按钮。在弹出的在plugin-ins串口找到 org.eclipse.cdt.ui ,右键单击,选择import as -> source project,导入之后在你的 workspace就可以看到这个插件工程。
在这里插入图片描述

第四步修改CDT插件源码

找到org.eclipse.cdt.ui/src/org.eclipse.cdt.internal.ui.text.contentassist/ContentAssistProcessor.java
修改public void setCompletionProposalAutoActivationCharacters(char[] activationSet)

public void setCompletionProposalAutoActivationCharacters(char[] activationSet) {
        //fCompletionAutoActivationCharacters= activationSet;
        String test = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        char[] triggers = test.toCharArray();
        fCompletionAutoActivationCharacters = triggers;
    }

找到
/org.eclipse.cdt.ui/src/org.eclipse.cdt.internal.ui.text.contentassist/CContentAssistProcessor.java
修改pro
tected boolean verifyAutoActivation(ITextViewer viewer, int offset)
switch语句中增加了default分支.

 protected boolean verifyAutoActivation(ITextViewer viewer, int offset) {
  IDocument doc = viewer.getDocument();
  if (doc == null) {
   return false;
  }
  if (offset <= 0) {
   return false;
  }
  try {
   char activationChar = doc.getChar(--offset);
   switch (activationChar) {
   case ':':
    return offset > 0 && doc.getChar(--offset) == ':';
   case '>':
    return offset > 0 && doc.getChar(--offset) == '-';
   case '.':
    // Avoid completion of float literals
    CHeuristicScanner scanner = new CHeuristicScanner(doc);
    int token = scanner.previousToken(--offset, Math.max(0, offset - 200));
    // The scanner reports numbers as identifiers
    if (token == Symbols.TokenIDENT
      && !Character.isJavaIdentifierStart(doc.getChar(scanner.getPosition() + 1))) {
     // Not a valid identifier
     return false;
    }
    return true;
   default:
                return Character.isAlphabetic(activationChar) || activationChar=='_';
   }
  } catch (BadLocationException e) {
  }
  return false;
 }

第五步:将修改后的CDT插件导出为jar文件

在工程上右键,然后点击Export按钮,选择Plug-in Development下的Deployable plug-ins and fragment,然后点击next。再选择路径后,点击finish就完成了
在这里插入图片描述
在这里插入图片描述

第六步:安装生成的jar文件

实际上jar插件只要放入插件目录中替代就行了,也就是将第五步产生的jar文件复制到C:\Users*.p2\pool\plugins目录下,将原来的替换。

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值