終于忍不住了,要為Megax加上語法加亮,我在正則還是lex上徘徊了大半年,始終沒有找到比較好的方法,一個編輯器如果支持非常嚴格的語法加亮的話,那么可配置性是相當的差的。像scintilla,你必須得寫個lex針對某種特定的語言才行。當然大多數的語言都有一些共性,比如你可以用c語言的語法文件去渲染java或者c#的。但是我不想這么做,我想要傻瓜也可以進行配置文件的編寫,像Editplus,但是Editplus做的不夠好。
目前完成了塊狀代碼的識別,這是最關鍵的,什么是塊狀的呢,主要是下面這三種:
1.注釋(單行,多行)
2.字符串(可續行或者不可)
3.子語言
對于子語言這一塊,c++里面可以嵌入asm,html里面可以嵌入css和js,像這樣的語言,我把它定義成子語言。但是子語言不可嵌套,在Megax里面我不處理嵌套的子語言(PS:誰他媽的有病啊,這么寫)。
完成上面這些,在遇到子語言的時候,只需要切換當前的schema就可以完成子語言的語法加亮,同時Megax定死了,最多支持4種sub language.
識別完之后,在用正則分別進行細節匹配,比如c++里面里面的#[多個空格]include和#[無空格]include都是關鍵字,或者注釋里面含有email地址之類的。
在進行行跳轉的時候,我們不需要識別這些,只需要識別塊狀的代碼,所以效率是非常的高,在我的機器上打開100萬行的代碼,跳轉到任意一行,均十分的流暢。
先寫這么多了,下面這張截圖暫時沒有子語言的支持,上班時間偷偷寫的啊。
另外高速自動換行基本實現了,效率和內存占用讓我很滿意,基本上沒有明顯的延遲,小勝Editplus。
最近下了EMEditor的最新版本,EM做的是越來越強大了,基礎功能和架構我覺得應該是目前最棒的編輯器。在打開超大文件的時候,用內存映射之后,剩下的內存占用主要是行信息。在編輯的時候,我一直認為內存映射會非常的慢,看來我需要重新審視一下。思路就是這樣的,EM加載大文件的時候會啟動一個新的線程,線程的同步著實是個大問題,不是我擅長的啊。。。。
周四回國了,好高興,回去要大吃一頓,想死我了。
posted @
2008-06-23 18:17 megax 閱讀(1995) |
評論 (4) |
編輯 收藏
今天在網上搜索自動機的文章的時候發現了一個和我想法差不多的人,他提到了e,簡單的試了一下,很慢,沒來得及細看。
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.
posted @
2008-06-21 23:45 megax 閱讀(647) |
評論 (1) |
編輯 收藏
今天頭好疼,睡到12點。。。
添加了MDI的拖放支持,并且根據不同的FileType顯示不同的圖標。
都是一些小細節,最近身體不好,有空了,在把core部分好好更新一下。
posted @
2008-06-08 00:06 megax 閱讀(327) |
評論 (0) |
編輯 收藏
今天上班本來說是導入新的系統,結果因為手順上幾句話,又讓我等,我靠。
整整一天,啥也沒干,凈坐著地鐵在東京來回的轉悠了,頭都暈死了。
下午,空閑的時候,找了個CSizingControlBar,添加了MDI支持,一些基本的代碼都出來了。
以前用的codeproject的一些代碼,很難用,而且集成進來,代碼風格也有點不倫不類。
TabCtrl倒置后的樣子很丑陋,而且在操作系統不同的theme下樣式也不一樣,抽個空自己寫一個吧。
其實就是個HWND管理工具,難度應該不是太大。
posted @
2008-06-05 21:45 megax 閱讀(344) |
評論 (0) |
編輯 收藏
最近睡眠不好,總是睡不著.
抽點空,把代碼重構了一遍,進一步優化了性能,改進了一些小bug.
把語法加亮這塊拿出來,以后有空了,在好好的封裝,以前寫了個通用的詞法分析器,
可是對于像html這樣其中可以嵌入其它的語言,還真不好弄.
輸入,刪除,剪貼板,Redo,Undo,都完成了,這個雛形算是出來了,剩下的其它的更細節的
操作打算留給腳本來操作.Lua比較好嵌入,就選擇它了.
自動換行這塊,得好好的弄弄,效率不是太讓我滿意.

posted @
2008-05-31 23:21 megax 閱讀(475) |
評論 (0) |
編輯 收藏
制作這個編輯器前前后后也有不短的時間了。
特此在cppBlog上申請一塊私留地,記述期間的點點滴滴,也不知道什么時候能完成。。。
我期望它能夠至少達到以下目標:
1.較低的內存占用(已實現)
2.可擴展的語法渲染(可以采用正則進行更加通用的匹配)(70%)
3.可自定義的鍵盤(未實現)
4.完全unicode支持和codepage自選擇(已實現)
5.可擴展的架構,包含plugin之類的(未實現)
6.對于超大文件的支持(已實現,文件最多和可用內存一般大)
7.同一種字體的多種style支持(未實現,效率上有問題)
暫時我就需要這么多了。
posted @
2008-03-11 14:34 megax 閱讀(777) |
評論 (4) |
編輯 收藏