From 52ce13175678961693e1f071e4d993116f1eb03b Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Fri, 15 Nov 2024 13:14:10 +0530 Subject: [PATCH 1/4] justl: Ability to set new working directory --- justl.el | 10 +++++++++- test/justfile | 5 +++++ test/justl-test.el | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/justl.el b/justl.el index 40b12b2..92f38c9 100644 --- a/justl.el +++ b/justl.el @@ -272,7 +272,8 @@ ARGS is a plist that affects how the process is run. (justl-compilation-setup-buffer buf directory mode) (with-current-buffer buf (insert (format "Just target execution started at %s \n\n" (substring (current-time-string) 0 19))) - (let* ((process (apply + (let* ((default-directory directory) + (process (apply #'start-file-process process-name buf command))) (setq justl--compile-command command) (setq-local justl-justfile (justl--justfile-from-arg (elt command 1))) @@ -290,6 +291,12 @@ ARGS is a plist that affects how the process is run. map) "Keymap for justl compilation log buffers.") +(defun justl-set-new-working-dir (dir) + "Set DIR as the new working directory. +This is usually used with no-cd recipe attribute." + (interactive "DNew Working Directory:") + (setq default-directory dir)) + (defun justl-recompile () "Execute the same just target again." (interactive) @@ -358,6 +365,7 @@ ARGS is a list of arguments." (justl--log-command process-name cmd) (justl--make-process cmd (list :buffer buffer-name :process process-name + :directory default-directory :mode mode)))) (defun justl--exec-without-justfile (process-name args) diff --git a/test/justfile b/test/justfile index 4574e74..37f8170 100644 --- a/test/justfile +++ b/test/justfile @@ -35,6 +35,11 @@ color: #!/usr/bin/env bash printf "\x1B[31mThis is red text\n" +# Some recipe +[no-cd] +recipe: + pwd + # private recipe _private: echo private diff --git a/test/justl-test.el b/test/justl-test.el index c132435..cd77d83 100644 --- a/test/justl-test.el +++ b/test/justl-test.el @@ -10,7 +10,7 @@ (ert-deftest justl--get-recipes-test () (should (equal - (list "default" "build-cmd" "plan" "push" "push2" "fail" "carriage-return" "color") + (list "default" "build-cmd" "plan" "push" "push2" "fail" "carriage-return" "color" "recipe") (mapcar 'justl--recipe-name (justl--get-recipes "./justfile"))))) (ert-deftest justl--finds-recipe-test () @@ -176,6 +176,20 @@ (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "_private" buf-string))))) +(ert-deftest justl--change-working-directory () + (justl) + (with-current-buffer (justl--buffer-name) + (search-forward "recipe") + (justl-exec-recipe) + (justl--wait-till-exit "*just-recipe*")) + (with-current-buffer "*just-recipe*" + (let ((content1 (buffer-substring-no-properties (point-min) (point-max)))) + (justl-set-new-working-dir "/tmp") + (justl-exec-recipe) + (justl--wait-till-exit "*just-recipe*") + (let ((content2 (buffer-substring-no-properties (point-min) (point-max)))) + (should (string-equal content1 content2)))))) + ; ;; (ert "justl--**") (provide 'justl-test) From 2da718343d5765e663dc99cc991e25810f46964f Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Fri, 15 Nov 2024 13:16:22 +0530 Subject: [PATCH 2/4] Remove test --- test/justl-test.el | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/justl-test.el b/test/justl-test.el index cd77d83..9a007ce 100644 --- a/test/justl-test.el +++ b/test/justl-test.el @@ -175,20 +175,6 @@ (with-current-buffer (justl--buffer-name) (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "_private" buf-string))))) - -(ert-deftest justl--change-working-directory () - (justl) - (with-current-buffer (justl--buffer-name) - (search-forward "recipe") - (justl-exec-recipe) - (justl--wait-till-exit "*just-recipe*")) - (with-current-buffer "*just-recipe*" - (let ((content1 (buffer-substring-no-properties (point-min) (point-max)))) - (justl-set-new-working-dir "/tmp") - (justl-exec-recipe) - (justl--wait-till-exit "*just-recipe*") - (let ((content2 (buffer-substring-no-properties (point-min) (point-max)))) - (should (string-equal content1 content2)))))) ; ;; (ert "justl--**") From b5d312318a234764b31ec225fbd4f2a8624b21f3 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Fri, 15 Nov 2024 13:19:04 +0530 Subject: [PATCH 3/4] Cleanup --- test/justl-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/justl-test.el b/test/justl-test.el index 9a007ce..382b01f 100644 --- a/test/justl-test.el +++ b/test/justl-test.el @@ -175,7 +175,7 @@ (with-current-buffer (justl--buffer-name) (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) (should (s-contains? "_private" buf-string))))) - ; + ;; (ert "justl--**") (provide 'justl-test) From 171974ec7596ac7a074379ccee79f590d2438889 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sat, 16 Nov 2024 10:38:00 +0530 Subject: [PATCH 4/4] Use setq-local --- justl.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justl.el b/justl.el index 92f38c9..3d0f816 100644 --- a/justl.el +++ b/justl.el @@ -295,7 +295,7 @@ ARGS is a plist that affects how the process is run. "Set DIR as the new working directory. This is usually used with no-cd recipe attribute." (interactive "DNew Working Directory:") - (setq default-directory dir)) + (setq-local default-directory dir)) (defun justl-recompile () "Execute the same just target again."