diff --git a/Changelog.org b/Changelog.org index e3d1170..40ca09a 100644 --- a/Changelog.org +++ b/Changelog.org @@ -5,6 +5,7 @@ - Add ~justl-include-private-recipes~ to show private recipes in the list (defaults to on). - Rewritten internals, using ~just~ itself to parse recipe information. +- Add ~justl-per-recipe-buffer~ to create new buffers per recipe. * 0.13 diff --git a/README.org b/README.org index b5ba00c..4c3d594 100644 --- a/README.org +++ b/README.org @@ -60,6 +60,10 @@ M-x justl-exec-recipe-in-dir To execute default recipe, call *justl-exec-default-recipe* +To execute multiple recipes in parallel, customize *justl-per-recipe-buffer* to +create dedicated buffers named /*just-RECIPE*/. This is useful to manage long +running process. + * Shortcuts On the just screen, place your cursor on a recipe: diff --git a/justl.el b/justl.el index dde097e..a762d96 100644 --- a/justl.el +++ b/justl.el @@ -109,6 +109,17 @@ other cases, it's a known path." :type 'boolean :safe 'booleanp) +(defcustom justl-per-recipe-buffer nil + "If non-nil, create a new buffer per recipe." + :type 'boolean + :safe 'booleanp) + +(defun justl--recipe-output-buffer (recipe-name) + "Return the buffer name for the RECIPE-NAME." + (if justl-per-recipe-buffer + (format "*just-%s*" recipe-name) + justl--output-process-buffer)) + (defun justl--process-error-buffer (process-name) "Return the error buffer name for the PROCESS-NAME." (format "*%s:err*" process-name)) @@ -167,12 +178,14 @@ CMD is the just command as a list." (justl--append-to-process-buffer (format "[%s] \ncommand: %S" process-name cmd)))) -(defun justl--sentinel (process _) - "Sentinel function for PROCESS." +(defun justl--sentinel (process buffer) + "Sentinel function for PROCESS. + +BUFFER is the name of the output buffer." (let ((process-name (process-name process)) (inhibit-read-only t) (exit-status (process-exit-status process))) - (with-current-buffer (get-buffer justl--output-process-buffer) + (with-current-buffer buffer (goto-char (point-max)) (if (zerop exit-status) (insert (format "\nTarget execution finished at %s" (substring (current-time-string) 0 19))) @@ -230,14 +243,12 @@ ARGS is a plist that affects how the process is run. - `:buffer' name for process buffer - `:process' name for compilation process - `:mode' mode for process buffer -- `:directory' set `default-directory' -- `:sentinel' process sentinel" +- `:directory' set `default-directory'" (let* ((buf (get-buffer-create (or (plist-get args :buffer) justl--output-process-buffer))) (process-name (or (plist-get args :process) justl--compilation-process-name)) (mode (or (plist-get args :mode) 'justl-compile-mode)) (directory (or (plist-get args :directory) (f-dirname justl-justfile))) - (sentinel (or (plist-get args :sentinel) #'justl--sentinel)) (inhibit-read-only t)) (setq next-error-last-buffer buf) (justl-compilation-setup-buffer buf directory mode) @@ -249,7 +260,7 @@ ARGS is a plist that affects how the process is run. (setq-local justl-justfile (justl--justfile-from-arg (elt command 1))) (run-hook-with-args 'compilation-start-hook process) (set-process-filter process 'justl--process-filter) - (set-process-sentinel process sentinel) + (set-process-sentinel process (lambda (proc _) (justl--sentinel proc buf))) (set-process-coding-system process 'utf-8-emacs-unix 'utf-8-emacs-unix) (pop-to-buffer buf))))) @@ -295,14 +306,15 @@ Error matching regexes from compile.el are removed." (setq-local overlay-arrow-string "") (setq next-error-overlay-arrow-position nil)) -(defun justl--exec (process-name args) +(defun justl--exec (process-name recipe-name args) "Utility function to run commands in the proper setting. PROCESS-NAME is an identifier for the process. Default to \"just\". +RECIPE-NAME is the name of the recipe. ARGS is a ist of arguments." (when (equal process-name "") (setq process-name justl-executable)) - (let ((buffer-name justl--output-process-buffer) + (let ((buffer-name (justl--recipe-output-buffer recipe-name)) (error-buffer (justl--process-error-buffer process-name)) (cmd (append (list justl-executable (justl--justfile-argument)) args)) (mode 'justl-compile-mode)) @@ -542,6 +554,7 @@ not executed." (let* ((recipe (justl--get-recipe-under-cursor))) (justl--exec justl-executable + (justl--recipe-name recipe) (append (transient-args 'justl-help-popup) (cons (justl--recipe-name recipe) (mapcar 'justl--read-arg @@ -557,6 +570,7 @@ not executed." recipe-name)))) (justl--exec justl-executable + recipe-name (append (transient-args 'justl-help-popup) (cons recipe-name diff --git a/test/justl-test.el b/test/justl-test.el index 7b45863..115403a 100644 --- a/test/justl-test.el +++ b/test/justl-test.el @@ -45,36 +45,36 @@ (with-current-buffer (justl--buffer-name) (search-forward "plan") (justl-exec-recipe) - (justl--wait-till-exit justl--output-process-buffer)) - (with-current-buffer justl--output-process-buffer + (justl--wait-till-exit (justl--recipe-output-buffer "plan"))) + (with-current-buffer (justl--recipe-output-buffer "plan") (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "planner" buf-string)))) (kill-buffer (justl--buffer-name)) - (kill-buffer justl--output-process-buffer)) + (kill-buffer (justl--recipe-output-buffer "plan"))) (ert-deftest justl--execute-test-exit-status () (justl) (with-current-buffer (justl--buffer-name) (search-forward "plan") (justl-exec-recipe) - (justl--wait-till-exit justl--output-process-buffer)) - (with-current-buffer justl--output-process-buffer + (justl--wait-till-exit (justl--recipe-output-buffer "plan"))) + (with-current-buffer (justl--recipe-output-buffer "plan") (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "Target execution finished" buf-string)))) (kill-buffer (justl--buffer-name)) - (kill-buffer justl--output-process-buffer)) + (kill-buffer (justl--recipe-output-buffer "plan"))) (ert-deftest justl--fail-recipe () (justl) (with-current-buffer (justl--buffer-name) (search-forward "fail") (justl-exec-recipe) - (justl--wait-till-exit justl--output-process-buffer)) - (with-current-buffer justl--output-process-buffer + (justl--wait-till-exit (justl--recipe-output-buffer "fail")) + (with-current-buffer (justl--recipe-output-buffer "fail") (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "exited abnormally" buf-string)))) (kill-buffer (justl--buffer-name)) - (kill-buffer justl--output-process-buffer)) + (kill-buffer (justl--recipe-output-buffer "fail")))) (ert-deftest justl--find-justfile-check () (should (equal (f-filename (justl--find-justfile default-directory)) "justfile"))) @@ -85,13 +85,13 @@ (with-current-buffer (justl--buffer-name) (search-forward "carriage-return") (justl-exec-recipe) - (justl--wait-till-exit justl--output-process-buffer)) - (with-current-buffer justl--output-process-buffer + (justl--wait-till-exit (justl--recipe-output-buffer "carriage-return"))) + (with-current-buffer (justl--recipe-output-buffer "carriage-return") (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "DONE\n" buf-string)) (should-not (s-contains? "1/3\r2/3\r3/3\rDONE\n" buf-string)))) (kill-buffer (justl--buffer-name)) - (kill-buffer justl--output-process-buffer)) + (kill-buffer (justl--recipe-output-buffer "carriage-return"))) (ert-deftest justl--execute-recipe-with-color () "A target printing color is handled properly." @@ -99,12 +99,12 @@ (with-current-buffer (justl--buffer-name) (search-forward "color") (justl-exec-recipe) - (justl--wait-till-exit justl--output-process-buffer)) - (with-current-buffer justl--output-process-buffer + (justl--wait-till-exit (justl--recipe-output-buffer "color"))) + (with-current-buffer (justl--recipe-output-buffer "color") (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "This is red text\n" buf-string)))) (kill-buffer (justl--buffer-name)) - (kill-buffer justl--output-process-buffer)) + (kill-buffer (justl--recipe-output-buffer "color"))) (ert-deftest justl--execute-default-recipe () "Checks that default recipe is printed." @@ -142,6 +142,22 @@ (should (s-contains? "ver1" buf-string)))) (kill-buffer justl--output-process-buffer)) +(ert-deftest justl--test-per-recipe-buffer () + "This test is a copy of 'justl--execute-recipe' setting the per-recipe and hardcoding the desired buffer name." + (let ((current justl-per-recipe-buffer)) + (customize-set-variable 'justl-per-recipe-buffer 't) + (justl) + (with-current-buffer (justl--buffer-name) + (search-forward "plan") + (justl-exec-recipe) + (justl--wait-till-exit "*just-plan*")) + (with-current-buffer "*just-plan*" + (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) + (should (s-contains? "Target execution finished" buf-string)))) + (kill-buffer (justl--buffer-name)) + (kill-buffer "*just-plan*") + (customize-set-variable 'justl-per-recipe-buffer current))) + ;; (ert "justl--**") (provide 'justl-test)