[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4c87ade 29/46: tiny.el: fixed a bug in `tiny-mapconcat-par
From: |
Oleh Krehel |
Subject: |
[elpa] master 4c87ade 29/46: tiny.el: fixed a bug in `tiny-mapconcat-parse'. |
Date: |
Sun, 22 Mar 2015 17:42:34 +0000 |
branch: master
commit 4c87ade6e0abb1166a22137914ccc3547c94bdc5
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
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]
;;
- [elpa] master b9c35e1 17/46: README.md: minor update., (continued)
- [elpa] master b9c35e1 17/46: README.md: minor update., Oleh Krehel, 2015/03/22
- [elpa] master 97b9fdf 14/46: tiny.el: fixed up the previous change., Oleh Krehel, 2015/03/22
- [elpa] master 80e64b8 18/46: README.md: minor update., Oleh Krehel, 2015/03/22
- [elpa] master 2bd9abb 21/46: tiny.el: moved tests to tiny-test.el., Oleh Krehel, 2015/03/22
- [elpa] master b99315d 20/46: tiny.el: updated the doc., Oleh Krehel, 2015/03/22
- [elpa] master 11722a1 19/46: tiny.el: fixed typos., Oleh Krehel, 2015/03/22
- [elpa] master b4fff55 23/46: tiny.el: fixed `tiny-tokenize', Oleh Krehel, 2015/03/22
- [elpa] master 5df4f79 25/46: tiny.el: removed `tiny-beginning-of-string', Oleh Krehel, 2015/03/22
- [elpa] master 8a3cab0 27/46: tiny.el: removed `tiny-replace-preceding-sexp', Oleh Krehel, 2015/03/22
- [elpa] master f1d1a2e 22/46: tiny-test.el: switched to ERT., Oleh Krehel, 2015/03/22
- [elpa] master 4c87ade 29/46: tiny.el: fixed a bug in `tiny-mapconcat-parse'.,
Oleh Krehel <=
- [elpa] master a6e4144 30/46: tiny.el (tiny-extract-sexps): can handle e.g. %0.1f(...) style formatting., Oleh Krehel, 2015/03/22
- [elpa] master 80cd28f 28/46: tiny-test.el: added a test for `tiny-replace-this-sexp', Oleh Krehel, 2015/03/22
- [elpa] master 08ba593 24/46: tiny.el: fixed `tiny-tokenize', Oleh Krehel, 2015/03/22
- [elpa] master e6abbc6 31/46: tiny.el (tiny-date): renamed from t-date. In format string it's just "date", Oleh Krehel, 2015/03/22
- [elpa] master c59bc94 36/46: tiny.el (tiny-extract-sexps): add missing let binding, Oleh Krehel, 2015/03/22
- [elpa] master cf74dd1 34/46: tiny.el: fix docs, Oleh Krehel, 2015/03/22
- [elpa] master b843226 26/46: tiny.el: removed `tiny-replace-sexp-desperately', Oleh Krehel, 2015/03/22
- [elpa] master 7893a02 35/46: tiny.el: add autoload to `tiny-expand', Oleh Krehel, 2015/03/22
- [elpa] master 075e4d0 33/46: Fix "m10|%0.2f", Oleh Krehel, 2015/03/22
- [elpa] master 4eef4e6 37/46: tiny.el: add a test case, Oleh Krehel, 2015/03/22