Copy and pasting lines with \n into prompt

Posted by Artel on Sun 06 Jul 2008 01:07 AM — 5 posts, 20,230 views.

USA #0
When using my mud's note system, I frequently use a external text editor to type longer messages. I intentionally set that text editor to treat newlines as \n instead of \r\n (because I even though I use a Windows machine, I frequently work with source code that comes from Linux developers and servers.) However, when I copy and paste stuff from the text editor to the MUSHclient prompt, all of the newlines show up as little squares instead of newlines. If it's not too difficult, it would be nice to have them show up as newlines.

Also, the same issue occurs when using \r instead of \r\n.

Using MUSHclient 4.30.
Australia Forum Administrator #1
It is a bit fiddly to do that, because the command window is an edit control, and I don't get notified when you paste into it. However you can run the (Lua) script below (eg. at world open time):


AcceleratorTo ("F8", [[ do 
local line = GetCommand ()
line = string.gsub (line, "\r\n", "\n")
line = string.gsub (line, "\r", "\n")
line = string.gsub (line, "\n", "\r\n")
PushCommand ()
SetCommand (line)
end
]], sendto.script)


Then once you have pasted some problem code into the command window, hit F8 and it will be fixed.

What it does is:

  • Gets the command window contents
  • Converts \r\n (normal DOS line endings) into straight \n
  • Converts \r (Mac line endings) into \n
  • Converts the resulting \n endings into normal DOS endings: \r\n
  • Puts it back into the command window.


Australia Forum Administrator #2
The other option is to use MUSHclient's internal text editor. Amongst other things it has an option to convert line endings (see Convert menu).
USA #3
Thank you Nick, the Lua script method will work for me.

Is there a way to make it auto run whenever I open any world? Or is the best way to just make this script a plugin and add it to all of my world?
Australia Forum Administrator #4
For any world, make it a plugin, and then add that to Global Options -> Plugins, and make that a default plugin to load.