文中所有引用的IP均归其原作者所有,本文仅供参考。
本文记录笔者自己在使用Emacs中学习到一些比较有用的知识和技巧,供自己以后参考,同时也方便后来人。
文章目录
- 一、个性化设置
-
- 1. 修改鼠标样式
- 2. SPC键的设置
- 3. 背景主题的设置
- 4. 自动全屏设置
- 5. Vim 快捷键设置
- 二、辅助功能设置
-
- 1. Spacemacs 换源
- 2. Emacs(spacemacs)+SumatraPDF逆向搜索设置(Emacsclient ERROR)
-
- (1)Spacemacs 中安装 latex
- (2)SumatraPDF 中设置逆向搜索
- 3. Windows 下 flycheck 设置
- 三、语言环境设置
-
- 1. C语言环境配置
- 2. Python语言环境配置
- 四、错误解决
-
- 1. MAC OS:AUCTeX cannot find a working Tex distribution
- 2. Emacs 中 XXX locked by [email protected]
以下是正文内容
一、个性化设置
1. 修改鼠标样式
参考链接
- 在 .spacemacs 文件中的
中加入如下命令:defun dotspacemacs/user-config ()
2. SPC键的设置
- 可修改在 .spacemacs 中的 defun dotspacemacs/init () 函数下的 dotspacemacs-emacs-leader-key "M-m"
3. 背景主题的设置
- 可修改在 .spacemacs 中的 defun dotspacemacs/init () 函数下的 dotspacemacs-themes 中按照如下设置
dotspacemacs-themes '(solarized-dark
solarized-light
solarized
)
另外,为避免 Spacemacs 每次加载时把主题包删掉,再下载这种令人窒息的操作,可以在 .spacemacs 下的 (defun dotspacemacs/layers ( ) 层中的 dotspacemacs-additional-packages '( ) 进行如下配置
4. 自动全屏设置
- 在 .spacemacs 下的 (defun dotspacemacs/init ()) 层中将
改为
5. Vim 快捷键设置
- 在 .spacemacs 下的 (defun dotspacemacs/user-config ()) 层中加入以下代码
(setq-default evil-escape-key-sequence "jk")
(setq-default evil-escape-delay 0.2)
重要参考:
- 从 vim 迁移到 spacemacs
- evil-escape
二、辅助功能设置
1. Spacemacs 换源
主要在
dotspacemacs/user-init ()
中添加
(setq configuration-layer--elpa-archives
'(("melpa-cn" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
("org-cn" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/org/")
("gnu-cn" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")))
2. Emacs(spacemacs)+SumatraPDF逆向搜索设置(Emacsclient ERROR)
(1)Spacemacs 中安装 latex
-
输入C-x C-f
后回车~/.spacemacs
- 在
中输入dotspacemacs-configuration-layer
latex
-
关闭 spacemacsC-x C-s
- 重新打开spacemacs,此时其会自动下载一些包,下载完成之后自动安装,安装完成就可以使用latex了
(2)SumatraPDF 中设置逆向搜索
- 安装SumatraPDF
- 打开SumatraPDF,进入settings→options→set inverse search command-line
- 输入"C:\Program Files\Emacs\x86_64\bin\emacsclient.exe" -n +%l “%f”
- 红色部位根据自己Emacs安装位置进行调整
- 最重要的部分: 打开spacemacs,
,输入:M-x
server-start
回车。
完成以上的部分基本就可以使用了。
注意 : 如果没有第五步,就会出现 Emacsclient ERROR。
并且根据笔者测试,每次完全关掉 spacemacs 后,就要 重新 打开该服务。
3. Windows 下 flycheck 设置
参考链接
用msys2安装aspell
- In MingW64 terminal search aspell:
- Installing aspell and dictionary you need :
pacman -S mingw64/mingw-w64-x86_64-aspell
pacman -S mingw64/mingw-w64-x86_64-aspell-en
- Find aspell.exe location with
, e.g.which aspell
C:\msys64\mingw64\bin
- Update in dotfile. Especially in Spacemacs:
(add-to-list 'exec-path "C:/msys64/mingw64/bin/")
(setq ispell-program-name "aspell")
(setq ispell-personal-dictionary "c:/msys64/mingw64/lib/aspell-0.60/en_GB")

三、语言环境设置
1. C语言环境配置
准备工作:
安装GCC
- Windows下配置Emacs + gcc编写编译C程序的简单方法
- window下 ‘g++’ 不是内部或外部命令
正式配置:
- 在 .spacemacs 配置文件中的 dotspacemacs-configuration-layers 中加入 c-c++ 配置。
- 重启Emacs。
-
新建C语言文件 hello.c,写入测试代码。C-x C-f
#include <stdio.h>
int main(void)
{
printf("This is a program test!\n");
return 0;
}
- 按下C-x C-s保存文件。
- 编译程序。通过命令
进行shell模式,然后使用M-x eshell
进行编译。gcc -Wall -o hello hello.c
- 运行:
即可运行编译好的可执行程序../hello.exe
- 切换回编辑区:
可以切换到某个buffer,如要切换回刚才那个hello.c编辑区,输入c-x b 'buffername'
。c-x b hello.c
2. Python语言环境配置
- 在 .spacemacs 配置文件中的 dotspacemacs-configuration-layers 中加入 python 支持。
- 重启Emacs。
- C-x C-f 新建C语言文件 hello.py,写入测试代码。
print(“hello world!!!”)
- 按下C-x C-s保存文件。
- 依次按
(或M-m c C
)再输入文件名编译程序。M-x compile
四、错误解决
1. MAC OS:AUCTeX cannot find a working Tex distribution
- SPC j d (或C-x C-f )打开
(或者是.spacemacs.d
根据自己配置决定)下的.emacs.d
.spacemacs.env
- 在 path 中加入 MACTeX 路径
参考链接
其他参考
2. Emacs 中 XXX locked by [email protected]
在 dotspacemacs/user-init () 中添加
(setq make-backup-files nil)
(setq create-lockfiles nil)