-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathraku-repl.el
96 lines (82 loc) · 2.98 KB
/
raku-repl.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; raku-repl -- Repl for support Raku
;;; Commentary:
;; Basic repl support for Raku
;;; Code:
(require 'comint)
(require 'raku-font-lock)
(defcustom raku-exec-path "raku"
"Raku executable path."
:type 'string
:group 'raku)
(defcustom raku-exec-arguments ""
"Raku command line arguments."
:type 'string
:group 'raku)
(defvar raku-prompt-regexp "^> "
"Prompt for `run-raku'.")
(defvar raku-buffer-name "Raku REPL"
"Buffer name for `run-raku.")
(define-derived-mode raku-repl-mode comint-mode "Raku"
"Major mode for `run-raku'."
;; Set up the prompt and make it read only.
(setq-local comint-prompt-regexp raku-prompt-regexp)
(setq-local comint-prompt-readonly t)
;; See raku-mode.el.
(setq-local syntax-propertize-function #'raku-syntax-propertize)
(add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil 'local)
(setq-local font-lock-syntactic-face-function #'raku-font-lock-syntactic-face)
(setq-local font-lock-defaults '(raku-font-lock-keywords nil nil))
(add-hook 'raku-mode-hook 'imenu-add-menubar-index)
(setq imenu-generic-expression raku-imenu-generic-expression
imenu-case-fold-search nil)
(setq-local comment-start "#")
(setq-local comment-start-skip "#+ *")
(setq-local comment-use-syntax t)
(setq-local comment-end "")
;; Don't jump beyond the prompt with M-{ or M-}.
(setq-local paragraph-start raku-prompt-regexp))
(defun run-raku ()
"Run an inferior instance of `raku' inside Emacs."
(interactive)
(let* ((raku-program raku-exec-path)
(check-proc (comint-check-proc raku-buffer-name))
(buffer (apply 'make-comint-in-buffer
raku-buffer-name
check-proc
raku-exec-path
'()
(split-string raku-exec-arguments))))
(with-current-buffer buffer
(raku-repl-mode))
(display-buffer buffer)))
(defun raku-comint-get-process ()
"Raku process name."
(get-process raku-buffer-name))
(defun raku-send-string-to-repl (str)
"Send STR to the repl."
(comint-send-string (raku-comint-get-process)
(concat str "\n")))
(defun raku-send-line-to-repl ()
"Send a line to the repl."
(interactive)
(run-raku)
(let ((str (buffer-substring-no-properties (line-beginning-position) (line-end-position))))
(raku-send-string-to-repl str)))
(defun raku-send-region-to-repl ()
"Send a region to the repl."
(interactive)
(run-raku)
(if (region-active-p)
(let ((buf (buffer-substring-no-properties (region-beginning)
(region-end))))
(raku-send-string-to-repl buf))
(message "No region selected")))
(defun raku-send-buffer-to-repl ()
"Send a buffer to the repl."
(interactive)
(run-raku)
(let ((buf (buffer-substring-no-properties (point-min)
(point-max))))
(raku-send-string-to-repl buf)))
(provide 'raku-repl)
;;; raku-repl.el ends here