Previous IDL Interface Guide: Creating Development Environment Macros Next

Building IDL Example Macros

Below are two examples that illustrate how a macro is created in IDL. The first example below is a UNIX-only example; the second example will work on either Microsoft Windows or UNIX.

Creating a Macro to Call a Text Editor in IDL for UNIX

On UNIX platforms, you can create a macro to open a file that is currently open in the IDL Editor in another editor, such as emacs or vi. Use the following procedure to create the macro:

  1. Select Macros Edit menu to bring up the Edit Macros dialog box. You can use this dialog to create, edit, or remove macros.
  2.  

  3. Complete the fields in the Edit Macros dialog:
    • Name: The name that you wish to appear in the Macros list in the Edit Macros dialog. For example, enter Edit in emacs.
    •  

    • Label: The name that you wish to appear on the Macros menu. For example, enter emacs.
    •  

    • Bitmap: The bitmap to use as the toolbar button label. Use the file paths and file name extensions discussed in Bitmaps for Control Panel Buttons.
    •  

    • Status bar text: The text that appears in the status bar when the mouse is help over the menu item or toolbar button.
    •  

    • Tip text: The text for the tool tip that appears when the mouse is held over the toolbar button.
    •  

    • IDL command: The IDL command to execute when the macro is selected. To create a macro for editing in Emacs, enter the following:
    • SPAWN, 'emacs +%L %P &'  
      

       

    • Select the Menu and/or Toolbar checkbox to specify whether the macro will appear in the Macros menu and/or the toolbar.

     

  4. Create the new macro by pressing the Add button. If you entered emacs in the Label field, a new "emacs" macro is added to the Macros list.
  5.  

  6. To add a macro for editing in vi, repeat the above steps, but enter the following in the "IDL command" field:
  7. SPAWN, 'xterm -e vi +%L %P &'  
    


Note
The IDLDE always checks to determine whether the current file has been externally modified before using it. If a file was modified with an external editor, IDLDE notifies you, and asks you to reload the file before using it. You can also use the Revert to Saved option from the File menu to reload the file.

Creating a Macro to Change the Working Directory

The following macro will select and change your current working directory. The steps below describe the fields of the Macros dialog on a Microsoft Windows system, but the macro will work equally well on a UNIX system.

First we will create a .pro file in IDL which will display a platform-specific directory-selection dialog.

  1. From the IDLDE, open a new IDL Editor window by selecting File New Editor.
  2.  

  3. Type (or copy) the following lines of code into the new Editor window to form a program:
  4. PRO cd_test  
    dir = DIALOG_PICKFILE(/DIRECTORY)  
      IF (dir) THEN BEGIN  
        PRINT, 'Changing to: ', dir  
        CD, dir  
      ENDIF  
    END  
    

     

  5. Save the file as cd_test.pro in a directory included in IDL's path. (The file must be in IDL's path so that IDL will find it automatically when the command cd_test is executed by the macro we will create.)
  6.  

  7. Select Macros Edit menu to bring up the Edit Macros dialog box.
  8.  

  9. Click Add to create a new macro. Enter "Change Directories" as the macro name.
  10.  

  11. Complete the following fields in the Edit Macros dialog:
    • Enter "cd_test" in the IDL command field.
    •  

    • Enter "Change Directories" in the Menu item name field.
    •  

    • Leave the Toolbar bitmap file field blank. This macro will appear only in the Macros menu.
    •  

    • Leave the Tooltip text field blank. This value is used only when a toolbar button is present.
    •  

    • Leave the Status bar text field blank. This value is used only when a toolbar button is present.

To use the new macro, select "Change Directories" from the Macros menu.

  IDL Online Help (March 06, 2007)