Skip to content

Commit f5ce3d5

Browse files
committed
Merge branch 'release/0.2.4'
2 parents 492e0d7 + d5f925b commit f5ce3d5

3 files changed

Lines changed: 48 additions & 14 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11+
timeout-minutes: 10
1112
strategy:
1213
fail-fast: false
1314
matrix:
1415
emacs-version:
15-
- '24.5'
16-
- '25.1'
17-
- '25.2'
1816
- '25.3'
1917
- '26.1'
2018
- '26.2'

nodejs-repl.el

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Copyright (C) 2012-2020 Takeshi Arabiki
44

55
;; Author: Takeshi Arabiki
6-
;; Version: 0.2.3
6+
;; Version: 0.2.4
77

88
;; This program is free software: you can redistribute it and/or modify
99
;; it under the terms of the GNU General Public License as published by
@@ -22,9 +22,10 @@
2222
;;
2323
;; This program is derived from comint-mode and provides the following features.
2424
;;
25-
;; * TAB completion same as Node.js REPL
25+
;; * token completion, same as Node.js REPL
2626
;; * file name completion in string
2727
;; * incremental history search
28+
;; * sending JavaScript codes to REPL
2829
;;
2930
;;
3031
;; Put this file in your Emacs lisp path (e.g. ~/.emacs.d/site-lisp)
@@ -40,6 +41,7 @@
4041
;; (add-hook 'js-mode-hook
4142
;; (lambda ()
4243
;; (define-key js-mode-map (kbd "C-x C-e") 'nodejs-repl-send-last-expression)
44+
;; (define-key js-mode-map (kbd "C-c C-j") 'nodejs-repl-send-line)
4345
;; (define-key js-mode-map (kbd "C-c C-r") 'nodejs-repl-send-region)
4446
;; (define-key js-mode-map (kbd "C-c C-l") 'nodejs-repl-load-file)
4547
;; (define-key js-mode-map (kbd "C-c C-z") 'nodejs-repl-switch-to-repl)))
@@ -73,7 +75,7 @@
7375
"Run Node.js REPL and communicate the process."
7476
:group 'processes)
7577

76-
(defconst nodejs-repl-version "0.2.3"
78+
(defconst nodejs-repl-version "0.2.4"
7779
"Node.js mode Version.")
7880

7981
(defcustom nodejs-repl-command "node"
@@ -223,7 +225,7 @@ See also `comint-process-echoes'"
223225
(not
224226
(let ((last-line (process-get proc 'last-line)))
225227
(or (string-match-p nodejs-repl-prompt-re last-line)
226-
(string= last-line string)))))
228+
(string-prefix-p string last-line)))))
227229
(process-put proc 'running-p nil)
228230
(accept-process-output proc interval)))
229231

@@ -308,7 +310,9 @@ when receive the output string"
308310

309311
(defun nodejs-repl--delete-prompt (string)
310312
;; Redundant prompts are included in outputs from Node.js REPL
311-
(when nodejs-repl-prompt-deletion-required-p
313+
(when (and nodejs-repl-prompt-deletion-required-p
314+
;; To avoid end-of-buffer error at the line of (forward-char (length nodejs-repl-prompt))
315+
(> (buffer-size) 0))
312316
(setq nodejs-repl-prompt-deletion-required-p nil)
313317
(let ((beg (or comint-last-output-start
314318
(point-min-marker)))
@@ -455,9 +459,7 @@ when receive the output string"
455459
;; See: https://github.com/abicky/nodejs-repl.el/issues/17
456460
(comint-send-string proc ".editor\n")
457461
(comint-send-region proc start end)
458-
(comint-send-string proc "\n")
459-
(with-current-buffer (process-buffer proc)
460-
(comint-send-eof))))
462+
(comint-send-string proc "\n\x04")))
461463

462464
;;;###autoload
463465
(defun nodejs-repl-send-buffer ()

test/test.el

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
(require 'nodejs-repl)
12
(require 'ert-expectations)
23

4+
(nodejs-repl)
5+
36
(expectations
47
(desc "run Node.js REPL")
5-
(expect nil
6-
(require 'nodejs-repl)
8+
(expect nodejs-repl-prompt
79
;; TODO: set adjust window width (candidates will change according to the width)
810
;;(adjust-window-trailing-edge (selected-window) (- 100 (window-width)) t)
9-
(nodejs-repl))
11+
(with-current-buffer (process-buffer (nodejs-repl--get-or-create-process))
12+
(with-timeout (10 (error "timeout"))
13+
(while (equal (buffer-string) "")
14+
(sleep-for 0.1))
15+
(buffer-string))))
1016

1117
(desc "nodejs-repl--get-last-token")
1218
(expect "$._foo0"
@@ -35,6 +41,34 @@
3541
(ansi-color-filter-apply i-value)
3642
(ansi-color-filter-apply return-value))))
3743

44+
(desc "nodejs-repl-send-region")
45+
(expect t
46+
(let* ((proc (nodejs-repl--get-or-create-process))
47+
(buf (process-buffer proc)))
48+
;; Emulate the case of https://github.com/abicky/nodejs-repl.el/issues/31
49+
(comint-send-string proc "1\n")
50+
(with-current-buffer buf
51+
(with-timeout (10 (error "timeout"))
52+
(while (not (string-suffix-p "> 1\n1\n> " (ansi-color-filter-apply (buffer-string))))
53+
(sleep-for 0.1))))
54+
(with-current-buffer (process-buffer (nodejs-repl--get-or-create-process))
55+
(goto-char (point-min)))
56+
57+
(with-temp-buffer
58+
(insert "2")
59+
(nodejs-repl-send-region (point-min) (point-max)))
60+
(with-current-buffer buf
61+
(with-timeout (10 (error "timeout"))
62+
(while (string-suffix-p "> 1\n1\n> " (ansi-color-filter-apply (buffer-string)))
63+
(sleep-for 0.1)))
64+
;; > .editor
65+
;; // Entering editor mode (^D to finish, ^C to cancel)
66+
;; 2
67+
;;
68+
;; 2
69+
;; >
70+
(string-suffix-p "2\n\n2\n> " (ansi-color-filter-apply (buffer-string))))))
71+
3872
(desc "nodejs-repl-execute")
3973
(expect "2\n"
4074
(nodejs-repl-execute "1 +\n1")

0 commit comments

Comments
 (0)