js-comint icon indicating copy to clipboard operation
js-comint copied to clipboard

Send multiline string

Open linktohack opened this issue 2 years ago • 6 comments

Node has special key for multiline string. .editor. The patch bellow will allow you to evaluate all or partial of this code for example

[1, 2, 3]
  .map((it) => it + 1)
  .filter((it) => it > 0)
  .reduce((prev, curr) => prev + curr, 0);
  (el-patch-feature js-comint)

  (with-eval-after-load 'js-comint
    (el-patch-defun js-comint-send-string (str)
      "Send STR to repl."
      (el-patch-swap
	(comint-send-string (js-comint-get-process)
			    (concat str "\n"))
	(let ((lines (string-lines str)))
	  (if (length= lines 1)
	      (comint-send-string (js-comint-get-process)
				  (concat str "\n"))
	    (comint-send-string (js-comint-get-process)
				(concat ".editor" "\n" str "\n"))
	    (process-send-eof (js-comint-get-process)))))))

linktohack avatar Nov 16 '22 10:11 linktohack

Thanks. Could you send me a pull request?

redguardtoo avatar Nov 20 '22 09:11 redguardtoo

Sure, will do

linktohack avatar Nov 22 '22 10:11 linktohack

How can I use .editor to evaluate your example when I'm using js-comint?

SequentialDesign avatar May 04 '23 23:05 SequentialDesign

Hmm, the above didn't work for me, but this did:

[1, 2, 3].
map((it) => it + 1).
filter((it) => it > 0).
reduce((prev, curr) => prev + curr, 0);

SequentialDesign avatar May 05 '23 03:05 SequentialDesign

@SequentialDesign you should try the version here https://github.com/redguardtoo/js-comint/pull/33/files if you're on a version newer than 27.x.

The last PR breaks for me, too https://github.com/redguardtoo/js-comint/pull/33

linktohack avatar Nov 09 '23 17:11 linktohack

After a quick test, I think (I hope!) this should work again with #34

saffroy avatar Nov 09 '23 19:11 saffroy