def add_setting(header, name, value)
      raise DuplicateSetting if setting_exists?(header, name)

      new_setting = %Q{[#{ header }]\n#{ name } = #{ value }\n}
      write do
        if contents.nil?
          new_setting
        elsif contents.scan(header_regexp(header)).empty?
          contents << "\n\n#{ new_setting }"
        else
          contents.gsub(header_regexp(header), new_setting)
        end
      end
    end
def add_setting(header, name, value)
      raise DuplicateSetting if setting_exists?(header, name)

      new_setting = %Q{[#{ header }]\n#{ name } = #{ value }\n}
      write do
        if contents.nil?
          new_setting
        elsif contents.scan(header_regexp(header)).empty?
          contents << "\n\n#{ new_setting }"
        else
          contents.gsub(header_regexp(header), new_setting)
        end
      end
    end
Adds specified setting to a specified section of the config:

  config.add_setting('merge-tools', 'kdiff3.executable', '~/bin/kdiff3')

 will write the following content to hgrc:

  [merge-tools]
  kdiff3.executable = ~/bin/kdiff3