Defining a new input format I need to define a new input format programmatically, probably as part of my module's hook_install().  I need to write code that duplicates the manual operations described on http://drupal.org/node/778976.

I have not been able to learn how to do this. Any pointers in the right direction will be appreciated.
Code from standard Drupal profile is your friend: http://drupalcode.org/project/drupal.git/blob/c5d6e6334fb7a71ecf1dbc7e06a7de8ad9547b27:/profiles/standard/standard.install#l14

  // Add text formats.
  $filtered_html_format = array(
    'format' =&gt; 'filtered_html',
    'name' =&gt; 'Filtered HTML',
    'weight' =&gt; 0,
    'filters' =&gt; array(
      // URL filter.
      'filter_url' =&gt; array(
        'weight' =&gt; 0,
        'status' =&gt; 1,
      ),
      // HTML filter.
      'filter_html' =&gt; array(
        'weight' =&gt; 1,
        'status' =&gt; 1,
      ),
      // Line break filter.
      'filter_autop' =&gt; array(
        'weight' =&gt; 2,
        'status' =&gt; 1,
      ),
      // HTML corrector filter.
      'filter_htmlcorrector' =&gt; array(
        'weight' =&gt; 10,
        'status' =&gt; 1,
      ),
    ),
  );
  $filtered_html_format = (object) $filtered_html_format;
  filter_format_save($filtered_html_format);


Enable permission for system roles (code):

// Enable default permissions for system roles.
$filtered_html_permission = filter_permission_name($filtered_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array($filtered_html_permission));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($filtered_html_permission));
user_role_grant_permissions(variable_get('user_admin_role', 0), array($filtered_html_permission));