1. 程式人生 > >source insight使用技巧-巨集,顏色.tom

source insight使用技巧-巨集,顏色.tom

4、SI中的自動對齊設定:
    在C程式裡, 如果遇到行末沒有分號的語句,如IF, WHILE, SWITCH等, 寫到該行末按回車,則新行自動相對上一行縮排兩列。
    Option->Document option下的Auto Indient中Auto Indient Type有三種類型 None,Simple,Smart。個人推薦選用Simple型別。
7、恢復ctrl+a的全選功能
    通過關鍵詞save 找到save all,更改為ctrl+shift+a,通過關鍵詞select找到select all,更改為ctrl +a


8:在Source Insight中新增自定義功能的步驟如下:


1.Source Insight中,Options->Custom Commands...->Add...,New Command name 隨便寫,我的是"Edit with Vim"
2.Run中寫入: "C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f
意思是在當前已經開啟的gvim窗口裡面開啟當前的檔案,並且跳轉到指定行
%l為當前的行號,%f為檔名
使用 --remote-silent 的作用是,如果已經打開了對應檔案,就不會開啟第二次,而是在已經開啟的檔案裡跳轉到對應行
3.還是同一個對話方塊裡面,選擇Keys->Assign New Key...->按F12,如果你已經將F12設定給其他命令,選擇其他的按鍵就行了

下面是一些常用自定義功能:( CUSTOM COMMANDS )

以下幾個自定義命令我把他們關聯到了選單。

自定義的選單名

功能

Run編輯框內容

Explore File

開啟資源管理器並選中當前檔案

ShellExecute open explorer /e,/select,%f

Edit with UE

在ultriEdit中編輯

"C:\Program Files\UltraEdit-32/uedit32" %f

Edit with VIM

在vim中編輯並定位到當前行

"C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f

AStyle_C

格式化當前檔案(後面章節會介紹)

"C:\AStyle\bin\AStyle.exe" --options="C:\AStyle\bin\c.opt" %f

Trim Whitespace

刪除整個檔案每行行末尾的空白字元

這個是從Edit: Trim Whitespace從加進來的,是SI自帶的功能,只是沒有放到選單上來而已。

關於這些%f、%l等引數什麼意思,這是SI的萬用字元,可以搜尋下SI幫助文件“Command Line Substitutions”章節,裡


檢視log
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:log /path:%f /notempfile /closeonend
diff
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:diff /path:%f /notempfile /closeonend
取得鎖定(check out)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:lock /path:%f /notempfile /closeonend
提交(check in)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:%f /notempfile /closeonend

提交所有(check in)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:*.* /notempfile /closeonend


更新(update)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:%f /notempfile /closeonend
更新整個目錄(update all)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:*.* /notempfile /closeonend
取消鎖定(undo check out)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:revert /path:%f /notempfile /closeonend
在ultriEdit中編輯
"C:\Program Files\UltraEdit-32/uedit32" %f
在vim中編輯並定位到當前行
"C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f

彙總其他小技巧:

讓{ 和 } 不縮排:


Options->Document Options->Auto Indent->Indent Open Brace/Indent Close Brace

hao space: SourceInsight 小技巧
1、按住"ctrl", 再用滑鼠指向某個變數,點選一下,就能進入這個變數的定義。

2、今天把一個用sourceinsight排版整齊的C檔案,偶然用VC開啟一看,全亂了。研究了半天,發現SI對每個字元的寬度不太一致。
    請教同事發現選上"view --> draft view", 就可以讓每個字元的寬度一致了。快捷鍵是 "Alt + F12

Source Insight是閱讀和編寫程式碼的好東東,基本上也算得上是經典之作了,雖然還有一點點小bug,不過對於我們這些C程式設計師來說可是一旦擁有別無所求。下列小技巧是在工作中同事整理總結的,對提高工作效率多少有點幫助,其中有些是對應於SVN的,沒有使用SVN做版本管理的人就不要白費力氣了。

ShellExecute open explorer /e,/select,%f
X:\Progra~1\TortoiseSVN\bin\TortoiseProc.exe /command:log /path:% /notempfile /closeonend
 X:\Progra~1\TortoiseSVN\bin\TortoiseProc.exe /command:diff /path:% /notempfile /closeonend

怎麼新增makefile檔案

Options -> Document Options... Alt-T    -> 點選Document Type的下拉框,然後選擇Make File,在右邊的File Filter中,在原先的*.mak後面加上一個分號,即多個不同過濾

