Skip to content

Commit

Permalink
fix(command): add setup function to reserve buffers
Browse files Browse the repository at this point in the history
There was a change in Emacs 30 that may lead to
`ship-mate--command-buffer-p` returning nil, meaning that hooking into
`compilation-start-hook` may fail.

Function `ship-mate-command` now sets
`compilation-process-setup-function` to set new local variable
`ship-mate--reserved` that may also be checked instead of
`ship-mate--this-command`.
  • Loading branch information
Walheimat committed Jul 10, 2024
1 parent ebb52c7 commit a17a304
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ship-mate.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ This is either nil, `ship-mate' or `other'.")
This is set by `ship-mate-command'.")

(defvar-local ship-mate--reserved nil
"Marker set to indicate the compilation was started by `ship-mate'.")

(defvar ship-mate--current-command-name nil
"The symbol name of the currently executed command.")

Expand Down Expand Up @@ -207,7 +210,8 @@ command hidden and 5 lets you edit the environment first."
;; Binding external variables.
(default-directory (project-root current))
(compilation-save-buffers-predicate (lambda () (memq (current-buffer) project-buffers)))
(compilation-buffer-name-function (funcall ship-mate-command-buffer-name-function-generator lowercase)))
(compilation-buffer-name-function (funcall ship-mate-command-buffer-name-function-generator lowercase))
(compilation-process-setup-function #'ship-mate-command--reserve))

(when command

Expand All @@ -229,6 +233,10 @@ command hidden and 5 lets you edit the environment first."

buffer))))

(defun ship-mate-command--reserve ()
"Reserve the current buffer for `ship-mate'."
(setq ship-mate--reserved t))

(defun ship-mate-command--current-project (&optional arg)
"Get the current project.
Expand Down Expand Up @@ -725,7 +733,8 @@ Optionally the PROJECT may be passed directly."
(let ((buffer (or buffer (current-buffer))))

(and (string-match-p "\\*ship-mate" (buffer-name buffer))
(not (null ship-mate--this-command)))))
(or (not (null ship-mate--this-command))
ship-mate--reserved))))

(defun ship-mate--command-buffer-predicate (buffer)
"Predicate to check if BUFFER is a `ship-mate' buffer.
Expand Down
22 changes: 22 additions & 0 deletions test/ship-mate-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@
(bydi-was-called ship-mate-environment--edit-in-minibuffer)
(bydi-was-set-to compilation-environment '("MOC=KING")))))

(ert-deftest ship-mate-command--reserve ()
:tags '(command)

(bydi ((:watch ship-mate--reserved))

(ert-with-test-buffer (:name "reserve")

(ship-mate-command--reserve)

(bydi-was-set-to ship-mate--reserved t))))

(ert-deftest ship-mate-command--current-project ()
(bydi ((:always project-current)
(:always project-prompt-project-dir)
Expand Down Expand Up @@ -824,6 +835,17 @@

(should-error (ship-mate--complete-buffer "Some prompt: "))))

(ert-deftest ship-mate--command-buffer-p--check-for-reserved ()
:tags '(command)

(ert-with-test-buffer (:name "*ship-mate-reserved*")

(should-not (ship-mate--command-buffer-p))

(ship-mate-command--reserve)

(should (ship-mate--command-buffer-p))))

(ert-deftest ship-mate--command-buffer-predicate ()
:tags '(completion)

Expand Down

0 comments on commit a17a304

Please sign in to comment.