Trimming Whitespace from the Ends of Lines

Posted by ShayCaron on Thu 28 Sep 2006 05:56 AM — 2 posts, 10,499 views.

USA #0
On a MUSH I frequent, some of the commands return extra whitespace at the ends of the lines, which makes the text wrap strangely on my screen. So I attempted to make a trigger that finds whitespace at the end of a line and omits that whitespace from output and from the log.

Trigger: \s+$
x Omit from log file
x Omit from output
x Regular expression

Unfortunately, that omits the entire *line* from the log/output, which definitely isn't what I need. Any suggestions on how I could get the effect I'm looking for?
Australia Forum Administrator #1
Try installing this small plugin - it filters incoming text, removing trailing spaces before a carriage-return/linefeed:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, September 28, 2006, 5:15 PM -->
<!-- MuClient version 3.80 -->

<!-- Plugin "Trim_White_Space" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Trim_White_Space"
   author="Nick Gammon"
   id="d9e7095fb1062a2504c79118"
   language="Lua"
   purpose="Trims whitespace at end of lines"
   date_written="2006-09-28 17:13:19"
   requires="3.67"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
function OnPluginPacketReceived (s)
  return (string.gsub (s, " +\r?\n", "\n"))
end -- function OnPluginPacketReceived
]]>
</script>


</muclient>



Just save the above text as Trim_White_Space.xml, put it into the plugins directory (in the MUSHclient installation directory), and then use the File -> Plugins to load it.