增加Emacs的复制与粘贴功能。具体通过定义几个复制函数,将相关数据复制到删除环上,然后定义这些函数的快捷键。粘贴可以用Ctrl+y实现。现在的.Emacs文件内容如下:
(setq initial-frame-alist '((top . 0) (left . 0) (width . 1024) (height . 768)))
(column-number-mode t)
(transient-mark-mode t)
(setq line-number-mode t)
;;(setq default-tab-width 8)
(setq default-tab-width 4)
(customize-set-variable 'scroll-bar-mode' right)
(setq default-directory "/home/zhouyi198631/Study")
(setq inhibit-startup-message t)
(setq global-font-lock-mode t)
(setq make-backup-files nil)
(setq auto-save-mode nil)
(setq x-select-enable-clipboard t)
(setq mouse-yank-at-point t)
;;(define-key global-map [home] 'beginning-of-buffer)
;;(define-key global-map [end] 'end-of-buffer)
(define-key global-map [f3] 'display-line-number-mode-on)
(define-key global-map [C-f4] 'other-window)
(define-key global-map [f5] 'redraw-display)
(define-key global-map [f7] 'compile)
(setq-default compile-command "make")
;;(define-key global-map [f8] 'du-onekey-compile)
(define-key global-map [f6] 'gdb)
(define-key global-map [C-f9] 'previous-error)
(define-key global-map [f9] 'next-error)
;;(set-default-font "9x15")
;;(set-default-font "-adobe-courier-medium-r-normal--14-100-100-100-m-90-iso10646-1")
(set-default-font "10x20")
;;(set-default-font "-outline-ÐÂËÎÌå-normal-r-normal-normal-14-*-96-96-c-*-gb2312")
;; Load CEDET
(load-file "~/.emacs.d/cedet-1.0pre6/common/cedet.el")
;; Enabling various SEMANTIC minor modes. See semantic/INSTALL for more ideas.
;; Select one of the following:
;; * This enables the database and idle reparse engines
;;(semantic-load-enable-minimum-features)
;; * This enables some tools useful for coding, such as summary mode
;; imenu support, and the semantic navigator
;;(semantic-load-enable-code-helpers)
;; * This enables even more coding tools such as the nascent intellisense mode
;; decoration mode, and stickyfunc mode (plus regular code helpers)
;;(semantic-load-enable-guady-code-helpers)
;; * This turns on which-func support (Plus all other code helpers)
(semantic-load-enable-excessive-code-helpers)
;; This turns on modes that aid in grammar writing and semantic tool
;; development. It does not enable any other features such as code
;; helpers above.
(semantic-load-enable-semantic-debugging-helpers)
;; 配置 Semantic
(setq semanticdb-project-roots (list (expand-file-name "/")))
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "//>") (hippie-expand nil) (indent-for-tab-command))
)
(define-key global-map [(control tab)] 'my-indent-or-complete)
(autoload 'senator-try-expand-semantic "senator")
(setq hippie-expand-try-functions-list '(
senator-try-expand-semantic
try-expand-dabbrev
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-expand-list
try-expand-list-all-buffers
try-expand-line
try-expand-line-all-buffers
try-complete-file-name-partially
try-complete-file-name
try-expand-whole-kill
))
(define-key global-map [(f4)] 'speedbar-get-focus)
(require 'cc-mode)
(c-set-offset 'inline-open 0)
;;(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)
(defun my-c-mode-common-hook()
(setq tab-width 8 indent-tabs-mode nil)
(c-set-style "k&r")
;;; hungry-delete and auto-newline
(c-toggle-auto-hungry-state 1)
(define-key c-mode-base-map [(control /')] 'hs-toggle-hiding)
;; (define-key c-mode-base-map [(return)] 'newline-and-indent)
;; (define-key c-mode-base-map [(f6)] 'compile)
(define-key c-mode-base-map [(meta /')] 'c-indent-command)
;; (define-key c-mode-base-map [(tab)] 'hippie-expand)
(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
(define-key c-mode-base-map [(meta /)] 'semantic-ia-complete-symbol-menu)
(setq c-macro-shrink-window-flag t)
(setq c-macro-preprocessor "cpp")
(setq c-macro-cppflags " ")
(setq c-macro-prompt-flag t)
(setq hs-minor-mode t)
(setq abbrev-mode t)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(defun my-c++-mode-hook()
(setq tab-width 8 indent-tabs-mode nil)
;; (c-set-style "stroustrup")
(c-set-style "k&r")
;; (define-key c++-mode-map [f3] 'replace-regexp)
)
(add-to-list 'load-path "~/.emacs.d")
(require 'display-line-number)
;;(load-library "linum.el")
(global-display-line-number-mode 1)
;;(setq display-line-number-mode-on t)
(add-hook 'c-mode-hook 'display-line-number-mode)
(add-hook 'cc-mode-hook 'display-line-number-mode)
(add-to-list 'load-path "~/.emacs.d/ecb-2.40")
;;(require 'ecb)
(require 'ecb-autoloads)
;;for gdb-many-window mode
(require 'gud)
(setq gdb-many-windows t)
;;(setq gud-tooltip-mode t)
;;(load-library "multi-gud.el")
;;(load-library "multi-gdb-ui.el")
(add-hook 'gdb-mode-hook '(lambda ()
(gud-tooltip-mode 1)
(define-key c-mode-base-map [f5] 'gud-go)
(define-key c-mode-base-map [C-f5] 'gud-run)
(define-key c-mode-base-map [S-f5] 'gud-cont)
(define-key c-mode-base-map [f7] 'compile)
(define-key c-mode-base-map [f8] 'gud-print)
(define-key c-mode-base-map [C-f8] 'gud-pstar)
(define-key c-mode-base-map [f9] 'gud-break)
(define-key c-mode-base-map [C-f9] 'gud-remove)
(define-key c-mode-base-map [f10] 'gud-next)
(define-key c-mode-base-map [C-f10] 'gud-until)
(define-key c-mode-base-map [S-f10] 'gud-jump)
(define-key c-mode-base-map [f11] 'gud-step)
(define-key c-mode-base-map [S-f11] 'gud-finish)))
;; 窗体切换
(require 'wcy-swbuff)
;; then you can use <C-tab> and <C-S-kp-tab> to switch buffer.
(define-key global-map (kbd "<C-tab>") 'wcy-switch-buffer-forward)
(define-key global-map (kbd "<C-S-kp-tab>") 'wcy-switch-buffer-backward)
(setq wcy-switch-buffer-active-buffer-face 'highlight)
(setq wcy-switch-buffer-inactive-buffer-face 'secondary-selection )
;; cscope in emacs
(add-to-list 'load-path "~/.emacs.d/cscope-15.7a/contrib/xcscope")
(require 'xcscope)
;; hotkey for cscope
(define-key global-map [(control f3)] 'cscope-set-initial-directory)
(define-key global-map [(control f4)] 'cscope-unset-initial-directory)
(define-key global-map [(control f5)] 'cscope-find-this-symbol)
(define-key global-map [(control f6)] 'cscope-find-global-definition)
(define-key global-map [(control f7)]
'cscope-find-global-definition-no-prompting)
(define-key global-map [(control f8)] 'cscope-pop-mark)
(define-key global-map [(control f9)] 'cscope-next-symbol)
(define-key global-map [(control f10)] 'cscope-next-file)
(define-key global-map [(control f11)] 'cscope-prev-symbol)
(define-key global-map [(control f12)] 'cscope-prev-file)
(define-key global-map [(meta f9)] 'cscope-display-buffer)
(define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
(set-face-background 'default "#334455")
(set-face-foreground 'default "wheat")
(set-cursor-color "white")
;;(add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0")
;;(require 'color-theme)
;;(color-theme-dark-blue)
(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.
'(ecb-source-path (quote ("/home/zhouyi198631/linux"))))
(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.
)
;; 复制一行
(defun copy-line (&optional arg)
"Save current line into Kill-Ring without mark the line"
(interactive "P")
(let ((beg (line-beginning-position))
(end (line-end-position arg)))
(copy-region-as-kill beg end))
)
;; 复制当前字
(defun copy-word (&optional arg)
"Copy words at point"
(interactive "P")
(let ((beg (progn (if (looking-back "[a-zA-Z0-9]" 1) (backward-word 1)) (point)))
(end (progn (forward-word arg) (point))))
(copy-region-as-kill beg end))
)
;; 复制一个段落
(defun copy-paragraph (&optional arg)
"Copy paragraphes at point"
(interactive "P")
(let ((beg (progn (backward-paragraph 1) (point)))
(end (progn (forward-paragraph arg) (point))))
(copy-region-as-kill beg end))
)
;; 复制一个字符串
(defun copy-string (&optional arg)
"Copy a sequence of string into kill-ring"
(interactive)
(setq onPoint (point))
(let (
( beg (progn (re-search-backward "[/t ]" (line-beginning-position) 3 1)
(if (looking-at "[/t ]") (+ (point) 1) (point) ) )
)
( end (progn (goto-char onPoint) (re-search-forward "[/t ]" (line-end-position) 3 1)
(if (looking-back "[/t ]") (- (point) 1) (point) ) )
)
)
(copy-region-as-kill beg end)
)
)
;; 快捷键
(setq x-select-enable-clipboard t)
(global-set-key (kbd "C-c w") (quote copy-word))
(global-set-key (kbd "C-c l") (quote copy-line))
(global-set-key (kbd "C-c p") (quote copy-paragraph))
(global-set-key (kbd "C-c s") (quote copy-string))