"""
Utilities and common tasks for wrapping the GMT modules.
"""

GMT_DOCS = 'http://gmt.soest.hawaii.edu/doc/latest'


def gmt_docs_link(module_func):
    """
    Add to a module docstring a link to the GMT docs for that module.

    The docstring must have the placeholder ``{gmt_mod}`` where you want the
    link to appear.

    Assumes that the name of the GMT module is the same as the function name.

    Use this function as a decorator for the module functions.

    Parameters
    ----------
    module_func : function
        The module function. Must have the same name as the GMT module.

    Returns
    -------
    module_func
        The same *module_func* but with the link inserted into the docstring.


    Examples
    --------

    >>> @gmt_docs_link
    ... def psconvert(**kwargs):
    ...     "Full docs at {gmt_mod}"
    ...     pass
    >>> print(psconvert.__doc__)
    Full docs at http://gmt.soest.hawaii.edu/doc/latest/psconvert.html

    """
    url = "{}/{}.html".format(GMT_DOCS, module_func.__name__)
    module_func.__doc__ = module_func.__doc__.format(gmt_mod=url)
    return module_func

@@ -278,16 +278,24 @@
 %7Bgmt_mod
+ule_docs
 %7D%60%60 wher
@@ -299,16 +299,20 @@
 here you
+%0A   
  want th
@@ -312,20 +312,16 @@
 want the
-%0A   
  link to
@@ -785,25 +785,23 @@
 ... def 
-psconvert
+gmtinfo
 (**kwarg
@@ -820,32 +820,85 @@
     
-%22Full docs at %7Bgmt_mod%7D%22
+'''%0A    ...     My nice module.%0A    ...     %7Bgmt_module_docs%7D%0A    ...     '''
 %0A   
@@ -925,25 +925,23 @@
 %3E print(
-psconvert
+gmtinfo
 .__doc__
@@ -950,17 +950,68 @@
     
-Full docs
+%3CBLANKLINE%3E%0A        My nice module.%0A        Full option list
  at 
@@ -1053,22 +1053,36 @@
 est/
-psconvert.html
+gmtinfo.html%0A    %3CBLANKLINE%3E
 %0A%0A  
@@ -1145,24 +1145,95 @@
 c.__name__)%0A
+    text = %22Full option list at%22%0A    full_text = ' '.join(%5Btext, url%5D)%0A
     module_f
@@ -1284,12 +1284,26 @@
 _mod
-=url
+ule_docs=full_text
 )%0A  

Fix issue with spacing when inserting gmt link