Endless Parentheses

Concise ramblings on Emacs productivity.

Better compile command

Having to confirm-before-save buffers every time you call compile is nearly as outrageous as having no key bound to compile in the first place. This snippet takes care of both and, as a bonus, makes the compilation window follow a predetermined size and ensures that point will follow the output.

;; This gives a regular `compile-command' prompt.
(define-key prog-mode-map [C-f9] #'compile)
;; This just compiles immediately.
(define-key prog-mode-map [f9]

;; I'm not scared of saving everything.
(setq compilation-ask-about-save nil)
;; Stop on the first error.
(setq compilation-scroll-output 'next-error)
;; Don't stop on info or warnings.
(setq compilation-skip-threshold 2)

(defcustom endless/compile-window-size 105
  "Width given to the non-compilation window."
  :type 'integer
  :group 'endless)

(defun endless/compile-please (comint)
  "Compile without confirmation.
With a prefix argument, use comint-mode."
  (interactive "P")
  ;; Do the command without a prompt.
    (compile (eval compile-command) (and comint t)))
  ;; Create a compile window of the desired width.
  (pop-to-buffer (get-buffer "*compilation*"))
   (- (frame-width)

Update 16 Jun 2015

Thanks to Clément and abo-abo for the variable suggestions, which also led me to find the compilation-skip-threshold variable. Warnings are important to fix, but in some languages it’s common to have warnings you can’t fix, so it’s nice for the compilation buffer to not stop scrolling on them.

Update 17 Jun 2016

The command now propagates the prefix argument to the compile function, so that you can start the buffer in comint-mode. See the update on this post for more information.

Say thanks on Gratipay
comments powered by Disqus