Skip to content

Commit

Permalink
Fix ts-load-file.
Browse files Browse the repository at this point in the history
Refactor code. Improve code-reuse. DRY things up.
  • Loading branch information
josteink committed Oct 6, 2016
1 parent 65a2a08 commit 83e27cb
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ts-comint.el
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,20 @@ prevent switching to the new buffer once created."
(replace-regexp-in-string "\033\\[[0-9]+[GKJ]" "" output))))
(setenv "NODE_NO_READLINE" "1")))

;;;###autoload
(defun ts-send-string (text)
"Send `TEXT' to the inferior Typescript process."
(interactive "r")
(run-ts ts-comint-program-command t)
(comint-send-string (get-buffer-process ts-comint-buffer)
(concat text "\n")))

;;;###autoload
(defun ts-send-region (start end)
"Send the current region to the inferior Typescript process."
(interactive "r")
(let ((text (buffer-substring-no-properties start end)))
(run-ts ts-comint-program-command t)
(comint-send-string (get-buffer-process ts-comint-buffer)
(concat text "\n"))))
(ts-send-string text)))

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

;;;###autoload
(defun ts-load-file-and-go (filename)
"Load file `FILENAME' in the Typescript interpreter."
(interactive "f")
(let ((filename (expand-file-name filename)))
(run-ts ts-comint-program-command t)
(comint-send-string ts-comint-buffer (ts--get-load-file-cmd filename))
(switch-to-ts ts-comint-buffer)))
(ts-load-file filename)
(switch-to-ts ts-comint-buffer))

;;;###autoload
(defun switch-to-ts (eob-p)
Expand Down

0 comments on commit 83e27cb

Please sign in to comment.