emacs配置

部分配置可以直接在菜单栏的options中设置(设置完记得要保存)

details不知道为什么显示不了了,放一个不能折叠的

;;设置一键编译
(defun compile-file ()(interactive)(compile (format "g++ -o %s %s -g -lm -Wall" (file-name-sans-extension (buffer-name))(buffer-name))))
(global-set-key [f9] 'compile-file)
;;;;设置编译快捷键(如果设置了一键编译不要与一键编译冲突)
;;(global-set-key [f9] 'compile)

;;考场必备
(global-set-key (kbd "C-a") 'mark-whole-buffer) ;;全选快捷键
(global-set-key (kbd "C-z") 'undo) ;;撤销快捷键
(global-set-key [f10] 'gud-gdb) ;;GDB调试快捷键
(global-set-key (kbd "RET") 'newline-and-indent) ;;换行自动缩进
(global-set-key (kbd "C-s") 'save-buffer) ;;设置保存快捷键
(setq-default kill-ring-max 65535) ;;扩大可撤销记录
;;(define-key key-translation-map [apps] (kbd "M-x")) ;; windows 系统下设置命令快捷键

;;设置缩进
;;;C++ 代码缩进长度。
(setq-default c-basic-offset 4)
;;;使用 tab 缩进
(setq-default indent-tabs-mode t)
;;;tab 的长度。务必和缩进长度一致
(setq-default default-tab-width 4)
(setq-default tab-width 4)

;;设置默认编码环境
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

;;不显示欢迎页面
(setq-default inhibit-startup-screen t)

;;设置标题
(setq-default frame-title-format "")

;;显示行号
(global-linum-mode t)

;;高亮
(global-hl-line-mode 1);;高亮当前行
(show-paren-mode t);;高亮匹配括号
(global-font-lock-mode t);;语法高亮

;;允许emacs和外部其他程序的粘贴 好像默认允许
(setq-default x-select-enable-clipboard t)

;;设置字体是 Ubuntu Mono 的 16 号,如果字体不存在会报错
(set-default-font "Ubuntu Mono-16")
;(set-default-font "Consolas-16") ;; windows 系统请用这条

;;鼠标滚轮支持
(mouse-wheel-mode t)

;;设置光标形状为竖线(默认为方块)
(setq-default cursor-type 'bar)

;;回答 yes/no 改成回答 y/n
(fset 'yes-or-no-p 'y-or-n-p)

;;透明度
(set-frame-parameter (selected-frame) 'alpha (list 85 60))
(add-to-list 'default-frame-alist (cons 'alpha (list 85 60)))

;;减少页面滚动的行数,防止整页地滚动
(setq-default scroll-margin 3 scroll-conservatively 10000)

;;优化文件树结构
(ido-mode t)

;;配色方案
(setq default-frame-alist
         '((vertical-scroll-bars)
           (top . 25)
           (left . 45)
           (width . 120)
           (height . 40)
           (background-color . "grey15")
           (foreground-color . "grey")
           (cursor-color . "gold1")
           (mouse-color . "gold1")
           (tool-bar-lines . 0)
           (menu-bar-lines . 1)
           (scroll-bar-lines . 0)
           (right-fringe)
           (left-fringe)))

(set-face-background 'highlight "gray5")
(set-face-foreground 'region "cyan")
(set-face-background 'region "blue")
(set-face-foreground 'secondary-selection "skyblue")
(set-face-background 'secondary-selection "darkblue")
(set-cursor-color "wheat")
(set-mouse-color "wheat")

(custom-set-variables
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
;;启动 Ctrl-x Ctrl-c Ctrl-v = 剪切 复制 粘贴
 '(cua-mode t nil (cua-base))
 '(show-paren-mode t)
;;隐藏工具栏
 '(tool-bar-mode nil))
;;关闭光标闪烁
 '(blink-cursor-mode nil)
(custom-set-faces)
最新版配置
;;设置一键编译
(defun compile-file ()(interactive)(compile (format "g++ -o %s %s -g -lm -Wall" (file-name-sans-extension (buffer-name))(buffer-name))))
(global-set-key [f9] 'compile-file)
;;;;设置编译快捷键(如果设置了一键编译不要与一键编译冲突)
;;(global-set-key [f9] 'compile)

;;考场必备
(global-set-key (kbd "C-a") 'mark-whole-buffer) ;;全选快捷键
(global-set-key (kbd "C-z") 'undo) ;;撤销快捷键
(global-set-key [f10] 'gud-gdb) ;;GDB调试快捷键
(global-set-key (kbd "RET") 'newline-and-indent) ;;换行自动缩进
(global-set-key (kbd "C-s") 'save-buffer) ;;设置保存快捷键
(setq-default kill-ring-max 65535) ;;扩大可撤销记录
;;(define-key key-translation-map [apps] (kbd "M-x")) ;; windows 系统下设置命令快捷键

;;设置缩进
;;;C++ 代码缩进长度。
(setq-default c-basic-offset 4)
;;;使用 tab 缩进
(setq-default indent-tabs-mode t)
;;;tab 的长度。务必和缩进长度一致
(setq-default default-tab-width 4)
(setq-default tab-width 4)

;;设置默认编码环境
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

;;不显示欢迎页面
(setq-default inhibit-startup-screen t)

;;设置标题
(setq-default frame-title-format "")

;;显示行号
(global-linum-mode t)

;;高亮
(global-hl-line-mode 1);;高亮当前行
(show-paren-mode t);;高亮匹配括号
(global-font-lock-mode t);;语法高亮

;;允许emacs和外部其他程序的粘贴 好像默认允许
(setq-default x-select-enable-clipboard t)

;;设置字体是 Ubuntu Mono 的 16 号,如果字体不存在会报错
(set-default-font "Ubuntu Mono-16")
;(set-default-font "Consolas-16") ;; windows 系统请用这条

;;鼠标滚轮支持
(mouse-wheel-mode t)

;;设置光标形状为竖线(默认为方块)
(setq-default cursor-type 'bar)

;;回答 yes/no 改成回答 y/n
(fset 'yes-or-no-p 'y-or-n-p)

;;透明度
(set-frame-parameter (selected-frame) 'alpha (list 85 60))
(add-to-list 'default-frame-alist (cons 'alpha (list 85 60)))

;;减少页面滚动的行数,防止整页地滚动
(setq-default scroll-margin 3 scroll-conservatively 10000)

;;优化文件树结构
(ido-mode t)

;;配色方案
(setq default-frame-alist
'((vertical-scroll-bars)
(top . 25)
(left . 45)
(width . 120)
(height . 40)
(background-color . "grey15")
(foreground-color . "grey")
(cursor-color . "gold1")
(mouse-color . "gold1")
(tool-bar-lines . 0)
(menu-bar-lines . 1)
(scroll-bar-lines . 0)
(right-fringe)
(left-fringe)))

(set-face-background 'highlight "gray5")
(set-face-foreground 'region "cyan")
(set-face-background 'region "blue")
(set-face-foreground 'secondary-selection "skyblue")
(set-face-background 'secondary-selection "darkblue")
(set-cursor-color "wheat")
(set-mouse-color "wheat")

(custom-set-variables
'(ansi-color-faces-vector
[default default default italic underline success warning error])
;;启动 Ctrl-x Ctrl-c Ctrl-v = 剪切 复制 粘贴
'(cua-mode t nil (cua-base))
'(show-paren-mode t)
;;隐藏工具栏
'(tool-bar-mode nil))
;;关闭光标闪烁
'(blink-cursor-mode nil)
(custom-set-faces)

本配置在 emacs26 起效(不排除其它版本出现不兼容情况)
;;设置一键编译
(defun compile-file ()(interactive)(compile (format "g++ -o %s %s -g -lm -Wall" (file-name-sans-extension (buffer-name))(buffer-name))))
(global-set-key [f9] 'compile-file)
;;;;设置编译快捷键(如果设置了一键编译不要与一键编译冲突)
;;(global-set-key [f9] 'compile)

;;考场必备
(global-set-key (kbd "C-a") 'mark-whole-buffer) ;;全选快捷键
(global-set-key (kbd "C-z") 'undo) ;;撤销快捷键
(global-set-key [f10] 'gud-gdb) ;;GDB调试快捷键
(global-set-key (kbd "RET") 'newline-and-indent) ;;换行自动缩进
(global-set-key (kbd "C-s") 'save-buffer) ;;设置保存快捷键
(setq-default kill-ring-max 65535) ;;扩大可撤销记录
;(define-key key-translation-map [apps] (kbd "M-x")) ;;windows 系统下设置命令快捷键

;;C++ 代码风格 一般控制缩进规则
;;;"bsd" = 所有大括号换行。
;;;"java" = 所有大括号不换行。else 接在右大括号后面。
;;;"k&r" = "awk" = 只有命名空间旁、定义类、定义函数时的大括号换行。else 接在右大括号后面。
;;;"stroustrup" = 只有命名空间旁、定义类、定义函数时的大括号换行。else 换行。
;;;"whitesmith" = 所有大括号换行。大括号有一次额外缩进。
;;;"gnu" = 所有大括号换行。每次左括号开始,会有一层额外缩进。这是 emacs 默认。
;;;"linux" = 只有命名空间旁、定义类、定义函数时的大括号换行。else 接在右大括号后面。一般来说,这个风格应该有 8 格的空格缩进。
(setq-default c-default-style "awk")

;;设置缩进
;;;C++ 代码缩进长度。
(setq-default c-basic-offset 4)
;;;使用 tab 缩进。
(setq-default indent-tabs-mode t)
;;;tab 的长度。务必和缩进长度一致。
(setq-default default-tab-width 4)
(setq-default tab-width 4)

;;设置默认编码环境
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

;;不显示欢迎页面。
(setq-default inhibit-startup-screen t)

;;设置标题。
(setq-default frame-title-format "")

;;显示行号。
(global-linum-mode t)

;;高亮当前行。
(global-hl-line-mode 1)

;;高亮匹配括号。
(show-paren-mode t)

;;剪贴板共享。
(setq-default x-select-enable-clipboard t)

;;启用 cua-mode (C-x C-c C-v 分别代表剪切,复制,粘贴)。
(cua-mode t)

;;设置字体是 Ubuntu Mono 的 16 号。
(set-default-font "Ubuntu Mono-16")
;(set-default-font "Consolas-16")

;; 语法高亮。
(global-font-lock-mode t)

;; 鼠标滚轮支持。
(mouse-wheel-mode t)

;;设置光标形状为竖线(默认为方块)
(setq-default cursor-type 'bar)

;; 回答 yes/no 改成回答 y/n。
(fset 'yes-or-no-p 'y-or-n-p)

;; 透明度。
(set-frame-parameter (selected-frame) 'alpha (list 85 60))
(add-to-list 'default-frame-alist (cons 'alpha (list 85 60)))

;; 优化页面滚动。
(setq-default scroll-margin 3 scroll-conservatively 10000)

;; 优化文件树结构。
(ido-mode t)

;; 配色方案。
(setq default-frame-alist
'((vertical-scroll-bars)
(top . 25)
(left . 45)
(width . 120)
(height . 40)
(background-color . "grey15")
(foreground-color . "grey")
(cursor-color . "gold1")
(mouse-color . "gold1")
(tool-bar-lines . 0)
(menu-bar-lines . 1)
(scroll-bar-lines . 0)
(right-fringe)
(left-fringe)))

(set-face-background 'highlight "gray5")
(set-face-foreground 'region "cyan")
(set-face-background 'region "blue")
(set-face-foreground 'secondary-selection "skyblue")
(set-face-background 'secondary-selection "darkblue")
(set-cursor-color "wheat")
(set-mouse-color "wheat")

(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.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
;; 启动 Ctrl-x Ctrl-c Ctrl-v = 剪切 复制 粘贴。
'(cua-mode t nil (cua-base))
'(show-paren-mode t)
;; 隐藏工具栏。
'(tool-bar-mode nil))
;; 关闭光标闪烁
'(blink-cursor-mode nil)
(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.
)

配置版本2
(global-set-key [f9] 'compile-file)
(global-set-key [f10] 'gud-gdb)
(global-set-key (kbd "C-s") 'save-buffer)
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "RET") 'newline-and-indent)
(global-linum-mode t)
(show-paren-mode t)
(define-key key-translation-map (kbd "C-d") (kbd "M-p M-y"))    
(global-set-key (kbd "M-p M-y") 'kill-whole-line)
(define-key key-translation-map (kbd "C-a") (kbd "C-x h"))
(setq c-default-style "awk")
;;;考场必备
(define-key key-translation-map (kbd "") (kbd "M-x"))
(ido-mode t)

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

(global-hl-line-mode 1)

(set-face-background 'highlight "gray5")
(set-face-foreground 'region "cyan")
(set-face-background 'region "blue")
(set-face-foreground 'secondary-selection "skyblue")
(set-face-background 'secondary-selection "darkblue")

;;;;;设置org模式
(setq org-startup-indented t)
;(setq org-log-done 'time)
;(s.etq org-log-done 'note)
;

;;;无关紧要
(set-cursor-color "wheat")
(set-mouse-color "wheat")
(global-font-lock-mode t);;高亮
;;;;;设置编译信息
(defun compile-file ()
(interactive)
(compile (format "g++ -o %s %s -g -lm -Wall -Wl,--stack=512000000 -std=c++11 -DDOWN_LINE" (file-name-sans-extension (buffer-name))(buffer-name))))
;;(global-set-key (kbd "") 'compile-file)
;;;;;设置一键调试
;;;;;改变emacs标题栏的标题
(setq frame-title-format "")
;;;;;允许emacs和外部其他程序的粘贴
(setq x-select-enable-clipboard t)
;; 显示列号
(setq column-number-mode t)
;;设置tab为4个空格的宽度
(setq tab-width 4)
(setq default-tab-width 4)
(setq c-basic-offset 4)
;;;;;启用时间显示设置,在minibuffer上面的那个杠上(忘了叫什么来着)
(display-time-mode 1)
;;;;;时间使用24小时制
(setq display-time-24hr-format t)
;;;;;时间显示包括日期和具体时间
(setq display-time-day-and-date t)
;;;;;时间的变化频率,单位多少来着?
(setq display-time-interval 10)
;;;;;是用滚轴鼠标
(mouse-wheel-mode t)
;;;;;备份设置
;;;;;emacs还有一个自动保存功能,默认在~/.emacs.d/auto-save-list里,这个非常有用,我这里没有改动,具体可以参见Sams teach yourself emacs in 24hours(我简称为sams24)
;;;;;备份设置方法,直接拷贝
(setq backup-by-copying t)
;; 自动存盘
(setq auto-save-mode t)
;;;;;去掉烦人的警告铃声
(setq visible-bell nil)
(setq ring-bell-function 'ignore)
;;;;;指针不要闪,我得眼睛花了
(blink-cursor-mode -1)
;;;;;滚动页面时比较舒服,不要整页的滚动
(setq scroll-step 1
scroll-margin 3
scroll-conservatively 10000)
;;;;;设定删除保存记录为200,可以方便以后无限恢复
(setq kill-ring-max 200)
;;;;;修改透明度
(set-frame-parameter (selected-frame) 'alpha (list 70 50))
(add-to-list 'default-frame-alist (cons 'alpha (list 70 50)))
(setq-default cursor-type 'bar)

(show-paren-mode 1);;括号匹配
(fset 'yes-or-no-p 'y-or-n-p);;酱油的
(setq make-backup-files nil)
(global-auto-revert-mode t);自动reload文件

(global-set-key (kbd "") 'gdb-many-windows)

(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.
'(blink-cursor-mode nil)
'(column-number-mode t)
'(cua-mode t nil (cua-base))
'(display-time-mode t)
'(inhibit-startup-screen t)
'(show-paren-mode t)
'(size-indication-mode t)
'(tool-bar-mode nil))
(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 (:family "Consolas" :foundry "outline" :slant normal :weight normal :height 158 :width normal)))))
(auto-insert-mode) ;;; Adds hook to find-files-hook
(setq auto-insert-directory "~/.emacs.d/mytemplates/") ;;; Or use custom, NOTE Trailing slash important
(setq auto-insert-query nil) ;;; If you don't want to be prompted before insertion
(define-auto-insert "." "moban.cpp")

posted @ 2018-12-08 16:45  akakw1  阅读(416)  评论(0编辑  收藏  举报