用monkey在aptana中添加自定义注释
aptana2.0以后会绑定monkey 比如说zencoding的安装就是基于这个的,直接新建工程新建文件夹script后菜单项中会自动显示等等,今天要说的是 我在aptana中好像没有找到好的注释快捷键 谁知道告我一声啊 ,所以我就研究了一下怎么用快捷键自动生成注释,就像zenconding那样快捷键生成,首先是看了几个aptana自带的Snippets的例子,好像有那么一点眉目了 ,然后动手开始写:
1 /*
2 * Menu:jie
3 * Kudos: Sergey Chikuyonok (http://chikuyonok.ru)
4 * License: EPL 1.0
5 * Key: Ctrl+Shift+a
6 * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
7 * @include "/EclipseMonkey/scripts/monkey-doc.js"
8 * OnLoad: main()
9 */
10 function main(){
11 var sourceEditor = editors.activeEditor, //定义活动窗体
12 range = sourceEditor.selectionRange, //选中区域
13 offset = range.startingOffset, //当前光标位置
14 source = sourceEditor.source, //获取当前屏幕的所有(string类型)
15 str = "", //要插入的字符串
16 data = new Date(),year = data.getFullYear(),mouth =data.getMonth(),day = data.getDay(),hours = data.getHours(),min = data.getMinutes() < 10 ? "0"+data.getMinutes() : data.getMinutes(),sec = data.getSeconds() < 10 ? "0"+data.getSeconds() : data.getSeconds(),
17 time = year+"-"+mouth +"-"+ day +" "+ hours +":"+ min +":"+sec,
18 filename = editors.absolutePath,
19 str = "/** =================================\n"+
20 " * Acthor: Jie\n"+
21 " * Email: liyujie1@gmail.com\n"+
22 " * Last modified: "+time+"\n" +
23 " * =================================*/\n",
24 len = str.length,
25 three = str.substring(0,3),
26 selection = source.substring(0,3); //截取前段字符串判断是否已添加过注释
27 selection === three ? sourceEditor.applyEdit(0,len,str) : sourceEditor.applyEdit(0,0,str)
28
29
30 //参数: 1. 当前光标位置 2.光标结束的位置 3.插入的内容
31 sourceEditor.applyEdit(0,len,str)
32 }
3 * Kudos: Sergey Chikuyonok (http://chikuyonok.ru)
4 * License: EPL 1.0
5 * Key: Ctrl+Shift+a
6 * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
7 * @include "/EclipseMonkey/scripts/monkey-doc.js"
8 * OnLoad: main()
9 */
10 function main(){
11 var sourceEditor = editors.activeEditor, //定义活动窗体
12 range = sourceEditor.selectionRange, //选中区域
13 offset = range.startingOffset, //当前光标位置
14 source = sourceEditor.source, //获取当前屏幕的所有(string类型)
15 str = "", //要插入的字符串
16 data = new Date(),year = data.getFullYear(),mouth =data.getMonth(),day = data.getDay(),hours = data.getHours(),min = data.getMinutes() < 10 ? "0"+data.getMinutes() : data.getMinutes(),sec = data.getSeconds() < 10 ? "0"+data.getSeconds() : data.getSeconds(),
17 time = year+"-"+mouth +"-"+ day +" "+ hours +":"+ min +":"+sec,
18 filename = editors.absolutePath,
19 str = "/** =================================\n"+
20 " * Acthor: Jie\n"+
21 " * Email: liyujie1@gmail.com\n"+
22 " * Last modified: "+time+"\n" +
23 " * =================================*/\n",
24 len = str.length,
25 three = str.substring(0,3),
26 selection = source.substring(0,3); //截取前段字符串判断是否已添加过注释
27 selection === three ? sourceEditor.applyEdit(0,len,str) : sourceEditor.applyEdit(0,0,str)
28
29
30 //参数: 1. 当前光标位置 2.光标结束的位置 3.插入的内容
31 sourceEditor.applyEdit(0,len,str)
32 }
里面的那些方法都是从demo里面找的,就找到这些,还用了一些基本的js,里面的注释内容也就是个字符串,类似vim写的注释吧,就凑合着能使,定义的快捷键为Key:最好别和其他的有冲突我的是ctrl+shift+a(老感觉不顺手呵呵,快捷键太多了 ),安装方法吧,就和安装zenconding一样,你可以在zenconding的scripts中新建一个js文件试试,如果不行就改个快捷键,有些快捷键老莫名其妙的无效 呵呵 这样写js和css的时候填注释就方便多啦

浙公网安备 33010602011771号