diff --git a/gdscript-godot.el b/gdscript-godot.el index 761c3b4..7f6cc72 100644 --- a/gdscript-godot.el +++ b/gdscript-godot.el @@ -102,20 +102,26 @@ When run with prefix argument, it offers extra debug options to choose from." (defun gdscript-godot-run-current-scene () "Run the current script file in Godot Engine. Use the universal prefix (C-u) to force a scene select." (interactive) - (gdscript-godot--run-command (gdscript-godot--select-scene current-prefix-arg))) + (let ((scene (gdscript-godot--select-scene current-prefix-arg))) + (when scene + (gdscript-godot--run-command scene)))) (defun gdscript-godot-run-current-scene-debug () "Run the current script file in Godot Engine. When run with prefix argument, it offers extra debug options to choose from." (interactive) - (gdscript-godot--debug-options-handler debug-options - (gdscript-godot--run-command "-d" debug-options (gdscript-godot--select-scene)))) + (let ((scene (gdscript-godot--select-scene current-prefix-arg))) + (when scene + (gdscript-godot--debug-options-handler debug-options + (gdscript-godot--run-command "-d" debug-options scene))))) (defun gdscript-godot-edit-current-scene () "Run the current script file in Godot Engine." (interactive) - (gdscript-godot--run-command "-e" (gdscript-godot--select-scene current-prefix-arg))) + (let ((scene (gdscript-godot--select-scene current-prefix-arg))) + (when scene + (gdscript-godot--run-command "-e" scene)))) (defun gdscript-godot--select-scene (&optional select-scene) "Select scene to run" diff --git a/gdscript-project.el b/gdscript-project.el index 5a10ace..ed30394 100644 --- a/gdscript-project.el +++ b/gdscript-project.el @@ -46,12 +46,13 @@ If current buffer is not visiting scene file return nil." (when (file-exists-p scene-name) scene-name)))) (defun gdscript-project--select-scene () - "Find all scenes files and let user choose one." + "Find all scenes files and let user choose one. Return `nil' if user cancels selection." (message "selecting scene") (let* ((rl (gdscript-util--find-project-configuration-file)) (scene-list (mapcar (lambda (x) (file-relative-name x rl)) (directory-files-recursively rl ".*.tscn" t))) - (prompt (format "Select scene to run" (buffer-name)))) - (gdscript-util--read scene-list prompt))) + (prompt (format "Select scene to run" (buffer-name))) + (selected-scene (gdscript-util--read scene-list prompt))) + selected-scene)) (defun gdscript-project--current-buffer-script () "Return the name of current script. @@ -70,7 +71,7 @@ If current buffer is not visiting script file return nil." (unwind-protect (let* ((prompt (format "Buffer %s is not script file, select script to run" (buffer-name))) (script-name (gdscript-util--read gdscript-project--script-list prompt))) - (gdscript-godot--run-script script-name)) + (when script-name (gdscript-godot--run-script script-name))) (when hydra-open (gdscript-hydra--menu/body))))) (defun gdscript-project--ag-cleanup () diff --git a/gdscript-utils.el b/gdscript-utils.el index bed8d61..7191b63 100644 --- a/gdscript-utils.el +++ b/gdscript-utils.el @@ -142,11 +142,9 @@ For example: (defun gdscript-util--read (items &optional prompt) "Let's choose single item from ITEMS from mini-buffer. - -PROMPT is prompt for read command." - (message "gdscript util read") - (let ((p (if prompt prompt "Options"))) - (cond ((and (featurep 'projectile) ) +PROMPT is prompt for read command. Return `nil' if user aborts." + (let* ((p (if prompt prompt "Options")) + (result (cond ((and (featurep 'projectile) ) (projectile-completing-read (format "%s: " p) items)) ((fboundp 'ivy-read) (ivy-read (format "%s: " p) items)) @@ -154,6 +152,7 @@ PROMPT is prompt for read command." (ido-completing-read (format "%s: " p) items)) (t (completing-read (format "%s (hit TAB to auto-complete): " p) items nil t))))) + (if quit-flag nil result))) (provide 'gdscript-utils)