天天看點

Spacemacs使用一、個性化設定二、輔助功能設定三、語言環境設定四、錯誤解決

文中所有引用的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. 修改滑鼠樣式

參考連結

  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)
           

重要參考:

  1. 從 vim 遷移到 spacemacs
  2. 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

  1. C-x C-f

    輸入

    ~/.spacemacs

    後回車
  2. dotspacemacs-configuration-layer

    中輸入

    latex

  3. C-x C-s

    關閉 spacemacs
  4. 重新打開spacemacs,此時其會自動下載下傳一些包,下載下傳完成之後自動安裝,安裝完成就可以使用latex了

(2)SumatraPDF 中設定逆向搜尋

  1. 安裝SumatraPDF
  2. 打開SumatraPDF,進入settings→options→set inverse search command-line
  3. 輸入"C:\Program Files\Emacs\x86_64\bin\emacsclient.exe" -n +%l “%f”
  4. 紅色部位根據自己Emacs安裝位置進行調整
  5. 最重要的部分: 打開spacemacs,

    M-x

    ,輸入:

    server-start

    回車。

    完成以上的部分基本就可以使用了。

注意 : 如果沒有第五步,就會出現 Emacsclient ERROR。

并且根據筆者測試,每次完全關掉 spacemacs 後,就要 重新 打開該服務。

3. Windows 下 flycheck 設定

參考連結

用msys2安裝aspell

  1. In MingW64 terminal search aspell:
  1. Installing aspell and dictionary you need :
pacman -S mingw64/mingw-w64-x86_64-aspell
    pacman -S mingw64/mingw-w64-x86_64-aspell-en
           
  1. Find aspell.exe location with

    which aspell

    , e.g.

    C:\msys64\mingw64\bin

  2. 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")
           
Spacemacs使用一、個性化設定二、輔助功能設定三、語言環境設定四、錯誤解決

三、語言環境設定

1. C語言環境配置

準備工作:

安裝GCC

  1. Windows下配置Emacs + gcc編寫編譯C程式的簡單方法
  2. window下 ‘g++’ 不是内部或外部指令

正式配置:

  1. 在 .spacemacs 配置檔案中的 dotspacemacs-configuration-layers 中加入 c-c++ 配置。
  2. 重新開機Emacs。
  3. C-x C-f

    建立C語言檔案 hello.c,寫入測試代碼。
#include <stdio.h>
 
int main(void)
{
	printf("This is a program test!\n");
 
	return 0;
}
           
  1. 按下C-x C-s儲存檔案。
  2. 編譯程式。通過指令

    M-x eshell

    進行shell模式,然後使用

    gcc -Wall -o hello hello.c

    進行編譯。
  3. 運作:

    ./hello.exe

    即可運作編譯好的可執行程式.
  4. 切換回編輯區:

    c-x b 'buffername'

    可以切換到某個buffer,如要切換回剛才那個hello.c編輯區,輸入

    c-x b hello.c

2. Python語言環境配置

  1. 在 .spacemacs 配置檔案中的 dotspacemacs-configuration-layers 中加入 python 支援。
  2. 重新開機Emacs。
  3. C-x C-f 建立C語言檔案 hello.py,寫入測試代碼。

    print(“hello world!!!”)

  4. 按下C-x C-s儲存檔案。
  5. 依次按

    M-m c C

    (或

    M-x compile

    )再輸入檔案名編譯程式。

四、錯誤解決

1. MAC OS:AUCTeX cannot find a working Tex distribution

  1. SPC j d (或C-x C-f )打開

    .spacemacs.d

    (或者是

    .emacs.d

    根據自己配置決定)下的

    .spacemacs.env

  2. 在 path 中加入 MACTeX 路徑

參考連結

其他參考

2. Emacs 中 XXX locked by [email protected]

在 dotspacemacs/user-init () 中添加

(setq make-backup-files nil)
(setq create-lockfiles nil)