ECB – Emacs Code Browser
Bài viết này nhằm tổng hợp và giới thiệu một số kinh nghiệm viết code dùng ECB-minor-mode trong Emacs.
ECB được tích hợp vào emacs nên việc cài đặt là không cần thiết. Tuy nhiên, để đảm bảo có version mới nhất, bạn nên tự cài đặt bằng cách download từ sourceforge.
Sau đó, bạn chỉ cần khai báo trong file cấu hình ~/.emacs nội dung sau
;; ECB = Emacs code browser(add-to-list ‘load-path “~/.emacs.d/share/ecb-snap”)
(require ‘ecb)
Sau đó, mỗi lần soạn thảo code, bạn run ecb bằng lệnh: M-x ecb-minor-mode
Một số thiết lập cần chỉnh sửa với ECB:
- path to source code
M-x customize-option <RET> ecb-source-path
Bạn thêm vào đường dẫn đến sources, điều này giúp ECB scan source files nhanh chóng. Đặc biệt ECB hỗ trợ remote coding, cho phép bạn chỉ định remote folder dùng TRAMP, ví dụ:
/ssh:username@machine:/path/to/source/
Code nagivation
Chức năng jump đến một subroutine/funciton chưa có trong ECB, bạn nên dùng etags
Tại thư mục cao nhất của source trees, chạy dòng lệnh
find . -name ‘*.[chCH]‘ | xargs etagsMột số options của etags có thể sử dụng
- –language=lang_name với lang_name có thể là auto, fortran, …
- –include=file: chèn một tag file khác vào tag file được tạo ra
Sau đó, run/restart emacs và nhấn: M-x visit-tags-table <RET>
Bạn nhập vào đường dẫn đến tag-file
- Để nhảy đến một function nào, chỉ việc nhấn M-. (Meta-dot) và nhập vào tên của function/subroutine.
- Sau đó, để nhảy trở về vị trí cũ, bạn chỉ việc nhấn M-* (Meta-star)
Để đảm bạo, mỗi lần bạn compile thì updated etags file được tạo ra, trong makefile, bạn có thể tự tạo ra 1 target nhằm tạo tag-files với rule
etags:
find . -name '*.[chCH]' | xargs etags
hoặc
tag: etags $(SRC)
với SRC là variable chứa thông tin tên mọi source files
NOTE: Hướng dẫn ở trên dùng cho file có đuôi .c hoặc .h và ở trên dùng regular expression để kết hợp 2 loại file vào 1. Nếu cho ngôn ngữ khác, bạn nên dùng extension tương ứng (ví dụ: .f95)
Function name auto complete
Bạn bind chức năng này với phím Ctrl-tab nếu đưa nội dung sau vào ~/.emacs
(add-hook 'c-mode-common-hook
(lambda ()
(define-key c-mode-map [(ctrl tab)] 'complete-tag)))
Harmonia
http://harmonia.cs.berkeley.edu/harmonia/projects/harmonia-mode/doc/index.html
References:
- http://ecb.sourceforge.net/docs/Remote-directories.html
- http://www.coverfire.com/archives/2004/06/24/emacs-source-code-navigation/
- http://www.gnu.org/software/emacs/manual/html_node/emacs/Tags.html
- http://www.linuxjournal.com/article/153
- http://en.wikipedia.org/wiki/Ctags
[...] Xin xem bài viết ECB. [...]
Emacs « Vietnamen’s Weblog
Tháng Bảy 17, 2009 lúc 10:38 sáng