branch: master commit 4c87ade6e0abb1166a22137914ccc3547c94bdc5 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
tiny.el: fixed a bug in `tiny-mapconcat-parse'. --- tiny-test.el | 18 ++++++++++++-- tiny.el | 70 +++++++++++++++++++++++++++++---------------------------- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/tiny-test.el b/tiny-test.el index 07667f8..77cfdc7 100644 --- a/tiny-test.el +++ b/tiny-test.el @@ -119,7 +119,8 @@ convert img10.jpg -monochrome -resize 50% -rotate 180 img10_mono.pdf")) ;; 2744:196:14 ;; 3375:225:15 ;; 4096:256:16")) - (should (equal (with-text-value "m\\n8|**** TODO Learning from Data Week %(+ x 2)\\nSCHEDULED: <%(t-date \"Oct 7\" (* x 7))> DEADLINE: <%(t-date \"Oct 14\" (* x 7))>" (lambda()(eval (read (tiny-mapconcat))))) + (should (equal (with-text-value "m\\n8|**** TODO Learning from Data Week %(+ x 2)\\nSCHEDULED: <%(t-date \"Oct 7\" (* x 7))> DEADLINE: <%(t-date \"Oct 14\" (* x 7))>" + (lambda()(eval (read (tiny-mapconcat))))) "**** TODO Learning from Data Week 2 SCHEDULED: <2013-10-07 Mon> DEADLINE: <2013-10-14 Mon> **** TODO Learning from Data Week 3 @@ -137,8 +138,19 @@ SCHEDULED: <2013-11-18 Mon> DEADLINE: <2013-11-25 Mon> **** TODO Learning from Data Week 9 SCHEDULED: <2013-11-25 Mon> DEADLINE: <2013-12-02 Mon> **** TODO Learning from Data Week 10 -SCHEDULED: <2013-12-02 Mon> DEADLINE: <2013-12-09 Mon>" - ))) +SCHEDULED: <2013-12-02 Mon> DEADLINE: <2013-12-09 Mon>")) + (should (string= (with-text-value "m\\n4|**** TODO Classical Mechanics Week %(+ x 5)\\nSCHEDULED: <%(t-date \"Oct 15\" (* x 7))> DEADLINE: <%(t-date \"Oct 23\" (* x 7))>" + (lambda()(eval (read (tiny-mapconcat))))) + "**** TODO Classical Mechanics Week 5 +SCHEDULED: <2013-10-15 Tue> DEADLINE: <2013-10-23 Wed> +**** TODO Classical Mechanics Week 6 +SCHEDULED: <2013-10-22 Tue> DEADLINE: <2013-10-30 Wed> +**** TODO Classical Mechanics Week 7 +SCHEDULED: <2013-10-29 Tue> DEADLINE: <2013-11-06 Wed> +**** TODO Classical Mechanics Week 8 +SCHEDULED: <2013-11-05 Tue> DEADLINE: <2013-11-13 Wed> +**** TODO Classical Mechanics Week 9 +SCHEDULED: <2013-11-12 Tue> DEADLINE: <2013-11-20 Wed>"))) (ert-deftest tiny-replace-this-sexp () (should (equal (with-text-value "(mapcar (lambda (x) (* x x)) '(1 2 3))" diff --git a/tiny.el b/tiny.el index a5ef22b..319fc24 100644 --- a/tiny.el +++ b/tiny.el @@ -152,38 +152,39 @@ Must throw an error when can't go up further." "Take the output of `tiny-mapconcat-parse' and replace the null values with defaults and return the formatted expression." - (let* ((parsed (tiny-mapconcat-parse)) - (n1 (or (nth 0 parsed) "0")) - (s1 (or (nth 1 parsed) " ")) - (n2 (nth 2 parsed)) - (expr (or (nth 3 parsed) "x")) - (lexpr (read expr)) - (n-have (if (and (listp lexpr) (eq (car lexpr) 'list)) - (1- (length lexpr)) - 0)) - (expr (if (zerop n-have) `(list ,lexpr) lexpr)) - (n-have (if (zerop n-have) 1 n-have)) - (tes (tiny-extract-sexps (or (nth 4 parsed) "%s"))) - (fmt (car tes)) - (n-need (cl-count nil (cdr tes))) - (idx -1) - (format-expression - (concat "(mapconcat (lambda(x) (let ((lst %s)) (format \"%s\" " - (mapconcat (lambda (x) (or x - (if (>= (1+ idx) n-have) - "x" - (format "(nth %d lst)" (incf idx))))) - (cdr tes) - " ") - ")))(number-sequence %s %s) \"%s\")"))) - (unless (>= (read n1) (read n2)) - (format - format-expression - expr - fmt - n1 - n2 - s1)))) + (let ((parsed (tiny-mapconcat-parse))) + (when parsed + (let* ((n1 (or (nth 0 parsed) "0")) + (s1 (or (nth 1 parsed) " ")) + (n2 (nth 2 parsed)) + (expr (or (nth 3 parsed) "x")) + (lexpr (read expr)) + (n-have (if (and (listp lexpr) (eq (car lexpr) 'list)) + (1- (length lexpr)) + 0)) + (expr (if (zerop n-have) `(list ,lexpr) lexpr)) + (n-have (if (zerop n-have) 1 n-have)) + (tes (tiny-extract-sexps (or (nth 4 parsed) "%s"))) + (fmt (car tes)) + (n-need (cl-count nil (cdr tes))) + (idx -1) + (format-expression + (concat "(mapconcat (lambda(x) (let ((lst %s)) (format \"%s\" " + (mapconcat (lambda (x) (or x + (if (>= (1+ idx) n-have) + "x" + (format "(nth %d lst)" (incf idx))))) + (cdr tes) + " ") + ")))(number-sequence %s %s) \"%s\")"))) + (unless (>= (read n1) (read n2)) + (format + format-expression + expr + fmt + n1 + n2 + s1)))))) (defun tiny-extract-sexps (str) "Returns (STR & FORMS), where each element of FORMS @@ -241,12 +242,13 @@ Return nil if nothing was matched, otherwise n1 nil) (throw 'done t))) ;; else capture the whole thing - ((looking-back "\\bm\\([^\n]*\\)") + ((looking-back "\\bm\\([^%|\n]*[0-9][^\n]*\\)") (setq str (match-string-no-properties 1) tiny-beg (match-beginning 0) tiny-end (match-end 0)) (when (zerop (length str)) - (throw 'done nil)))) + (throw 'done nil))) + (t (throw 'done nil))) ;; at this point, `str' should be either [sep]<num>[expr][fmt] ;; or [expr][fmt] ;;