-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
racket-shell.el
89 lines (69 loc) · 2.68 KB
/
racket-shell.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
;;; racket-shell.el -*- lexical-binding: t -*-
;; Copyright (c) 2022 by Greg Hendershott.
;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc.
;; Author: Greg Hendershott
;; URL: https://github.com/greghendershott/racket-mode
;; SPDX-License-Identifier: GPL-3.0-or-later
(require 'racket-custom)
(require 'racket-util)
(require 'shell)
(require 'term)
(defun racket-racket ()
"Use command-line racket to run the file.
Uses a shell or terminal buffer as specified by the configuration
variable `racket-shell-or-terminal-function'."
(interactive)
(racket--shell-or-terminal
(concat (shell-quote-argument (racket--buffer-file-name)))))
(defun racket-raco-test ()
"Use command-line raco test to run the \"test\" submodule.
Uses a shell or terminal buffer as specified by the configuration
variable `racket-shell-or-terminal-function'."
(interactive)
(racket--shell-or-terminal
(concat "-l raco test -x "
(shell-quote-argument (racket--buffer-file-name)))))
(defun racket--shell-or-terminal (args)
(racket--save-if-changed)
(let* ((exe (shell-quote-argument
(if (file-name-absolute-p racket-program)
(expand-file-name racket-program) ;handle e.g. ~/
racket-program)))
(cmd (concat exe " " args))
(win (selected-window)))
(funcall racket-shell-or-terminal-function cmd)
(select-window win)))
(defun racket-shell (cmd)
"Run CMD using `shell'.
A value for the variable `racket-shell-or-terminal-function'."
(let ((buf (shell)))
(comint-simple-send buf cmd)))
(defun racket-term (cmd)
"Run CMD using `term'.
A value for the variable `racket-shell-or-terminal-function'."
(let ((buf (term (or explicit-shell-file-name
(getenv "ESHELL")
(getenv "SHELL")
"/bin/sh"))))
(term-simple-send buf cmd)))
(defun racket-ansi-term (cmd)
"Run CMD using `ansi-term'.
A value for the variable `racket-shell-or-terminal-function'."
(let ((buf (ansi-term (or explicit-shell-file-name
(getenv "ESHELL")
(getenv "SHELL")
"/bin/sh"))))
(term-simple-send buf cmd)))
(declare-function vterm "ext:vterm")
(declare-function vterm-send-return "ext:vterm")
(declare-function vterm-send-string "ext:vterm")
(defun racket-vterm (cmd)
"Run CMD using `vterm', if that package is installed.
A value for the variable `racket-shell-or-terminal-function'."
(unless (require 'vterm nil 'noerror)
(error "Package 'vterm' is not available"))
(vterm)
(vterm-send-string cmd)
(vterm-send-return))
(provide 'racket-shell)
;; racket-shell.el ends here