branch: elpa/raku-mode
commit edccdba86f10cd79b108b19e87bc6366790f1db1
Author: Matias Linares <[email protected]>
Commit: Matias Linares <[email protected]>
Don't hang emacs if cannot find the Raku executable
---
perl6-repl.el | 116 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 62 insertions(+), 54 deletions(-)
diff --git a/perl6-repl.el b/perl6-repl.el
index d05c0d2932..db78020bb6 100644
--- a/perl6-repl.el
+++ b/perl6-repl.el
@@ -10,9 +10,7 @@
;;(term-send-raw-string "\^y") ;sends a C-y, which yanks the killed line
)
-
-(setq perl6-repl--buffer-name "Perl6 REPL")
-
+(setq perl6-repl--buffer-name "Raku REPL")
(defun perl6-repl--buffer-name-earmuf ()
(concat "*" perl6-repl--buffer-name "*"))
@@ -22,10 +20,14 @@
:type 'string
:group 'perl6)
+(defun perl6-exec-path-exists-p ()
+ (or (file-executable-p perl6-exec-path)
+ (executable-find perl6-exec-path)))
+
(defun perl6-repl-other-window ()
"Runs Perl6 in a `term' buffer in another window."
(interactive)
- (let ((termbuf (apply 'make-term perl6-repl--buffer-name "perl6" nil)))
+ (let ((termbuf (apply 'make-term perl6-repl--buffer-name perl6-exec-path
nil)))
(set-buffer termbuf)
(term-mode)
(term-set-escape-char 24) ;this sets the escape char to C-x instead of C-c
@@ -33,68 +35,74 @@
(switch-to-buffer-other-window termbuf)))
+(defun perl6-repl-ready-p ()
+ (or (< (point) 2)
+ (not (equal (buffer-substring (- (point)2)
+ (point))
+ "> "))))
+
(defun perl6-create-new-repl ()
(progn (perl6-repl-other-window)
- (while (or (< (point)
- 2)
- (not (equal (buffer-substring (- (point)
- 2)
- (point))
- "> ")))
+ (while (perl6-repl-ready-p)
(sit-for 0.1))))
(defun perl6-send-line-to-repl (&optional line)
(interactive)
- (let ((jbuf (get-buffer (perl6-repl--buffer-name-earmuf)))
- (cbuf (current-buffer))
- (cwin (selected-window))
- (pos (point))
- (linecontents
- (progn (when line ;if a line is passed to the function, go there
- (goto-char (point-min))
- (forward-line (- line 1)))
- (buffer-substring (line-beginning-position)
(line-end-position))))
- ) ;save pos of start of next line
- (if jbuf (switch-to-buffer jbuf)
- ;;if there is not a perl6 REPl open, open it and wait for prompt
-
- (perl6-create-new-repl))
- (perl6-repl-send-line linecontents)
- (select-window cwin)
- (switch-to-buffer cbuf)
- (goto-char pos)))
+ (if (perl6-exec-path-exists-p)
+ (let ((jbuf (get-buffer (perl6-repl--buffer-name-earmuf)))
+ (cbuf (current-buffer))
+ (cwin (selected-window))
+ (pos (point))
+ (linecontents
+ (progn (when line ;if a line is passed to the function, go there
+ (goto-char (point-min))
+ (forward-line (- line 1)))
+ (buffer-substring (line-beginning-position)
(line-end-position))))
+ ) ;save pos of start of next line
+ (if jbuf (switch-to-buffer jbuf)
+ ;;if there is not a perl6 REPl open, open it and wait for prompt
+
+ (perl6-create-new-repl))
+ (perl6-repl-send-line linecontents)
+ (select-window cwin)
+ (switch-to-buffer cbuf)
+ (goto-char pos))
+ (message "Cannot execute %s" perl6-exec-path)))
(defun perl6-send-region-to-repl ()
(interactive)
- (let ((jbuf (get-buffer (perl6-repl--buffer-name-earmuf)))
- (cbuf (current-buffer))
- (cwin (selected-window))
- (pos (mark))
- (contents (buffer-substring (mark)
- (point))))
- (if jbuf (switch-to-buffer jbuf)
- ;;if there is not a perl6 REPl open, open it and wait for prompt
- (perl6-create-new-repl))
- (set-text-properties 0 (length contents) nil contents)
- (mapc 'perl6-repl-send-line (split-string contents "\n+"))
- (select-window cwin)
- (switch-to-buffer cbuf)
- (goto-char pos)))
+ (if (perl6-exec-path-exists-p)
+ (let ((jbuf (get-buffer (perl6-repl--buffer-name-earmuf)))
+ (cbuf (current-buffer))
+ (cwin (selected-window))
+ (pos (mark))
+ (contents (buffer-substring (mark)
+ (point))))
+ (if jbuf (switch-to-buffer jbuf)
+ ;;if there is not a perl6 REPl open, open it and wait for prompt
+ (perl6-create-new-repl))
+ (set-text-properties 0 (length contents) nil contents)
+ (mapc 'perl6-repl-send-line (split-string contents "\n+"))
+ (select-window cwin)
+ (switch-to-buffer cbuf)
+ (goto-char pos))
+ (message "Cannot execute %s" perl6-exec-path)))
(defun perl6-send-buffer-to-repl ()
(interactive)
- (let ((jbuf (get-buffer (perl6-repl--buffer-name-earmuf)))
- (cbuf (current-buffer))
- (cwin (selected-window))
- (contents (buffer-string)))
- (if jbuf (switch-to-buffer jbuf)
- (perl6-create-new-repl))
- ;; Send te line to the repl
- (set-text-properties 0 (length contents) nil contents)
- (mapc 'perl6-repl-send-line (split-string contents "\n+"))
- (select-window cwin)
- (switch-to-buffer cbuf)))
-
+ (if (perl6-exec-path-exists-p)
+ (let ((jbuf (get-buffer (perl6-repl--buffer-name-earmuf)))
+ (cbuf (current-buffer))
+ (cwin (selected-window))
+ (contents (buffer-string)))
+ (if jbuf (switch-to-buffer jbuf)
+ (perl6-create-new-repl))
+ ;; Send te line to the repl
+ (set-text-properties 0 (length contents) nil contents)
+ (mapc 'perl6-repl-send-line (split-string contents "\n+"))
+ (select-window cwin)
+ (switch-to-buffer cbuf))
+ (message "Cannot execute %s" perl6-exec-path)))
(provide 'perl6-repl)