branch: elpa/idris-mode
commit 5442961d09bd7ca3920acb37855e2fe141d71573
Merge: 7211af2fc8 b21ed26ede
Author: Jan de Muijnck-Hughes <[email protected]>
Commit: GitHub <[email protected]>

    Merge pull request #643 from keram/jump-to-repl-from-cold
    
    Improve user experience of `idris-switch-to-repl` command
---
 idris-commands.el | 18 ++++++++++++------
 idris-repl.el     | 39 +++++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/idris-commands.el b/idris-commands.el
index a5aaf2a7a4..eabdc08686 100644
--- a/idris-commands.el
+++ b/idris-commands.el
@@ -251,9 +251,11 @@ A prefix argument SET-LINE forces loading but only up to 
the current line."
         (goto-char (overlay-end (car warnings-backward)))
       (user-error "No warnings or errors until beginning of buffer"))))
 
-(defun idris-load-file-sync ()
+(defun idris-load-file-sync (&optional no-errors)
   "Pass the current buffer's file synchronously to the inferior Idris process.
-This sets the load position to point, if there is one."
+This sets the load position to point, if there is one.
+
+If NO-ERRORS is passed the warnings from Idris will be ignored."
   (save-buffer)
   (idris-ensure-process-and-repl-buffer)
   (if (buffer-file-name)
@@ -274,11 +276,15 @@ This sets the load position to point, if there is one."
                  (idris-eval
                   (if idris-load-to-here
                       `(:load-file ,fn ,(idris-get-line-num 
idris-load-to-here))
-                    `(:load-file ,fn))))
+                    `(:load-file ,fn))
+                  no-errors))
                 (idris-currently-loaded-buffer (current-buffer)))
-            (idris-update-options-cache)
-            (idris-make-clean)
-            (idris-update-loaded-region (car result)))))
+            ;; Currently on success the result contains `(nil)`, on failure 
just nil
+            (if (and no-errors (null result))
+                (message "Failed to load current file into Idris")
+              (idris-update-options-cache)
+              (idris-make-clean)
+              (idris-update-loaded-region (car result))))))
     (user-error "Cannot find file for current buffer")))
 
 
diff --git a/idris-repl.el b/idris-repl.el
index add8346f19..92a1e1924e 100644
--- a/idris-repl.el
+++ b/idris-repl.el
@@ -186,11 +186,37 @@ If ALWAYS-INSERT is non-nil, always insert a prompt at 
the end of the buffer."
       (idris-repl-insert-prompt)
       (insert current-input))))
 
-(defun idris-switch-to-repl ()
-  "Select the output buffer and scroll to bottom."
-  (interactive)
-  (pop-to-buffer (idris-repl-buffer))
-  (goto-char (point-max)))
+(defcustom idris-x-switch-to-repl-copy-region t
+  "*Experimental*
+When using the `idris-switch-to-repl' command with an active region,
+copy the region and paste it into the REPL.
+This copy does not modify the user's kill ring."
+  :group 'idris
+  :type 'boolean)
+
+(autoload 'idris-load-file-sync "idris-commands.el")
+;;;###autoload
+(defun idris-switch-to-repl (&optional load-file)
+  "Switch to the Idris REPL buffer.
+
+If called from an Idris file and LOAD-FILE is non-nil,
+load the current file into the REPL before switching.
+Errors during file loading are ignored.
+
+*Experimental*
+When feature flag `idris-x-switch-to-repl-copy-region' is enabled
+and there is an active region, paste the region into the REPL."
+  (interactive "P")
+  (let ((region (if (and idris-x-switch-to-repl-copy-region (use-region-p))
+                    (buffer-substring-no-properties
+                     (region-beginning) (region-end)))))
+    (idris-run)
+    (when (and (derived-mode-p 'idris-mode) load-file)
+      (idris-load-file-sync t))
+    (pop-to-buffer (idris-repl-buffer))
+    (goto-char (point-max))
+    (when region
+      (insert region))))
 
 (define-obsolete-function-alias 'idris-switch-to-output-buffer 
'idris-switch-to-repl "2022-12-28")
 
@@ -199,7 +225,8 @@ If ALWAYS-INSERT is non-nil, always insert a prompt at the 
end of the buffer."
 (defun idris-repl ()
   (interactive)
   (idris-run)
-  (idris-switch-to-repl))
+  (pop-to-buffer (idris-repl-buffer))
+  (goto-char (point-max)))
 
 (defvar idris-repl-mode-map
   (let ((map (make-sparse-keymap)))

Reply via email to