熟悉工具的使用能在一定程度上提高工作效率,但工具永遠只是工具,大家要把重點放在內功的修煉上。
符號導航
符號(變量、宏定義、結構定義、枚舉、函數等等)在SI 中的檢索非常方便。Ctrl+鼠標左鍵或Ctrl+=可以立即轉到符號的定義處,Alt+/可以打開一個窗口查看符號的定義。F7 瀏覽或查找工程的全局變量和函數,F8 瀏覽查找當前文件的全局變量和函數(Source Insight 4 不可用)。Ctrl+/打開 Lookup Reference 窗口用於搜索符號在工程中的索引,所有搜索結果在搜索窗口中顯示,點擊搜索結果左邊的紅色源鏈接即可打開其所在位置。Lookup Reference 是在整個工程文件中進行搜索,要只在當前文件或特定的目錄下進行搜索,使用 Ctrl+H 或Ctrl+Shfit+H 進行搜索,F3 和 F4 是上一個、下一個搜索結果的快捷鍵。
使用Shift+F8 可以讓當前的符號在整個工程文件中高亮顯示。(Source Insight 4 使用F8讓當前的符號在整個工程文件中高亮顯示)
參數設置
SI 有很自由的自定義功能,幾乎所有的窗口都可以自定義字體、顏色,可以輕鬆地把各種類型關鍵字、變量、標誌符、函數、宏、註釋等定義爲不同的顏色和顯示方式(正體或斜體、加粗或正常、加下劃線、放大顯示等),可以隨意的增加修改刪除菜單項和快捷鍵。更重要的是,可以通過自定義命令執行外部程序,也可以通過 SI 自己的宏語言,自己寫一段程序實現特定的功能,這些可以提高我們工作的效率,從重複繁瑣的工作中解脫出來。
字體選擇
在 SI 中樣式是可以被繼承,如果要從根本上改變字體,最簡單的方式就是直接修改根樣式中的字體,因爲其它樣式都會由此繼承而來。選擇 Options/Document Options 頁面內的 Font Options 中的Screen Fonts 字體,即可改變根樣式中的字體。
SI 中的默認配置爲Verdana 字體,是一種非等寬字體,爲了使編寫的代碼在各種編輯器中看起來都有良好的對齊效果,強烈建議使用等寬字體,Courier、New Courier 和宋體等都是較好的選擇。
背景色設置
Options->preference->color->windows background設置背景色
縮進設置
選擇 Options/Document Options 頁面,點擊其內的Auto Indent 按鈕,在彈出的Auto Indenting 窗口中,Auto Indent Type 選擇 Smart,取消勾選Smart Indent Options 中的兩個可選項。同時 Options->Document Options 中,Tab Width 輸入4,取消Expand tabs 複選框。
Edit Condition
當中代碼中有大量的預編譯定義,在閱讀這樣的代碼時最痛苦的是不能簡單判斷程序實際執行的代碼分支。大量分支同時存在,常常會混淆我們的視聽。比如對於下面的代碼:
#ifdef DEV1
……
#else
……
#endif
如果確定我們當前分析的是 DEV1 的執行情況,那麼可以選擇上下文件菜單的Edit Condition 選項,在彈出的 Conditional Parsing 窗口中把DEV1 的值設置爲True,那麼#ifdef DEV1 就等價於#if 1 了,相當註釋掉了#else 分枝的代碼。反之,設置爲 Flase 時,則註釋掉#ifdef DEV1 分枝的代碼。
中文間距過大問題
默認情況下,往Source Insight 裏輸入中文,字間距相當的大。是因爲字體設置的原因,進行如下設置如下可解決:
1. Options->Style Properties,打開樣式對話框;
2. 在左邊 Style Name 下找到Comment Multi Line 和 Comment.在其右邊對應的 Font 屬性框下的Font Name 中選“Pick...” 設置爲宋體、常規、小四。確定,退回Style Properties 界面,Size 設爲 10。
Smart Rename
在上下文件菜單中選 Smart Rename 或按Ctrl+'組合鍵,即可彈出Smart Rename 窗口。它有很強大的功能,但最便捷的使用方式是更改函數內局部變量的名字,操作只作用於函數內部,速度非常快。
恢復 Ctrl+A 的全選功能
利用自定義快捷鍵,把功能定義成熟悉的按鍵。比如一般的編輯器,按下 Ctrl+A 是全選功能,但默認是 SI 的全選沒有快捷鍵,Ctrl+A 默認是保存全部的操作。在 Custom Key 對話框中,通過關鍵詞save 找到save all,更改爲Ctrl+Shift+A,通過關鍵詞select 找到select all,更改爲Ctrl+A。
添加文件類型
用戶可以定義自己的類型,Options->Document Options->add type,定義文件類型名以及文件名後綴。 勾選 include when adding to projects 在添加目錄下文件到工程時該類文件就會添加進 SI 的工程。如果需要將所有文件添加進 SI 的工程,可以定義一種文件類型*.*。
列操作
先按下Alt 鍵,接着鼠標左鍵拖動鼠標進行列選擇,然後就可以刪除指定的列。
添加自定義功能
在 SI 中可以自定義命令,方便的調用外部程序。舉個例子:
1. Options->Custom Commands...->Add...,New Command name 隨便填入命令的名字;
2. Run 中寫入: ShellExecute open explorer /e,/select,%f;
意思是打開資源管理器並選中當前文件。%f 爲文件名。
3. 還是同一個對話框裏面,選擇 Keys->Assign New Key...->按下執行該命令的快捷鍵下面是一些關於TortoiseSVN 的常用自定義功能(需要更改相應的TSVN 安裝目錄):
查看修改(diff): "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:diff /path:%f /notempfile/closeonend
提交(check in): "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:%f /notempfile/closeonend
更新(update):"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:%f /notempfile/closeonend
宏語言使用
大家可能很少用到SI的宏語言(Source Insight macro language),這是一種功能強大的編程語言,幾乎可以實現在編程過程可能使用到的各種功能。這裏不準備對如何使用宏語言進行編程作介紹(可參閱SI幫助文檔中的“Macro Language Guide”部分。),只介紹如何使用已編好的程序。更多的宏文件在http://www.sourceinsight.com/public/macros/下載。
宏文件導入與使用
宏文件,以.em 爲後綴使用宏語言編寫的文件,源文件中的每個“macro 宏名()”定義一個宏函數(功能),爲宏名定義菜單或快捷鍵即可使用該功能。宏文件的使用方法如下:
1. Project->Open Project
打開 Base 工程(該工程一般在"我的文檔/Source Insight/Projects/Base"中);
2. Project->Add and Remove Project Files
加入宏文件;
3. Options->Menu Assignments(或者把該宏功能定義爲快捷鍵)
打開 Menu Assignments 窗口,在Command 中輸入Macro,選中要使用的宏,添加到合適的菜單中。或者打開 Key Assignment 窗口,選中要使用的宏,點Assigned New Key,選擇要使用的快捷鍵。設置完後,選擇對應的菜單項或按快捷鍵,即可實現宏函數功能。
參考資料
首選SI 自帶的幫助文檔(按F1 啓動),有非常詳細的說明。
原文:https://www.cnblogs.com/chinhao/p/4630144.html
macro InsFileHeader()
{
szMyName = "XXX" /* Enter your name */
/* Get current time */
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
if (Month < 10)
szMonth = "0@Month@"
else
szMonth = Month;
szFileName = Ask("Enter file name and its extention, for example, \"main.c\": ");
/* promote the description of the file*/
szDescription = Ask("Enter the description of file:")
hBuf = GetCurrentBuf()
hbuf = GetCurrentBuf()
InsBufLine(hbuf, 0, "/*")
InsBufLine(hbuf, 1, " *")
InsBufLine(hbuf, 2, " *")
InsBufLine(hbuf, 3, " *\\file @szfileName@")
InsBufLine(hbuf, 4, " *\\brief @szDescription@.")
InsBufLine(hbuf, 5, " *")
InsBufLine(hbuf, 6, " *\\author @szMyName@")
InsBufLine(hbuf, 7, " *\\version 1.0.0")
InsBufLine(hbuf, 8, " *\\date @szMonth@\/@szDay@\/@Year@")
InsBufLine(hbuf, 9, " *")
InsBufLine(hbuf, 10, " *\\history \\arg 1.0.0 @szMonth@\/@szDay@\/@Year@, @szMyName@, Create file.")
InsBufLine(hbuf, 11, " */")
}
macro InsFunHeader()
{
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
szFunc = GetCurSymbol()
ln = GetSymbolLine(szFunc)
szDescription = Ask("Enter the description of function:")
// begin assembling the title string
InsBufLine(hbuf, ln + 0, "/*!")
InsBufLine(hbuf, ln + 1, " *\\fn @szFunc@()")
InsBufLine(hbuf, ln + 2, " *\\brief @szDescription@.")
InsBufLine(hbuf, ln + 3, " *\\details ")
InsBufLine(hbuf, ln + 4, " * ")
InsBufLine(hbuf, ln + 5, " *\\param[in] N\/A.")
InsBufLine(hbuf, ln + 6, " *\\param[out] N\/A.")
InsBufLine(hbuf, ln + 7, " * ")
InsBufLine(hbuf, ln + 8, " *\\return N\/A.")
InsBufLine(hbuf, ln + 9, " *\\retval N\/A.")
InsBufLine(hbuf, ln + 10, " * ")
InsBufLine(hbuf, ln + 11, " *\\note")
InsBufLine(hbuf, ln + 12, " */")
}
macro InsVarComments()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
szDef = Ask("Enter the name of the variable:")
szDescription = Ask("Enter the description of Varaables:")
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln + 0, "/*!")
InsBufLine(hbuf, ln + 1, " *\\def @szDef@")
InsBufLine(hbuf, ln + 2, " *\\brief @szDescription@")
InsBufLine(hbuf, ln + 3, " */")
}
macro addNameTime()
{
szMyName = "XXX" /* Enter your name */
hwnd = GetCurrentWnd()
se = getwndsel(hwnd)
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
str = GetBufSelText(hbuf)
/* Get current time */
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
if (Month < 10)
szMonth = "0@Month@"
else
szMonth = Month;
hbuf = GetCurrentBuf()
if (se.fExtended)
{
str = "/*!<" #str# "*/"
SetBufSelText(hbuf, str)
}
else
{
str = "/*!< @szMyName@ : @szMonth@/@szDay@/@Year@*/"
se.ichFirst = se.iChFirst + 3
se.ichLim = se.ichLim + 3
SetBufSelText(hbuf, str)
SetBufIns (hbuf, ln, se.iChFirst)
SetWndSel(hwnd, se)
}
}
macro preventIncludeRepeatly()
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
lnLast = GetWndSelLnLast(hwnd)
/* get file name */
szFileName = Ask("Enter name of header file:")
szFileName = toupper(szFileName)
szFileName = cat("__", szFileName)
szFileName = cat(szFileName, "_H__")
hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnFirst, "#ifndef @szFileName@")
InsBufLine(hbuf, lnFirst +1, "#define @szFileName@")
InsBufLine(hbuf, lnFirst +2, "")
InsBufLine(hbuf, lnLast +4, "")
InsBufLine(hbuf, lnLast +5, "#endif /* @szFileName@ */")
}
macro InsertCPlusPlus()
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
lnLast = GetWndSelLnLast(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnFirst, "#ifdef __cplusplus")
InsBufLine(hbuf, lnFirst +1, "extern \"C\" {")
InsBufLine(hbuf, lnFirst +2, "#endif")
InsBufLine(hbuf, lnFirst +3, "")
InsBufLine(hbuf, lnLast +5, "")
InsBufLine(hbuf, lnLast +6, "#ifdef __cplusplus")
InsBufLine(hbuf, lnLast +7, "}")
InsBufLine(hbuf, lnLast +8, "#endif")
}
macro addComment()
{
hwnd = GetCurrentWnd()
se = getwndsel(hwnd)
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
str = GetBufSelText(hbuf)
if (se.fExtended)
{
str = "/*!<" #str# "*/"
SetBufSelText(hbuf, str)
}
else
{
str = "/*!< */"
se.ichFirst = se.iChFirst + 3
se.ichLim = se.ichLim + 3
SetBufSelText(hbuf, str)
SetBufIns (hbuf, ln, se.iChFirst)
SetWndSel(hwnd, se)
}
}
macro addFileInformation()
{
addGlobalFunctions()
addPublicFunctions()
addLocalFunctions()
addLocalPrototypes()
addExternPrototypes()
addFunctions()
addVariables()
addTypes()
addDefines()
addIncludeFiles()
addConfigrations()
}
macro addConfigrations()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* CONFIGURATIONS */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addIncludeFiles()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* INCLUDE_FILES */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addDefines()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* DEFINES */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addTypes()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* TYPES */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addVariables()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* VARIABLES */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addFunctions()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* FUNCTIONS */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addExternPrototypes()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* EXTERN_PROTOTYPES */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addLocalPrototypes()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* LOCAL_PROTOTYPES */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addLocalFunctions()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* LOCAL_FUNCTIONS */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addPublicFunctions()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* PUBLIC_FUNCTIONS */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
macro addGlobalFunctions()
{
hwnd = GetCurrentWnd()
ln = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, ln, "/**********************************************************************/")
InsBufLine(hbuf, ln +1, "/* GLOBAL_FUNCTIONS */")
InsBufLine(hbuf, ln +2, "/**********************************************************************/")
}
/*======================================================================
* -------Source Insight3 中文操作(左右鍵、刪除和後退鍵)支持宏-------
* 用原來作者提供的方法使用工程中有的問題,於是換了種方式試了一下,測試OK,
* 現在只需按照下面的說明①--③應用即可,已經測試OK
* 感謝丁兆傑([email protected])及互聯網上辛勤耕耘的朋友們!!!
* Evan: [email protected]
*
* ① Project→Open Project,打開Base項目,將本文中的所有內容函數複製到utils.em文件的最後
* ② 重啓SourceInsight;
* ③ Options→Key Assignments,將下面宏依次與相應按鍵綁定:
Marco: SuperBackspace綁定到BackSpace鍵;
Marco: SuperCursorLeft綁定到<-鍵,
Marco: SuperCursorRight綁定到->鍵,
Marco: SuperShiftCursorLeft綁定到Shift+<-,
Macro: SuperShiftCursorRight綁定到shift+->,
Macro: SuperDelete綁定到del。
* ④ Enjoy
======================================================================*/
/*======================================================================
1、BackSpace後退鍵
======================================================================*/
macro SuperBackspace()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
stop; // empty buffer
// get current cursor postion
ipos = GetWndSelIchFirst(hwnd);
// get current line number
ln = GetBufLnCur(hbuf);
if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
// sth. was selected, del selection
SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight
// del the " "
SuperBackspace(1);
stop;
}
// copy current line
text = GetBufLine(hbuf, ln);
// get string length
len = strlen(text);
// if the cursor is at the start of line, combine with prev line
if (ipos == 0 || len == 0) {
if (ln <= 0)
stop; // top of file
ln = ln - 1; // do not use "ln--" for compatibility with older versions
prevline = GetBufLine(hbuf, ln);
prevlen = strlen(prevline);
// combine two lines
text = cat(prevline, text);
// del two lines
DelBufLine(hbuf, ln);
DelBufLine(hbuf, ln);
// insert the combined one
InsBufLine(hbuf, ln, text);
// set the cursor position
SetBufIns(hbuf, ln, prevlen);
stop;
}
num = 1; // del one char
if (ipos >= 1) {
// process Chinese character
i = ipos;
count = 0;
while (AsciiFromChar(text[i - 1]) >= 160) {
i = i - 1;
count = count + 1;
if (i == 0)
break;
}
if (count > 0) {
// I think it might be a two-byte character
num = 2;
// This idiot does not support mod and bitwise operators
if ((count / 2 * 2 != count) && (ipos < len))
ipos = ipos + 1; // adjust cursor position
}
}
// keeping safe
if (ipos - num < 0)
num = ipos;
// del char(s)
text = cat(strmid(text, 0, ipos - num), strmid(text, ipos, len));
DelBufLine(hbuf, ln);
InsBufLine(hbuf, ln, text);
SetBufIns(hbuf, ln, ipos - num);
stop;
}
/*======================================================================
2、刪除鍵——SuperDelete.em
======================================================================*/
macro SuperDelete()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
stop; // empty buffer
// get current cursor postion
ipos = GetWndSelIchFirst(hwnd);
// get current line number
ln = GetBufLnCur(hbuf);
if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
// sth. was selected, del selection
SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight
// del the " "
SuperDelete(1);
stop;
}
// copy current line
text = GetBufLine(hbuf, ln);
// get string length
len = strlen(text);
if (ipos == len || len == 0) {
totalLn = GetBufLineCount (hbuf);
lastText = GetBufLine(hBuf, totalLn-1);
lastLen = strlen(lastText);
if (ipos == lastLen)// end of file
stop;
ln = ln + 1; // do not use "ln--" for compatibility with older versions
nextline = GetBufLine(hbuf, ln);
nextlen = strlen(nextline);
// combine two lines
text = cat(text, nextline);
// del two lines
DelBufLine(hbuf, ln-1);
DelBufLine(hbuf, ln-1);
// insert the combined one
InsBufLine(hbuf, ln-1, text);
// set the cursor position
SetBufIns(hbuf, ln-1, len);
stop;
}
num = 1; // del one char
if (ipos > 0) {
// process Chinese character
i = ipos;
count = 0;
while (AsciiFromChar(text[i-1]) >= 160) {
i = i - 1;
count = count + 1;
if (i == 0)
break;
}
if (count > 0) {
// I think it might be a two-byte character
num = 2;
// This idiot does not support mod and bitwise operators
if (((count / 2 * 2 != count) || count == 0) && (ipos < len-1))
ipos = ipos + 1; // adjust cursor position
}
// keeping safe
if (ipos - num < 0)
num = ipos;
}
else {
i = ipos;
count = 0;
while(AsciiFromChar(text) >= 160) {
i = i + 1;
count = count + 1;
if(i == len-1)
break;
}
if(count > 0) {
num = 2;
}
}
text = cat(strmid(text, 0, ipos), strmid(text, ipos+num, len));
DelBufLine(hbuf, ln);
InsBufLine(hbuf, ln, text);
SetBufIns(hbuf, ln, ipos);
stop;
}
/*======================================================================
3、左移鍵——SuperCursorLeft.em
======================================================================*/
macro IsComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
return 0;
//當前位置
pos = GetWndSelIchFirst(hwnd);
//當前行數
ln = GetBufLnCur(hbuf);
//得到當前行
text = GetBufLine(hbuf, ln);
//得到當前行長度
len = strlen(text);
//從頭計算漢字字符的個數
if(pos > 0)
{
i=pos;
count=0;
while(AsciiFromChar(text[i-1]) >= 160)
{
i = i - 1;
count = count+1;
if(i == 0)
break;
}
if((count/2)*2==count|| count==0)
return 0;
else
return 1;
}
return 0;
}
macro moveleft()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
stop; // empty buffer
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
if(GetBufSelText(hbuf) != "" || (ipos == 0 && ln == 0)) // 第0行或者是選中文字,則不移動
{
SetBufIns(hbuf, ln, ipos);
stop;
}
if(ipos == 0)
{
preLine = GetBufLine(hbuf, ln-1);
SetBufIns(hBuf, ln-1, strlen(preLine)-1);
}
else
{
SetBufIns(hBuf, ln, ipos-1);
}
}
macro SuperCursorLeft()
{
moveleft();
if(IsComplexCharacter())
moveleft();
}
/*======================================================================
4、右移鍵——SuperCursorRight.em
======================================================================*/
macro moveRight()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
stop; // empty buffer
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln);
if(GetBufSelText(hbuf) != "") //選中文字
{
ipos = GetWndSelIchLim(hwnd);
ln = GetWndSelLnLast(hwnd);
SetBufIns(hbuf, ln, ipos);
stop;
}
if(ipos == strlen(text)-1 && ln == totalLn-1) // 末行
stop;
if(ipos == strlen(text))
{
SetBufIns(hBuf, ln+1, 0);
}
else
{
SetBufIns(hBuf, ln, ipos+1);
}
}
macro SuperCursorRight()
{
moveRight();
if(IsComplexCharacter()) // defined in SuperCursorLeft.em
moveRight();
}
/*======================================================================
5、shift+右移鍵——ShiftCursorRight.em
======================================================================*/
macro IsShiftRightComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
return 0;
selRec = GetWndSel(hwnd);
pos = selRec.ichLim;
ln = selRec.lnLast;
text = GetBufLine(hbuf, ln);
len = strlen(text);
if(len == 0 || len < pos)
return 1;
//Msg("@len@;@pos@;");
if(pos > 0)
{
i=pos;
count=0;
while(AsciiFromChar(text[i-1]) >= 160)
{
i = i - 1;
count = count+1;
if(i == 0)
break;
}
if((count/2)*2==count|| count==0)
return 0;
else
return 1;
}
return 0;
}
macro shiftMoveRight()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
stop;
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln);
selRec = GetWndSel(hwnd);
curLen = GetBufLineLength(hbuf, selRec.lnLast);
if(selRec.ichLim == curLen+1 || curLen == 0)
{
if(selRec.lnLast == totalLn -1)
stop;
selRec.lnLast = selRec.lnLast + 1;
selRec.ichLim = 1;
SetWndSel(hwnd, selRec);
if(IsShiftRightComplexCharacter())
shiftMoveRight();
stop;
}
selRec.ichLim = selRec.ichLim+1;
SetWndSel(hwnd, selRec);
}
macro SuperShiftCursorRight()
{
if(IsComplexCharacter())
SuperCursorRight();
shiftMoveRight();
if(IsShiftRightComplexCharacter())
shiftMoveRight();
}
/*======================================================================
6、shift+左移鍵——ShiftCursorLeft.em
======================================================================*/
macro IsShiftLeftComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
return 0;
selRec = GetWndSel(hwnd);
pos = selRec.ichFirst;
ln = selRec.lnFirst;
text = GetBufLine(hbuf, ln);
len = strlen(text);
if(len == 0 || len < pos)
return 1;
//Msg("@len@;@pos@;");
if(pos > 0)
{
i=pos;
count=0;
while(AsciiFromChar(text[i-1]) >= 160)
{
i = i - 1;
count = count+1;
if(i == 0)
break;
}
if((count/2)*2==count|| count==0)
return 0;
else
return 1;
}
return 0;
}
macro shiftMoveLeft()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
stop;
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln);
selRec = GetWndSel(hwnd);
//curLen = GetBufLineLength(hbuf, selRec.lnFirst);
//Msg("@curLen@;@selRec@");
if(selRec.ichFirst == 0)
{
if(selRec.lnFirst == 0)
stop;
selRec.lnFirst = selRec.lnFirst - 1;
selRec.ichFirst = GetBufLineLength(hbuf, selRec.lnFirst)-1;
SetWndSel(hwnd, selRec);
if(IsShiftLeftComplexCharacter())
shiftMoveLeft();
stop;
}
selRec.ichFirst = selRec.ichFirst-1;
SetWndSel(hwnd, selRec);
}
macro SuperShiftCursorLeft()
{
if(IsComplexCharacter())
SuperCursorLeft();
shiftMoveLeft();
if(IsShiftLeftComplexCharacter())
shiftMoveLeft();
}