레이블이 emacs인 게시물을 표시합니다. 모든 게시물 표시
레이블이 emacs인 게시물을 표시합니다. 모든 게시물 표시

2012년 5월 29일 화요일

emacs & cscope

출처 : http://stdnstr.tistory.com/106


emacs & cscope

TIPs 2010/01/21 12:05
참조 :
KLDP
http://www.cs.cmu.edu/cgi-bin/info2www?(emacs)Find%20Tag
Ubuntu forums
Blog

ETAGS

tag 생성
$ find . -name '*.[csSh]' | etags -
$ find . -name '*.cc' -or -name '*.h' | etags -

M-. TAG        Find first definition of TAG (`find-tag').
M-*            Pop back to where you previously invoked `M-.' and friends.
C-u M-.        Find next alternate definition of last tag specified.
C-u - M-.      Go back to previous tag found.
C-M-. PATTERN  Find a tag whose name matches PATTERN (`find-tag-regexp').
C-u C-M-.      Find the next tag whose name matches the last pattern used.
C-x 4 . TAG    Find first definition of TAG, but display it in another window (`find-tag-other-window').
C-x 5 . TAG    Find first definition of TAG, and create a new frame to select the buffer (`find-tag-other-frame').



CSCOPE

cscope download : http://cscope.sourceforge.net/
emacs el package load : (require ‘xcscope)
xcscope.el : /usr/share/emacs/site-lisp
Database 생성 : cscope-index-files

C-c s s     Find symbol.
C-c s d     Find global definition.
C-c s g     Find global definition (alternate binding).
C-c s G     Find global definition without prompting.
C-c s c     Find functions calling a function.
C-c s C     Find called functions (list functions called from a function).
C-c s t     Find text string.
C-c s e     Find egrep pattern.
C-c s f     Find a file.
C-c s i     Find files #including a file. 

2012년 5월 23일 수요일

emacs config file

출처 : http://chaoxifer.egloos.com/1258767

;; Font
;(set-default-font "Lucida Grande")

; Color
(require 'color-theme)
(color-theme-initialize)
(set-foreground-color "white")
(set-background-color "#4D4F4F")
(set-fringe-style "none")

; Change Switch buffer key
(global-unset-key (kbd "C-x <LEFT>"))
(global-set-key (kbd "C-,") 'previous-buffer)

(global-unset-key (kbd "C-x <RIGHT>"))
(global-set-key (kbd "C-.") 'next-buffer)

; 소스파일 브라우저 (cscope를 먼저 설치한다)
; xcscope.el 파일을 복사한다
; M-x cscope-index-file <ret>
(require 'xcscope) ; cscope 설치 후 연동

; line number
(add-hook 'find-file-hook (lambda ()(linum-mode 1)))

; Easier Transition between Windows
; M-up, M-down, M-lest and M-right keys
(windmove-default-keybindings 'meta)

;emacs tab configuration
(setq c-basic-offset 4
          tab-width 4
          indent-tabs-mode t)

; 엔터 입력시 자동 들여쓰기 다른 방법
(load "cc-mode")
(define-key c++-mode-map "\r" 'reindent-then-newline-and-indent)
(define-key c-mode-map "\r" 'reindent-then-newline-and-indent)
(define-key java-mode-map "\r" 'reindent-then-newline-and-indent)

; compile and debug
(global-set-key (kbd "<f7>") 'compile)
(global-set-key (kbd "<f4>") 'next-error)
;(global-set-key (kbd "\C-[") 


; 나눔고딕 글꼴을 미리 설치한다
(set-fontset-font "fontset-default" '(#x1100 . #xffdc)  '("NanumGothicCoding" . "unicode-bmp")) ;;; 유니코드 한글영역
(set-fontset-font "fontset-default" '(#xe0bc . #xf66e)  '("NanumGothicCoding" . "unicode-bmp")) ;;;유니코드 사용자 영역

;------------------------------------------------------------
;; for colorful ls in the shell-mode
;------------------------------------------------------------
(ansi-color-for-comint-mode-on)


(setq compilation-auto-jump-to-first-error t) 
(setq make-backup-files nil) ; do not create back files
(setq gdb-many-windows t) ; gdb windows

(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) ; disable scroll bar
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) ; disable tool bar
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1)) ; disable menu bar

(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.
 '(frame-background-mode (quote dark))
 '(global-hl-line-mode t))
(custom-set-faces
  ;; custom-set-faces 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.
 '(default ((t (:inherit nil :stipple nil :background "#4D4F4F" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 130 :width normal :foundry "unknown" :family "Lucida Grande"))))
 '(button ((((supports :underline t)) nil)))
 '(custom-button ((((type x w32 ns) (class color)) (:underline t))))
 '(custom-button-mouse ((((type x w32 ns) (class color)) (:background "#4D4F4F"))))
 '(custom-button-pressed ((((type x w32 ns) (class color)) (:background "#4D4F4F"))))
 '(font-lock-comment-face ((((class color) (min-colors 88) (background dark)) (:foreground "#FF7777"))))
 '(font-lock-function-name-face ((((class color) (min-colors 88) (background dark)) (:foreground "deep sky blue" :underline "ivory" :weight bold))))
 '(font-lock-keyword-face ((((class color) (min-colors 88) (background dark)) (:foreground "DeepSkyBlue1"))))
 '(font-lock-string-face ((((class color) (min-colors 88) (background dark)) (:foreground "LightSalmon"))))
 '(font-lock-variable-name-face ((((class color) (min-colors 88) (background dark)) (:foreground "cornsilk"))))
 '(fringe ((((class color) (background dark)) (:background "#4D4F4F" :foreground "#4D4F4F"))))
 '(hl-line ((t (:inherit highlight))))
 '(link ((((class color) (min-colors 88) (background dark)) (:foreground "light goldenrod" :underline nil))))
 '(mode-line ((((class color) (min-colors 88)) (:background "#4d5f5f" :foreground "white"))))
 '(mode-line-highlight ((((class color) (min-colors 88)) nil)))
 '(region ((((class color) (min-colors 88) (background dark)) (:background "gray"))))
 '(tool-bar ((nil nil)))
 '(variable-pitch ((default nil) (nil nil))))

Emacs 윈도용 설정파일

출처 : http://blog.naver.com/bonalena/20013545314


;;; =============================================================
;;; Fonts and Frame for Windows 95/NT
;;; =============================================================
; To see list of fonts in your Windows 95/NT,
; (w32-select-font) or
; (insert (prin1-to-string (x-list-fonts "*")))
(if (eq window-system 'w32)
    (progn
       ;(setq w32-enable-italics t)
       ;; for better font dialog menu for fontset
       (setq w32-use-w32-font-dialog t)
       (setq w32-enable-unicode-output t)
       (setq initial-frame-alist '((top . 10) (left . 30)))
       (setq default-frame-alist
           (append '( ;; Choose only one for your default font set.
       (font . "-outline-HyhwpEQ-normal-r-normal-normal-*-*-96-96-p-*-ksc5601.1987")
;       (font . "-outline-\307\321\304\304\265\270\277\362-normal-r-normal-normal-*-*-96-96-p-*-ksc5601.1987")
         (width . 100)
         (height . 52)
         (background-color . "gray85")
         (foreground-color . "Black")
         (vertical-scroll-bars . right))
           default-frame-alist))))

;;; =============================================================
;;; Mode Line and Minibuffer Settings
;;; =============================================================
;(icomplete-mode)
(partial-completion-mode 1)
(column-number-mode 1)
;; For bug fix of localized date output and better display for Korean
;(setq display-time-string-forms
;'((if
;     (and
;      (not display-time-format)
;      display-time-day-and-date)
;     (decode-coding-string (format-time-string "%m/%d (%a) " now)
;                           (car default-process-coding-system))
;   "")
;  (decode-coding-string
;   (format-time-string
;    (or display-time-format
;        (if display-time-24hr-format "%H:%M" "%p %-I:%M"))
;    now)
;   (car default-process-coding-system))
;  load
;  (if mail " Mail" "")))
(setq display-time-day-and-date t)
(display-time)

;;; =============================================================
;;; Misc. Setting
;;; =============================================================
;; In Unix terminal mode, make Backspace and Control-h key work as real backspace key.
;; (In any Emacs, F1 key work as an help key, too.)
(if (and (not (eq system-type 'windows-nt)) (null window-system))
    (keyboard-translate ?\C-h ?\C-?))
(setq scroll-step 1)
(global-set-key [?\C-x?\C-j] 'goto-line)
(setq query-replace-highlight t)
(show-paren-mode)
(transient-mark-mode 1)
(auto-compression-mode 1)  ; For auto compression and decompression

;;; =============================================================
;;; Syntax Highlighting, Spell Checking, Completion
;;; (ftp://ftp.hanq.net/pub/gnu/ (Source Code))
;;; (http://www.cat.rpi.edu/~tibbetts/ispell_toc.html (Windows 95/NT))
;;; =============================================================
(global-font-lock-mode 1)
(setq font-lock-maximum-decoration t)
;(setq font-lock-support-mode 'lazy-lock-mode)
(add-hook 'flyspell-mode-hook
   (function (lambda ()
        (define-key flyspell-mode-map "\M-\t"
   'flyspell-mode-complete))))
;(add-hook 'text-mode-hook 'turn-on-flyspell-mode)
(defun turn-on-flyspell-mode ()
  (flyspell-mode 1))
;; Enable fly spell checking only for strings and comments in program modes.
;; (font lock mode should be enabled for use of this feature)
;(add-hook 'c-mode-common-hook 'turn-on-flyspell-mode-program)
;(add-hook 'sh-mode-hook 'turn-on-flyspell-mode-program)
;(add-hook 'makefile-mode-hook 'turn-on-flyspell-mode-program)
;(add-hook 'emacs-lisp-mode-hook 'turn-on-flyspell-mode-program)
(defun turn-on-flyspelL-mode-program ()
  (setq flyspell-generic-check-word-p 'program-mode-flyspell-verify)
  (flyspell-mode 1))
(defun program-mode-flyspell-verify ()
  (let ((prop (get-text-property (point) 'face)))
    (or (eq prop 'font-lock-string-face)
 (eq prop 'font-lock-comment-face))))
(defun flyspell-mode-complete ()
  (interactive)
  (cond ((eq major-mode 'emacs-lisp-mode)
  (ispell-complete-word))
 ((or (eq major-mode 'latex-mode)
      (eq major-mode 'tex-mode))
  (or (TeX-complete-symbol)
      (ispell-complete-word)))
 (t
  (let ((prop (get-text-property (point) 'face)))
    (if (or (eq prop 'font-lock-string-face)
     (eq prop 'font-lock-comment-face))
        (ispell-complete-word)
      (let ((complete-func (lookup-key (current-local-map) "\M-\t")))
        (if complete-func
     (funcall complete-func)
   (complete-tag))))))))
(setq Info-default-directory-list
      (append '("/usr/local/teTeX/info/") Info-default-directory-list ))

;;; =============================================================
;;; Text Mode
;;; =============================================================
(setq default-major-mode (quote text-mode))
;(add-hook 'text-mode-hook
;          (function (lambda ()
;                      (setq fill-column 70)
;                      (turn-on-auto-fill))))
;;; =============================================================
;;; Programming Modes
;;; =============================================================
(c-add-style
 "java"
 '((c-basic-offset . 4)
   (c-comment-only-line-offset 0 . 0)
   (c-hanging-comment-starter-p)
   (c-offsets-alist
    (topmost-intro-cont . +)
    (statement-block-intro . +)
    (substatement-open . 0)
    (substatement . +)
    (inline-open . 0)
    (label . 0)
    (statement-case-open . +)
    (statement-cont . +)
    (knr-argdecl-intro . 5)
    (arglist-intro . +)
    (arglist-close . c-lineup-arglist)
    (brace-list-entry . 0)
    (access-label . 0)
    (inher-cont . c-lineup-java-inher)
    (func-decl-cont . c-lineup-java-throws))))
(add-hook 'java-mode-hook
   (function (lambda ()
        (c-set-style "java"))))
(add-hook 'c-mode-hook
   (function (lambda ()
        (c-set-style "stroustrup"))))
(add-hook 'c++-mode-hook
   (function (lambda ()
        (c-set-style "stroustrup"))))
(add-hook 'idl-mode-hook
   (function (lambda ()
        (c-set-style "stroustrup"))))

;;; =============================================================
;;; Compilation Modes
;;; =============================================================
; To avoid cursor disappearing problem.
; There should be better solution.
(if (and (eq system-type 'windows-nt)
         (null window-system))
    (progn
      (setq-default grep-command "grep -n -e")
      (setq-default grep-find-command
                    '("find . -type f -exec grep -n -e {} /dev/null \\;" . 32))
      (setq-default grep-find-use-xargs nil)))

;;; =============================================================
;;; Version Control
;;; =============================================================
(setq vc-make-backup-files t)

;;; =============================================================
;;; Settings for Non-standard Packages
;;; =============================================================
;;; =============================================================
;;; Crypting
;;; ftp://archive.cis.ohio-state.edu/pub/emacs-lisp/misc/crypt++.el.Z
;;; http://www.cs.washington.edu/homes/voelker/ntemacs.html
;;; =============================================================
(condition-case nil
    (require 'crypt++)
  (error nil))
;;; =============================================================
;;; Calcualtor (ftp://ftp.hanq.net/pub/gnu/calc-2.02f.tar.gz)
;;; =============================================================
;;; Commands added by calc-public-autoloads on Mon Oct  6 21:31:58 1997.
(autoload 'calc-dispatch    "calc" "Calculator Options" t)
(autoload 'full-calc     "calc" "Full-screen Calculator" t)
(autoload 'full-calc-keypad    "calc" "Full-screen X Calculator" t)
(autoload 'calc-eval     "calc" "Use Calculator from Lisp")
(autoload 'defmath     "calc" nil t t)
(autoload 'calc      "calc" "Calculator Mode" t)
(autoload 'quick-calc     "calc" "Quick Calculator" t)
(autoload 'calc-keypad     "calc" "X windows Calculator" t)
(autoload 'calc-embedded    "calc" "Use Calc inside any buffer" t)
(autoload 'calc-embedded-activate  "calc" "Activate =>'s in buffer" t)
(autoload 'calc-grab-region    "calc" "Grab region of Calc data" t)
(autoload 'calc-grab-rectangle    "calc" "Grab rectangle of data" t)
(global-set-key "\e#" 'calc-dispatch)
;;; End of Calc autoloads.

;;; =============================================================
;;; HTML Helper Mode (http://www.santafe.edu/~nelson/tools/)
;;; =============================================================
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
;(setq auto-mode-alist (append '(("\\.html$" . html-helper-mode)
;                                ("\\.jsp$" . html-helper-mode))
;                              auto-mode-alist))
(add-hook 'html-helper-load-hook '(lambda () (require 'html-font)))
(add-hook 'html-helper-mode-hook '(lambda () (font-lock-mode 1)))
(setq html-helper-do-write-file-hooks t)
(setq html-helper-build-new-buffer t)

;;; =============================================================
;;; AUC TeX - Integrated environment for editing LaTeX files.
;;; (ftp://ftp.dante.de/tex-archive/support/auctex)
;;; teTeX, MikTeX (http://free.kaist.ac.kr/ChoF/)
;;; =============================================================
(condition-case nil
    (require 'tex-site)
  (error nil))
(add-hook
 'TeX-mode-hook
 (function
  (lambda ()
    (define-key TeX-mode-map "\C-x`" 'TeX-next-error)
    (define-key LaTeX-mode-map "\C-x`" 'TeX-next-error))))
(if (eq system-type 'windows-nt)
    (setq TeX-view-style '(("^a5$" "yap %d -paper a5")
                           ("^landscape$" "yap %d -paper a4r -s 4")
                           ("." "yap %d"))))

;;; =============================================================
;;; JDE - Java Development Environment (http://sunsite.auc.dk/jde/)
;;; =============================================================
;;; Copy `/usr/local/share/emacs/20.3/site-lisp/jde-2.1.3/jtags*' to `/usr/local/bin/'
(condition-case nil
    (require 'jde)
  (error nil))
(if (eq system-type 'windows-nt)
    (setq jde-db-source-directories '("C:/jdk1.2/src/"))
  (setq jde-db-source-directories '("/usr/local/jdk1.2/src")))

;;; =============================================================
;;; Telnet (http://www.watchit.com/~iganza/jtelnet.html) for Windows 95/NT
;;; =============================================================
;; Install JDK from http://java.sun.com/
;; Change followings properly for your system configuration
(if (eq system-type 'windows-nt)
    (progn
      (setq jtelnet-java-path "java")
      ;; for JDK 1.2.x
      (setq jtelnet-class-arg "-cp")
      (setq jtelnet-class-path
     (concat
      (apply 'concat (mapcar
        (lambda (x) (if (= x ?/) "\\" (char-to-string x)))
        data-directory))
      "..\\site-lisp\\jtelnet"))
      ;; for JDK 1.1.x
      ;(setq jtelnet-class-arg "-classpath")
      ;(setq jtelnet-class-path
      ;      (concat "d:\\jdk1.1\\lib\\classes.zip;"
      ;              (apply 'concat (mapcar
      ;                              (lambda (x) (if (= x ?/) "\\" (char-to-string x)))
      ;                              data-directory))
      ;              "..\\site-lisp\\jtelnet")))
      (condition-case nil
   (require 'jtelnet)
 (error nil))))
 
;;; ================================================================================
;;; Talk (ftp://archive.cis.ohio-state.edu/pub/emacs-lisp/packages/etalk-0.8.tar.gz)
;;; ================================================================================
;;; Need to build and install "etalk" executable in Emacs bin directory.
(autoload 'etalk "etalk"
  "Talk to anyone on any machine through BSD talk protocol." t)
(autoload 'etalk-batch "etalk"
  "Talk to anyone on any machine through BSD talk protocol from command line." t)
(autoload 'etalk-mail "etalk"
  "Talk to anyone on any machine through mail as connector." t)
(autoload 'finger "finger"
  "Run finger on a host." t)

;;; =============================================================
;;; Misc.
;;; =============================================================
(autoload 'which "which" nil t)

;;; =============================================================
;;; Private Settting and Customization
;;; =============================================================
;; To see available colors, run `M-x list-colors-dislay'


(require 'cl)
(when enable-multibyte-characters
  (set-language-environment "Korean")
 
  (setq-default file-name-coding-system 'euc-kr)
  (setq default-korean-keyboard "3")
  ;; (setq input-method-verbose-flag nil
  ;;       input-method-highlight-flag nil)
  (prefer-coding-system 'euc-kr)
  (set-default-coding-systems 'euc-kr)
  (set-keyboard-coding-system 'euc-kr)
  (set-terminal-coding-system 'euc-kr)
  (define-key encoded-kbd-mode-map [27] nil)

;  (set-selection-coding-system 'compound-text-with-extensions)
(set-selection-coding-system
 (cond ((eq system-type 'windows-nt) 'euc-kr-dos)
       (t 'euc-kr)))

  ;; Hangul Mail setting
  (setq-default sendmail-coding-system 'euc-kr))
(unless (or enable-multibyte-characters window-system)
  (standard-display-european t)
  (set-input-mode (car (current-input-mode))
                  (nth 1 (current-input-mode))
                  0))

;; sealover's setup (by Learning GNU Emacs)
(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(setq-default transient-mark-mode t)
;;(enable-flow-control)
(global-unset-key "\e\e")
(global-unset-key "\C-x\C-u")
(define-key global-map "\C-x?" 'help-command)
(define-key global-map "\C-h" 'backward-char)
;;(setq suggest-key-bindings nil)
(set-background-color "black")
(set-foreground-color "white")
(set-cursor-color "khaki")
(set-face-foreground 'region "white")
(set-face-background 'region "mediumblue")
;;;;(global-font-lock-mode 1 t)
;; mode-line color
(when enable-multibyte-characters
  (set-face-foreground 'modeline "blue")
  (set-face-background 'modeline "khaki"))
(unless enable-multibyte-characters
  (set-face-foreground 'modeline "Red")
  (set-face-background 'modeline "Yellow"))
;;shell environment
(setq-default shell-cd-regexp nil)
(setq-default shell-pushd-regexp nil)
(setq-default shell-popd-regexp nil)
;(setq explicit-shell-file-name "/usr/local/bin/bash")
;; secure on shell mode
(add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt)
(setq default-tab-width 4)
;; c-mode
(add-hook 'c-mode-hook '(lambda() (c-set-style "gnu")))
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(setq truncate-partial-width-windows nil)

MAC OS X에서 Emacs 사용

출처 : http://nadagill.egloos.com/816704


Emacs 설치
http://emacsformacosx.com/ 에 접속하면 바로 설치할 수 있다.
color-theme 설치
첨부한 color-theme를 Download 받는다.
$ cd ~/.emacs.d/vendor
$ tar xzvf color-theme.tar.gz
auto-complete 설치
첨부한 auto-complete을 Download 받는다.
$ cd ~/.emacs.d/vendor
$ tar xzvf auto-complete.tar.gz
cscope 설치
여기에서 package를 Download 받는다.
$ cd ~/.emacs.d/vendor
$ tar xzvf cscope-15.7a.tar.gz
$ cd cscope-15.7a
$ ./configure --prefix=/usr/local
$ sudo make install
이 작업이 완료돼면 다음과 같이 실행파일을 copy해 준다.
$ cd ~/.emacs.d/vendor/cscope-15.7a/contrib
$ cd xcscope
$ sudo cp cscope-indexer /usr/local/bin
.emacs의 설정
vi ~/.emacs
;; Command key is meta key 설정
(setq mac-option-key-is-meta t)
(setq mac-command-key-is-meta nil)
;; 환영 메세지 안보이게 설정
(setq inhibit-startup-message t)
;; windows size 설정
(set-frame-width (selected-frame) 180)
(set-frame-height (selected-frame) 50)
;; windows position 설정
(set-frame-position (selected-frame) 0 0)
;; color theme load
(add-to-list 'load-path "~/.emacs.d/vendor/color-theme")
(require 'color-theme)
(color-theme-initialize)
(color-theme-deep-blue)
;; font 설정
(when window-systemauto-complete.tar.gz
 (set-face-font 'default "-outline-Courier New-normal-normal-normal-mono-12-*-*-*-c-*-iso10646-1") ; 영문
 (set-fontset-font "fontset-default" '(#x1100 . #xffdc)  '("NanumGothic" . "unicode-bmp")) ; 한글
 (set-fontset-font "fontset-default" '(#xe0bc . #xf66e)  '("NanumGothic" . "unicode-bmp")) ; 사용자
)
;; cscope load
(add-to-list 'load-path "~/.emacs.d/vendor/cscope-15.7a/contrib/xcscope")
(require 'xcscope)
;; auto complete 설정
(add-to-list 'load-path "~/.emacs.d/vendor/auto-complete")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/vendor/auto-complete/ac-dict")
(ac-config-default)
;; 화면 분할
(split-window-horizontally)
;; 화면 크기 동일하게 설정
(balance-windows)
;; line number 표시
(global-linum-mode 1)
;; backup file 생성하지 않기 설정
(setq make-backup-files nil)
;; indent 설정
(defun linux-c-mode ()
  "C mode with adjusted defaults for use with the Linux kernel."
  (interactive)
  (c-mode)
  (c-set-style "K&R")
  (setq c-basic-offset 4))
(setq auto-mode-alist (cons '("/Users/nadagill/Project/linux.*-.*\\.[ch]$" . linux-c-mode)
    auto-mode-alist))
;; 선택된 영역 delete로 지우기
(delete-selection-mode nil)
;; key binding
;; hyper key binding
(setq mac-command-modifier 'hyper)
;; meta + arrow 창 전환
(windmove-default-keybindings 'meta)
;; goto line 설정
(global-set-key [(hyper l)] 'goto-line)
;; undo 설정
(global-set-key [(hyper z)] 'undo)
;; paste 설정
(global-set-key [(hyper v)] 'yank)
;; copy 설정
(global-set-key [(hyper c)] 'copy-region-as-kill)
;; cut 설정
(global-set-key [(hyper x)] 'kill-region)
;; find file 설정
(global-set-key [(hyper o)] 'find-file)
;; save 설정
(global-set-key [(hyper s)] 'save-buffer)
;; save & quit 설정
(global-set-key [(hyper q)] 'save-buffers-kill-emacs)
;; shell mode 진입
(global-set-key [(hyper shift s)] 'eshell)
;; compile 설정
(global-set-key [(hyper shift c)] 'compile)
;; scroll 설정
(global-set-key [(meta up)] 'scroll-down)
(global-set-key [(meta down)] 'scroll-up)
(global-set-key [(meta left)] 'beginning-of-line)
(global-set-key [(meta right)] 'end-of-line)
;; cscope 관련 key binding 설정
;; index file 만들기 설정
(global-set-key [(hyper a)] 'cscope-index-files)
;; find symbol
(global-set-key [(hyper /)] 'cscope-find-this-symbol)
;; previous symbol
(global-set-key [(hyper ,)] 'cscope-prev-symbol)
;; next symbol
(global-set-key [(hyper .)] 'cscope-next-symbol)
;; exec path 설정
(custom-set-variables
 '(exec-path (quote ("/usr/bin" "/bin" "/usr/sbin" "/sbin" "/Applications/Emacs.app/Contents/MacOS/bin" "/usr/local/bin" ))))
(custom-set-faces)

2012년 5월 16일 수요일

xcscope(1) - Linux man page

출처 : http://linux.die.net/man/1/xcscope


Name

xcscope.el - xemacs cscope lisp support package

Description

xcscope is a lisp package for use in integrating cscope functionality into xemacs

Installation

Installation steps:
0. (It is, of course, assumed that cscope is already properly installed on the current system.)
1. Ensure that the location of cscope-indexer is located in your path
2. Ensure that the location of xcscope.el is in the xemacs module load path
3. Edit your ~/.emacs file to add the line:
(require'xcscope)
5. If you intend to use xcscope.el often you can optionally edit your ~/.emacs file to add keybindings that reduce the number of keystrokes required. For example, the following will add "C-f#" keybindings, which are easier to type than the usual "C-c s" prefixed keybindings. Note that specifying "global-map" instead of "cscope:map" makes the keybindings available in all buffers:
(define-key global-map [(ctrl f3)] 'cscope-set-initial-directory)(define-key global-map [(ctrl f4)] 'cscope-unset-initial-directory)
(define-key global-map [(ctrl f5)] 'cscope-find-this-symbol)
(define-key global-map [(ctrl f6)] 'cscope-find-global-definition)
(define-key global-map [(ctrl f7)]
cscope-find-global-definition-no-prompting)
(define-key global-map [(ctrl f8)] 'cscope-pop-mark)
(define-key global-map [(ctrl f9)] 'cscope-next-symbol)
(define-key global-map [(ctrl f10)] 'cscope-next-file)
(define-key global-map [(ctrl f11)] 'cscope-prev-symbol)
(define-key global-map [(ctrl f12)] 'cscope-prev-file)
(define-key global-map [(meta f9)] 'cscope-display-buffer)
(define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
6. Restart (X)Emacs. That's it.

Using This Module

* Basic usage:
If all of your C/C++/lex/yacc source files are in the same directory, you can just start using this module. If your files are spread out over multiple directories, see "Advanced usage", below.Just edit a source file, and use the pull-down or pop-up (button 3) menus to select one of:
Find symbolFind global definition
Find called functions
Find functions calling a function
Find text string
Find egrep pattern
Find a file
Find files #including a file
The cscope database will be automatically created in the same directory as the source files (assuming that you've never used cscope before), and a buffer will pop-up displaying the results. You can then use button 2 (the middle button) on the mouse to edit the selected file, or you can move the text cursor over a selection and press [Enter].Hopefully, the interface should be fairly intuitive.
* Locating the cscope databases:
This module will first use the variable, 'cscope-database-regexps', to search for a suitable database directory. If a database location cannot be found using this variable then a search is begun at the variable, 'cscope-initial-directory', if set, or the current directory otherwise. If the directory is not a cscope database directory then the directory's parent, parent's parent, etc. is searched until a cscope database directory is found, or the root directory is reached. If the root directory is reached, the current directory will be used.A cscope database directory is one in which EITHER a cscope database file (e.g., "cscope.out") OR a cscope file list (e.g., "cscope.files") exists. If only "cscope.files" exists, the corresponding "cscope.out" will be automatically created by cscope when a search is done. By default, the cscope database file is called "cscope.out", but this can be changed (on a global basis) via the variable, 'cscope-database-file'. There is limited support for cscope databases that are named differently than that given by 'cscope-database-file', using the variable, 'cscope-database-regexps'.
Note that the variable, 'cscope-database-regexps', is generally not needed, as the normal hierarchical database search is sufficient for placing and/or locating the cscope databases. However, there may be cases where it makes sense to place the cscope databases away from where the source files are kept; in this case, this variable is used to determine the mapping. One use for this variable is when you want to share the database file with other users; in this case, the database may be located in a directory separate from the source files.
Setting the variable, 'cscope-initial-directory', is useful when a search is to be expanded by specifying a cscope database directory that is a parent of the directory that this module would otherwise use. For example, consider a project that contains the following cscope database directories:
/users/jdoe/sources/users/jdoe/sources/proj1
/users/jdoe/sources/proj2
If a search is initiated from a .c file in /users/jdoe/sources/proj1 then (assuming the variable, 'cscope-database-regexps', is not set) /users/jdoe/sources/proj1 will be used as the cscope data base directory. Only matches in files in /users/jdoe/sources/proj1 will be found. This can be remedied by typing "C-c s a" and then "M-del" to remove single path element in order to use a cscope database directory of /users/jdoe/sources. Normal searching can be restored by typing "C-c s A".
* Keybindings:
All keybindings use the "C-c s" prefix, but are usable only while editing a source file, or in the cscope results buffer:C-c s s Find symbol.
C-c s d Find global definition.
C-c s g Find global definition (alternate binding).
C-c s G Find global definition without prompting.
C-c s c Find functions calling a function.
C-c s C Find called functions (list functions called
from a function).
C-c s t Find text string.
C-c s e Find egrep pattern.
C-c s f Find a file.
C-c s i Find files #including a file.
These pertain to navigation through the search results:C-c s b Display *cscope* buffer.
C-c s B Auto display *cscope* buffer toggle.
C-c s n Next symbol.
C-c s N Next file.
C-c s p Previous symbol.
C-c s P Previous file.
C-c s u Pop mark.
These pertain to setting and unsetting the variable, 'cscope-initial-directory', (location searched for the cscope database directory):C-c s a Set initial directory.
C-c s A Unset initial directory.
These pertain to cscope database maintenance:C-c s L Create list of files to index.
C-c s I Create list and index.
C-c s E Edit list of files to index.
C-c s W Locate this buffer's cscope directory
( "W" --> "where" ).
C-c s S Locate this buffer's cscope directory.
(alternate binding: "S" --> "show" ).
C-c s T Locate this buffer's cscope directory.
(alternate binding: "T" --> "tell" ).
C-c s D Dired this buffer's directory.
* Advanced usage:
If the source files are spread out over multiple directories, you've got a few choices:[ NOTE: you will need to have the script, "cscope-indexer", properly installed in order for the following to work. ]
1. If all of the directories exist below a common directory (without any extraneous, unrelated subdirectories), you can tell this module to place the cscope database into the top-level, common directory. This assumes that you do not have any cscope databases in any of the subdirectories. If you do, you should delete them; otherwise, they will take precedence over the top-level database.
If you do have cscope databases in any subdirectory, the following instructions may not work right.
It's pretty easy to tell this module to use a top-level, common directory:
a. Make sure that the menu pick, "Cscope/Index recursively", is checked (the default value).
b. Select the menu pick, "Cscope/Create list and index", and specify the top-level directory. This will run the script, "cscope-indexer", in the background, so you can do other things if indexing takes a long time. A list of files to index will be created in "cscope.files", and the cscope database will be created in "cscope.out".
Once this has been done, you can then use the menu picks (described in "Basic usage", above) to search for symbols.
Note, however, that, if you add or delete source files, you'll have to either rebuild the database using the above procedure, or edit the file, "cscope.files" to add/delete the names of the source files. To edit this file, you can use the menu pick, "Cscope/Edit list of files to index".
2. If most of the files exist below a common directory, but a few are outside, you can use the menu pick, "Cscope/Create list of files to index", and specify the top-level directory. Make sure that "Cscope/Index recursively", is checked before you do so, though. You can then edit the list of files to index using the menu pick, "Cscope/Edit list of files to index". Just edit the list to include any additional source files not already listed.Once you've created, edited, and saved the list, you can then use the menu picks described under "Basic usage", above, to search for symbols. The first time you search, you will have to wait a while for cscope to fully index the source files, though. If you have a lot of source files, you may want to manually run cscope to build the database:
cd top-level-directory # or whereverrm -f cscope.out # not always necessary
cscope -b
3. If the source files are scattered in many different, unrelated places, you'll have to manually create cscope.files and put a list of all pathnames into it. Then build the database using:
cd some-directory # wherever cscope.files existsrm -f cscope.out # not always necessary
cscope -b
Next, read the documentation for the variable, "cscope-database-regexps", and set it appropriately, such that the above-created cscope database will be referenced when you edit a related source file.Once this has been done, you can then use the menu picks described under "Basic usage", above, to search for symbols.
* Interesting configuration variables:
cscope-truncate-linesThis is the value of 'truncate-lines' to use in cscope buffers; the default is the current setting of 'truncate-lines'. This variable exists because it can be easier to read cscope buffers with truncated lines, while other buffers do not have truncated lines.
cscope-use-relative-paths
If non-nil, use relative paths when creating the list of files to index. The path is relative to the directory in which the cscope database will be created. If nil, absolute paths will be used. Absolute paths are good if you plan on moving the database to some other directory (if you do so, you'll probably also have to modify 'cscope-database-regexps'). Absolute paths may also be good if you share the database file with other users (you'll probably want to specify some automounted network path for this).
cscope-index-recursively
If non-nil, index files in the current directory and all subdirectories. If nil, only files in the current directory are indexed. This variable is only used when creating the list of files to index, or when creating the list of files and the corresponding cscope database.
cscope-name-line-width
The width of the combined "function name:line number" field in the cscope results buffer. If negative, the field is left-justified.
cscope-do-not-update-database
If non-nil, never check and/or update the cscope database when searching. Beware of setting this to non-nil, as this will disable automatic database creation, updating, and maintenance.
cscope-display-cscope-buffer
If non-nil, display the *cscope* buffer after each search (default). This variable can be set in order to reduce the number of keystrokes required to navigate through the matches.
cscope-database-regexps
List to force directory-to-cscope-database mappings. This is a list of '(REGEXP DBLIST [ DBLIST ... ])', where:
REGEXP is a regular expression matched against the current buffer's current directory. The current buffer is typically some source file, and you're probably searching for some symbol in or related to this file. Basically, this regexp is used to relate the current directory to a cscope database. You need to start REGEXP with "^" if you want to match from the beginning of the current directory.
DBLIST is a list that contains one or more of:
( DBDIR )( DBDIR ( OPTIONS ) )
( t )
t
Here, DBDIR is a directory (or a file) that contains a cscope database. If DBDIR is a directory, then it is expected that the cscope database, if present, has the filename given by the variable, 'cscope-database-file'; if DBDIR is a file, then DBDIR is the path name to a cscope database file (which does not have to be the same as that given by 'cscope-database-file'). If only DBDIR is specified, then that cscope database will be searched without any additional cscope command-line options. If OPTIONS is given, then OPTIONS is a list of strings, where each string is a separate cscope command-line option.In the case of "( t )", this specifies that the search is to use the normal hierarchical database search. This option is used to explicitly search using the hierarchical database search either before or after other cscope database directories.
If "t" is specified (not inside a list), this tells the searching mechanism to stop searching if a match has been found (at the point where "t" is encountered). This is useful for those projects that consist of many subprojects. You can specify the most-used subprojects first, followed by a "t", and then followed by a master cscope database directory that covers all subprojects. This will cause the most-used subprojects to be searched first (hopefully quickly), and the search will then stop if a match was found. If not, the search will continue using the master cscope database directory.
Here, 'cscope-database-regexps' is generally not used, as the normal hierarchical database search is sufficient for placing and/or locating the cscope databases. However, there may be cases where it makes sense to place the cscope databases away from where the source files are kept; in this case, this variable is used to determine the mapping.
This module searches for the cscope databases by first using this variable; if a database location cannot be found using this variable, then the current directory is searched, then the parent, then the parent's parent, until a cscope database directory is found, or the root directory is reached. If the root directory is reached, the current directory will be used.
A cscope database directory is one in which EITHER a cscope database file (e.g., "cscope.out") OR a cscope file list (e.g., "cscope.files") exists. If only "cscope.files" exists, the corresponding "cscope.out" will be automatically created by cscope when a search is done. By default, the cscope database file is called "cscope.out", but this can be changed (on a global basis) via the variable, 'cscope-database-file'. There is limited support for cscope databases that are named differently than that given by 'cscope-database-file', using the variable, 'cscope-database-regexps'.
Here is an example of 'cscope-database-regexps':
(setq cscope-database-regexps'(
( "^/users/jdoe/sources/proj1"
( t )
( "/users/jdoe/sources/proj2")
( "/users/jdoe/sources/proj3/mycscope.out")
( "/users/jdoe/sources/proj4")
t
( "/some/master/directory" ("-d" "-I/usr/local/include") )
)
( "^/users/jdoe/sources/gnome/"
( "/master/gnome/database" ("-d") )
)
))
If the current buffer's directory matches the regexp, "^/users/jdoe/sources/proj1", then the following search will be done:
1. First, the normal hierarchical database search will be used to
locate a cscope database.
2. Next, searches will be done using the cscope database
directories, "/users/jdoe/sources/proj2", "/users/jdoe/sources/proj3/mycscope.out", and "/users/jdoe/sources/proj4". Note that, instead of the file, "cscope.out", the file, "mycscope.out", will be used in the directory "/users/jdoe/sources/proj3".
3. If a match was found, searching will stop.
4. If a match was not found, searching will be done using
"/some/master/directory", and the command-line options "-d" and "-I/usr/local/include" will be passed to cscope.
If the current buffer's directory matches the regexp,
"^/users/jdoe/sources/gnome", then the following search will be done:
The search will be done only using the directory,
"/master/gnome/database". The "-d" option will be passed to cscope.
If the current buffer's directory does not match any of the above
regexps, then only the normal hierarchical database search will be done.
* Other notes:
1. The script, "cscope-indexer", uses a sed command to determine what is and is not a C/C++/lex/yacc source file. It's idea of a source file may not correspond to yours.2. This module is called, "xcscope", because someone else has already written a "cscope.el" (although it's quite old).

KNOWN BUGS:

1. Cannot handle whitespace in directory or file names.
2. By default, colored faces are used to display results. If you happen to use a black background, part of the results may be invisible (because the foreground color may be black, too). There are at least two solutions for this:
2a. Turn off colored faces, by setting 'cscope-use-face' to 'nil', eg:
(setq cscope-use-face nil)
2b. Explicitly set colors for the faces used by cscope. The faces are
cscope-file-facecscope-function-face
cscope-line-number-face
cscope-line-face
cscope-mouse-face
The face most likely to cause problems (e.g., black-on-black
color) is 'cscope-line-face'.
3. The support for cscope databases different from that specified by 'cscope-database-file' is quirky. If the file does not exist, it will not be auto-created (unlike files names by 'cscope-database-file'). You can manually force the file to be created by using touch(1) to create a zero-length file; the database will be created the next time a search is done.

How To Integrate Emacs & Cscope To Browse Linux Kernel Source Code

출처 : http://techtooltip.wordpress.com/2012/01/06/how-to-integrate-emacs-cscope-to-browse-linux-kernel-source-code/


This post is about cscope integration with emacs, for more details about cscope itself please refer to cscope home page  and cscope man page.
Installation:
To get started we need to install emacs, cscope and xcscope emacs extension. As per cscope documentation the emacs support for cscope is provided in cscope/contrib/xcscope folder, however the ubuntu package did not have this folder as part of cscope package. It is provided as additional package called cscope-el (The cscope-el package installs /usr/share/emacs23/site-lisp/cscope/xcscope.elc). So install all these packages using:
1sudo apt-get install emacs23 cscope cscope-el
Download the required kernel source tar ball from kernel.org, I wanted linux-2.6.11.12. It can be downloaded using wget as:
 Configuration:
We need to configure emacs to load cscope support, edit your ~/.emacs or ~/.emacs.d/init.el to include following line.
1(require 'xcscope)
Generate Cscope Database:
There are two ways to generate cscope database from kernel source, first is to use kernel make file and second is to use cscope directly. But first we need to extract the kernel source from the downloaded tar ball as given below.
1cd ~/Downloads
2tar -jxvf linux-2.6.11.12.tar.bz2
Method1: Generate cscope database using kernel make file, by using this method, list of files to be scanned by cscope is also generated by kernel make file. The file containing this list is named cscope.files. This is safer method if you don’t know which files to be included.
1cd ~/Downloads/linux-2.6.11.12
2make cscope
Method2: Generate cscope database directly using cscope.
In this method you can either scan all files in the current folder recursively by passing -R command line option to cscope or  you need to create a file named cscope.files  which can either contain list of files to be scanned (one file on each line) or using the special find construct as explained in Using cscope on large project page. The following command will scan the complete kernel source code tree, the -k option ensures that include files in /usr/include are ignored while building the database.
1cd ~/Downloads/linux-2.6.11.12
2cscope -b -q -k -R
Irrespective of the method the database file named cscope.out will be created.
Browsing the code:
To browse the code from emacs, first we need to tell the location of the database. This is done by executing command “M-x cscope-set-initial-directory” and specify the directory containing the cscope database. This step is not required if emacs is lanuched from the same directory.
Once the initial directory is set, you can search the code for given symbol using “M-x cscope-find-this-symbol” command, the text near cursor will be the default symbol to find. You can move through the results using p (previous match) and n (next match) keys, the corresponding files are opened in other buffer in emacs. Example output for symbol KERN_ALERT is shown below.
Emacs and Xcscope Find Symbol Output
The other useful commands include:
Find symbol.
Find global definition.
Find functions calling a function.
Find called functions (list functions called from a function).
Find text string.
Find egrep pattern.
Find a file.
For a complete list of commands supported by xcscope please refer to xcscope man page.
What didn’t Work for Me:
Using xcscope.el: If you download the xcscope.el and try to add it in emacs through config file as:
1(load-file "/usr/share/emacs/site-lisp/xcscope.el")
2(require 'xcscope)
I got the following error at emacs startup:
1Warning (initialization): An error occurred while loading `/home/dzambare/.emacs.d/init.el':
2 
3File error: Cannot open load file, xcscope
4 
5To ensure normal operation, you should investigate and remove the
6cause of the error in your initialization file.  Start Emacs with
7the `--debug-init' option to view a complete error backtrace.
The solution is to get rid of this file and install cscope-el package as explain in Installation section above.
Alternate Interface:
You can also use cscope’s inbuilt console based UI to browse and edit files. It can be launched by following command from the directory containing cscope database. The screenshot below shows how it looks like.
1cscope -d
Cscope in-build user interface
Cscope in-build user interface
End Notes:
  1. Even though this post is related to Linux kernel source, same method will work fine for any c project.
  2. Cscope scans all files only during first run, during subsequent executions it will only scan the files changed since last run.
  3. When you invoke first emacs command related to cscope it will automatically invokes cscope to make the database up to date.
  4. Example of xcscope key binding are provided in xcscope man page
Version Nos of Key Components:
  • OS: Kubuntu 11.10
  • Cscope:  15.7a
  • Xcscope: 15.7a
Links Related to This Post: