Fork me on GitHub

11/21/2010

讓 vim 的 class 和 function 也有語法高亮度 (syntax highlight)

1. 建立檔案 ~/.vim/syntax/c.vim

2. 在 c.vim 當中加入

" Highlight Class and Function names
syn match    cCustomParen    "(" contains=cParen
syn match    cCustomFunc     "\w\+\s*(" contains=cCustomParen
syn match    cCustomScope    "::"
syn match    cCustomClass    "\w\+\s*::" contains=cCustomScope


hi cCustomFunc guifg=yellowgreen
hi cCustomClass guifg=#00FF00

3. 重新啟動 vim

參考資料:
1. class & function names highlighting in Vim - Stack Overflow

...

幫 vim 加上 NERDtree 檔案系統瀏覽功能

一般 IDE 都會有一個類似檔案總館的樹狀資料結構,vim 也可以透過 NERDTree 這個 plugin 達成!

1. 下載 NERDTree

2. 解壓縮至 ~/.vim 資料夾當中,將對應的檔案放到對應的資料夾底下,沒有該資料夾則自行創建

3. 重新啟動 vim

一些使用的技巧如下:

1. 使用 :NERDTreeToggle 開啟/關閉 NERDTree 視窗,也可以設定對應的快速鍵來達成
map :NERDTreeToggle

2. 用 Ctrl + ww 來切換 NERDTree 和原始碼視窗

3. 在 NERDTree 當中用 t 使用新分頁開啟檔案並跳轉過去,使用 T 新分頁開啟檔案但不跳轉過去

其他:

Press i to open the file in a new horizontal split.
Press s to open the file in a new vertical split.
Press p to go to parent directory.
Press r to refresh the current directory.

參考資料
Command Center: Vim Plugins You Should Know About: NERDTree

...

11/19/2010

幫 vim 加上 C++ code completion 功能

IDE 的自動補完功能是非常方便的,如何讓 vim 也有類似 IDE 那般方便的 auto-completion 呢。以下記錄實作的方式。

1. 在 ~/.vim 下建立資料夾 tags

2. 建立 stdc++ tags, 下載並解壓縮 modified libstdc++ headers 到 ~/.vim/tags/cpp_src

3. 建立 ctags 吧
--c++-kinds=+pl : 為C++文件增加函數原型的標籤, 添加 l 讓局部變數也能自動補完
--fields=+iaS : 在標籤文件中加入繼承信息(i)、類成員的訪問控制信息(a)、以及函數的指紋(S)
--extra=+q : 為標籤增加類修飾符。注意,如果沒有此選項,將不能對類成員補全

$ cd ~/.vim/tags
$ ctags -R --sort=1 --c++-kinds=+pl --fields=+iaS --extra=+q --language-force=C++ -f cpp cpp_src 

如果你想要針對特定使用之函式庫也能有自動補完功能,那麼也需要針對該函式庫建立相對應的 tag 檔案,舉 Qt4 為例 (只針對 QtCore 的部份建立 tags):

$ cd ~/.vim/tags
$ ctags -R --sort=1 --c++-kinds=+pl --fields=+iaS --extra=+q --language-force=C++ -f qt4Core /Library/Frameworks/QtCore.framework/Headers


4. 編輯你的 ~/.vimrc 檔案

" configure tags - add additional tags here or comment out not-used ones
set tags+=~/.vim/tags/cpp
set tags+=~/.vim/tags/qt4Core



" build tags of your own project with Ctrl-L
map <C-L> :!ctags -R --sort=yes --c  -kinds= p --fields= iaS --extra= q .<CR>


" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview

5. 然後就可以開始使用啦,新增局部變數的時候記得 更新一下 tags 檔案,就可以 選擇要自動補完的函數或變數囉!

參考資料
1. C++ code completion - Vim Tips Wiki
2. Vim and Ctags tips and tricks - Stack Overflow

3.  The Only Winning Move » Code Completion for Qt4 in Vim - Mac OS X Version

...

11/18/2010

為 MacVim 裝上 taglist 套件

vim 是一個強大的文字編輯器,使用 taglist 套件,我們可以概覽程式碼的結構並在各個原始碼文件中跳轉瀏覽,非常方便!

Tag List 插件需要 Ctags 這個程序的支持,然而,系統自帶的 Ctags 功能比較簡單,支持的語言也少(如不支持 C++、Java 等語言),所以推薦安裝更強大的 Exuberant Ctags

首先到官方網站下載 Exuberant Ctags 的源代碼,最新版本是5.8。

接著解壓到本地並進入文件夾,確保你的 Mac 上面已經安裝了 XCode 之後,就可以開始編譯安裝 Exuberant Ctags:

./configure
make
sudo make install


Exuberant Ctags 就會被安裝在 /usr/local/ 目錄下了,但是由於系統中原先已經內置了Ctags,如果沒有將 /usr/local/bin 添加到系統路徑中的話,默認執行的是 /usr/bin/ctags,可以在命令行中執行:

