Skip to content

Commit 1686c02

Browse files
committed
Ensure Idris is running and current Idris is file loaded when using idris-switch-to-repl
Why: Allows to jump to the repl without having to manually start repl using a shortcut
1 parent da5c22f commit 1686c02

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

idris-common-utils.el

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,15 @@ corresponding values in the CDR of VALUE."
365365
'()
366366
`((t (error "ELISP destructure-case failed: %S" ,tmp))))))))
367367

368+
(defun idris-idr-p (&optional buffer)
369+
"Return t if BUFFER is an Idris file (.idr)."
370+
(if-let* ((file-name (buffer-file-name buffer)))
371+
(string-equal (downcase (file-name-extension file-name)) "idr")))
372+
368373
(defun idris-lidr-p (&optional buffer)
369-
"Return t if BUFFER is a literate Idris file, or nil otherwise.
370-
Use the current buffer if BUFFER is not supplied or is nil."
371-
(let ((file-name (buffer-file-name buffer)))
372-
;; We check for nil here because idris-lidr-p might be called on
373-
;; buffers that don't have associated files, such as the REPL
374-
;; buffer or an info buffer
375-
(and (stringp file-name)
376-
(string= (file-name-extension file-name) "lidr"))))
374+
"Return t if BUFFER is a literate Idris file (.lidr)."
375+
(if-let* ((file-name (buffer-file-name buffer)))
376+
(string-equal (downcase (file-name-extension file-name)) "lidr")))
377377

378378
(defun idris-make-file-link-overlay (start end keymap help-echo)
379379
(let ((overlay (make-overlay start end)))

idris-repl.el

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,14 @@ If ALWAYS-INSERT is non-nil, always insert a prompt at the end of the buffer."
186186
(idris-repl-insert-prompt)
187187
(insert current-input))))
188188

189+
(autoload 'idris-load-file-sync "idris-commands.el")
190+
;;;###autoload
189191
(defun idris-switch-to-repl ()
190-
"Select the output buffer and scroll to bottom."
192+
"Load the current Idris file buffer and jump to the Idris REPL."
191193
(interactive)
194+
(if (or (idris-idr-p) (idris-lidr-p))
195+
(idris-load-file-sync)
196+
(user-error "This command can only be run from a buffer visiting an Idris `.idr' or `.lidr' file"))
192197
(pop-to-buffer (idris-repl-buffer))
193198
(goto-char (point-max)))
194199

@@ -199,7 +204,8 @@ If ALWAYS-INSERT is non-nil, always insert a prompt at the end of the buffer."
199204
(defun idris-repl ()
200205
(interactive)
201206
(idris-run)
202-
(idris-switch-to-repl))
207+
(pop-to-buffer (idris-repl-buffer))
208+
(goto-char (point-max)))
203209

204210
(defvar idris-repl-mode-map
205211
(let ((map (make-sparse-keymap)))

0 commit comments

Comments
 (0)