[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/raku-mode 7d006af233 187/253: Simple perl6/raku repl
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/raku-mode 7d006af233 187/253: Simple perl6/raku repl |
Date: |
Sat, 29 Jan 2022 08:28:56 -0500 (EST) |
branch: elpa/raku-mode
commit 7d006af2331f7a3c46169e89014607f9fa2b44ac
Author: Matias Linares <matiaslina@gmail.com>
Commit: Matias Linares <matiaslina@gmail.com>
Simple perl6/raku repl
This adds repl support to perl6-mode with the following actions:
* Send a line to the repl
* Send a region to the repl
* Send the whole buffer to the repl
---
perl6-repl.el | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
diff --git a/perl6-repl.el b/perl6-repl.el
new file mode 100644
index 0000000000..543cfe75a6
--- /dev/null
+++ b/perl6-repl.el
@@ -0,0 +1,116 @@
+(require 'term)
+
+(defun perl6-repl-send-line (astring)
+ ;;send home if we have a regular perl6 prompt this line
+ ;;otherwise, simulate "C-b" until we get to the beginning
+ (if (equal (buffer-substring (- (line-beginning-position) 2)
(line-beginning-position)) "> ") (term-send-home)
+ (progn (while (> (- (point) (line-beginning-position)) 2)
(term-send-string "\^b"))))
+ (term-send-raw-string astring) ;send the argument as perl6 input
+ (term-send-raw-string "\^M") ;sends a return to execute astring
+ ;;(term-send-raw-string "\^y") ;sends a C-y, which yanks the killed line
+ )
+
+
+(setq perl6-repl--buffer-name "Perl6 REPL")
+
+
+(defun perl6-repl--buffer-name-earmuf ()
+ (concat "*" perl6-repl--buffer-name "*"))
+
+
+(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)))
+ (set-buffer termbuf)
+ (term-mode)
+ (term-set-escape-char 24) ;this sets the escape char to C-x instead of C-c
+ (term-char-mode)
+ (switch-to-buffer-other-window termbuf)))
+
+
+(defun perl6-create-new-repl ()
+ (progn (perl6-repl-other-window)
+ (while (or (< (point)
+ 2)
+ (not (equal (buffer-substring (- (point)
+ 2)
+ (point))
+ "> ")))
+ (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)))
+
+
+(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)))
+
+(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)))
+
+;; Menu for evaluation
+(defun perl6-repl--initialize-menu ()
+ (interactive)
+ (define-key-after
+ perl6-mode-map
+ [menu-bar perl6-interaction]
+ (cons "Raku Interaction" (make-sparse-keymap "Perl6 Interaction"))
+ 'tools)
+ (define-key
+ perl6-mode-map
+ [menu-bar perl6-interaction eval-line]
+ '("Evaluate line" . perl6-send-line-to-repl))
+ (define-key
+ perl6-mode-map
+ [menu-bar perl6-interaction eval-region]
+ '("Evaluate region" . perl6-send-region-to-repl))
+ (define-key
+ perl6-mode-map
+ [menu-bar perl6-interaction eval-buffer]
+ '("Evaluate buffer" . perl6-send-buffer-to-repl)))
+
+(provide 'perl6-repl)
- [nongnu] elpa/raku-mode c1b2f9e112 109/253: Less aggressive syntaxification of sigils/twigils, (continued)
- [nongnu] elpa/raku-mode c1b2f9e112 109/253: Less aggressive syntaxification of sigils/twigils, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 6553c30843 093/253: Highlight ::?CLASS and such correctly, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 861a7b469b 110/253: Highlight string delimiters like operators, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 5f66f10dbe 143/253: Correctly highlight $foo.?method, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 9f07c8b52a 139/253: Highlight 'unit' keyword, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 5456e2b044 145/253: Fix highlighting of <-a -b -c>, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 81805cfa8e 154/253: remove vars (to main file) per comments from syohex, clean up some, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 4b01244490 157/253: make this work for nqp also, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode edccdba86f 191/253: Don't hang emacs if cannot find the Raku executable, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 88de065795 186/253: add test file for HEREDOC indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 7d006af233 187/253: Simple perl6/raku repl,
ELPA Syncer <=
- [nongnu] elpa/raku-mode 9cbd9b26f9 168/253: Merge branch 'patch-1' of https://github.com/Altai-man/perl6-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 4ad9987e25 185/253: add TODO note for HEREDOC indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 8f6804ad17 207/253: Merge pull request #26 from matiaslina/raku-rename, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 0dd62e4d1f 217/253: Add missing 's' to parent customization group name., ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 13ebcd87ce 220/253: trivial change Perl 6 to Raku, plus temp change of URL meanwhile, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 98db56c6ec 212/253: Add some clarifying comments., ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode acc516e76d 225/253: Uncomment code blocks in POD., ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 341c898848 029/253: Add note about electricity, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode e7a3770427 008/253: Recommend `:defer t` with use-package, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 032fa40e1b 068/253: Highlight [RSXZ] metaoperators, ELPA Syncer, 2022/01/29