21
21
import random
22
22
import types
23
23
24
+ import textwrap
25
+
24
26
# import the local copy of matplotlib, not the installed one
25
27
#sys.path.insert(0, './lib')
26
28
from matplotlib .axes import Axes
@@ -62,7 +64,7 @@ def %(func)s(%(argspec)s):
62
64
MISC_FN_TEMPLATE = AUTOGEN_MSG + """
63
65
@docstring.copy_dedent(Axes.%(func)s)
64
66
def %(func)s(%(argspec)s):
65
- %(ret)s = gca().%(func)s(%(call)s)
67
+ %(ret)s = gca().%(func)s(%(call)s)
66
68
draw_if_interactive()
67
69
return %(ret)s
68
70
"""
@@ -189,6 +191,8 @@ def format_value(value):
189
191
'formatvalue' ) % value )
190
192
return '=' + repr (value )
191
193
194
+ text_wrapper = textwrap .TextWrapper (break_long_words = False )
195
+
192
196
for fmt , cmdlist in [(PLOT_TEMPLATE , _plotcommands ),
193
197
(MISC_FN_TEMPLATE , _misccommands )]:
194
198
for func in cmdlist :
@@ -206,13 +210,23 @@ def format_value(value):
206
210
defaults = ()
207
211
208
212
# How to call the wrapped function
209
- call = list (map (str , args ))
213
+ call = []
214
+ for i , arg in enumerate (args ):
215
+ if len (defaults ) < len (args ) - i :
216
+ call .append ('%s' % arg )
217
+ else :
218
+ call .append ('%s=%s' % (arg , arg ))
219
+
210
220
if varargs is not None :
211
221
call .append ('*' + varargs )
212
222
if varkw is not None :
213
223
call .append ('**' + varkw )
214
224
call = ', ' .join (call )
215
225
226
+ text_wrapper .width = 80 - 19 - len (func )
227
+ join_with = '\n ' + ' ' * (18 + len (func ))
228
+ call = join_with .join (text_wrapper .wrap (call ))
229
+
216
230
# Add a hold keyword argument if needed (fmt is PLOT_TEMPLATE) and
217
231
# possible (if *args is used, we can't just add a hold
218
232
# argument in front of it since it would gobble one of the
@@ -229,6 +243,10 @@ def format_value(value):
229
243
formatvalue = format_value )
230
244
argspec = argspec [1 :- 1 ] # remove parens
231
245
246
+ text_wrapper .width = 80 - 5 - len (func )
247
+ join_with = '\n ' + ' ' * (5 + len (func ))
248
+ argspec = join_with .join (text_wrapper .wrap (argspec ))
249
+
232
250
# A gensym-like facility in case some function takes an
233
251
# argument named washold, ax, or ret
234
252
washold , ret , ax = 'washold' , 'ret' , 'ax'
0 commit comments