規則以分號間隔開,再加上*makefile,變成 *.mak;*makefile,並且選中Include when adding to projects,這樣,以後再新建工程的時候,就可以識別makefile或Makefile了(

好像此處Source Insight並不區分大小寫)。

 Source Insight常用的快捷鍵:
    Ctrl+= :Jump to definition
    Ctrl+/ :Look up reference
    F3 : search backward
    F4 : search forward
    F5: go to Line
    F7 :Look up symbols
    F8 :Look up local symbols
    F9 :Ident left
    F10 :Ident right
    Alt+, :Jump backword
    Alt+. : Jump forward
    Shift+F3 : search the word under cusor backward
    Shift+F4 : search the word under cusor forward
    F12 : incremental search
    Shift+Ctrl+f: search in project
    shift+F8 : hilight word

顏色

source insight是一個出色的程式編輯器和程式碼瀏覽器,利用好它會給編寫和閱讀原始碼帶來極大的方便。想要配置好source insight可不是一件輕鬆的事,我比較喜歡深色背景有利於保護眼睛,但同時也必須更改程式碼顏色來匹配背景色,source insight的很多視窗、選項都可以指定字型、顏色,實在讓人犯暈!最麻煩的是原始碼視窗的配置了,這裡簡單提一下,source insight的最終配色是由Style Properties決定的(右鍵選單-->Style Properties)

左邊一欄是風格名,選中的是當前游標下的風格名,這些風格之間是有繼承關係的,可以看到有很多=號,這代表繼承了父風格(Parent Style),pick則是讓你單獨設定,最右邊還可以匯入、匯出、新增風格等。所有風格最終由Default Text繼承而來的,Font Name是灰的,它由Document Options(Alt+T)中的當前文件型別 Screen Fonts決定的(所以不同的檔案型別,如C,Python,Java它們的字型可以不同的)。Background是由Options-->Preferences-->Colors中的Window Background決定的,其實Default Text的背景就是原始碼視窗的背景。Foreground也一樣,pick了它等於設定了Options-->Preferences-->Colors中的Default Text。我也暈了,汗……

正是這些風格讓source insight五彩繽紛:

SI

還要提一句,sourceinsight中還有一個Draft View(Alt+F12),在這個模式中會忽略Style Properties中字型部分設定,統一改用Draft View(見左邊欄)中設定的字型。我製作了一個背景為深黑色,字型為Fixdays的配置檔案(包含其它設定)讓大家下載:http://download.csdn.net/source/2480193

羅嗦了半天,WRK還沒說呢,關於如何使用請看中文官網的文章 。source insight分析完WRK後大家肯定會發現連IRP、DEVICE_OBJECT這樣的結構都沒法解析,其實罪魁禍首就是那些函式巨集,比如_IRP前面的DECLSPEC_ALIGN(),如果用我前面的配置檔案調過顏色的話一眼就可以看出,source insight把它當成了Declare Function了,這些巨集大多起修飾作用並無實質影響,但一樣的巨集在MS的程式碼中數不勝數(如非vc6的crt,標頭檔案,連printf都解析不來)。可以看看這個帖子http://topic.csdn.net/u/20100613/16/b32fc799-c7f2-4648-9d91-cc933f9ffeb8.html ,我一開始以為是BUG,但source insight提供瞭解決方案,那就是Token Macro。Token Macro就是source insight的前處理器,它可以像C前處理器那樣展開巨集,正是為了對抗那些混淆source insight的巨集而設計的。Token Macro是一個以.tom結尾的檔案,對C/C++來說是C.tom,只要把它放在source insight建立工程的目錄下,就可以立馬起作用(不用重新parse一遍,不過有些時候還是parse一遍好),它會跟程式目錄下的全域性C.tom結合去展開巨集。Token Macro編寫非常簡單,跟#define語法差不多(但沒它強大)。大家看看我針對WRK做的C.tom就明白了,由於大多數函式巨集只起修飾作用不會影響程式碼的解析,所以我把大多數巨集做成了空巨集。

Token Macro Syntax

A token macro file consists of token macros, one per line. The format of a token macro is:

macroname <no text here means macro is a no-op>
macroname substituted text here
macroname(parameter list) substituted text with 
parameter names
macroname(parameter) text##parameter // concatenates 
text 
; comments begin with a semicolon 

Some examples of token macros:

MyStructure(sname) struct sname
NoOperation
BuildName(name1, name2) name1##name2

另外條件編譯也是一個可能讓source insight分析出錯的地方,預設它會分析所有的條件分支。但碰到這樣的情形就糟糕了:

[cpp] view plaincopyprint?
  1. void MyFunc  
  2. #ifdef XYZ
  3.     (int param1, int param2)  
  4. #else
  5.     (long param1, long param2)  
  6. #endif
  7. {  
  8.     …  
  9. }  
  10. void DoThing(  
  11. int param1,  
  12. #ifdef ABC
  13. int param2)  
  14. #else
  15. int param2, param3)  
  16. #endif

很不幸,WRK中也有這樣的問題,這個可以通過新增Condition的方法解決。

我在Global Conditons中添加了;

  • MIDL_PASS    0
  • __midl    0

