使用编译时,邪恶模式具有不可预测的行为

Evil mode has unpredictable behavior when using compile

我有这个问题,每当我 运行 编译命令邪恶模式创建一个新的 window 而不是在屏幕上使用 windows 正常编译命令会或它会在当前 window 上编译。

以下图为例: 如果没有邪恶模式,如果我有 2 个 windows 在拆分中打开并且我在左边的 window 和我 运行 M-x compile 并指定一个参数(假设它将是一个名为 build.bat 的批处理脚本)emacs 将使用右侧的屏幕,如下图所示:

https://i.stack.imgur.com/LeoMm.png

.emacs 是:

(require 'ido)
(require 'compile)
(ido-mode t)

; Compilation
(defun make-without-asking ()
  (interactive)
  (switch-to-buffer-other-window "*compilation*")
  (compile "build.bat")
  (other-window 1))
(define-key global-map "\em" 'make-without-asking)

(add-to-list 'default-frame-alist '(font . "Liberation Mono-11.5"))
(set-face-attribute 'default t :font "Liberation Mono-11.5")
(set-face-attribute 'font-lock-builtin-face nil :foreground "#DAB98F")
(set-face-attribute 'font-lock-comment-face nil :foreground "gray50")
(set-face-attribute 'font-lock-constant-face nil :foreground "olive drab")
(set-face-attribute 'font-lock-doc-face nil :foreground "gray50")
(set-face-attribute 'font-lock-function-name-face nil :foreground "burlywood3")
(set-face-attribute 'font-lock-keyword-face nil :foreground "DarkGoldenrod3")
(set-face-attribute 'font-lock-string-face nil :foreground "olive drab")
(set-face-attribute 'font-lock-type-face nil :foreground "burlywood3")
(set-face-attribute 'font-lock-variable-name-face nil :foreground "burlywood3")

  (menu-bar-mode -1)
  (set-foreground-color "burlywood3")
  (set-background-color "#161616")
  (set-cursor-color "#40FF40")

然而,一旦我添加邪恶模式,行为就变得不可预测,因为它有时会创建一个新的 window 或者它会在我所在的 window 上编译。 在下面的示例中,我在右侧的 window 启用了邪恶模式,当我 运行 M-x compilebuild.bat 作为参数时(像以前一样),邪恶模式编译代码并在同一个 window 上显示 *compilation* 缓冲区,而不是使用左侧的 window:

https://i.stack.imgur.com/MdNpg.png

开启邪恶模式的.emacs是:

(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("gnu" . "https://elpa.gnu.org/packages/")))
(require 'package)

(package-initialize)

(unless package-archive-contents
  (package-refresh-contents))

(setq package-selected-packages '(evil))
(package-install-selected-packages)

(require 'ido)
(require 'compile)
(require 'evil)
(evil-mode 1)
(ido-mode t)

; Compilation
(defun make-without-asking ()
  (interactive)
  (switch-to-buffer-other-window "*compilation*")
  (compile "build.bat")
  (other-window 1))
(define-key global-map "\em" 'make-without-asking)

(add-to-list 'default-frame-alist '(font . "Liberation Mono-11.5"))
(set-face-attribute 'default t :font "Liberation Mono-11.5")
(set-face-attribute 'font-lock-builtin-face nil :foreground "#DAB98F")
(set-face-attribute 'font-lock-comment-face nil :foreground "gray50")
(set-face-attribute 'font-lock-constant-face nil :foreground "olive drab")
(set-face-attribute 'font-lock-doc-face nil :foreground "gray50")
(set-face-attribute 'font-lock-function-name-face nil :foreground "burlywood3")
(set-face-attribute 'font-lock-keyword-face nil :foreground "DarkGoldenrod3")
(set-face-attribute 'font-lock-string-face nil :foreground "olive drab")
(set-face-attribute 'font-lock-type-face nil :foreground "burlywood3")
(set-face-attribute 'font-lock-variable-name-face nil :foreground "burlywood3")

  (menu-bar-mode -1)
  (set-foreground-color "burlywood3")
  (set-background-color "#161616")
  (set-cursor-color "#40FF40")

我刚刚切换到 neovim 并使用 vimscript 设置了这个功能,它更容易。