Skip to content

Commit

Permalink
Allow replacing running Flutter process with one from other project
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Dec 2, 2020
1 parent 78b3c57 commit 696228a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion flutter.el
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ the `flutter` process."
ARGS is a space-delimited string of CLI flags passed to
`flutter`, and can be nil."
`(flutter--from-project-root
(let* ((buffer (get-buffer-create flutter-buffer-name))
(let* ((buffer (flutter--get-buffer-create flutter-buffer-name))
(alive (flutter--running-p))
(arglist (if ,args (split-string ,args))))
(unless alive
Expand All @@ -129,6 +129,21 @@ ARGS is a space-delimited string of CLI flags passed to
(flutter-mode)))
,@body)))

(defun flutter--get-buffer-create (buffer-or-name)
"Same as `get-buffer-create' but ensures BUFFER-OR-NAME has our CWD.
If the existing buffer's CWD doesn't match, kill it and recreate it."
(let* ((existing-buf (get-buffer buffer-or-name))
(existing-buf-cwd (when existing-buf
(with-current-buffer existing-buf
default-directory))))
(if (string= default-directory existing-buf-cwd)
existing-buf
(when existing-buf
(unless (kill-buffer existing-buf)
(error "Flutter already running in %s" existing-buf-cwd)))
(get-buffer-create buffer-or-name))))

(defun flutter--running-p ()
"Return non-nil if the `flutter` process is already running."
(comint-check-proc flutter-buffer-name))
Expand Down

0 comments on commit 696228a

Please sign in to comment.