Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote justl--justfile to a safe, local defcustom #33

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
fail-fast: false
matrix:
emacs_version:
- release-snapshot
- 28.2
- 27.2
- 26.3
ignore_warnings:
- false
steps:
Expand Down
45 changes: 25 additions & 20 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@
:type 'integer
:group 'justl)

(defcustom justl-justfile nil
"Buffer local variable which points to the justfile.

If this is NIL, it means that no justfiles was found. In any
other cases, it's a known path."
:type 'string
:local t
:group 'justl
:safe 'stringp)

(cl-defstruct justl-jrecipe name args)
(cl-defstruct justl-jarg arg default)

Expand Down Expand Up @@ -170,11 +180,6 @@ NAME is the buffer name."
(insert (format "%s\n" str))
(read-only-mode nil))))

(defvar-local justl--justfile nil
"Buffer local variable which points to the justfile.

If this is NIL, it means that no justfiles was found. In any
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.
Expand Down Expand Up @@ -215,7 +220,7 @@ It searches either for the filename justfile or .justfile"
(let ((justfile-path (justl--find-any-justfiles dir)))
(if justfile-path
(progn
(setq-local justl--justfile justfile-path)
(setq-local justl-justfile justfile-path)
justfile-path))))

(defun justl--get-recipe-name (str)
Expand Down Expand Up @@ -341,7 +346,7 @@ ARGS is a plist that affects how the process is run.
(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)))
(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)
Expand All @@ -352,7 +357,7 @@ ARGS is a plist that affects how the process is run.
(let* ((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)))
(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)
Expand All @@ -372,8 +377,8 @@ ARGS is a plist that affects how the process is run.
(interactive)
(justl--make-process justl--compile-command (list :buffer justl--output-process-buffer
:process "just"
:directory (if justl--justfile
(f-dirname justl--justfile)
:directory (if justl-justfile
(f-dirname justl-justfile)
default-directory)
:mode 'justl-compile-mode)))

Expand Down Expand Up @@ -470,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" justl-justfile))

(defun justl--justfile-from-arg (arg)
"Return justfile filepath from ARG."
Expand Down Expand Up @@ -554,15 +559,15 @@ and output of process."
Populates the eshell buffer with RECIPE name so that it can be
tweaked further by the user."
(let* ((eshell-buffer-name (format "justl - eshell - %s" recipe))
(default-directory (f-dirname justl--justfile)))
(default-directory (f-dirname justl-justfile)))
(progn
(eshell)
(insert (format "just %s" recipe)))))

(defun justl--exec-with-eshell (recipe)
"Opens eshell buffer and execute the just RECIPE."
(let* ((eshell-buffer-name (format "justl - eshell - %s" recipe))
(default-directory (f-dirname justl--justfile)))
(default-directory (f-dirname justl-justfile)))
(progn
(eshell)
(insert (format "just %s" recipe))
Expand All @@ -572,7 +577,7 @@ tweaked further by the user."
"Execute just recipe in eshell."
(interactive)
(let* ((recipe (justl--get-word-under-cursor))
(justl-recipe (justl--get-recipe-from-file justl--justfile recipe))
(justl-recipe (justl--get-recipe-from-file justl-justfile recipe))
(t-args (transient-args 'justl-help-popup))
(recipe-has-args (justl--jrecipe-has-args-p justl-recipe)))
(if recipe-has-args
Expand All @@ -590,7 +595,7 @@ tweaked further by the user."
"Open eshell with the recipe but do not execute it."
(interactive)
(let* ((recipe (justl--get-word-under-cursor))
(justl-recipe (justl--get-recipe-from-file justl--justfile recipe))
(justl-recipe (justl--get-recipe-from-file justl-justfile recipe))
(t-args (transient-args 'justl-help-popup))
(recipe-has-args (justl--jrecipe-has-args-p justl-recipe)))
(if recipe-has-args
Expand Down Expand Up @@ -647,7 +652,7 @@ tweaked further by the user."
"Execute just recipe."
(interactive)
(let* ((recipe (justl--get-word-under-cursor))
(justl-recipe (justl--get-recipe-from-file justl--justfile recipe))
(justl-recipe (justl--get-recipe-from-file justl-justfile recipe))
(t-args (transient-args 'justl-help-popup))
(recipe-has-args (justl--jrecipe-has-args-p justl-recipe)))
(if recipe-has-args
Expand All @@ -665,7 +670,7 @@ tweaked further by the user."
"Execute just recipe with arguments."
(interactive)
(let* ((recipe (justl--get-word-under-cursor))
(justl-recipe (justl--get-recipe-from-file justl--justfile recipe))
(justl-recipe (justl--get-recipe-from-file justl-justfile recipe))
(t-args (transient-args 'justl-help-popup))
(user-args (read-from-minibuffer
(format "Arguments seperated by spaces:"))))
Expand All @@ -680,9 +685,9 @@ tweaked further by the user."
"Go to the recipe on justfile."
(interactive)
(let* ((recipe (justl--get-word-under-cursor))
(justl-recipe (justl--get-recipe-from-file justl--justfile recipe)))
(justl-recipe (justl--get-recipe-from-file justl-justfile recipe)))
(progn
(find-file justl--justfile)
(find-file justl-justfile)
(goto-char 0)
(when (re-search-forward (concat (justl-jrecipe-name justl-recipe) ".*:") nil t 1)
(let ((start (point)))
Expand All @@ -705,7 +710,7 @@ tweaked further by the user."
(let* ((justfiles (justl--find-justfiles default-directory))
(entries (justl--get-recipies-with-desc justfiles)))
(when (not (eq justl--list-command-exit-code 0) )
(error "Just process exited with exit-code %s. Check justfile syntax"
(error "Just process exited with exit-code %s. Check justfile syntax"
justl--list-command-exit-code))
(justl--save-line)
(setq tabulated-list-entries (justl--tabulated-entries entries))
Expand Down