From 8fe07c5e54082b4b3a606ca25166788391683346 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Tue, 8 Aug 2023 19:12:08 +0530 Subject: [PATCH 1/8] Tramp support --- justl.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/justl.el b/justl.el index 236d5fd..d1f8770 100644 --- a/justl.el +++ b/justl.el @@ -407,7 +407,7 @@ Error matching regexes from compile.el are removed." (setq next-error-overlay-arrow-position nil)) (defun justl--exec (process-name args) - "Utility function to run commands in the proper context and namespace. + "Utility function to run commands in the proper setting. PROCESS-NAME is an identifier for the process. Default to \"just\". ARGS is a ist of arguments." @@ -427,7 +427,7 @@ ARGS is a ist of arguments." :mode mode)))) (defun justl--exec-without-justfile (process-name args) - "Utility function to run commands in the proper context and namespace. + "Utility function to run commands in the proper setting. PROCESS-NAME is an identifier for the process. Default to \"just\". ARGS is a ist of arguments." @@ -462,7 +462,7 @@ CMD is the command string to run. Returns a list with status code and output of process." (justl--log-command "just-command" cmd) (with-temp-buffer - (let ((justl-status (call-process-shell-command cmd nil t)) + (let ((justl-status (process-file-shell-command cmd nil t)) (buf-string (buffer-substring-no-properties (point-min) (point-max)))) (list justl-status buf-string)))) @@ -475,7 +475,7 @@ and output of process." (defun justl--justfile-argument () "Provides justfile argument with the proper location." - (format "--justfile=%s" justl-justfile)) + (format "--justfile=%s" (tramp-file-local-name justl-justfile))) (defun justl--justfile-from-arg (arg) "Return justfile filepath from ARG." @@ -486,10 +486,10 @@ and output of process." "Return all the recipies in JUSTFILE with description." (let* ((t-args (transient-args 'justl-help-popup)) (recipe-status (justl--exec-to-string-with-exit-code - (format "%s %s --justfile=%s --list --unsorted" + (format "%s %s --justfile=%s --list --unsorted --color=never" justl-executable (string-join t-args " ") - justfile))) + (tramp-file-local-name justfile)))) (justl-status (nth 0 recipe-status)) (recipe-lines (split-string (nth 1 recipe-status) @@ -745,7 +745,7 @@ tweaked further by the user." (buffer-disable-undo) (setq truncate-lines t) (let* ((justfiles (justl--find-justfiles default-directory)) - (entries (justl--get-recipies-with-desc justfiles))) + (entries (justl--get-recipies-with-desc justfiles))) (if (or (null justfiles) (not (eq justl--list-command-exit-code 0)) ) (progn (when (null justfiles) From d582a06f8b5b430c5bae3a2d3371e491e3b11d1d Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Wed, 9 Aug 2023 08:45:05 +0530 Subject: [PATCH 2/8] Fix minor bugs related to tramp's interactive function --- justl.el | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/justl.el b/justl.el index d1f8770..8cd0be2 100644 --- a/justl.el +++ b/justl.el @@ -466,11 +466,11 @@ and output of process." (buf-string (buffer-substring-no-properties (point-min) (point-max)))) (list justl-status buf-string)))) -(defun justl--get-recipies () - "Return all the recipies." +(defun justl--get-recipies (justfile) + "Return all the recipies from JUSTFILE." (let ((recipies (split-string (justl--exec-to-string - (format "%s --summary --unsorted" - justl-executable))))) + (format "%s --justfile=%s --summary --unsorted --color=never" + justl-executable (tramp-file-local-name justfile)))))) (mapcar #'string-trim-right recipies))) (defun justl--justfile-argument () @@ -501,11 +501,6 @@ and output of process." (mapcar (lambda (x) (list (justl--get-recipe-name (nth 0 x)) (nth 1 x))) recipes) nil))) -(defun justl--get-jrecipies () - "Return list of JRECIPE." - (let ((recipies (justl--get-recipies))) - (mapcar #'make-justl-jrecipe recipies))) - (defun justl--list-to-jrecipe (list) "Convert a single LIST of two elements to list of JRECIPE." (make-justl-jrecipe :name (nth 0 list) :args (nth 1 list))) @@ -513,19 +508,22 @@ and output of process." (defun justl-exec-recipe-in-dir () "Populate and execute the selected recipe." (interactive) - (let* ((recipe (completing-read "Recipies: " (justl--get-recipies) - nil nil nil nil "default")) - (justl-recipe (justl--get-recipe-from-file justl-justfile recipe)) - (recipe-has-args (justl--jrecipe-has-args-p justl-recipe))) - (if recipe-has-args - (let* ((cmd-args (justl-jrecipe-args justl-recipe)) - (user-args (mapcar (lambda (arg) (read-from-minibuffer - (format "Just arg for %s:" (justl-jarg-arg arg)) - (justl--util-maybe (justl-jarg-default arg) ""))) - cmd-args))) - (justl--exec-without-justfile justl-executable - (cons (justl-jrecipe-name justl-recipe) user-args))) - (justl--exec-without-justfile justl-executable (list recipe))))) + (let* ((justfile (justl--find-justfiles default-directory))) + (if (not justfile) + (error "No justfiles found")) + (let* ((recipe (completing-read "Recipies: " (justl--get-recipies justfile) + nil nil nil nil "default")) + (justl-recipe (justl--get-recipe-from-file justfile recipe)) + (recipe-has-args (justl--jrecipe-has-args-p justl-recipe))) + (if recipe-has-args + (let* ((cmd-args (justl-jrecipe-args justl-recipe)) + (user-args (mapcar (lambda (arg) (read-from-minibuffer + (format "Just arg for %s:" (justl-jarg-arg arg)) + (justl--util-maybe (justl-jarg-default arg) ""))) + cmd-args))) + (justl--exec-without-justfile justl-executable + (cons (justl-jrecipe-name justl-recipe) user-args))) + (justl--exec-without-justfile justl-executable (list recipe)))))) (defun justl-exec-default-recipe () "Execute default recipe." From f25f421e2941140a4ebf449de283466810371923 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Wed, 9 Aug 2023 10:59:59 +0530 Subject: [PATCH 3/8] Fix traversing bug related to justfiles --- justl.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/justl.el b/justl.el index 8cd0be2..fa9654a 100644 --- a/justl.el +++ b/justl.el @@ -207,7 +207,7 @@ was found." dir))) (if justfiles (car justfiles) - (let ((justfile-paths (directory-files-recursively dir "justfile"))) + (let ((justfile-paths (directory-files-recursively dir justl--justfile-regex))) (if justfile-paths (car justfile-paths) nil))))) @@ -734,6 +734,9 @@ tweaked further by the user." (defun justl () "Invoke the justl buffer." (interactive) + (let ((justfile (justl--find-justfiles default-directory))) + (when (null justfile) + (error "No justfiles found"))) (justl--save-line) (justl--pop-to-buffer (justl--buffer-name)) (justl-mode)) @@ -743,7 +746,7 @@ tweaked further by the user." (buffer-disable-undo) (setq truncate-lines t) (let* ((justfiles (justl--find-justfiles default-directory)) - (entries (justl--get-recipies-with-desc justfiles))) + (entries (justl--get-recipies-with-desc justfiles))) (if (or (null justfiles) (not (eq justl--list-command-exit-code 0)) ) (progn (when (null justfiles) From 5cb37c2b05761810563a29a0c8317049f98155e6 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Wed, 9 Aug 2023 11:26:40 +0530 Subject: [PATCH 4/8] Update changelog and add Dockerfile --- Changelog.org | 7 ++++++- test/Dockerfile | 11 +++++++++++ test/README.org | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/Dockerfile create mode 100644 test/README.org diff --git a/Changelog.org b/Changelog.org index 15886fc..49e40ac 100644 --- a/Changelog.org +++ b/Changelog.org @@ -1,7 +1,12 @@ * Unreleased -- justl-exec-recipe-in-dir prompts for arguments when needed. Fixes +- TRAMP support +- ~justl-exec-recipe-in-dir~ prompts for arguments when needed. Fixes [[https://github.com/psibi/justl.el/issues/30][issue 30]]. +- Fix directory traversing when searching for justfiles. +- Improve error handling when a justfile is not found on different + cases. +- Add documentation on how to test it with TRAMP and docker. * 0.12 diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..79b9e3b --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,11 @@ +FROM fpco/pid1:22.04 + +RUN apt update -y && apt install -y curl + +RUN curl -sL https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz | tar xz && mv just /usr/local/bin/just + +RUN mkdir /home/sibi + +WORKDIR /home/sibi + +COPY justfile /home/sibi/justfile diff --git a/test/README.org b/test/README.org new file mode 100644 index 0000000..7444e16 --- /dev/null +++ b/test/README.org @@ -0,0 +1,26 @@ +* Testing tramp + +- Create a local docker image + +#+begin_src sh +docker image build . -f Dockerfile -t just-test +#+end_src + +- Run the container: + +#+begin_src sh +docker run -it just-test bash +#+end_src + +- Now do the followin in emacs: + +#+begin_src sh +M-x docker-container +#+end_src + +Go to the container that is running and get shell access. Once you get +shell access, run the usual justl commands there: + +#+begin_src +justl-exec-recipe-in-dir +#+end_src From 6d4e3764d9f1bfca7a242565cca1010fc8741dab Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Wed, 9 Aug 2023 11:27:47 +0530 Subject: [PATCH 5/8] Update README --- README.org | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 964ab4f..b5ba00c 100644 --- a/README.org +++ b/README.org @@ -5,7 +5,8 @@ justl.el mode is a major mode for driving [[https://github.com/casey/just][justfiles]]. As compared to the [[https://melpa.org/#/just-mode][just-mode]], this mode is built for listing and executing the -recipes in the justfile via the [[https://magit.vc/manual/transient][transient]] keymaps. +recipes in the justfile via the [[https://magit.vc/manual/transient][transient]] keymaps. Also works with +[[https://www.gnu.org/software/tramp/][TRAMP]]. [[https://user-images.githubusercontent.com/737477/132949123-87387b7e-8f7d-45de-ac32-8815d9c1dc5d.png]] From 544968a3eb5a27a238a5c0fed2f7b4525e31664d Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Wed, 9 Aug 2023 11:32:58 +0530 Subject: [PATCH 6/8] Bump minimum version to emacs 27.1 --- Changelog.org | 1 + justl.el | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog.org b/Changelog.org index 49e40ac..550cf3a 100644 --- a/Changelog.org +++ b/Changelog.org @@ -7,6 +7,7 @@ - Improve error handling when a justfile is not found on different cases. - Add documentation on how to test it with TRAMP and docker. +- Update CI to support Emacs 29.1 * 0.12 diff --git a/justl.el b/justl.el index fa9654a..ef9d561 100644 --- a/justl.el +++ b/justl.el @@ -24,7 +24,7 @@ ;; Keywords: just justfile tools processes ;; URL: https://github.com/psibi/justl.el ;; License: GNU General Public License >= 3 -;; Package-Requires: ((transient "0.1.0") (emacs "25.3") (s "1.2.0") (f "0.20.0")) +;; Package-Requires: ((transient "0.1.0") (emacs "27.1") (s "1.2.0") (f "0.20.0")) ;;; Commentary: From 2ad581c88c8622ec8f2017b7f265a9b22f18900f Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Wed, 9 Aug 2023 11:39:38 +0530 Subject: [PATCH 7/8] Update tests --- justl.el | 1 + test/justl-test.el | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/justl.el b/justl.el index ef9d561..34414a7 100644 --- a/justl.el +++ b/justl.el @@ -76,6 +76,7 @@ (require 'compile) (require 'comint) (require 'subr-x) +(require 'tramp) (defgroup justl nil "Justfile customization group." diff --git a/test/justl-test.el b/test/justl-test.el index 589d779..2577adf 100644 --- a/test/justl-test.el +++ b/test/justl-test.el @@ -12,7 +12,7 @@ (should (equal (list "default" "build-cmd" "plan" "push" "push2" "fail" "carriage-return" "color") - (justl--get-recipies)))) + (justl--get-recipies "./justfile")))) (ert-deftest justl--list-to-recipe-test () (should (equal @@ -257,7 +257,8 @@ (justl--wait-till-exit justl--output-process-buffer) (with-current-buffer justl--output-process-buffer (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) - (should (s-contains? "planner" buf-string))))) + (should (s-contains? "planner" buf-string)))) + (kill-buffer justl--output-process-buffer)) (ert-deftest justl--execute-interactive-recipe-failure () "Checks justl-exec-recipe-in-dir indrectly (failure case)." @@ -265,7 +266,8 @@ (justl--wait-till-exit justl--output-process-buffer) (with-current-buffer justl--output-process-buffer (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) - (should (s-contains? "exited abnormally" buf-string))))) + (should (s-contains? "exited abnormally" buf-string)))) + (kill-buffer justl--output-process-buffer)) (ert-deftest justl--execute-interactive-recipe-multiple-args () "Checks justl-exec-recipe-in-dir indrectly (failure case)." @@ -273,9 +275,10 @@ (justl--wait-till-exit justl--output-process-buffer) (with-current-buffer justl--output-process-buffer (let ((buf-string (buffer-substring-no-properties (point-min) (point-max)))) - (should (s-contains? "ver1" buf-string))))) + (should (s-contains? "ver1" buf-string)))) + (kill-buffer justl--output-process-buffer)) -;; (ert "justl--**") +(ert "justl--**") (provide 'justl-test) ;;; justl-test.el ends here From 067e5cd4cbafc86c89afbe279cfba3c68ee23317 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Wed, 9 Aug 2023 21:25:29 +0530 Subject: [PATCH 8/8] Comment justl--** --- 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 2577adf..373ba9f 100644 --- a/test/justl-test.el +++ b/test/justl-test.el @@ -278,7 +278,7 @@ (should (s-contains? "ver1" buf-string)))) (kill-buffer justl--output-process-buffer)) -(ert "justl--**") +;; (ert "justl--**") (provide 'justl-test) ;;; justl-test.el ends here