这两天跑图书馆,做题做不下去了就玩emacs的配置解闷,还没完成,不过还是顺手贴一下好了
;;;F11:打开ecb
(global-set-key [(f11)] 'ecb-activate)
;;;F12:关闭ecb
(global-set-key [(f12)] 'ecb-deactivate)
;;;M-g 转到指定行号
(global-set-key [(meta g)] 'goto-line)
;;;设置选择起点
(global-set-key (kbd "C-x <SPC>") 'set-mark-command)
;;;高亮选择
(transient-mark-mode t)
;;;显示行号
(setq line-number-mode t)
;;;显示列号
(setq column-number-mode t)
;;打开括号匹配显示模式
(show-paren-mode t)
;;括号匹配时可以高亮显示另外一边的括号,但光标不会烦人的跳到另一个括号处。
(setq show-paren-style 'parenthesis)
;;与系统剪贴板互通
(setq x-select-enable-clipboard t)
;; "C-,"设为屏幕左移命令
(global-set-key (kbd "C-.") 'scroll-left)
;; "C-."设为屏幕右移命令
(global-set-key (kbd "C-,") 'scroll-right)
(global-set-key (kbd "M-p") 'scroll-down)
(global-set-key (kbd "M-n") 'scroll-up)
;;;; CC-mode配置 http://cc-mode.sourceforge.net/
(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 4 indent-tabs-mode nil)
;;; hungry-delete and auto-newline
(c-toggle-hungry-state 1)
;(c-toggle-auto-newline 0)
;(c-toggle-electric-state 0)
;;按键定义
(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 [(f7)] 'my-compile)
(define-key c-mode-base-map [(f9)] 'my-run)
(define-key c-mode-base-map [(f12)] 'my-edit-input-data)
(define-key c-mode-base-map [(control c) (control a)] 'my-copy-whole-file)
;(define-key c-mode-base-map [(meta \`)] 'c-indent-command)
;(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
(define-key c-mode-base-map [(tab)] 'c-indent-line-or-region)
(define-key c-mode-base-map [(control c) (control /)] 'indent-for-comment)
;(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)
;;doxymacs
;;(doxymacs-mode)
)
;;;;;;做题用的小工具
;;编译当前编辑的程序
(defun my-compile()
(interactive)
(compile (concat "g++ " (file-name-nondirectory buffer-file-name)))
)
;;运行当前程序,以程序名+".in"作为输入文件
(defun my-run()
(interactive)
(shell-command (concat "./a.out" " < " (file-name-sans-extension buffer-file-name) ".in") "Output")
(display-buffer "Output")
)
;;新开一个水平分割window显示输入文件
(defun my-edit-input-data()
(interactive)
(split-window-horizontally)
(find-file-other-window (concat (file-name-sans-extension buffer-file-name) ".in"))
)
;;复制当前文件的内容,用于提交程序到OJ上
(defun my-copy-whole-file()
(interactive)
;;(mark-whole-buffer)
(kill-ring-save (point-min) (point-max))
)
;;重新载入.emacs文件
(defun my-reload-conf()
(interactive)
(load-file "~/.emacs")
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;;;;我的C++语言编辑策略
(defun my-c++-mode-hook()
(setq tab-width 4 indent-tabs-mode t)
(c-set-style "stroustrup")
;; (define-key c++-mode-map [f3] 'replace-regexp)
)
(put 'scroll-left 'disabled nil)
(defun my-html-mode()
(define-key html-mode-map [(return)] 'newline-and-indent)
;;(define-key html-mode-map [(/)] 'indent-according-mode)
)
(add-hook 'html-mode 'my-html-mode)