[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/raku-mode 44faa06bba 197/253: Use comint.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/raku-mode 44faa06bba 197/253: Use comint. |
Date: |
Sat, 29 Jan 2022 08:28:57 -0500 (EST) |
branch: elpa/raku-mode
commit 44faa06bba8582166b13f53c86a6925414aa6a44
Author: Matias Linares <matiaslina@gmail.com>
Commit: Matias Linares <matiaslina@gmail.com>
Use comint.
---
perl6-mode.el | 8 +++-
perl6-repl.el | 141 ++++++++++++++++++++++------------------------------------
2 files changed, 60 insertions(+), 89 deletions(-)
diff --git a/perl6-mode.el b/perl6-mode.el
index e21e8cb353..72e899a292 100644
--- a/perl6-mode.el
+++ b/perl6-mode.el
@@ -50,7 +50,7 @@
(define-key map (kbd "C-c C-r") 'perl6-send-region-to-repl)
(define-key map (kbd "C-c C-h") 'perl6-send-buffer-to-repl)
map)
- "Keymap for `perl6-mode'")
+ "Keymap for `perl6-mode'.")
(easy-menu-define perl6-mode-menu perl6-mode-map
"Menu for `perl6-mode'"
@@ -77,6 +77,12 @@
(setq-local comment-start-skip "#+ *")
(setq-local comment-use-syntax t)
(setq-local comment-end "")
+ ;; REPL
+ (setq comint-prompt-regexp perl6-prompt-regexp)
+ (setq comint-prompt-read-only t)
+ ;; this makes it so commands like M-{ and M-} work.
+ (set (make-local-variable 'paragraph-separate) "\\'")
+ (set (make-local-variable 'paragraph-start) perl6-prompt-regexp)
;; Indentation (see SMIE in the Emacs manual)
;; TODO add rules for HEREDOC indentation
(smie-setup perl6-smie-grammar #'perl6-smie-rules
diff --git a/perl6-repl.el b/perl6-repl.el
index 549c457073..0dab25cdf6 100644
--- a/perl6-repl.el
+++ b/perl6-repl.el
@@ -1,108 +1,73 @@
-(require 'term)
+;;; perl6-repl -- Repl for support Raku
-(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
- )
+;;; Commentary:
+;; Basic repl support for Raku
-(setq perl6-repl--buffer-name "Raku REPL")
-
-(defun perl6-repl--buffer-name-earmuf ()
- (concat "*" perl6-repl--buffer-name "*"))
+;;; Code:
+(require 'comint)
(defcustom perl6-exec-path "raku"
"Raku executable path."
: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 ()
- "Runs Perl6 in a `term' buffer in another window."
- (interactive)
- (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
- (term-char-mode)
- (switch-to-buffer-other-window termbuf)))
-
+(defcustom perl6-exec-arguments ""
+ "Raku command line arguments."
+ :type 'string
+ :group 'perl6)
-(defun perl6-repl-ready-p ()
- (or (< (point) 2)
- (not (equal (buffer-substring (- (point)2)
- (point))
- "> "))))
+(defvar perl6-prompt-regexp "^> "
+ "Prompt for `run-perl6'.")
-(defun perl6-create-new-repl ()
- (progn (perl6-repl)
- (while (perl6-repl-ready-p)
- (sit-for 0.1))))
+(defvar perl6-buffer-name "Raku REPL"
+ "Buffer name for `run-perl6.")
-(defun perl6-send-line-to-repl (&optional line)
+(defun run-perl6 ()
+ "Run an inferior instance of `raku' inside Emacs."
(interactive)
+ (let* ((perl6-program perl6-exec-path)
+ (check-proc (comint-check-proc perl6-buffer-name))
+ (buffer (apply 'make-comint-in-buffer
+ perl6-buffer-name
+ check-proc
+ perl6-exec-path
+ '()
+ (split-string perl6-exec-arguments))))
+ (display-buffer buffer)))
+
+(defun perl6-comint-get-process ()
+ "Raku process name."
+ (get-process perl6-buffer-name))
- (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
+(defun perl6-send-string-to-repl (str)
+ "Send STR to the repl."
+ (comint-send-string (perl6-comint-get-process)
+ (concat str "\n")))
- (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-line-to-repl ()
+ "Send a line to the repl."
+ (interactive)
+ (run-perl6)
+ (let ((str (buffer-substring-no-properties (line-beginning-position)
(line-end-position))))
+ (perl6-send-string-to-repl str)))
-(defun perl6-send-region-to-repl (begin end)
- (interactive (if (use-region-p)
- (list (region-beginning)
- (region-end))
- (list nil nil)))
- (if (and begin end (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-no-properties begin end)))
- (if jbuf (switch-to-buffer jbuf)
- ;;if there is not a perl6 REPl open, open it and wait for prompt
- (perl6-create-new-repl))
- (mapc 'perl6-repl-send-line (split-string contents "\n+"))
- (select-window cwin)
- (switch-to-buffer cbuf))
- (message "Cannot execute %s" perl6-exec-path)))
+(defun perl6-send-region-to-repl ()
+ "Send a region to the repl."
+ (interactive)
+ (run-perl6)
+ (if (region-active-p)
+ (let ((buf (buffer-substring-no-properties (region-beginning)
+ (region-end))))
+ (perl6-send-string-to-repl buf))
+ (message "No region selected")))
(defun perl6-send-buffer-to-repl ()
+ "Send a buffer to the repl."
(interactive)
- (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)))
+ (run-perl6)
+ (let ((buf (buffer-substring-no-properties (point-min)
+ (point-max))))
+ (perl6-send-string-to-repl buf)))
(provide 'perl6-repl)
+;;; perl6-repl.el ends here
- [nongnu] elpa/raku-mode 3d4a45d644 128/253: No identifiers in comments after recent changes, (continued)
- [nongnu] elpa/raku-mode 3d4a45d644 128/253: No identifiers in comments after recent changes, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 883a60e8ef 127/253: Clean up label pattern, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode c8e8ebe289 150/253: fix the range of choices more completely, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 8319cebe75 147/253: remove imenu item, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode fbac3c871d 196/253: Merge branch 'repl' of github.com:matiaslina/perl6-mode into repl, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 92c9915396 160/253: More fixes for highlighting of angled strings, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode cf8119a28a 184/253: add reference for indentation support, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 5b9c5b29b6 179/253: List link to original author's code, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 8e7ff8d726 193/253: Rename perl6-repl-other-window to perl6-repl, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 0d3df72743 183/253: update capability and plans, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 44faa06bba 197/253: Use comint.,
ELPA Syncer <=
- [nongnu] elpa/raku-mode 9ea05bdb3e 236/253: add future desirable points in mature raku-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode fd54a7b397 231/253: add: font lock for quit, doc and close and delete start, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 155b0b7a4a 249/253: Update CHANGELOG.md, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 20610a83b5 247/253: Merge pull request #53 from phikal/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode fd286b2d1a 246/253: Remove pkg-info dependency, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode a316c3f195 240/253: Remove leftover debugging garbage, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 7dfe01182d 080/253: Highlight reduce operators, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 57a25ccadd 142/253: Remove commented code I accidentally left in, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 7322d74a5d 169/253: Changing to my copy of cask, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode b6cca3307b 203/253: Merge pull request #25 from matiaslina/repl, ELPA Syncer, 2022/01/29