我的Emacs配置

;;请在~/下创建.saves和.semanticdb文件夹

;--------------设置有用的个人信息---------------

(setq user-full-name "Bai YongHui")
(setq user-mail-address "ai.robort@gmail.com")

;-------------------设置基本信息----------------

;;设置背景颜色
(set-background-color "black")
;;设置字体颜色
(set-foreground-color "white")

;;设置tab宽度为4
(setq-default indent-tabs-mode  nil)
(setq tab-width 4 c-basic-offset 4)
;;(setq tab-width 4 indent-tabs-mode nil)

;;设置光标不闪
(blink-cursor-mode 1)
;;设置光标为线条状
(setq-default cursor-type 'bar)

;;设置是否显示光标所在列号
(column-number-mode t)
;;设置是否显示光标所在行号(默认显示)
(line-number-mode t)

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

;;以 y/n代表 yes/no
(fset 'yes-or-no-p 'y-or-n-p)

;;滚动条在右侧
(set-scroll-bar-mode 'right)

;滚动页面时比较舒服,不要整页的滚动
(setq     scroll-step 1
scroll-margin 3
scroll-conservatively 10000)

;;滚动页面时比较舒服,不要整页的滚动
(setq     scroll-step 1
scroll-margin 3
scroll-conservatively 10000)

;;显示时间
(display-time-mode t)
;;启动Emacs Server
(server-start)

;;高亮当前行
(require 'hl-line)
(global-hl-line-mode t)

;;在buffer左侧显示行号
(dolist (hook (list
'c-mode-hook
'c++-mode-hook
'emacs-lisp-mode-hook
'lisp-interaction-mode-hook
'lisp-mode-hook
'emms-playlist-mode-hook
'java-mode-hook
'asm-mode-hook
'haskell-mode-hook
'rcirc-mode-hook
'emms-lyrics-mode-hook
'erc-mode-hook
'sh-mode-hook
'makefile-gmake-mode-hook
))
(add-hook hook (lambda () (linum-mode 1))))

;;高亮当前行
(require 'hl-line)
(global-hl-line-mode t)

;;在标题栏显示buffer的名字(默认不显示)
(setq frame-title-format "%b@emacs")

;;支持emacs和外部程序的粘贴
(setq x-select-enable-clipboard t)

;;设置备份策略
(setq make-backup-files t)    ;;启用备份功能
(setq vc-make-backup-files t)    ;;使用版本控制系统的时候也启用备份功能
(setq version-control t)    ;;启用版本控制,即可以备份多次
(setq kept-old-versions 2)    ;;备份最原始的版本两次,即第一次编辑前的文档,和第二次编
                ;;辑前的文档
(setq kept-new-versions 6)    ;;备份最新的版本6次,理解同上
(setq delete-old-versions t)    ;;删掉不属于以上3种版本的版本
(setq backup-directory-alist '(("." . "~/.saves")));;设置备份文件的路径到~/.saves中
(setq backup-by-copying t)    ;;备份设置方法,直接拷贝

(setq backup-enable-predicate 'ecm-backup-enable-predicate);;设置备份条件
;;关闭匹配下列目录或文件的备份功能
(defun ecm-backup-enable-predicate (filename)
(and (not (string= "/tmp/" (substring filename 0 5)))
(not (string-match "semanticdb" filename))
))

;;关闭自动保存模式
;(setq auto-save-mode nil)
;;不生成 #filename# 临时文件
(setq auto-save-default nil)

;;自动的在文件末增加一新行
(setq require-final-newline t)
;;当光标在行尾上下移动的时候,始终保持在行尾。
(setq track-eol t)

;--------------快捷键设置----------------

;编译和调试
(global-set-key [f7] 'compile)        ;;编译
(global-set-key [C-f7] 'gdb)        ;;调试
(setq-default compile-command "make")    ;;
(global-set-key [C-f8] 'previous-error)    ;;上一个错误
(global-set-key [f8] 'next-error)    ;;下一个错误

;;F9:格式化代码,以使代码缩进清晰,容易阅读
(global-set-key [f9] 'c-indent-line-or-region)
;;F10:注释 / 取消注释
(global-set-key [f10] 'comment-or-uncomment-region)

;Ctrl+F11:复制区域到寄存器
(global-set-key [C-f11] 'copy-to-register)
;;F11:粘贴寄存器内容
(global-set-key [(f11)] 'insert-register)

;;C-x c 复制整行, 而"C-u 5 C-x c"复制 5 行   没用呀!!!
(global-set-key (kbd "C-x c") 'copy-lines)        ;;复制一行或者多行
(global-set-key (kbd "C-x d") 'zl-delete-line)        ;;删除一行
;(global-set-key (kbd "C-x a") 'kill-match-paren)    ;;删除匹配括号间内容

;;撤消
(global-set-key (kbd "C-z") 'undo)
;;全选
(global-set-key (kbd "C-a") 'mark-whole-buffer)
;;保存
(global-set-key (kbd "C-s") 'save-buffer)

;;跳转到某行
(global-set-key [(meta g)] 'goto-line)
;;Tab补全或缩进
(global-set-key [(tab)] 'my-indent-or-complete)

;--------------编程相关----------------

;;打开代码折叠功能
(add-hook 'c-mode-hook 'hs-minor-mode)
(add-hook 'c++-mode-hook 'hs-minor-mode)

;;定义C/C++风格
;(add-hook 'c-mode-hook 'my-c-cpp-mode)
(add-hook 'c++-mode-hook 'my-c-cpp-mode)
;(defun my-c-cpp-mode();该行使用会出错

;;出错
;;将回车代替C-j的功能,换行的同时对齐
;(define-key c-mode-map [return] 'newline-and-indent)
;(interactive)
;(define-key c++-mode-map [return] 'newline-and-indent)
;(interactive)
;(define-key c-mode-base-map [(return)] 'newline-and-indent)

;;出错
;;设置程序的对齐风格
;(c-set-style "K&R")

;;在模式栏中显示当前光标所在函数
(which-function-mode)
;;自动缩进的宽度设置为4
(setq c-basic-offset 4)

;;预处理设置
(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)

;;我的C++语言编辑策略
(defun my-c++-mode-hook()
(c-set-style "stroustrup")
;;(define-key c++-mode-map [f3] 'replace-regexp)  
)
;--------------自动补全----------------

;;;自定义hippie-expand补全或缩进函数
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "\\>")
(hippie-expand nil)
(indent-for-tab-command)
)
)

;; hippie-expand 自动补全策略
(setq hippie-expand-try-functions-list
'(
senator-try-expand-semantic        ;优先调用senator的分析结果
try-expand-dabbrev-visible         ;dabbrev策略, 可见窗口优先
try-expand-dabbrev                 ;dabbrev策略
try-expand-dabbrev-all-buffers     ;dabbrev策略, 包括所有窗口(除了当前窗口)
try-expand-dabbrev-from-kill       ;dabbrev策略, 从所有删除记录里搜索
try-complete-file-name             ;补全文件名
try-complete-file-name-partially   ;补全文件名, 匹配优先
try-expand-list                    ;补全list
try-expand-list-all-buffers        ;补全list, 包括所有窗口(除了当前窗口)
try-expand-line                    ;整行补全
try-expand-line-all-buffers        ;整行补全, 包括所有窗口(除了当前窗口)
try-complete-lisp-symbol           ;补全符号, 符号太多了, 设置低优先级利于高效补全
try-complete-lisp-symbol-partially ;补全符号, 包括所有窗口(除了当前窗口)
try-expand-whole-kill              ;kill-ring里面补全
))


;;配置semantic,代码分析,智能补全
(setq semanticdb-default-save-directory (expand-file-name "~/.semanticdb"))
;设置semantic.cache路径
(setq semanticdb-project-roots (list (expand-file-name "/")))
;配置Semantic的检索范围
(autoload 'senator-try-expand-semantic "senator")
;优先调用了senator的分析结果
(add-hook 'semantic-init-hooks 'semantic-idle-completions-mode)
;空闲时进行补全分析
(setq-default semantic-idle-scheduler-idle-time 432000)
;避免semantic占用CPU过多

;;C/C++语言启动时自动加载semantic对/usr/include的索引数据库
(setq semanticdb-search-system-databases t)
(add-hook 'c-mode-common-hook
(lambda ()
(setq semanticdb-project-system-databases
(list (semanticdb-create-database
semanticdb-new-database-class
"/usr/include")))))
(add-hook 'c++-mode-common-hook
(lambda ()
(setq semanticdb-project-system-databases
(list (semanticdb-create-database
semanticdb-new-database-class
"/usr/include")))))


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在Ubuntu上安装和配置Emacs的步骤: 1. 打开终端并输入以下命令以更新软件包列表: ```shell sudo apt update ``` 2. 输入以下命令以安装Emacs: ```shell sudo apt install emacs ``` 3. 安装完成后,您可以通过输入以下命令来启动Emacs: ```shell emacs ``` 4. 如果您想要在Emacs中使用中文输入法,请安装fcitx输入法框架和fcitx-emacs插件。输入以下命令以安装它们: ```shell sudo apt install fcitx fcitx-config-gtk fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-ui-classic fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx-sunpinyin fcitx-table-all fcitx-frontend-all fcitx-pinyin fcitx-module-x11 fcitx-config-gtk2 fcitx-module-dbus fcitx-module-kimpanel fcitx-module-x11 fcitx-ui-classic fcitx-module-cloudpinyin fcitx

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值