which ctags

如果返回的不是 /usr/local/bin/ctags,那麼需要修改一下環境變數

echo $PATH 可以印出現在的 PATH 設定。

$ sudo vi /etc/paths 則可以編輯 PATH 設定,將 usr/local/bin 移至 usr/bin 前方,儲存後重開 Terminal。

接著再檢查一次 which ctags 是不是返回 /usr/local/bin/ctags,是的話就正確了。

Exuberant Ctags 安裝完畢之後就可以安裝 Tag List 插件了,在官方網站上下載 Tag List 然後解壓,將 plugin 文件夾中的 taglist.vim 復制到 ~/.vim/plugin/ 中,將 doc 文件夾中的 taglist.txt 復制到 ~/.vim/doc/ 中,如果~目錄下沒有對應的文件夾請自行創建。

最後,處理 Tag List 的幫助文件,先命令行進入 ~/.vim/doc 文件夾,然後啟動 Vim,在 Vim 中執行(注意命令中的 .)

:helptags .

注意:

1. This plugin relies on the Vim "filetype" detection mechanism to determine the type of the current file. You have to turn on the Vim filetype detection by adding the following line to your .vimrc file:

filetype on

2. You can now use the ":TlistToggle" command (previously ":Tlist") to open/close the taglist window. You can use the ":help taglist" command to get more information about using the taglist plugin.

參考資料:

1. Vim Taglist plugin installation: http://vim-taglist.sourceforge.net/installation.html
2. 安裝Exuberant Ctags及Tag List插件: http://aug6th.com/blog/?p=12/

使用方法:

1. Terminal 到你要瀏覽的專案資料夾目錄下,輸入

ctags -R 建立 tag 標籤檔

2. 用 MacVim 開啟一原始檔,並且下

:TlistToggle 開啟 taglist


11/17/2010

Qt 在 mac 下用 g++ compile

將程式寫好之後 在路徑下

1. qmake -project : 產生 .pro 檔案

2. mac {
        CONFIG -= app_bundle
    }
    
不要 Makefile 創建 app bundle
    
3. 直接 qmake 會產生 Xcode project, qmake -spec macx-g++ 則會生成一個 makefile

4. make 輸出執行檔

參考資料:How to compile a simple Qt and c++ application using g++ on mac os x?

...

11/14/2010

iPhone Human Interface Guidelines Notes (2, 3 chapters)

Chap2. Creating a Great User Interface

基於實現方式 iOS 可將軟體分為三類:iPhone Application, Web-only content, Hybrid application

三種 Application Styles:
1. Productivity 2. Utility 3. Immersive

學習不同的 application style 經常心存下列疑問
1. user用這個app的動機
2. user使用這個app的體驗
3. app的焦點和主要目標
4. app如何組織和顯示使用這關心的資訊

記住人們在使用iOS device的時候通常一邊在走路, 並且周遭的環境非常容易使人分心

運用80/20法則決定應該要有哪些功能, 只做那些絕大部分的人需要的功能

好的介面設計並非基於device的能力, 而是基於使用者如何思考和運作你的app

隱喻:如果可以, 讓app的操作盡量符合真實世界的物件或行為

直接處理:使用者可以直接感受到控制的東西是tangible, 而非abstract
1. 當user執行動作時, 物件依然是可見的
2. 而且結果可以直接讓user感受到

美學整合並不是好看就好, 而是評估外表和功能之間的一致性

Chap3. From Product Definition to Branding

建構一個產品定義描述(product definition statement)
首先你要先了解目標客戶族群, 將你想要傳達的功能和目標客戶族群放在腦中, 試著將這些功能列表轉換成一句描述

產品定義描述:描述產品提供的解決方案以及其目標客戶群

學習典範app的特性

# 簡化和易用性
1. 主要的功能要立即且明顯(可以在一開始使用最少的按鈕和明顯的label說明,讓使用者一目了然)
2. 將經常使用、高階的資訊置放於螢幕頂端(考慮手指操作, 拇指最容易觸擊的地方就是螢幕頂端)
3. 縮短使用者輸入的長度(當使用者持需輸入而看不到任何進展是令人挫敗的, 盡量縮短讓使用者輸入的過程, 或者是切分他們, 讓使用者可以看到每一步輸入都有些許的進展)
4. 簡短的表達資訊
5. 提供手指大小的target

# 專注於主要task
謹記產品定義描述, 當你決定什麼資訊要顯示在螢幕上的時候問自己, 使用者當下非常需要這個資訊或功能嗎?

# 溝通效率
使用者時時都要知道自己的動作是否有被處理或者造成什麼錯誤, 但是無謂的互動會造成厭煩. 站在使用者的立場使用他們懂得詞彙, 避免專業術語.

# 適當的支援手勢
盡量使用最簡單易懂的tap和drag, 利用使用者已經習慣內建的手勢語意, 來提升app一致的操作體驗

...