文中所有引用的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)