Project-Specific conditions添加了:

  • _AMD64_    0
  • _MSC_VER    1300
  • _NDIS_    1
  • _NTDDK_    1
  • _NTIFS_    1
  • _WIN64    0
  • _X86_    1

這樣不符合條件的分支程式碼會不進行解析,用灰色表示。

另外,sourceinsight還有一個小BUG,用typedef定義函式指標型別時,當函式指標返回型別(也用typedef定義)和函式指標型別定義在同一行時,函式指標返回型別無法解析。如:

[cpp] view plaincopyprint?
  1. typedef
  2. NTSTATUS (*WMIENTRY)(  
  3. ……);//NTSTATUS無法解析
  4. typedef NTSTATUS  
  5. (*WMIENTRY)(  
  6. ……);//NTSTATUS可以解析

還有typedef定義函式指標型別時,函式的引數也都是不染色!這個問題似乎沒有什麼解決方法,用Custom Parsing也無濟於事。

還有一種情況會讓source insight解析出錯,比如IopfCompleteRequest、NtQueryEaFile函式,在函式名和{之間有一段多行巨集,這樣source insight就解析的有問題了。這應該是個BUG,不知道大家有什麼解決辦法,我迫不得已只好挪動一下巨集的位置!

現在幾乎所有的問題都解決了,程式碼中都染上顏色了吧,呵呵……

SI

SI

SI

SI

Token Macro Files

The token macros are listed in a file with a .tom extension. The globaltoken macro file resides in the Source Insight program directory. The project-specifictoken macro file, if any, is stored in project’s data directory. The projecttoken macro file is combined with the global file, with the projectmacros taking precedence.

Token Macro Syntax

A token macro file consists oftoken macros, one per line. The format of atoken macro is:

macroname <no text here means macro is a no-op>
macroname substituted text here
macroname(parameter list) substituted text with 
parameter names
macroname(parameter) text##parameter // concatenates 
text 
; comments begin with a semicolon 

Some examples of token macros:

MyStructure(sname) struct sname
NoOperation
BuildName(name1, name2) name1##name2

Each built-in language parser has a corresponding token macro file. The name of the token macro file for each language is summarized below:

Table 4.2: Token Macro Files for Different Languages

Language

File Name

C and C++

C.tom – a default copy ships with Source Insight.

HTML

Html.tom

Java

Java.tom

Resource Files

Rc.tom

x86 Assembly Language

X86.tom

Perl

Perl.tom

EditingToken Macros

If you want to change the token macros, simply open the token macro file, make your changes, and save the file. Source Insight will recognize that thetoken macros have changed for the appropriate language. Open files are automatically re-parsed.

When you edit a token macro file, you must save it to disk before Source Insight will re-parse your open files. However, Source Insight will not automatically re-parse your whole project. You should make all your changes to thetoken macro file first, then use the Rebuild Project command to re-parse your whole project. Until your project is re-parsed, the symbol information stored in Source Insight’s symbol database will not reflect the changes you made to yourtoken macros.

Project SpecificToken Macros

Each project can have its own set of token macro files. Source Insight does not create them automatically, but you can yourself. A projecttoken macro file is saved in the project's data directory. When Source Insight parses a source file, it combines the projecttoken macros with the global set saved in the Source Insight program directory. The projecttoken macros take precedence over the global ones. By adding project specifictoken macros, you can tailor thetoken macro expansion for each project individually.

 例項:

static __attribute__((unused)) char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];

static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
      ulong base_addr)
{

載入了C.tom後就可以顯示下面的函數了,

C.tom內容如下

__attribute__(unused)

__initdata
__init
__init		  
__initdata	
__initconst	
__exitdata	
__exit_call	                                    
__ref                                           
__refdata                                       
__refconst                                                
__init_refok                                              
__initdata_refok                                          
__exit_refok                                              
__exitused                                                
__exitused  		                                          
__exit                                                     
__devinit       	                                         
__devinitdata                                             
__devinitconst                                                           
__devexit                                                                
__devexitdata                                                            
__devexitconst                                                           
__cpuinit                                                                
__cpuinitdata                                                            
__cpuinitconst                                                           
__cpuexit                                                                
__cpuexitdata                                                            
__cpuexitconst                                                           
__meminit                                                                
__meminitdata                                                            
__meminitconst               
__memexit                    
__memexitdata                
__memexitconst               
__HEAD					             
__INIT					             
__FINIT					             
__INITDATA			             
__INITRODATA		             
__FINITDATA			             
__DEVINIT                    
__DEVINITDATA                
__DEVINITRODATA              
__CPUINIT       
__CPUINITDATA  
__CPUINITRODATA
__MEMINIT      
__MEMINITDATA  
__MEMINITRODATA 
__REF         
__REFDATA       
__REFCONST