Emacs 学习笔记

Dev-C++ 难用的一逼,于是我决定使用口碑很好的 Emacs 提高我的码码质量。


如题,Emacs 有很多好处,比如说:

  • Dev-C++ 好用
  • 各大算法比赛基本上都预装该软件
  • 配置文件可以自定义
  • 快捷键设置的很科学
  • 可以打发我不想改题的时间

下载

设置

打开 bin 目录的 emacs.exe 就可以运行了,如果不想要那个黑黑的命令行,就用 runemacs.exe

设置字体

因为看 Dev-C++consolas 看习惯了,所以我就直接设置 consolas 了。

Options 中的 Set Default Font ,然后就可以调字体了

设置主题

搜了一下网上的主题,比较喜欢一个 Atom One Dark ThemeAtom 的移植主题,因为学校电脑有问题,我就没有装。


更新分割线 $\Uparrow \Uparrow$

其实安装主题非常的简单,按照文档取安装就可以了。

配置文件:

1
2
3
4
5
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/"))
(package-initialize)
(load-theme 'atom-one-dark t)

Bug 修复

在 Win10 有一个 $bug$ ,有的电脑有,有的没有,然鹅我就是这么不幸 qwq

$bug$ 就是如果出现了中文的字体,就会变得非常的卡。

但是解决非常简单,配置文件加一段代码:

1
2
3
4
5
(set-default-font "Consolas-12")
(set-fontset-font "fontset-default" 'chinese-gbk "微软雅黑")
(setq face-font-rescale-alist '(("宋体" . 1.2)
("微软雅黑" . 1.1)
))

全部配置文件

然后就放一下我的配置文件(根据我们老师 @cab 的配置文件 + 自己一些修改):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(global-hl-line-mode t)
(ido-mode t)
(setq frame-title-format "%b @17shou_VIP")

(
defun compile-file ()
(interactive)
(compile (format "g++ -o \"%s\" \"%s\" -g -lm -Wall" (file-name-sans-extension (buffer-name))(buffer-name)))
)

(
defun compile-file-cpp11 ()
(interactive)
(compile (format "g++ -o \"%s\" \"%s\" -g -lm -Wall -std=c++11" (file-name-sans-extension (buffer-name))(buffer-name)))
)

(global-set-key (kbd "C-s") 'save-buffer)
(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "<f8>") 'gud-gdb)
(global-set-key (kbd "<f9>") 'compile-file)
(global-set-key (kbd "C-<f9>") 'compile-file-cpp11)
(global-set-key (kbd "<f10>") 'eshell)
(global-set-key (kbd "C-a") 'mark-whole-buffer)
(global-set-key (kbd "C-w") 'kill-buffer)

(set-default-font "Consolas-12")
(set-fontset-font "fontset-default" 'chinese-gbk "微软雅黑")
(setq face-font-rescale-alist '(("宋体" . 1.2)
("微软雅黑" . 1.1)
))

(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)
'(cua-mode t nil (cua-base))
'(inhibit-startup-screen t)
'(show-paren-mode t)
'(tool-bar-mode nil))

(setq default-tab-width 4)
(setq-default indent-tabs-mode nil)
(setq c-basic-offset 4)
(setq auto-save-mode t)
(setq visible-bell nil)
(setq kill-ring-max 200)
(global-auto-revert-mode t)
(global-linum-mode t)
(blink-cursor-mode -1)
(show-paren-mode 1)
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

(set-frame-parameter (selected-frame) 'alpha (list 95 65))
(add-to-list 'default-frame-alist (cons 'alpha (list 95 65)))

(global-set-key [(f11)] 'loop-alpha)
(setq alpha-list '((100 100) (95 65) (85 55) (75 45) (65 35)))

(defun loop-alpha ()
(interactive)
(let ((h (car alpha-list)))
((lambda (a ab)
(set-frame-parameter (selected-frame) 'alpha (list a ab))
(add-to-list 'default-frame-alist (cons 'alpha (list a ab)))
) (car h) (car (cdr h)))
(setq alpha-list (cdr (append alpha-list (list h))))
)
)
(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.
)

(setq scroll-step 1
scroll-margin 3
scroll-conservatively 10000)

(setq ring-bell-function 'ignore)

(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/"))
(package-initialize)
(load-theme 'atom-one-dark t)

(add-to-list 'default-frame-alist '(fullscreen . maximized))

具体功能自己看配置文件,然后放一下结果图,非常帅气:

快捷键

  • 导入 .emacs 文件:</kbd>M-X</kbd> + load-file + 【.emacs 地址】
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×