1. 程式人生 > >我的emacs簡易配置

我的emacs簡易配置

only too number ini def col list lang reg

;;------------語言環境字符集設置(utf-8)-------------

(set-language-environment 'Chinese-GB)
(set-keyboard-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-selection-coding-system 'utf-8)
(modify-coding-system-alist 'process "*" 'utf-8)
(setq default-process-coding-system '(utf-8 . utf-8))
(setq-default pathname-coding-system 'utf-8)
(set-file-name-coding-system 'utf-8)
(setq ansi-color-for-comint-mode t)
;;處理shell-mode亂碼,好像沒作用

;;------語言環境字符集設置結束------------

;;--------------窗口界面設置------------------

(set-foreground-color "grey")
(set-background-color "black")
(set-cursor-color "gold1")
(set-mouse-color "gold1")

(set-scroll-bar-mode nil)
;;取消滾動欄

;;(customize-set-variable 'scroll-bar-mode 'right))
;;設置滾動欄在窗口右側,而默認是在左側

(tool-bar-mode nil)
;;取消工具欄

;;啟動設置
(setq default-frame-alist
             '((vertical-scroll-bars)
               (top . 25)
               (left . 45)
               (width . 120)
               (height . 40)
               (background-color . "black")
               (foreground-color . "grey")
               (cursor-color . "gold1")
               (mouse-color . "gold1")
               (tool-bar-lines . 0)
               (menu-bar-lines . 1)
               (right-fringe)
               (left-fringe)))

;;啟動自動最大化(數據自己調整,註意格式,如(top . 0),圓點前後都要留有空格)
;;(setq initial-frame-alist '((top . 0) (left . 0) (width . 142) (height . 49)))


;; 設置另外一些顏色:語法高亮顯示的背景和主題,區域選擇的背景和主題,二次選擇的背景和選擇
(set-face-foreground 'highlight "white")
(set-face-background 'highlight "blue")
(set-face-foreground 'region "cyan")
(set-face-background 'region "blue")
(set-face-foreground 'secondary-selection "skyblue")
(set-face-background 'secondary-selection "darkblue")

;;------------窗口界面設置結束-----------------


;;-------------方便編程操作設置----------------


;;把c語言風格設置為k&r風格
(add-hook 'c-mode-hook
'(lambda ()
(c-set-style "k&r")))

(autoload 'css-mode "css-mode" "CSS editing mode" t)
;;css-mode.el編輯css文件

(autoload 'htmlize-buffer "htmlize" "HTMLize mode" t)
;;把buffer的內容連同顏色轉為html格式


(setq auto-mode-alist
      ;; 將文件模式和文件後綴關聯起來
      (append '(("\\.py\\'" . python-mode)
                ("\\.s?html?\\'" . html-helper-mode)
                ("\\.asp\\'" . html-helper-mode)
                ("\\.phtml\\'" . html-helper-mode)
                ("\\.css\\'" . css-mode))
              auto-mode-alist))

(defun my-compile()
    (interactive)
    (save-some-buffers t)
    (let((file(file-name-nondirectory buffer-file-name)))
      (compile(format "g++ %s -g -o %s" file(file-name-sans-extension file))))
)


(global-linum-mode t)
(global-set-key [f9] 'my-compile)


(set-frame-parameter (selected-frame) 'alpha '(85  50))
 (add-to-list 'default-frame-alist '(alpha  (85  50)))

 (defun toggle-transparency ()
   (interactive)
   (let ((alpha (frame-parameter nil 'alpha)))
     (set-frame-parameter
      nil 'alpha
      (if (eql (cond ((numberp alpha) alpha)
                     ((numberp (cdr alpha)) (cdr alpha))
                     ;; Also handle undocumented ( ) form.
                     ((numberp (cadr alpha)) (cadr alpha)))
               100)
          '(85  50) '(100  100)))))
 (global-set-key (kbd "C-c t") 'toggle-transparency)
 
 
 (setq c-default-style
      '((java-mode . "java")(other . "awk")))
      
;;------------方便編程操作設置結束--------------------
(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.
 '(cua-mode t nil (cua-base)))
(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.
 )

;;在標題欄顯示buffer的名字(默認不顯示)
(setq frame-title-format "%b@emacs")

;;顯示匹配括號
(show-paren-mode t)
(setq show-paren-style 'parentheses)

;;全選
(global-set-key (kbd "C-a") 'mark-whole-buffer)

;滾動頁面時比較舒服,不要整頁的滾動
(setq     scroll-step 1
scroll-margin 3
scroll-conservatively 10000)


;;4格縮進
(setq-default indent-tabs-mode nil) ; tab 改為插入空格
(setq c-basic-offset 4) ; c c++ 縮進4個空格
(setq c-default-style "linux"); 沒有這個 { } 就會瞎搞
(setq default-tab-width 4)

;;其中最重要的一段:[F9]編譯
(defun my-compile()
    (interactive)
    (save-some-buffers t)
    (let((file(file-name-nondirectory buffer-file-name)))
      (compile(format "g++ %s -g -o %s" file(file-name-sans-extension file))))
)


(global-linum-mode t)
(global-set-key [f9] 'my-compile)

我的emacs簡易配置