Skip to content

Commit 83e27cb

Browse files
committed
Fix ts-load-file.
Refactor code. Improve code-reuse. DRY things up.
1 parent 65a2a08 commit 83e27cb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ts-comint.el

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,20 @@ prevent switching to the new buffer once created."
150150
(replace-regexp-in-string "\033\\[[0-9]+[GKJ]" "" output))))
151151
(setenv "NODE_NO_READLINE" "1")))
152152

153+
;;;###autoload
154+
(defun ts-send-string (text)
155+
"Send `TEXT' to the inferior Typescript process."
156+
(interactive "r")
157+
(run-ts ts-comint-program-command t)
158+
(comint-send-string (get-buffer-process ts-comint-buffer)
159+
(concat text "\n")))
160+
153161
;;;###autoload
154162
(defun ts-send-region (start end)
155163
"Send the current region to the inferior Typescript process."
156164
(interactive "r")
157165
(let ((text (buffer-substring-no-properties start end)))
158-
(run-ts ts-comint-program-command t)
159-
(comint-send-string (get-buffer-process ts-comint-buffer)
160-
(concat text "\n"))))
166+
(ts-send-string text)))
161167

162168
;;;###autoload
163169
(defun ts-send-region-and-go (start end)
@@ -206,17 +212,14 @@ prevent switching to the new buffer once created."
206212
"Load file `FILENAME' in the Typescript interpreter."
207213
(interactive "f")
208214
(let ((filename (expand-file-name filename)))
209-
(run-ts ts-comint-program-command t)
210-
(comint-send-string ts-comint-buffer (ts--get-load-file-cmd filename))))
215+
(ts-send-string (ts--get-load-file-cmd filename))))
211216

212217
;;;###autoload
213218
(defun ts-load-file-and-go (filename)
214219
"Load file `FILENAME' in the Typescript interpreter."
215220
(interactive "f")
216-
(let ((filename (expand-file-name filename)))
217-
(run-ts ts-comint-program-command t)
218-
(comint-send-string ts-comint-buffer (ts--get-load-file-cmd filename))
219-
(switch-to-ts ts-comint-buffer)))
221+
(ts-load-file filename)
222+
(switch-to-ts ts-comint-buffer))
220223

221224
;;;###autoload
222225
(defun switch-to-ts (eob-p)

0 commit comments

Comments
 (0)