2010年5月20日 星期四

emacs and program tracing

使用 emacs tracing pogram 之時,陸續發現幾個方便的按鍵,因為沒什麼系統性,又怕忘記,只好開個 blog 來紀錄:

C-M-p
C-M-n

   如同 Visual C++ 的括號追蹤,游標可以來回跳至成對的括號位置。
   小技巧,遇到 { 時,游標要放在括號的位置上
                 遇到 } 時,游標要放在括號的右邊一格

C-c C-p
C-c C-n
   從游標處往上找,移至最近的 #ifdef  
   從游標處往下找,移至最近的 #endif 後面一格

C-c C-u
   移至上一層的 #ifdef
[ Note ] C-c 是 mode specific command 之意,在此例就是 C mode


C-x C-b
   列出 buffers list

C-x C-→
C-x C-←

   跳至前後一個 buffer

C-x C-q
   toggle buffer read only

M-% string RET new-string RET
   Replace string with new-string

C-M-% gregexp RET new-string RET
   Replace some matches for regexp with newstring.

C-h a [RET] apropos-key
   可以用某些 key word 找出命令。例如讓 apropos-key`window` 就會找出含有 `window` 字串的命令。

C-x {
  buffer window 水平變大

C-x }
   buffer window 水平變小

C-x z
   重複上一個指令動作,緊接著直接按 z 就可再重複

C-h i
   可以在 emacs 裡面看 info pages, 進去後,按 [m]emacs [RET] 可以跳進 emacs info 閱讀。(其實就是在emacs里邊閱讀 info pages)
例如:在
(emacs)Top:: > *Note Keyboard Macros:: > Save Keyboard Macro 一節,
可以找到有關設定 macro 的方法。

M-n 餵給命令所需參數
   以 C-v (往上捲動,內容往下)這命令為例,內定的參數是捲動一整頁,若給它前面加參數1,像這樣:
     M-1 C-v
 就只會往上捲一行了。參數也可以是負數喔!例如這樣按:
    按住 "Alt" 然後按 "-" "1" 然後放開 "Alt" 就是輸入參數 -1 的意思,mini-buffer 表示為
     M- M-1
  用在剛剛的命令就成了 :M- M-1 C-v "往下捲動一行" 了。
  OK, 亂玩一下,恰好有個命令是往下捲動一頁 M-v
 所以 M- M-1 C-v 效果等於 M-1 M-v,都會往下捲動一行
 
另外 C-u 是輸入參數 4 的意思
 C-u C-v 往上捲 4 行,C-u C-u C-v 表示會捲 16 行喔

C-s C-w ... C-s
  尋找 String, 中間的 C-w 可以從游標處往後選字,直到你要尋找的字整個進來為止,接著按 C-s 就可以望下開始找了!超好用!

M-x set-buffer-file-coding-system RET unix
or
C-x  <RET>  f  unix  <RET>
    把 Dos 文字格式(\r\n)轉為 Unix文字格式(\n)

M-x delete-trailing-whitespace <RET>
    移除多餘的行尾空白,符合 Linux Coding Style

下面是我的 .emacs 內容:

; auto complete
(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)

; edit properties
(modify-frame-parameters nil '((wait-for-wm . nil)))
(setq scroll-margin 0 scroll-conservatively 10000 )
(global-font-lock-mode "t")
;(require 'hl-line)
;(global-hl-line-mode t)
(transient-mark-mode t)
(setq ring-bell-function 'ignore)
;(require 'paren)
;(show-paren-mode 1)
(setq c-default-style "linux")
;(setq c-basic-offset 4)

(which-function-mode "t")

(require 'color-theme)
(color-theme-initialize)
(color-theme-hober)

(load-file "/usr/share/emacs/site-lisp/xcscope.el")
(require 'xcscope)

(setq cscope-do-not-update-database "t")
(setq cscope-set-initial-directory "./")
(autoload 'gtags-mode "gtags" "" t)

(setq ecb-tip-of-the-day nil)

; key bindings
;bind C-> to 'M-x enlarge-window'
(global-set-key (kbd "C-.") (quote enlarge-window))
;bind C-< to 'M-x shrink-window'
(global-set-key (kbd "C-,") (quote shrink-window))
;set <M-f11> as 'scroll-other-window-up-one-line'
(fset 'scroll-other-window-up-one-line "\2551\226")
;set <f11> as 'scroll-other-window-down-one-line'
(fset 'scroll-other-window-down-one-line "\261\226")

;(global-set-key [f5] 'cscope-find-this-file)
;(global-set-key [f6] 'cscope-find-this-symbol)
;(global-set-key [f7] 'cscope-pop-mark)
;(global-set-key [f8] 'cscope-find-global-definition)
;(global-set-key [f9] 'cscope-find-global-definition-no-prompting)
;(global-set-key [M-up] 'cscope-prev-symbol)'gtags-find-rtag)
;(global-set-key [M-down] 'cscope-next-symbol)

(global-set-key "\C-cgA" 'gtags-visit-rootdir)
(global-set-key "\C-cgr" 'gtags-find-rtag)
(global-set-key "\C-cgs" 'gtags-find-symbol)

(global-set-key [f5] 'gtags-find-file)
(global-set-key [f6] 'gtags-find-with-grep)
(global-set-key [f7] 'gtags-pop-stack)
(global-set-key [f8] 'gtags-find-tag)
(global-set-key [f9] 'gtags-find-tag-from-here)


(global-set-key [M-f11] 'scroll-other-window-up-one-line)
(global-set-key [f11] 'scroll-other-window-down-one-line)
(global-set-key [C-f12] 'ecb-activate)
(global-set-key [f12] 'ecb-toggle-ecb-windows)
(global-set-key [C-f1] 'color-theme-select)

(setq c-mode-hook '(lambda () (gtags-mode 1) (auto-complete-mode 1)))

(let ((frame '((left . 0)
           (top . 0)
           (width . 110)
           (height . 28)
           (tool-bar-lines . nil)
           (vertical-scroll-bars . nil)
           (background-color . "black")
           (foreground-color . "white")         
)))
  (setq default-frame-alist frame)
  (setq initial-frame-alist frame)
)

;(defun my-font-face ()
;  (custom-set-faces
;   '(default ((t (:inherit nil :stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 138 :width normal :foundry "unknown" :family "DejaVu Sans Mono"))))
;   '(ecb-tag-header-face ((t (:background "midnight blue"))))
;   '(ecb-default-highlight-face ((((class color) (background dark)) (:background "#28FF46FF66FF"))))
;))

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(display-time-mode t)
 '(ecb-options-version "2.32")
 '(show-paren-mode t))


#





沒有留言:

張貼留言