終于忍不住了,要為Megax加上語法加亮,我在正則還是lex上徘徊了大半年,始終沒有找到比較好的方法,一個(gè)編輯器如果支持非常嚴(yán)格的語法加亮的話,那么可配置性是相當(dāng)?shù)牟畹摹O駍cintilla,你必須得寫個(gè)lex針對(duì)某種特定的語言才行。當(dāng)然大多數(shù)的語言都有一些共性,比如你可以用c語言的語法文件去渲染java或者c#的。但是我不想這么做,我想要傻瓜也可以進(jìn)行配置文件的編寫,像Editplus,但是Editplus做的不夠好。
目前完成了塊狀代碼的識(shí)別,這是最關(guān)鍵的,什么是塊狀的呢,主要是下面這三種:
1.注釋(單行,多行)
2.字符串(可續(xù)行或者不可)
3.子語言
對(duì)于子語言這一塊,c++里面可以嵌入asm,html里面可以嵌入css和js,像這樣的語言,我把它定義成子語言。但是子語言不可嵌套,在Megax里面我不處理嵌套的子語言(PS:誰他媽的有病啊,這么寫)。
完成上面這些,在遇到子語言的時(shí)候,只需要切換當(dāng)前的schema就可以完成子語言的語法加亮,同時(shí)Megax定死了,最多支持4種sub language.
識(shí)別完之后,在用正則分別進(jìn)行細(xì)節(jié)匹配,比如c++里面里面的#[多個(gè)空格]include和#[無空格]include都是關(guān)鍵字,或者注釋里面含有email地址之類的。
在進(jìn)行行跳轉(zhuǎn)的時(shí)候,我們不需要識(shí)別這些,只需要識(shí)別塊狀的代碼,所以效率是非常的高,在我的機(jī)器上打開100萬行的代碼,跳轉(zhuǎn)到任意一行,均十分的流暢。
先寫這么多了,下面這張截圖暫時(shí)沒有子語言的支持,上班時(shí)間偷偷寫的啊。
另外高速自動(dòng)換行基本實(shí)現(xiàn)了,效率和內(nèi)存占用讓我很滿意,基本上沒有明顯的延遲,小勝Editplus。
最近下了EMEditor的最新版本,EM做的是越來越強(qiáng)大了,基礎(chǔ)功能和架構(gòu)我覺得應(yīng)該是目前最棒的編輯器。在打開超大文件的時(shí)候,用內(nèi)存映射之后,剩下的內(nèi)存占用主要是行信息。在編輯的時(shí)候,我一直認(rèn)為內(nèi)存映射會(huì)非常的慢,看來我需要重新審視一下。思路就是這樣的,EM加載大文件的時(shí)候會(huì)啟動(dòng)一個(gè)新的線程,線程的同步著實(shí)是個(gè)大問題,不是我擅長(zhǎng)的啊。。。。
周四回國(guó)了,好高興,回去要大吃一頓,想死我了。
今天在網(wǎng)上搜索自動(dòng)機(jī)的文章的時(shí)候發(fā)現(xiàn)了一個(gè)和我想法差不多的人,他提到了e,簡(jiǎn)單的試了一下,很慢,沒來得及細(xì)看。
On a good day I spend anywhere from 8 to 12 hours writing code. Unfortunately, even though I've been doing this for ten years now, I have yet to find a text editor that satisfies all my needs.
I suspect TextMate would fulfill all my wildest fantasies, but I don't have a Mac. A few months ago I wrote about e, which is currently the closest thing to TextMate for Windows. Sadly, my infatuation with e is quickly wearing off; it gets slower, more bloated, and less stable with each release. Intype shows promise, but is missing some very important features and is apparently being developed by a team of hypothermic sloths with refactoritis.
My needs aren't complex, nor are they numerous:
- High performance, low resource usage
During a typical debugging session, I have Firefox, IE7, Opera, Safari, and an IE6 VMWare image running in addition to my email client, IM client, several SSH terminals, and my text editor. Every last megabyte of RAM is precious, yet many text editors (especially recent builds of e) have no qualms about gobbling up a hundred megs or more and responding like a pregnant cow in a lake of molasses. You're a fucking text editor, not a goddamn video game. Learn how to manage memory efficiently.
- Good, customizable syntax highlighting
Shareable color schemes in the form of editable files is a must. GUI dialogs that force me to open a color palette and choose each individual color for each individual language construct are an instant disqualifier, especially if I have to do this for every single language (I'm looking at you Aptana).
- Good anti-aliased font rendering
This comes for free on Windows if you just let the OS render the damn fonts, but plenty of text editors still seem to get this wrong. I have to stare at these fonts all day, every day, so I need them crisp and readable, not pixelated or blurry. If I can't use my favorite font, that's an instant failing grade (suck it, jEdit).
- Some kind of outline- or symbol-based navigation
I need to be able to jump to any class, method, CSS selector, etc. instantly, preferably with a hotkey and a few keystrokes. This is one thing that e does very, very well, but that no other Windows text editor can seem to get right. It does me no good if you display the outline in a lovely treeview with expandable nodes for each class and method but don't give me a keyboard shortcut. I'm not going to use the mouse. I refuse. Mouse equals fail.
- Stay the hell out of my way
I don't want auto-indent, I don't want auto-formatting, I don't want auto-complete, I don't want auto-fucking-anything. I know what I'm doing and I want you to get out of my way and let me do it, because if you try to do it for me you'll only fuck it up.
At this point, I've pretty much given up all hope of finding a Windows text editor that does these five simple things and does them well. I've resigned myself to the fact that I'm either going to have to return to the dark and painful world of desktop application programming and write my own damn text editor or I'm going to have to bite the bullet, get a Mac, and use TextMate.
Since I don't have the time or the desire to write my own text editor, it's looking like I'll probably end up throwing money at the problem. Sigh.
今天頭好疼,睡到12點(diǎn)。。。
添加了MDI的拖放支持,并且根據(jù)不同的FileType顯示不同的圖標(biāo)。
都是一些小細(xì)節(jié),最近身體不好,有空了,在把core部分好好更新一下。
今天上班本來說是導(dǎo)入新的系統(tǒng),結(jié)果因?yàn)槭猪樕蠋拙湓挘肿屛业龋铱俊?br>整整一天,啥也沒干,凈坐著地鐵在東京來回的轉(zhuǎn)悠了,頭都暈死了。
下午,空閑的時(shí)候,找了個(gè)CSizingControlBar,添加了MDI支持,一些基本的代碼都出來了。
以前用的codeproject的一些代碼,很難用,而且集成進(jìn)來,代碼風(fēng)格也有點(diǎn)不倫不類。
TabCtrl倒置后的樣子很丑陋,而且在操作系統(tǒng)不同的theme下樣式也不一樣,抽個(gè)空自己寫一個(gè)吧。
其實(shí)就是個(gè)HWND管理工具,難度應(yīng)該不是太大。
最近睡眠不好,總是睡不著.
抽點(diǎn)空,把代碼重構(gòu)了一遍,進(jìn)一步優(yōu)化了性能,改進(jìn)了一些小bug.
把語法加亮這塊拿出來,以后有空了,在好好的封裝,以前寫了個(gè)通用的詞法分析器,
可是對(duì)于像html這樣其中可以嵌入其它的語言,還真不好弄.
輸入,刪除,剪貼板,Redo,Undo,都完成了,這個(gè)雛形算是出來了,剩下的其它的更細(xì)節(jié)的
操作打算留給腳本來操作.Lua比較好嵌入,就選擇它了.
自動(dòng)換行這塊,得好好的弄弄,效率不是太讓我滿意.

制作這個(gè)編輯器前前后后也有不短的時(shí)間了。
特此在cppBlog上申請(qǐng)一塊私留地,記述期間的點(diǎn)點(diǎn)滴滴,也不知道什么時(shí)候能完成。。。
我期望它能夠至少達(dá)到以下目標(biāo):
1.較低的內(nèi)存占用(已實(shí)現(xiàn))
2.可擴(kuò)展的語法渲染(可以采用正則進(jìn)行更加通用的匹配)(70%)
3.可自定義的鍵盤(未實(shí)現(xiàn))
4.完全unicode支持和codepage自選擇(已實(shí)現(xiàn))
5.可擴(kuò)展的架構(gòu),包含plugin之類的(未實(shí)現(xiàn))
6.對(duì)于超大文件的支持(已實(shí)現(xiàn),文件最多和可用內(nèi)存一般大)
7.同一種字體的多種style支持(未實(shí)現(xiàn),效率上有問題)
暫時(shí)我就需要這么多了。