branch: elpa/raku-mode commit b6cca3307b2df98d208967ab5a1bc9b9e705ffbf Merge: 4ed7c06294 2e622f86e0 Author: Altai-man <alexander.kiryu...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #25 from matiaslina/repl Add REPL support --- README.md | 11 ++++++++- perl6-mode.el | 25 +++++++++++++++++++- perl6-repl.el | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7556bd148d..f29a55d074 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ This mode needs GNU Emacs 24.4. * Basic syntax highlighting * Basic indentation * Identifier index menu (variables, subs, classes, etc.) +* REPL interaction #### Planned * Complete syntax highlighting * Better indentation support (uses Emacs SMIE grammar, see the Emacs manual) * Help system -* REPL interaction * ETags support * `find-file-at-point` for module names * Electricity (`electric-pair-mode` needs some context-sensitive help) @@ -58,6 +58,15 @@ This includes any file with `perl6` in the shebang, as well as any file with a `.p6`, `.pm6`, or `.pl6` extension. It also applies to any `.pm`, `.pl`, and `.t` files whose first line of code looks like Perl 6. +Start the REPL with <kbd>M-x run-perl6 RET</kbd>. The following +keybindings are available to interact with the REPL: + +* <kbd>C-c C-c</kbd>: Send the current line to the REPL +* <kbd>C-c C-r</kbd>: Send the selected region to the REPL +* <kbd>C-c C-h</kbd>: Send the whole buffer to the REPL + +The REPL will start if needed with this keybindings. + Use <kbd>M-x customize-group RET perl6</kbd> to customize Perl 6 Mode. ## Contribute diff --git a/perl6-mode.el b/perl6-mode.el index 0e9b6316e9..6cbe1449ce 100644 --- a/perl6-mode.el +++ b/perl6-mode.el @@ -42,6 +42,22 @@ (require 'perl6-font-lock) (require 'perl6-indent) (require 'perl6-imenu) +(require 'perl6-repl) + +(defvar perl6-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-c") 'perl6-send-line-to-repl) + (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'.") + +(easy-menu-define perl6-mode-menu perl6-mode-map + "Menu for `perl6-mode'" + '("Raku" + ["Send line to repl" perl6-send-line-to-repl] + ["Send region to repl" perl6-send-region-to-repl] + ["Send buffer to repl" perl6-send-buffer-to-repl])) ;;;###autoload (define-derived-mode perl6-mode prog-mode "Perl6" @@ -61,11 +77,18 @@ (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) + (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 :forward-token #'perl6-smie--forward-token - :backward-token #'perl6-smie--backward-token)) + :backward-token #'perl6-smie--backward-token) + (use-local-map perl6-mode-map)) + + (provide 'perl6-mode) diff --git a/perl6-repl.el b/perl6-repl.el new file mode 100644 index 0000000000..0dab25cdf6 --- /dev/null +++ b/perl6-repl.el @@ -0,0 +1,73 @@ +;;; perl6-repl -- Repl for support Raku + +;;; Commentary: +;; Basic repl support for Raku + +;;; Code: +(require 'comint) + +(defcustom perl6-exec-path "raku" + "Raku executable path." + :type 'string + :group 'perl6) + +(defcustom perl6-exec-arguments "" + "Raku command line arguments." + :type 'string + :group 'perl6) + +(defvar perl6-prompt-regexp "^> " + "Prompt for `run-perl6'.") + +(defvar perl6-buffer-name "Raku REPL" + "Buffer name for `run-perl6.") + +(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)) + +(defun perl6-send-string-to-repl (str) + "Send STR to the repl." + (comint-send-string (perl6-comint-get-process) + (concat str "\n"))) + +(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 () + "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) + (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