当前位置: 代码网 > it编程>开发工具>Eclipse > Atom块注释插件multi-comment的安装和使用

Atom块注释插件multi-comment的安装和使用

2025年03月30日 Eclipse 我要评论
本篇文章给大家介绍一下atom实现块注释(/* */)的方法,了解块注释插件multi-comment的安装和使用。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。相关推荐:《atom

本篇文章给大家介绍一下atom实现块注释(/* */)的方法,了解块注释插件multi-comment的安装和使用。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

atom块注释插件multi-comment的安装和使用

相关推荐:《atom》

atom插件:multi-comment

1. atom - multi-comment简介:

a block-comment module built with the focus to interact with the default line-comment-command.翻译为:使用焦点构建的块注释模块,用于与默认的行注释命令交互。

2. multi-comment插件的安装

  1. 打开atom,在菜单栏以此打开:packages(扩展) >> setting view(设置界面) >> install packages/themes(安装 插件/主题),即可 进入插件/主题安装界面。

  2. 在 插件/主题安装界面 中 搜索 multi-comment,然后点击 install(安装)如下图(已安装):
    multi-comment的安装

3. multi-comment插件的改造

  • 首先,在上图中 点击插件 空白区域,进入插件设置界面,然后点击 view code,如下图:
    在这里插入图片描述
    点击之后的界面如下图:
    在这里插入图片描述

1. 默认的块注释 快捷键 修改为:ctrl + shift + /

  • 打开项目中的 keymapsmultiline-js-comment.json 文件
    • 修改快捷键为:“ctrl-shift-/”,如下代码:
{
  "atom-workspace": {
    "ctrl-shift-/": "multi-comment:toggle"
  }}
登录后复制
  • 保存代码
    • 快捷键 ctrl+s保存。

2. 修改默认 注释符 开始标记 /* 后 和 结束标记 */ 前 分别多加了1个空格。

  • 打开项目中的 libmulti-comment-langs.js 文件
    • 修改如下代码中的opentoken (设置 块注释开始标记)和 closetoken(设置 块注释结束标记),并保存:
const languages = [
  {
    name: 'coffeescript',
    test: /^source.coffee.?/,
    opentoken: '###',
    closetoken: '###',
    /* when used at line start line-scoprdescriptor will override
    so we cheat with leading 	 */
    option: { tab: '\t' }
  },
  {
    name: 'javascript',
    test: /^source.js.?/,
    opentoken: '/*',
    closetoken: '*/'
  },
  {
    name: 'java',
    test: /^source.java.?/,
    opentoken: '/*',
    closetoken: '*/'
  },
  {
    name: 'css',
    test: /^source.css.?/,
    opentoken: '/*',
    closetoken: '*/',
    option: { scaninside: true }
  },
  {
    name: 'php',
    test: /html.php/,
    opentoken: '/* ',
    closetoken: ' */'
  },
  {
    name: 'ruby',
    test: /^source.ruby.?/,
    opentoken: '=begin',
    closetoken: '=end',
    option: { newline: '\n' }
  },
  {
    name: 'c',
    test: /^source.c.?/,
    opentoken: '/*',
    closetoken: '*/'
  }];
登录后复制
  • 本例中:
    • 修改的是php语言的。

3. 修改 使用快捷键注释后的光标效果

  • multi-comment插件 注释 选中的内容,发现注释后光标进行了移动(自然的,注释内容选中也就取消了),于是:
    • 在项目中 找到 libmulti-comment.js 文件在 发现如下代码中 // set cursor position 即最后两行代码 进行了光标移动的操作。
  addcomment() {
    const range = this.editor.getselectedbufferrange();
    const text = this.editor.gettextinbufferrange(range);
    const [open, close] =
    (this.lang.commenttokens.option && this.lang.commenttokens.option.newline) ?
      [`
${this.lang.commenttokens.open}
`, `
${this.lang.commenttokens.close}
`] :
    (this.lang.commenttokens.option && this.lang.commenttokens.option.tab) ?
      [`	${this.lang.commenttokens.open}`, `	${this.lang.commenttokens.close}`] :
      [this.lang.commenttokens.open, this.lang.commenttokens.close];

    this.editor.settextinbufferrange(range, `${open}${text}${close}`);
    // set cursor position
    const landposition = pointmove(this.editor.getcursorbufferposition(), - (close.length - 1), this.editor);
    this.editor.setcursorbufferposition(landposition);
  }
登录后复制
  • 将其以上两行代码注释后,发现另外一个问题:在空白行 即没有选中内容的情况下,直接生成注释后,光标没有跳转到 注释开始标记 与 结束标记的中间,解决办法:
    • 将最后两行代码进行如下改造,并保存:

将代码:

	// set cursor position
    const landposition = pointmove(this.editor.getcursorbufferposition(), - (close.length - 1), this.editor);
    this.editor.setcursorbufferposition(landposition);
登录后复制

修改为:

    if (text === '') {
      // set cursor position
      const landposition = pointmove(this.editor.getcursorbufferposition(), - (close.length - 1), this.editor);
      this.editor.setcursorbufferposition(landposition);
    }
登录后复制

加粗样式完成以上修改工作后,想要的插件的效果还没有在atom中立刻生效,因此需要 先关闭atom,并重新打开。
此时想要的插件的效果就实现了。

更多编程相关知识,请访问:atom!!

以上就是atom块注释插件multi-comment的安装和使用的详细内容,更多请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com