LOADING...

加载过慢请开启缓存(浏览器默认开启)

loading

Spacemacs

安装

建议使用 develop 分支,稳定分支有太多没有及时修复的问题:

git clone -b develop https://github.com/syl20bnr/spacemacs ~/.emacs.d

拉完项目后首次启动 emacs,会提示一些选项选择,然后自动下载依赖包。

配置

Spacemacs 的所有配置只需要修改 ~/.spacemacs 文件。

Spacemacs 有两套快捷键布局,loader 键是触发 Spacemacs 定制的快捷键:

  • vim(evil):loader 是空格
  • emacs:loader 是 M-m

通用配置

(defun 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/"))))

主题

Emacs 默认的主题在透明 TUI 下有更好的显示,但是在 GUI 下 ilight-bright 合适:

(defun dotspacemacs/init ()
  ......
  dotspacemacs-themes '(default
                        twilight-bright
                        spacemacs-dark
                        spacemacs-light)
  ......
)

字体

Victor 的斜体有着非常令人喜悦的观感,所以还可以为关健字等都调为斜体:

(defun dotspacemacs/init ()
  ......
  dotspacemacs-default-font '("VictorMono Nerd Font Mono"
                              :size 14.0
                              :weight normal
                              :width normal)
  ......
)
......
(defun dotspacemacs/emacs-custom-settings ()
  ......
  (custom-set-faces
    '(font-lock-builtin-face ((t (:slant italic :weight bold))))
    '(font-lock-constant-face ((t (:slant italic :weight bold))))
    '(font-lock-function-name-face ((t (:slant italic :weight bold))))
    '(font-lock-keyword-face ((t (:slant italic :weight bold))))
    '(font-lock-preprocessor-face ((t (:slant italic :weight bold))))
    '(font-lock-type-face ((t (:slant italic :weight bold))))
    '(font-lock-variable-name-face ((t (:slant italic :weight bold)))))
  ......
)

一般 Emacs 配置

(defun dotspacemacs/user-config ()
  ; (fset 'yes-or-no-p 'y-or-n-p)      ;; y/n instead of yes/no
  ; (setq-default save-place t)        ;; save the current line of a file
  ; (setq make-backup-files nil)       ;; disable backup automatically
  ; (setq auto-save-mode nil)

  ;; navigating parentheses
  (define-key global-map "\C-c}" 'forward-list)
  (define-key global-map "\C-c{" 'backward-list)
  (define-key global-map "\C-c)" 'forward-sexp)
  (define-key global-map "\C-c(" 'backward-sexp)
)

常用插件

少时积累,老时舍弃,历经时间后的断舍离,常用的只余数几(打勾的为 Spacemacs 已有的):

  • ace-jump-mode/avy:根据字母的跳转神器,M-m j 触发
  • company:用来补全代码的,比 ac 更新,有挺强的后端,和 lsp 完美集成
  • flycheck:即时语法检测
  • geiser:scheme 的 repl,相当 slime 于 Common Lisp
  • htmlize:当有涉及导出为 html 时候,可以高亮该文件
  • projectile:快速查找 git 项目文件
  • rainbow-identifiers:彩虹化标识,所有的标识都有一个自己的颜色,个人最喜欢的插件
  • switch-window:多窗口切换利器,但是 Spacemacs 的 M-m <num> 已经不错了
  • git-timemachine:触发后,可以在 git 代码里面看到历史的文件的模样

以 rainbow-identifiers 为例安装配置:

(defun dotspacemacs/layers ()
  (setq-default
    ......
    dotspacemacs-additional-packages '(rainbow-identifiers)
  ))
......
(defun dotspacemacs/user-config ()
  ......
  ;; rainbow-identifiers-mode
  (add-hook 'prog-mode-hook #'rainbow-identifiers-mode)
  (setq rainbow-identifiers-choose-face-function 'rainbow-identifiers-cie-l*a*b*-choose-face
        rainbow-identifiers-cie-l*a*b*-lightness 36
        rainbow-identifiers-cie-l*a*b*-saturation 100
        rainbow-identifiers-cie-l*a*b*-color-count 360)
  (setq rainbow-identifiers-faces-to-override '(font-lock-type-face font-lock-variable-name-face))
  )

Lsp

(defun dotspacemacs/layers ()
  (setq-default
    ......
    dotspacemacs-configuration-layers
    '(
      ......
      lsp
      )
  ))

Emacs Lsp-mode 项目已经为很多编程语言做了适配,Spacemacs 在其基础上做了很多预设配置,对应的需要开启 Spacemacs 对该编程语言的支持,少数的编程语言需要指定后端是的服务是 lsp 提供的:

(defun dotspacemacs/layers ()
  (setq-default
    ......
    dotspacemacs-configuration-layers
    '(
      emacs-lisp
      erlang
      graphviz
      java
      javascript
      (php :variables php-backend 'lsp)
      (python :variables python-backend 'lsp python-lsp-server 'pyright)
      rust
      shell-scripts
      )
  ))

Dap

Spacemacs 已经集成了 Dap 和 Hydra,开启配置即可:

(defun dotspacemacs/layers ()
  (setq-default
    ......
    dotspacemacs-configuration-layers
    '(
      ......
      dap
      )
  ))

问题

Fcitx 无法输入中文

如果中文的环境配置正常,只有 Emacs 无法输入中文,那么很有可能是字体库的问题,系统需要安装 100dpi,75dpi,terminus,bitstream 字体(有时还需要像 cyberbit 这种有 cjk 的字体),然后加入到系统 X11 字体的配置文件中,如 /etc/X11/xorg.conf.d/fonts.conf,然后配合 fc-cache 和 xlsfonts 来弄:

Section "Files"
    FontPath "/usr/share/fonts/100dpi"
EndSection

lsp-java 依赖安装失败

因为依赖现在是从 raw.githubcontent.com 获取的。可以在 github 先把 pom.xml 内容复制,然后使用下载工具把所需要的二进制下载到本地,文件列表如下:

  • Pivotal.vscode-spring-boot-x.x.x.vsix
  • vscjava.vscode-java-dependency-x.x.x.vsix
  • vscode-java-test.zip
  • dgileadi.java-decompiler-x.x.x.vsix

然后执行:

sed -i "s|https://github.com/emacs-lsp/lsp-java/releases/download/2.2/|file://`pwd`/|g" pom.xml
/usr/bin/java -classpath /opt/maven/boot/plexus-classworlds-2.6.0.jar \
              -Dclassworlds.conf=/opt/maven/bin/m2.conf \
              -Dmaven.home=/opt/maven \
              -Dlibrary.jansi.path=/opt/maven/lib/jansi-native \
              -Dmaven.multiModuleProjectDirectory=`pwd` org.codehaus.plexus.classworlds.launcher.Launcher \
              -Djdt.js.server.root=$HOME/.emacs.d/.cache/lsp/eclipse.jdt.ls/ \
              -Djunit.runner.root=$HOME/.emacs.d/eclipse.jdt.ls/test-runner/ \
              -Djunit.runner.fileName=junit-platform-console-standalone.jar \
              -Djava.debug.root=$HOME/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles clean package \
              -Djdt.download.url=file:///`pwd`/jdt-language-server-latest.tar.gz

Java 项目 Getter 和 Setter 报错

下载 lombok.jar,然后在 Emacs 的 customize 里面找到 lsp-java-vmargs,追加上 -javaagent:${lombok.jar_path}-Xbootclasspath/a:${lombok.jar_path}

PHP 项目无法调试

PHP 的调试是依赖 Xdebug 的,所以需要先安装并且在配置文件先开启:

xdebug.remote_enable = 1
xdebug.remote_autostart = 1

配置完后,需要执行 dap-php-select,该命令会自动下载 vscode-php-debug 作为组件,配置的位置为项目下的 ./.vscode/launch.json,加上 ignore 为了屏蔽一些错误:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "ignore": [
                "**/vendor/**/*.php"
            ]
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}