compile.el 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ;; https://endlessparentheses.com/restarting-the-compilation-buffer-in-comint-mode.html
  2. ;; https://endlessparentheses.com/better-compile-command.html
  3. ;; https://endlessparentheses.com/provide-input-to-the-compilation-buffer.html
  4. ;; Stop on the first error.
  5. (setq compilation-scroll-output 'first-error)
  6. ;; I'm not scared of saving everything.
  7. (setq compilation-ask-about-save nil)
  8. ;; Don't stop on info or warnings.
  9. (setq compilation-skip-threshold 2)
  10. (defcustom endless/compile-window-size 105
  11. "Width given to the non-compilation window."
  12. :type 'integer
  13. :group 'endless)
  14. (defun endless/compile-please (comint)
  15. "Compile without confirmation.
  16. With a prefix argument, use comint-mode.
  17. Now I can actually interact with this REPL via C-c i or just
  18. quickly get rid of it with C-d. If you run into the same
  19. situation, you should also set the following option in your
  20. .pryrc file."
  21. (interactive "P")
  22. ;; Do the command without a prompt.
  23. (save-window-excursion
  24. (compile (eval compile-command) (and comint t)))
  25. ;; Create a compile window of the desired width.
  26. (pop-to-buffer (get-buffer "*compilation*"))
  27. (enlarge-window
  28. (- (frame-width)
  29. endless/compile-window-size
  30. (window-width))
  31. 'horizontal))
  32. (defun endless/toggle-comint-compilation ()
  33. "Restart compilation with (or without) `comint-mode'."
  34. (interactive)
  35. (cl-callf (lambda (mode) (if (eq mode t) nil t))
  36. (elt compilation-arguments 1))
  37. (recompile))
  38. (with-eval-after-load 'compile
  39. (define-key compilation-mode-map (kbd "C-c i")
  40. #'endless/toggle-comint-compilation)
  41. (define-key compilation-minor-mode-map (kbd "C-c i")
  42. #'endless/toggle-comint-compilation)
  43. (define-key compilation-shell-minor-mode-map (kbd "C-c i")
  44. #'endless/toggle-comint-compilation))
  45. ;;;
  46. ;;; Colorize
  47. ;;;
  48. (setq compilation-environment '("TERM=xterm-256color"))
  49. (defun my/advice-compilation-filter (f proc string)
  50. (funcall f proc (xterm-color-filter string)))
  51. (advice-add 'compilation-filter :around #'my/advice-compilation-filter)