在Ultraedit中用宏實現(xiàn)將選中的代碼設置為注釋
2024-07-21 02:15:58
供稿:網(wǎng)友
 
最近因為機器問題,開始使用ultraedit,以前用過幾次,如今仔細玩味了一把,才發(fā)現(xiàn)這款編輯器真實太好用了,功能比較強大,確實是編碼的利器,目前ue已經(jīng)發(fā)布到v11,已經(jīng)缺省支持c#語言的著色(這也是我選擇ue的一個重要原因拉)。晚上在調(diào)試一個c#小程序的時候,發(fā)現(xiàn)ue有一個對于代碼debug來說不方面的地方,就是缺少對代碼塊或代碼行注釋的功能,尤其ue不是完備的開發(fā)ide,缺少這樣的功能真是讓調(diào)試起來不怎么方便,讓我不得不一行一行地手動在行首加"//",或?qū)σ恍┨囟ǖ拇a塊添加首尾的"/*"和"*/",不像在vb或vs.net中直接選中想要變成注釋的行,點一下工具欄上的按鈕就ok,可惜啊。
好在ue支持宏,于是k了一下ue宏的語法,小搞了一下,效果還不錯,呵呵
下面是對代碼塊設成注釋的宏語句,使用前需要先選中希望注釋的代碼塊,選中的首尾位置可以在首位行的任意位置,這里用的是"/*"和"*/",本來希望做成對每一行加"//",這樣就像vs.net了,可惜ue宏不支持變量,所以沒想到實現(xiàn)的好辦法。
insertmode
columnmodeoff
hexoff
unixreoff
ifsel
startselect
key end
cut 
key home
ifcolnum 1
key end
endif
"/* "
timedate
"
"
key end
paste 
key end
"
"
timedate
" */"
endif
下面是對代碼解除注釋的宏代碼,同樣需要選中希望解除注釋的代碼塊,選中的首尾位置可以在首位行的任意位置。
insertmode
columnmodeoff
hexoff
unixreon
ifsel
cut 
"[email protected]#"
paste 
deleteline
"[email protected]@#"
top
find "[email protected]#"
deleteline
find "[email protected]@#"
delete
endif
下面是對單行代碼加"//"注釋的宏代碼,這個就簡單多了 :-)
insertmode
columnmodeoff
hexoff
unixreoff
"[email protected]#"
key home
ifcolnum 1
else
key home
endif
"//"
find "[email protected]#"
delete
最后是解除行注釋的宏代碼:
insertmode
columnmodeoff
hexoff
unixreoff
"[email protected]#"
key home
ifcharis "/"
delete
ifcharis "/"
delete
else
"/"
endif
endif
find "[email protected]#"
delete
對行的注釋和解除注釋不需要選中行,只需要光標落在此行中即可。這里要提一下的是,本來對于行解除注釋的宏想寫成如下形式的:
insertmode
columnmodeoff
hexoff
unixreoff
"[email protected]#"
key home
ifcharis "/"
key right arrow
ifcharis "/"
key right arrow
deletetostartofline
endif
endif
find "[email protected]#"
delete
這樣可讀性好些,實現(xiàn)邏輯也合理,讓人faint的是,我用的是uev11的中文版,不支持key right arrow,如果使用宏錄制功能,得到的是key  右箭頭 →,但如果手動寫key  右箭頭 →,系統(tǒng)就報錯,說沒有這個命令,真讓人不得其解~~~這里由于存在一些邏輯,所以不能錄制,只能手寫。
reference:
ultraedit offical forum: http://www.ultraedit.com/index.php?name=forums&file=index&c=1ultraedit help document. http://manni-heumann.de/macro_ref_chm.zip
p.s. 很久沒搞到這么晚了,好在今晚宿舍沒人,外面小雨還在下,天氣也涼快了一些。