Welcome Guest.   Make a donation to an author on the site August 28, 2014, 10:18:38 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Your Support Funds this Site: View the Supporter Yearbook.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: A Macro+Tool config for ultraedit for procesing blocks of text externally  (Read 8024 times)
mouser
First Author
Administrator
*****
Posts: 33,279



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« on: July 11, 2005, 02:09:19 PM »

Here is the combination of MACRO and TOOL that i use to let me select a block of text in a file and process it by an external exe program, capture the output and paste it back replacing the originally selected text.
The key feature of this technique is that it allows you to use an easy undo to undo the change (Ctrl+Z) and preserves your place in the file after the operation.
The sample tool below runs the open source Astyle exe (C++ coder formatter) on the selected block, and is configured to implement whitesmith style c++ indentation (http://en.wikipedia.org/w...t_style#Whitesmiths_style), which i love.

MyAstyle MACRO
-------------------------
[copy or print]
InsertMode
ColumnModeOff
HexOff
UnixReOff
Copy
NewFile
Paste
SaveAs "C:\Temp\Astyle.tmp"
CloseFile
RunTool "MyAstyle"
Open "C:\Temp\Astyle.tmp"
SelectAll
Copy
CloseFile
ToggleBookmark
Paste
Open "C:\Temp\Astyle.tmp.orig"
SelectAll
Copy
CloseFile
PreviousBookmarkSelect
ToggleBookmark



MyAstyle TOOL Configuration:
-----------------------------
[copy or print]
COMMANDLINE -> D:\Libraries\astyle\astyle.exe --mode=c --indent-brackets --brackets=break --indent=tab --one-line=keep-blocks --one-line=keep-statements C:\Temp\Astyle.tmp
WORKINGDIR  -> C:\Temp\
MENUITEMNAME-> MyAstyle
DONT CHECK "CAPTURE OUTPUT" - this has the exe write output to a file.

if your exe outputs to stdout, then you should check "capture output" and modify the macro and remove the lines from the first Open to the subsequent Closefile.
« Last Edit: July 11, 2005, 02:13:28 PM by mouser » Logged
Jussi Jumppanen
Member
**
Posts: 35

View Profile Give some DonationCredits to this forum member
« Reply #1 on: September 12, 2005, 10:16:37 PM »

Here is the combination of MACRO and TOOL that i use to let me select a block of text in a file and process it by an external exe program, capture the output and paste it back replacing the originally selected text.

Just out of curiosity I whippped up this Zeus Lua macro which performs the same task smiley

[copy or print]
--
--        Name: Astyle Macro
--      Author: Jussi Jumppanen
--    Language: Lua Macro
-- Description: A simple Lua macro that takes the currently selected
--              text, saves it to the c:\temp\astlye.tmp file, runs it
--              through the astyle.exe utility, then pastes the result
--              back into the cdocument.
--
--  How To Run: Save to style.lua in the zScript directory.
--
--              All Zeus macros can be run using the macro execute menu
--              item or they can be bound to the keyboard or can be
--              attached to the macro drop down or popup menus.
--
function key_macro()
  -- macro only works for read/write documents
  if is_read_only() == 1 then
    message("The current document is marked as read only!")
    beep()
    return
  end

  -- macro needs some marked text
  if (is_marked() == 0) then
    message("To use this macro you need to first mark some text.")
    beep()
    return 1
  end

  -- get the current marked text
  local marked_text = macro_tag("$M")

  -- file that will be created
  local file_name = "c:\\temp\\astyle.tmp"

  -- open the temp file in binary write mode
  local file_out = io.open(file_name, "w+b")

  if file_out ~= nil then
    -- write the text to file
    file_out:write(marked_text)
    file_out:close()

    -- command line to be run
    local command = "astyle.exe --mode=c --indent-brackets --brackets=break --indent=tab --one-line=keep-blocks --one-line=keep-statements " ..  file_name

    -- command options: wait for tool to finish
    local flags = 32

    -- run command which should display a DOS window
    if system(command , 0, flags) == 0 then
       -- open the temp file in text reading mode
       local file_in = io.open(file_name, "r+t")

       if file_in ~= nil then
          local result = ""

          -- read in the file
          for line in file_in:lines() do
            result = result .. line .. "\r\n"
          end

          -- close the input
          file_in:close()

          -- add the result to the clipboard
          set_clipboard_text(result)

          -- paste the result into the document deleting the original text
          MarkPaste()
      else
        -- failed to open file
        message_box(1, "Error opening the '" .. file_name .. "' results file.")
      end
    else
      -- failed to run tool
      message_box(1, command .. "\nError running program!'")
    end
  else
    -- failed to create file
    message_box(1, "Error creating the '" .. file_name .. "' file.")
  end
end

key_macro()
« Last Edit: September 15, 2005, 05:54:31 PM by Jussi Jumppanen » Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.031s | Server load: 0.13 ]