From 4e757e30925414e4491b68c284cf140cc015b4ff Mon Sep 17 00:00:00 2001 From: Ryan Faulhaber Date: Sun, 7 Mar 2021 13:06:28 -0500 Subject: [PATCH] Adds rustic-cargo-init --- rustic-cargo.el | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/rustic-cargo.el b/rustic-cargo.el index d9a21b4f..f0309adb 100644 --- a/rustic-cargo.el +++ b/rustic-cargo.el @@ -353,27 +353,42 @@ Execute process in PATH." ;;; New project -;;;###autoload -(defun rustic-cargo-new (project-path &optional bin) - "Run 'cargo new' to start a new package in the path specified by PROJECT-PATH. -If BIN is not nil, create a binary application, otherwise a library." - (interactive "DProject path: ") - (let ((bin (if (or bin (y-or-n-p "Create new binary package? ")) +(defun rustic-create-project (project-path is-new &optional bin) + "Run either 'cargo new' if IS-NEW is non-nil, or 'cargo init' otherwise. +Creates or initializes the directory at the path specified by PROJECT-PATH. If +BIN is not nil, create a binary application, otherwise a library." + (let* ((cmd (if is-new "new" "init")) + (bin (if (or bin (y-or-n-p "Create new binary package? ")) "--bin" - "--lib")) - (new-sentinel (lambda (_process signal) + "--lib")) + (new-sentinel (lambda (_process signal) (when (equal signal "finished\n") (message (format "Created new package: %s" (file-name-base project-path))) - (if rustic-cargo-open-new-project - (find-file (concat project-path "/src/main.rs")))))) - (proc "rustic-cargo-new-process") - (buf "*cargo-new*")) + (when rustic-cargo-open-new-project + (find-file + (concat project-path (if (string= bin "--bin") "/src/main.rs" "/src/lib.rs"))))))) + (proc (format "rustic-cargo-%s-process" cmd)) + (buf (format "*cargo-%s*" cmd))) (make-process :name proc :buffer buf - :command (list rustic-cargo-bin "new" bin project-path) + :command (list rustic-cargo-bin cmd bin project-path) :sentinel new-sentinel))) +;;;###autoload +(defun rustic-cargo-new (project-path &optional bin) + "Run 'cargo new' to start a new package in the path specified by PROJECT-PATH. +If BIN is not nil, create a binary application, otherwise a library." + (interactive "DProject path: ") + (rustic-create-project project-path t bin)) + +;;;###autoload +(defun rustic-cargo-init (project-path &optional bin) + "Run 'cargo init' to initialize a directory in the path specified by PROJECT-PATH. +If BIN is not nil, create a binary application, otherwise a library." + (interactive "DProject path: ") + (rustic-create-project project-path nil bin)) + ;;; Cargo commands (defun rustic-run-cargo-command (command &optional args)