emacscompilationevil-mode

Evil mode has unpredictable behavior when using compile


I have this issue, where whenever I run the compile command evil mode creates a new window instead of using the windows on the screen which the normal compile command would or it would compile on the current window I am on.

Take the following images as examples: Without evil mode, if I have 2 windows open in a split and I am on a window on the left and I run M-x compile and specify an argument (assume it will be a batch script called build.bat) emacs will use the screen on the right as shown in this image:

https://i.sstatic.net/LeoMm.png

The .emacs is:

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

However, as soon as I add evil mode the behavior becomes unpredictable as it would sometimes create a new window or it will compile on the window I am on. In the following example I am on the window on the right with evil mode enabled and when I run M-x compile with build.bat as the argument (like before), evil mode compiles the code and shows the *compilation* buffer on the same window instead of using the window on the left:

https://i.sstatic.net/MdNpg.png

The .emacs with evil mode enabled is:

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

Solution

  • I just switched over to neovim and setup this functionlity using vimscript, it was much easier.