2
2
3
3
; ;; Copyright (C) 2008 Paul Huff
4
4
; ;; Copyright (C) 2015 Stefano Mazzucco
5
+ ; ;; Copyright (C) 2016 Jostein Kjønigsen
5
6
6
7
; ;; Author: Paul Huff <paul.huff@gmail.com>, Stefano Mazzucco <MY FIRST NAME - AT - CURSO - DOT - RE>
7
- ; ;; Maintainer: Chen Bin <chenbin.sh AT gmail DOT com>
8
- ; ;; Created: 15 Feb 2014
9
- ; ;; Version: 0.0.5
8
+ ; ;; Created: 28 September 2016
9
+ ; ;; Version: 0.0.1
10
10
; ;; URL: https://github.com/josteink/ts-comint
11
11
; ;; Package-Requires: ()
12
12
; ;; Keywords: javascript, node, inferior-mode, convenience
37
37
; ;; Commentary:
38
38
39
39
; ; ts-comint.el is a comint mode for Emacs which allows you to run a
40
- ; ; compatible javascript repl like Node.js/Spidermonkey/Rhino inside Emacs.
41
- ; ; It also defines a few functions for sending javascript input to it
40
+ ; ; compatible typescript repl like Tsun inside Emacs.
41
+ ; ; It also defines a few functions for sending typescript input to it
42
42
; ; quickly.
43
43
44
44
; ; Usage:
48
48
; ; Do: `M-x run-ts'
49
49
; ; Away you go.
50
50
51
- ; ; If you have nvm, you can select the versions of node.js installed and run
52
- ; ; them. This is done thanks to nvm.el.
53
- ; ; Please note nvm.el is optional. So you need *manually* install it.
54
- ; ; To enable nvm support, run `ts-do-use-nvm' .
55
- ; ; The first time you start the JS interpreter with run-ts, you will be asked
56
- ; ; to select a version of node.js
57
- ; ; If you want to change version of node js, run `ts-select-node-version'
58
-
59
51
; ; You can add the following couple of lines to your .emacs to take advantage of
60
52
; ; cool keybindings for sending things to the javascript interpreter inside
61
53
; ; of Steve Yegge's most excellent js2-mode.
62
54
; ;
63
- ; ; (add-hook 'js2 -mode-hook
55
+ ; ; (add-hook 'typescript -mode-hook
64
56
; ; (lambda ()
65
57
; ; (local-set-key (kbd "C-x C-e") 'ts-send-last-sexp)
66
58
; ; (local-set-key (kbd "C-M-x") 'ts-send-last-sexp-and-go)
81
73
:group 'inferior-ts )
82
74
83
75
(defcustom inferior-ts-program-arguments nil
84
- " List of command line arguments to pass to the JavaScript interpreter."
76
+ " List of command line arguments to pass to the Typescript interpreter."
85
77
:group 'inferior-ts )
86
78
87
79
(defcustom inferior-ts-mode-hook nil
88
80
" *Hook for customizing inferior-ts mode."
89
81
:type 'hook
90
82
:group 'inferior-ts )
91
83
84
+ (defcustom inferior-ts-mode-ansi-color t
85
+ " Use ansi-colors for inferior Typescript mode."
86
+ :group 'inferior-ts )
92
87
93
88
(defvar inferior-ts-buffer nil
94
- " Name of the inferior JavaScript buffer." )
89
+ " Name of the inferior Typescript buffer." )
95
90
96
91
(defvar ts-prompt-regexp " ^\\ (?:> \\ )"
97
92
" Prompt for `run-ts' ." )
98
93
99
94
100
- (defun ts-list-nvm-versions (prompt )
101
- " List all available node versions from nvm prompting the user with PROMPT.
102
- Return a string representing the node version."
103
- (let ((candidates (sort (mapcar 'car (nvm--installed-versions)) 'string< )))
104
- (completing-read prompt
105
- candidates nil t nil
106
- nil
107
- (car candidates))))
108
95
;;;### autoload
109
- (defun ts-do-use-nvm ()
110
- " Enable nvm."
111
- (setq ts-use-nvm t ))
112
-
113
96
(defun ts--is-nodejs ()
114
97
(string= " node"
115
98
(substring-no-properties inferior-ts-program-command -4 nil )))
@@ -123,8 +106,8 @@ Return a string representing the node version."
123
106
124
107
;;;### autoload
125
108
(defun run-ts (cmd &optional dont-switch-p )
126
- " Run an inferior Javascript process, input and output via buffer `*js *' .
127
- If there is a process already running in `*js *' , switch to that buffer.
109
+ " Run an inferior Typescript process, input and output via buffer `*ts *' .
110
+ If there is a process already running in `*ts *' , switch to that buffer.
128
111
With argument, allows you to edit the command line (default is value
129
112
of `inferior-ts-program-command' ).
130
113
Runs the hook `inferior-ts-mode-hook' \( after the `comint-mode-hook'
@@ -144,26 +127,41 @@ is run).
144
127
(setq inferior-ts-program-arguments (split-string cmd))
145
128
(setq inferior-ts-program-command (pop inferior-ts-program-arguments)))))
146
129
147
- (if (not (comint-check-proc " *js *" ))
130
+ (if (not (comint-check-proc " *ts *" ))
148
131
(with-current-buffer
149
- (apply 'make-comint " js " inferior-ts-program-command
132
+ (apply 'make-comint " ts " inferior-ts-program-command
150
133
nil inferior-ts-program-arguments)
151
134
(inferior-ts-mode)))
152
- (setq inferior-ts-buffer " *js *" )
135
+ (setq inferior-ts-buffer " *ts *" )
153
136
(if (not dont-switch-p)
154
- (pop-to-buffer " *js*" )))
137
+ (pop-to-buffer " *ts*" ))
138
+
139
+ ; ; apply terminal preferences
140
+ (if inferior-ts-mode-ansi-color
141
+ (progn
142
+ ; ; based on
143
+ ; ; http://stackoverflow.com/questions/13862471/using-node-ts-with-ts-comint-in-emacs
144
+
145
+ ; ; We like nice colors
146
+ (ansi-color-for-comint-mode-on )
147
+ ; ; Deal with some prompt nonsense
148
+ (add-to-list
149
+ 'comint-preoutput-filter-functions
150
+ (lambda (output )
151
+ (replace-regexp-in-string " \0 33\\ [[0-9]+[GKJ]" " " output))))
152
+ (setenv " NODE_NO_READLINE" " 1" )))
155
153
156
154
;;;### autoload
157
155
(defun ts-send-region (start end )
158
- " Send the current region to the inferior Javascript process."
156
+ " Send the current region to the inferior Typescript process."
159
157
(interactive " r" )
160
158
(run-ts inferior-ts-program-command t )
161
159
(comint-send-region inferior-ts-buffer start end)
162
160
(comint-send-string inferior-ts-buffer " \n " ))
163
161
164
162
;;;### autoload
165
163
(defun ts-send-region-and-go (start end )
166
- " Send the current region to the inferior Javascript process."
164
+ " Send the current region to the inferior Typescript process."
167
165
(interactive " r" )
168
166
(run-ts inferior-ts-program-command t )
169
167
(comint-send-region inferior-ts-buffer start end)
@@ -172,7 +170,7 @@ is run).
172
170
173
171
;;;### autoload
174
172
(defun ts-send-last-sexp-and-go ()
175
- " Send the previous sexp to the inferior Js process."
173
+ " Send the previous sexp to the inferior Typescript process."
176
174
(interactive )
177
175
(ts-send-region-and-go
178
176
(save-excursion
@@ -183,7 +181,7 @@ is run).
183
181
184
182
;;;### autoload
185
183
(defun ts-send-last-sexp ()
186
- " Send the previous sexp to the inferior Javascript process."
184
+ " Send the previous sexp to the inferior Typescript process."
187
185
(interactive )
188
186
(ts-send-region
189
187
(save-excursion
@@ -194,14 +192,14 @@ is run).
194
192
195
193
;;;### autoload
196
194
(defun ts-send-buffer ()
197
- " Send the buffer to the inferior Javascript process."
195
+ " Send the buffer to the inferior Typescript process."
198
196
(interactive )
199
197
(ts-send-region (point-min ) (point-max )))
200
198
201
199
202
200
;;;### autoload
203
201
(defun ts-send-buffer-and-go ()
204
- " Send the buffer to the inferior Javascript process."
202
+ " Send the buffer to the inferior Typescript process."
205
203
(interactive )
206
204
(ts-send-region-and-go (point-min ) (point-max )))
207
205
@@ -241,7 +239,7 @@ With argument, position cursor at end of buffer."
241
239
m))
242
240
243
241
;;;### autoload
244
- (define-derived-mode inferior-ts-mode comint-mode " Inferior Javascript "
242
+ (define-derived-mode inferior-ts-mode comint-mode " Inferior Typescript "
245
243
" Major mode for interacting with an inferior javascript process.
246
244
247
245
The following commands are available:
@@ -252,25 +250,13 @@ A typescript process can be fired up with M-x run-ts.
252
250
Customization: Entry to this mode runs the hooks on comint-mode-hook and
253
251
inferior-ts-mode-hook (in that order).
254
252
255
- You can send text to the inferior Javascript process from other buffers containing
256
- Javascript source.
257
- switch-to-js switches the current buffer to the Javascript process buffer.
258
- ts-send-region sends the current region to the Javascript process.
253
+ You can send text to the inferior Typescript process from other buffers containing
254
+ Typescript source.
255
+ switch-to-js switches the current buffer to the Typescript process buffer.
256
+ ts-send-region sends the current region to the Typescript process.
259
257
"
260
258
:group 'inferior-ts
261
259
(use-local-map inferior-ts-mode-map))
262
260
263
- ; ; based on
264
- ; ; http://stackoverflow.com/questions/13862471/using-node-ts-with-ts-comint-in-emacs
265
- (setq inferior-ts-mode-hook
266
- (lambda ()
267
- ; ; We like nice colors
268
- (ansi-color-for-comint-mode-on )
269
- ; ; Deal with some prompt nonsense
270
- (add-to-list
271
- 'comint-preoutput-filter-functions
272
- (lambda (output )
273
- (replace-regexp-in-string " \0 33\\ [[0-9]+[GKJ]" " " output)))))
274
-
275
261
(provide 'ts-comint )
276
262
; ;; ts-comint.el ends here
0 commit comments