write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie
我一直希望有個工具能夠便捷的進行語法高亮,因為很多地方都可以用到。特別是,假如我在Google Document或者Office中編輯文件的時候,或者是在Windows Live Writer中編寫博客文章的時候(WLW中有插件支持,但還是沒有此工具這么方便,并且現(xiàn)在寫博客的時候我已經(jīng)改用Google Document了),我都希望能便捷的進行語法高亮,但是并不是都那么容易實現(xiàn)。特別是像Google Document這樣不支持插件的工具,因為Google Document不支持插件,不能進行語法高亮,所以長時間以來我都不將其作為博客的編寫工具,直到,你知道的,我決定寫個工具來解決這個問題。于是,就有了今天這個工具。其實本程序?qū)嶋H是原來的chc2c工具的一個UI版本, code-highlight-clipboard2clipboard chc2c是一個命令行工具,可能很多人會比較排斥,雖然我建一些快捷方式也能實現(xiàn)比較便捷的效果。當然,怎么說還是UI工具來的方便,此功能托管在Google Code上: onekeycodehighlighter 已經(jīng)有下載了: ClipboardHighlighter0.1.rar 因為還是使用Gvim來完成實際工作,所以, gvim 的安裝還是不可少,假如有人發(fā)現(xiàn)綠色版簡易版支持語法高亮和ToHtml的vim請推薦給我,我直接放在下載包中,這樣大家就可以不用安裝gvim了。對了,安裝后,將gvim添加到PATH中,這樣我才能找到并執(zhí)行它。
可以通過config.py文件來配置,配置文件中的注釋說明的很詳細了,簡單的修改應該沒有問題,config文件本身就是一個python腳本,只要你滿足我原來的變量名不變,你可以做很多事情。
默認情況下,我僅添加了c,cpp,python,java,javascript的語法高亮支持,其他的語法在config中配置吧。config中除了syntaxSupport 以外,都支持動態(tài)改變。比如保存的文件名,是否有行號,顏色主題等。
使用中軟件為一個任務欄中的圖標,右鍵點擊會出現(xiàn)菜單:
實際編寫的主要工具為PyQt。因為此工具有一些特殊的功能要求,比如全局快捷鍵,比如用ctypes來調(diào)用了Win32的API,比如我要使用System Tray Icon,比如對剪貼板的操作等等等等,我覺得可以將這些例子分為單獨的文章來講解,目前僅貼出一些此工具轉(zhuǎn)換的效果給大家看看。
下面是一些示例:
配置文件(Python):
MOD_ALT = 0x0001
MOD_NONE = 0x000
MOD_CONTROL = 0x0002
MOD_SHIFT = 0x0004
MOD_WIN = 0x0008
# the syntax support you want in the trayicon menu
syntaxSupport = ["c", "cpp", "python", "java", "javascript"]
# the global hotkey define,the modifier can be used is listed above.
modifier = MOD_WIN
hotkey = 'Z'
# do you need display line number before every line?
isLineNumber = False
#------------------------------------------------------------------------------------
# you need not change these below at most time if you don't know what it is.
# the color theme you want use. (corresponding to gvim)
color = 'default'
# if you want to save the transformed in a file.
filename = ''
C++:
//激活創(chuàng)建OpenGL窗口
void EnableOpenGL()
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
ghDC = GetDC( ghWnd );
ZeroMemory( &pfd, sizeof ( pfd ) );
pfd.nSize = sizeof ( pfd );
pfd.nVersion = 1;//版本,一般設為1
pfd.dwFlags = PFD_DRAW_TO_WINDOW | //一組表明象素緩沖特性的標志位
PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA; //明象素數(shù)據(jù)類型是RGBA還是顏色索引;
pfd.cColorBits = 32; //每個顏色緩沖區(qū)中顏色位平面的數(shù)目,對顏色索引方式是緩沖區(qū)大小
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE; //被忽略,為了一致性而包含的
iFormat = ChoosePixelFormat( ghDC, &pfd );//選擇一個像素格式
SetPixelFormat( ghDC, iFormat, &pfd ); //設置到DC中
ghRC = wglCreateContext( ghDC );//創(chuàng)建繪圖描述表
wglMakeCurrent( ghDC, ghRC ); //使之成為當前繪圖描述表
}
java:
//: holding/AddingGroups.java
packageholding; /* Added by Eclipse.py */
// Adding groups of elements to Collection objects.
importjava.util.*;
public class AddingGroups {
public static void main(String[] args) {
Collection<integer> collection =<br><font color="#804040"><b>new</b></font>ArrayList<integer>(Arrays.asList(<font color="#ff00ff">1</font>, <font color="#ff00ff">2</font>, <font color="#ff00ff">3</font>, <font color="#ff00ff">4</font>, <font color="#ff00ff">5</font>));<br> Integer[] moreInts = { <font color="#ff00ff">6</font>, <font color="#ff00ff">7</font>, <font color="#ff00ff">8</font>, <font color="#ff00ff">9</font>, <font color="#ff00ff">10</font>};<br> collection.addAll(Arrays.asList(moreInts));<br><font color="#0000ff">// Runs significantly faster, but you can't</font><br><font color="#0000ff">// construct a Collection this way:</font><br> Collections.addAll(collection, <font color="#ff00ff">11</font>, <font color="#ff00ff">12</font>, <font color="#ff00ff">13</font>, <font color="#ff00ff">14</font>, <font color="#ff00ff">15</font>);<br> Collections.addAll(collection, moreInts);<br><font color="#0000ff">// Produces a list "backed by" an array:</font><br> List<integer> list = Arrays.asList(<font color="#ff00ff">16</font>, <font color="#ff00ff">17</font>, <font color="#ff00ff">18</font>, <font color="#ff00ff">19</font>, <font color="#ff00ff">20</font>);<br> list.set(<font color="#ff00ff">1</font>, <font color="#ff00ff">99</font>); <font color="#0000ff">// OK -- modify an element</font><br><font color="#0000ff">// list.add(21); // Runtime error because the</font><br><font color="#0000ff">// underlying array cannot be resized.</font><br> }<br> } <font color="#0000ff">///:~</font><br></integer></integer></integer>
javascript:
// This function recursively looks at Node n and its descendants,
// converting all Text node data to uppercase
functionupcase(n){
if (n.nodeType == 3/*Node.TEXT_NODE*/){
// If the node is a Text node, create a new Text node that
// holds the uppercase version of the node's text, and use the
// replaceChild() method of the parent node to replace the
// original node with the new uppercase node.
n.data = n.data.toUpperCase();
}
else {
// If the node is not a Text node, loop through its children
// and recursively call this function on each child.
varkids = n.childNodes;
for (vari = 0; i [i]);
}
}
再來個不一樣的,delek主題+行號的Python效果:
1
2 MOD_ALT = 0x0001
3 MOD_NONE = 0x000
4 MOD_CONTROL = 0x0002
5 MOD_SHIFT = 0x0004
6 MOD_WIN = 0x0008
7
8 # the syntax support you want in the trayicon menu
9 syntaxSupport = [ " c " , " cpp " , " python " , " java " , " javascript " ]
10
11 # the global hotkey define,the modifier can be used is listed above.
12 modifier = MOD_WIN
13 hotkey = ' Z '
14
15 # do you need display line number before every line?
16 isLineNumber = True
17
18 #------------------------------------------------------------------------------------
19 # you need not change these below at most time if you don't know what it is.
20 # the color theme you want use. (corresponding to gvim)
21 color = ' delek '
22
23 # if you want to save the transformed in a file.
24 filename = ''
呵呵,效果不錯吧?唯一的問題是因為使用了vim,所以總是會彈出一個gvim的窗口,有點影響視覺效果,但是好在不影響使用,對于支持的語法我重新貼一下:
2html a2ps
a65 aap abap abaqus
abc abel acedb ada
aflex ahdl alsaconf amiga
aml ampl ant antlr
apache apachestyle arch art
asm asm68k asmh8300 asn
aspperl aspvbs asterisk asteriskvm
atlas autohotkey autoit automake
ave awk ayacc b
baan basic bc bdf
bib bindzone blank bst
btm bzr c calendar
catalog cdl cdrdaoconf cdrtoc
cf cfg ch change
changelog chaskell cheetah chill
chordpro cl clean clipper
cmake cmusrc cobol coco
colortest conaryrecipe conf config
context cpp crm crontab
cs csc csh csp
css cterm ctrlh cuda
cupl cuplsim cvs cvsrc
cweb cynlib cynpp d
dcd dcl debchangelog debcontrol
debsources def denyhosts desc
desktop dictconf dictdconf diff
dircolors diva django dns
docbk docbksgml docbkxml dosbatch
dosini dot doxygen dracula
dsl dtd dtml dtrace
dylan dylanintr dylanlid ecd
edif eiffel elf elinks
elmfilt erlang eruby esmtprc
esqlc esterel eterm eviews
exim expect exports fasm
fdcc fetchmail fgl flexwiki
focexec form forth fortran
foxpro framescript freebasic fstab
fvwm fvwm2m4 gdb gdmo
gedcom git gitcommit gitconfig
gitrebase gitsendemail gkrellmrc gnuplot
gp gpg grads gretl
groff groovy group grub
gsp gtkrc haml hamster
haskell haste hastepreproc hb
help hercules hex hitest
hog hostconf html htmlcheetah
htmldjango htmlm4 htmlos ia64
ibasic icemenu icon idl
idlang indent inform initex
initng inittab ipfilter ishd
iss ist jal jam
jargon java javacc javascript
jess jgraph jproperties jsp
kconfig kix kscript kwt
lace latte ld ldapconf
ldif lex lftp lhaskell
libao lifelines lilo limits
lisp lite litestep loginaccess
logindefs logtalk lotos lout
lpc lprolog lscript lsl
lss lua lynx m4
mail mailaliases mailcap make
man manconf manual maple
masm mason master matlab
maxima mel messages mf
mgl mgp mib mma
mmix mmp modconf model
modsim3 modula2 modula3 monk
moo mp mplayerconf mrxvtrc
msidl msmessages msql mupad
mush muttrc mysql named
nanorc nasm nastran natural
ncf netrc netrw nosyntax
nqc nroff nsis objc
objcpp ocaml occam omnimark
openroad opl ora pamconf
papp pascal passwd pcap
pccts pdf perl pf
pfmain php phtml pic
pike pilrc pine pinfo
plaintex plm plp plsql
po pod postscr pov
povini ppd ppwiz prescribe
privoxy procmail progress prolog
promela protocols psf ptcap
purifylog pyrex python qf
quake r racc radiance
ratpoison rc rcs rcslog
readline rebol registry
remind resolv reva rexx
rhelp rib rnc rnoweb
robots rpcgen rpl rst
rtf ruby samba sas
sass sather scheme scilab
screen sd sdl sed
sendpr sensors services setserial
sgml sgmldecl sgmllnx sh
sicad sieve simula sinda
sindacmp sindaout sisu skill
sl slang slice slpconf
slpreg slpspi slrnrc slrnsc
sm smarty smcl smil
smith sml snnsnet snnspat
snnsres snobol4 spec specman
spice splint spup spyce
sql sqlanywhere sqlforms sqlinformix
sqlj sqloracle sqr squid
sshconfig sshdconfig st stata
stp strace sudoers svn
syncolor synload syntax sysctl
tads tags tak takcmp
takout tar tasm tcl
tcsh terminfo tex texinfo
texmf tf tidy tilde
tli tpp trasys trustees
tsalt tsscl tssgm tssop
uc udevconf udevperm udevrules
uil updatedb valgrind vb
vera verilog verilogams vgrindefs
vhdl vim viminfo virata
vmasm voscm vrml vsejcl
wdiff web webmacro wget
whitespace winbatch wml wsh
wsml wvdial xbl xdefaults
xf86conf xhtml xinetd xkb
xmath xml xmodmap xpm
xpm2 xquery xs xsd
xslt xxd yacc yaml
z8a zsh
blue
color
darkblue
default
delek
desert
elflord
evening
koehler
morning
murphy
pablo
peachpuff
ron
shine
slate
torte
zellner
支持的顏色主題,語言語法都是通過config來配置,其實操作就是選擇好語言,copy,Win+Z,paste。。。。。。。。。。
原創(chuàng)文章作者保留版權 轉(zhuǎn)載請注明原作者 并給出鏈接
write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
