From 5c4072f85ad3ed83260e13d152d2fbaad165b66d Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Thu, 10 Mar 2022 22:39:42 +0530 Subject: [PATCH 1/2] Handle all justfiles --- Changelog.org | 8 +++++++- justl.el | 44 ++++++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Changelog.org b/Changelog.org index cbb509d..c0582af 100644 --- a/Changelog.org +++ b/Changelog.org @@ -1,3 +1,9 @@ +* 0.7 (Unreleased) + +- Finds all types of justfiles now and makes it compatible with the + ~just~ program. Earlier it used to just working with ~justfile~ and + ~.justfile. + * 0.6 - Make the directory parsing smart. Now invoking justl from any @@ -15,7 +21,7 @@ buffer. - Fix bug when process execution itself throws error. - Migrate from the deprecated ~define-transient-command~ -- Fix justl process when you pass transient argument for ~--color~~ +- Fix justl process when you pass transient argument for ~--color~ * 0.4 diff --git a/justl.el b/justl.el index e660b99..cc72da2 100644 --- a/justl.el +++ b/justl.el @@ -135,6 +135,9 @@ NAME is the buffer name." (defconst justl--output-process-buffer "*just*" "Just output process buffer name.") +(defconst justl--justfile-regex "[Jj][Uu][sS][tT][fF][iI][lL][eE]" + "Justfile name.") + (defun justl--is-variable-p (str) "Check if string STR is a just variable." (s-contains? ":=" str)) @@ -160,17 +163,32 @@ NAME is the buffer name." If this is NIL, it means that no justfiles was found. In any other cases, it's a known path.") -(defun justl--find-any-justfiles (dir filename) - "Find just FILENAME inside a sub-directory DIR or a parent directory. +(defun justl--traverse-upwards (fn &optional path) + "Traverse up as long as FN return nil, starting at PATH. + +Variant of f.el's f-traverse-upwards but returns justfiles." + (unless path + (setq path default-directory)) + (when (f-relative? path) + (setq path (f-expand path))) + (let ((result (funcall fn path))) + (if result + result + (unless (f-root? path) + (justl--traverse-upwards fn (f-parent path)))))) + +(defun justl--find-any-justfiles (dir) + "Find justfiles inside a sub-directory DIR or a parent directory. Returns the absolute path if FILENAME exists or nil if no path was found." - (let ((justfile-dir (f-traverse-upwards - (lambda (path) - (f-exists? (f-expand filename path))) - dir))) - (if justfile-dir - (f-expand filename justfile-dir) + (let ((case-fold-search t) + (justfiles (justl--traverse-upwards + (lambda (path) + (directory-files path t justl--justfile-regex)) + dir))) + (if justfiles + (car justfiles) (let ((justfile-paths (directory-files-recursively dir filename))) (if justfile-paths (car justfile-paths) @@ -181,17 +199,11 @@ was found." DIR represents the directory where search will be carried out. It searches either for the filename justfile or .justfile" - (let ((justfile-path (justl--find-any-justfiles dir "justfile"))) + (let ((justfile-path (justl--find-any-justfiles dir))) (if justfile-path (progn (setq justl--justfile justfile-path) - justfile-path) - (let ((dot-justfile-path (justl--find-any-justfiles dir ".justfile"))) - (if dot-justfile-path - (progn - (setq justl--justfile dot-justfile-path) - dot-justfile-path) - nil))))) + justfile-path)))) (defun justl--get-recipe-name (str) "Compute the recipe name from the string STR." From 6654dc4668cb99b1000d90a8e4a860e6d986df45 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Thu, 10 Mar 2022 22:46:47 +0530 Subject: [PATCH 2/2] Fix docs --- justl.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/justl.el b/justl.el index cc72da2..9420239 100644 --- a/justl.el +++ b/justl.el @@ -166,7 +166,7 @@ other cases, it's a known path.") (defun justl--traverse-upwards (fn &optional path) "Traverse up as long as FN return nil, starting at PATH. -Variant of f.el's f-traverse-upwards but returns justfiles." +Variant of f.el's 'f-traverse-upwards but returns justfiles." (unless path (setq path default-directory)) (when (f-relative? path) @@ -180,16 +180,16 @@ Variant of f.el's f-traverse-upwards but returns justfiles." (defun justl--find-any-justfiles (dir) "Find justfiles inside a sub-directory DIR or a parent directory. -Returns the absolute path if FILENAME exists or nil if no path +Returns the absolute path if file exists or nil if no path was found." (let ((case-fold-search t) (justfiles (justl--traverse-upwards - (lambda (path) - (directory-files path t justl--justfile-regex)) - dir))) + (lambda (path) + (directory-files path t justl--justfile-regex)) + dir))) (if justfiles (car justfiles) - (let ((justfile-paths (directory-files-recursively dir filename))) + (let ((justfile-paths (directory-files-recursively dir "justfile"))) (if justfile-paths (car justfile-paths) nil)))))