<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on vrijdag, augustus 03, 2007, 2:06  -->
<!-- MuClient version 4.14 -->

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

<!-- Amended slightly by Nick Gammon, from Worstje's version, on 17 Feb 2008 -->

<muclient>
<plugin
   name="Copy_Output"
   author="Worstje"
   id="a0df42a8e796d974f4364245"
   language="Lua"
   purpose="Allows you to use CTRL+C for the output window if 'All typing goes to command window' is turned on."
   save_state="n"
   date_written="2007-08-03 02:04:12"
   requires="4.00"
   version="1.0"
   >

</plugin>

<aliases>
  <alias
    match="^Copy_Output:Copy:1bb75c016bc3e2b9d4c292db$"
    enabled="y"
    regexp="y"
    omit_from_output="y"
    sequence="100"
    script="CopyScript"
  >
  </alias>
</aliases>


<!--  Script  -->

<script>
<![CDATA[

-- Thank you, Shaun Biggs, for taking your time to write the CopyScript
-- (formerly Copy2) function below. It was slightly altered by me to suit
-- my usage (wordwrapped lines and no \r\n at start of selection).

-- See forum: http://www.gammon.com.au/forum/bbshowpost.php?id=8052

-- some long alias that no-one will ever want to type
Accelerator ("Ctrl+C", "Copy_Output:Copy:1bb75c016bc3e2b9d4c292db")

function CopyScript(name, line, wildcs)

  -- find selection in output window, if any
  local first_line, last_line = GetSelectionStartLine(), 
                                math.min (GetSelectionEndLine(), GetLinesInBufferCount ())

  local first_column, last_column = GetSelectionStartColumn(), GetSelectionEndColumn()
  
  -- nothing selected, do normal copy
  if first_line <= 0 then
    DoCommand("copy")
    return
  end -- if nothing to copy from output window
  
  local copystring = ""
  
  -- iterate to build up copy text
  for line = first_line, last_line do
  
    if line < last_line then
      copystring = copystring .. GetLineInfo(line).text:sub (first_column)  -- copy rest of line
      first_column = 1
      
      -- Is this a new line or merely the continuation of a paragraph?
      if GetLineInfo (line, 3) then
        copystring = copystring .. "\r\n"
      end  -- new line
      
    else
      copystring = copystring .. GetLineInfo(line).text:sub (first_column, last_column - 1)
    end -- if
        
  end  -- for loop
  
  -- Get rid of a spurious extra new line at the start.
  if copystring:sub (1, 2) == "\r\n" then
    copystring = copystring:sub (3)
  end   -- if newline at start
  
  -- finally can set clipboard contents
  SetClipboard(copystring)
  
end -- function CopyScript
]]>
</script>

</muclient>