lua-mode icon indicating copy to clipboard operation
lua-mode copied to clipboard

Fix sending of long code strings to REPL using temporary files (#89)

Open arbv opened this issue 8 years ago • 6 comments

Now we will try to handle long chunk strings (> 500 characters) via temporary files.

arbv avatar Jun 22 '16 20:06 arbv

Is there anything that can be done (besides fixing the merge conflicts) to get this PR merged? I am running into issues with long buffers and would like to see this merged into the main repo.

I am willing to help if anything is needed.

jtecca avatar Mar 31 '18 14:03 jtecca

Hi, please accept my apologies, this PR somehow flew under the radar for me.

I think this feature has to be off by default, because sending via tempfiles won't work over network. Alternatively, it could be on by default for macOS, and off by default otherwise.

Also, could the Lua part be simplified a bit?

  • only protect the part up to parsing the code by pcall, return a callable chunk from that, and then remove the file itself, and then report the error if it failed or execute the chunk if it didn't
  • use assert on io.open to do the same with less code
  • same for f:read although I don't think it returns an error message (does it?)

immerrr avatar Apr 02 '18 08:04 immerrr

I believe this feature should be on by default on Windows too. I made this PR initially because I had problems on Windows.

arbv avatar Apr 05 '18 05:04 arbv

Oh, then I was wrongly under impression that it was about macOS! Then yes, it should be on by default for Windows.

immerrr avatar Apr 05 '18 12:04 immerrr

I just wanted to leave a short note based on my experience with Aquamacs (though I think it's not specific to Aquamacs) and the temporary file code (as posted in 9eddee) which I think needs a fix.

The name of every temporary file written by lua-send-string is added to the recentf-list which soon makes it cluttered with .tmp names and renders the corresponding Open Recent menu unusable. For my usage I modified the code to use the same file repeatedly for the whole session. The other way around is to prevent the temporary file names completely from going into the recent file menu by adding a matching regexp to recentf-exclude (".*/luamode.*\.tmp" should do).

If you think this is an issue that's worth fixing (I personally do think so) leave a comment here. The fix I use is so simple (using a global var to store the name) that I doubt it's worth forking but I can do a fork if you think it's of any use.

vacech avatar Aug 11 '18 20:08 vacech

You could also consider simplifying the part of lua-send-string that sends the command to process the temp file to

(process-send-string
     lua-process
     (format "local tmp = '%s'; local _, e = pcall(function () dofile(tmp) end);
 if e then error(e) end; os.remove(tmp)\n" tmp-file))

which for me seems to work well and inserts way less text into the lua REPL.

vacech avatar Aug 16 '18 14:08 vacech