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

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

cf2630c556219dcdee7e9d0d50cd2e1d.png

相关推荐:《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插件的安装打开Atom,在菜单栏以此打开:Packages(扩展) >> Setting View(设置界面) >> Install Packages/Themes(安装 插件/主题),即可 进入插件/主题安装界面。

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

962c074434b7b3747a73dc38958419a1.png

3. multi-comment插件的改造首先,在上图中 点击插件 空白区域,进入插件设置界面,然后点击 View Code,如下图:

7f623240fedfe443e84f032bbc251e4f.png

点击之后的界面如下图:

a24bd2627f51d00b239eadc0d0a5d345.png

1. 默认的块注释 快捷键 修改为:Ctrl + Shift + /打开项目中的 keymaps\multiline-js-comment.json 文件

修改快捷键为:“ctrl-shift-/”,如下代码:{

"atom-workspace": {

"ctrl-shift-/": "multi-comment:toggle"

}}保存代码

快捷键 Ctrl+S保存。

2. 修改默认 注释符 开始标记 /* 后 和 结束标记 */ 前 分别多加了1个空格。打开项目中的 lib\multi-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 \t */

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插件 注释 选中的内容,发现注释后光标进行了移动(自然的,注释内容选中也就取消了),于是:

在项目中 找到 lib\multi-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) ?

[`\n${this.lang.commentTokens.open}\n`, `\n${this.lang.commentTokens.close}\n`] :

(this.lang.commentTokens.option && this.lang.commentTokens.option.tab) ?

[`\t${this.lang.commentTokens.open}`, `\t${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,并重新打开。

此时想要的插件的效果就实现了。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值