[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode a2a1b1d 208/217: compile mode with sbt thin cli
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode a2a1b1d 208/217: compile mode with sbt thin client |
Date: |
Sun, 29 Aug 2021 11:31:14 -0400 (EDT) |
branch: elpa/scala-mode
commit a2a1b1d960d088a852e73026ff541435f4207378
Author: Sam Halliday <sam.halliday@gmail.com>
Commit: Sam Halliday <sam.halliday@gmail.com>
compile mode with sbt thin client
---
scala-compile.el | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
diff --git a/scala-compile.el b/scala-compile.el
new file mode 100644
index 0000000..96bdaa8
--- /dev/null
+++ b/scala-compile.el
@@ -0,0 +1,120 @@
+;;; scala-compile.el --- batch compile scala -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020 Sam Halliday
+;; License: GPL 3 or any later version
+
+;;; Commentary:
+;;
+;; An idiomatic `compilation-mode' batch compilation command that detects
+;; warnings and errors, extracting line numbers, columns and ranges.
+;;
+;; Relies on a batch tool, such as the sbt thin client (`sbt --client`) which
+;; can be compiled to native binary (`sbtn`) from their repo with `sbt
+;; buildNativeThinClient` or mystery meat binaries downloaded from
+;; https://github.com/sbt/sbtn-dist/releases/
+;;
+;;; Code:
+
+(require 'compile)
+(require 'ansi-color)
+(require 'files)
+(require 'subr-x)
+
+(defcustom scala-compile-always-ask t
+ "`scala-compile' will always ask for confirmation before running a command
unless: the universal argument is provided or it is called with a string
argument or if this is set to nil (in which case the last command used in the
buffer is used). To change the command, the user must provide a prefix
argument."
+ :type 'booleanp
+ :group 'scala)
+
+(defcustom scala-compile-suggestion nil
+ "Files can specify a suggested command to run, e.g. runMain and testOnly."
+ :type 'stringp
+ :group 'scala
+ :safe 'stringp
+ :local t)
+
+(defcustom scala-compile-alt "sbtn clean && sbtn reload"
+ "`scala-compile' uses this command when called with the `-' prefix."
+ :type 'stringp
+ :group 'scala)
+
+(defvar scala-compilation-error-regexp-alist
+ '(;; Sbt 1.0.x
+
("^\\[error][[:space:]]\\([/[:word:]]:?[^:[:space:]]+\\):\\([[:digit:]]+\\):\\([[:digit:]]+\\):"
1 2 3 2 1)
+ ;; Sbt 0.13.x
+
("^\\[error][[:space:]]\\([/[:word:]]:?[^:[:space:]]+\\):\\([[:digit:]]+\\):" 1
2 nil 2 1)
+ ;; https://github.com/Duhemm/sbt-errors-summary
+
("^\\[error][[:space:]]\\[E[[:digit:]]+][[:space:]]\\([/[:word:]]:?[^:[:space:]]+\\):\\([[:digit:]]+\\):\\([[:digit:]]+\\):$"
1 2 3 2 1)
+
("^\\[warn][[:space:]]+\\[E[[:digit:]]+][[:space:]]\\([/[:word:]]:?[^:[:space:]]+\\):\\([[:digit:]]+\\):\\([[:digit:]]+\\):$"
1 2 3 1 1)
+
("^\\[warn][[:space:]]\\([/[:word:]]:?[^:[:space:]]+\\):\\([[:digit:]]+\\):" 1
2 nil 1 1)
+
("^\\[info][[:space:]]\\([/[:word:]]:?[^:[:space:]]+\\):\\([[:digit:]]+\\):" 1
2 nil 0 1)
+ ;; failing scalatests
+ ("^\\[info][[:space:]]+\\(.*\\) (\\([^:[:space:]]+\\):\\([[:digit:]]+\\))"
2 3 nil 2 1)
+
("^\\[warn][[:space:]][[:space:]]\\[[[:digit:]]+][[:space:]]\\([/[:word:]]:?[^:[:space:]]+\\):\\([[:digit:]]+\\):\\([[:digit:]]+\\):"
1 2 3 1 1)
+ )
+ "The `compilation-error-regexp-alist' for `scala'.")
+
+(defvar scala--compile-history
+ '("sbtn compile"
+ "sbtn test"
+ "sbtn testOnly "))
+
+(defvar-local scala--compile-command nil)
+(defvar scala--compile-project "build.sbt")
+
+;;;###autoload
+(defun scala-compile (&optional edit-command)
+ "`compile' specialised to Scala.
+
+First use in a buffer or calling with a prefix will prompt for a
+command, otherwise the last command is used.
+
+The command history is global.
+
+A universal argument will invoke `scala-compile-alt', which
+will cause the subsequent call to prompt.
+
+A prefix argument will ensure that the user is prompted to
+confirm the selection.
+
+A string argument will run the command (for scripting)."
+ (interactive "P")
+ (save-some-buffers (not compilation-ask-about-save)
+ compilation-save-buffers-predicate)
+
+ (when scala-compile-suggestion
+ (add-to-list 'scala--compile-history scala-compile-suggestion))
+
+ (let* ((last scala--compile-command)
+ (command (pcase edit-command
+ ((and 'nil (guard last)) last)
+ ('- scala-compile-alt)
+ ((pred stringp) edit-command)
+ (_ (read-shell-command
+ "Compile command: "
+ (or last (car scala--compile-history))
+ '(scala--compile-history . 1))))))
+ (setq scala--compile-command
+ (unless (or
+ scala-compile-always-ask
+ (equal command scala-compile-alt))
+ command))
+ (let ((default-directory
+ (or
+ (locate-dominating-file default-directory scala--compile-project)
+ default-directory)))
+ (compilation-start
+ command
+ 'scala-compilation-mode
+ (lambda (_)
+ (concat "*scala-compilation-" (file-name-nondirectory
(directory-file-name default-directory)) "*"))
+ ))))
+
+(defun scala--compile-ansi-color ()
+ (ansi-color-apply-on-region compilation-filter-start (point-max)))
+
+(define-compilation-mode scala-compilation-mode "scala-compilation"
+ (add-hook 'compilation-filter-hook
+ #'scala--compile-ansi-color nil t))
+
+(provide 'scala-compile)
+;;; scala-compile.el ends here
- [nongnu] elpa/scala-mode 461f9a5 134/217: Fix issue #63 and names with _ and reserved word, (continued)
- [nongnu] elpa/scala-mode 461f9a5 134/217: Fix issue #63 and names with _ and reserved word, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode ababc73 151/217: remove interactive, update filename., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 27efa44 019/217: updated README, added LICENSE, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode d6f8cee 135/217: scala 2.10 preamble, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 03cfbe4 148/217: Add types to index items., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode ed645d2 153/217: move create index function for imenu to big setq with everything else., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 618f0fb 163/217: remove 'scala-indent:indent-on-parentheses in preference of smartparens, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 56cba29 194/217: Fix bad syntax when `*/` is prefixed by an opcode. (#143), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode a1ff6f3 202/217: feat: add Scala 3 keywords, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 46bb948 198/217: Fix #155, remove ob-scala.el, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode a2a1b1d 208/217: compile mode with sbt thin client,
ELPA Syncer <=
- [nongnu] elpa/scala-mode 54fa36f 200/217: Merge pull request #159 from kpbochenek/fix-files-association-alist, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 5058a85 204/217: doc: clarify Scala versions supported, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 0c5ed9e 022/217: deleted example files, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 61a511f 021/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode fe5c2c4 031/217: Fixes #11: was still using the slow regexp, not faster, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 1a3d958 029/217: forward/backward-sexp, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode e30b35a 008/217: Indentation working, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 59cdd94 074/217: Add `scala-indent:use-javadoc-style` defcustom., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 347faeb 075/217: Add Evan Meagher to contributors list., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 081a92b 081/217: scala-indent:remove-indent-from-previous-empty-line, ELPA Syncer, 2021/08/29