branch: elpa/idris-mode commit 6fbd9cff31a9bc1d56bf03cbd8674e67484e58db Author: Marek L <nospam.ke...@gmail.com> Commit: Marek L <nospam.ke...@gmail.com>
Improve `idris-switch-working-directory` by - adding error handling and success check - changing the value of variable `idris-process-current-working-directory` only if the directory was changed successfully to avoid invalid state. - displaying message from Idris to user --- idris-commands.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/idris-commands.el b/idris-commands.el index 75b9a05433..f4de6782ab 100644 --- a/idris-commands.el +++ b/idris-commands.el @@ -91,13 +91,23 @@ (idris-repl-buffer)) (defun idris-switch-working-directory (new-working-directory) - "Switch working directory." + "Switch working directory to NEW-WORKING-DIRECTORY." (unless (string= idris-process-current-working-directory new-working-directory) (idris-ensure-process-and-repl-buffer) - (if (> idris-protocol-version 1) - (idris-eval `(:interpret ,(concat ":cd " (prin1-to-string new-working-directory)))) - (idris-eval `(:interpret ,(concat ":cd " new-working-directory)))) - (setq idris-process-current-working-directory new-working-directory))) + (let* ((path (if (> idris-protocol-version 1) + (prin1-to-string new-working-directory) + new-working-directory)) + (eval-result (idris-eval `(:interpret ,(concat ":cd " path)))) + (result-msg (or (car-safe eval-result) ""))) + ;; Check if the message from Idris contains the new directory path. + ;; Before check drop the last character (slash) in the path + ;; as the message does not include it. + (if (string-match-p (file-truename (substring new-working-directory 0 -1)) + result-msg) + (progn + (message result-msg) + (setq idris-process-current-working-directory new-working-directory)) + (error "Failed to switch the working directory %s" eval-result))))) (defun idris-list-holes-on-load () "Use the user's settings from customize to determine whether to list the holes."