summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-08-17 23:33:37 +0200
committerStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-08-17 23:33:37 +0200
commitbadf822ea07c7c551aeeef3cde4660a1251e1584 (patch)
tree9089243f72e1107632c652d3851e2e08624fa15d
parent15e12897da265f818e3be6f2e27fff4391bf22ee (diff)
optparse --help bugfix
-rw-r--r--modules/language/python/format2.scm52
-rw-r--r--modules/language/python/module/optparse.py4
2 files changed, 40 insertions, 16 deletions
diff --git a/modules/language/python/format2.scm b/modules/language/python/format2.scm
index 4a9af31..22cb318 100644
--- a/modules/language/python/format2.scm
+++ b/modules/language/python/format2.scm
@@ -7,6 +7,7 @@
#:use-module (language python exceptions)
#:use-module (language python number)
#:use-module (language python dict)
+ #:use-module (language python list)
#:export (format fnm))
(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
@@ -36,11 +37,11 @@
(define (get-n p)
(match p
- ((#:% #t _ `* `* . _)
+ ((#:% #f _ #:* #:* . _)
2)
- ((#:% #t _ `* _ . _)
+ ((#:% #f _ #:* _ . _)
1)
- ((#:% #t _ _ `* . _)
+ ((#:% #f _ _ #:* . _)
1)
(_
0)))
@@ -65,14 +66,21 @@
x)))
("s" (lambda (x)
- (if (is-a? x <p>)
- (aif it (ref x '__str__)
- (scm-format #f "~a" (it))
- (scm-format #f "~a" x))
- (scm-format #f "~a" x))))
+ (let ((s (if (is-a? x <p>)
+ (aif it (ref x '__str__)
+ (scm-format #f "~a" (it))
+ (scm-format #f "~a" x))
+ (scm-format #f "~a" x))))
+ (+ s (* " " (max 0 (- min (len s))))))))
+
+ ("a" (lambda (x)
+ (let ((s (scm-format #f "~a" x)))
+ (+ s (* " " (max 0 (- min (len s))))))))
+
+ ("r" (lambda (x)
+ (let ((s (scm-format #f "~a" x)))
+ (+ s (* " " (max 0 (- min (len s))))))))
- ("a" (lambda (x) (scm-format #f "~a" x)))
- ("r" (lambda (x) (scm-format #f "~a" x)))
("%"
(lambda (x) (* "%" (if min min 1))))
((or "f" "F" "e" "E" "g" "G")
@@ -200,15 +208,27 @@
(define (analyze p)
(match p
- ((#:% #f c `* `* _ tp)
- (lambda (x min prec)
+ ((#:% #f c #:* #:* _ tp)
+ (lambda (min prec x)
((create c min prec tp) x)))
- ((#:% #f c `* prec _ tp)
- (lambda (x min)
+ ((#:% #f c #:* prec _ tp)
+ (lambda (min x)
((create c min prec tp) x)))
- ((#:% #f c min `* _ tp)
- (lambda (x prec)
+ ((#:% #f c #:* prec _ tp)
+ (lambda (min x)
((create c min prec tp) x)))
+ ((#:% #f c min #:* _ tp)
+ (lambda (prec x)
+ ((create c min prec tp) x)))
+
+ ((#:% #f (and c (or "s" "r" "a")) min prec _ tp)
+ (create c 0 prec tp))
+
+ ((#:% tag (and c (or "s" "r" "a")) min prec _ tp)
+ (let ((f (create c 0 prec tp)))
+ (lambda (x)
+ (f (pylist-ref x tag)))))
+
((#:% #f c min prec _ tp)
(create c min prec tp))
((#:% tag c min prec _ tp)
diff --git a/modules/language/python/module/optparse.py b/modules/language/python/module/optparse.py
index 043ea9a..657c97d 100644
--- a/modules/language/python/module/optparse.py
+++ b/modules/language/python/module/optparse.py
@@ -380,9 +380,11 @@ class IndentedHelpFormatter (HelpFormatter):
self, indent_increment, max_help_position, width, short_first)
def format_usage(self, usage):
+ pk('IndentedHelpFormatter usage')
return _("Usage: %s\n") % usage
def format_heading(self, heading):
+ pk('IndentedHelpFormatter heading')
return "%*s%s:\n" % (self.current_indent, "", heading)
@@ -399,9 +401,11 @@ class TitledHelpFormatter (HelpFormatter):
self, indent_increment, max_help_position, width, short_first)
def format_usage(self, usage):
+ pk('TitledHelpFormatter heading')
return "%s %s\n" % (self.format_heading(_("Usage")), usage)
def format_heading(self, heading):
+ pk('TitledHelpFormatter heading')
return "%s\n%s\n" % (heading, "=-"[self.level] * len(heading))