[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 075e4d0 33/46: Fix "m10|%0.2f"
From: |
Oleh Krehel |
Subject: |
[elpa] master 075e4d0 33/46: Fix "m10|%0.2f" |
Date: |
Sun, 22 Mar 2015 17:42:36 +0000 |
branch: master
commit 075e4d0b238fcfa6135b1825dd64613279782a04
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Fix "m10|%0.2f"
---
tiny-test.el | 32 +++++++++++++++++---------------
tiny.el | 53 +++++++++++++++++++++++++++++++----------------------
2 files changed, 48 insertions(+), 37 deletions(-)
diff --git a/tiny-test.el b/tiny-test.el
index adcd43e..6fa1659 100644
--- a/tiny-test.el
+++ b/tiny-test.el
@@ -35,7 +35,9 @@ with point at the end of TXT."
(should (equal (with-text-value "m97,120stringxupcasex)x"
#'tiny-mapconcat-parse)
'("97" "," "120" "(string x (upcase x) x)" nil)))
(should (equal (with-text-value "m\\n;; 10|%(+ x x) and %(* x x) and %s"
#'tiny-mapconcat-parse)
- '(nil "\\n;; " "10" nil "%(+ x x) and %(* x x) and %s"))))
+ '(nil "\\n;; " "10" nil "%(+ x x) and %(* x x) and %s")))
+ (should (equal (with-text-value "m10|%0.2f" #'tiny-mapconcat-parse)
+ '(nil nil "10" nil "%0.2f"))))
(ert-deftest tiny-extract-sexps ()
(should (equal (tiny-extract-sexps "expr1 %(+ x x), nothing %% char %c, hex
%x, and expr2 %(* x x), float %0.2f and sym %s")
@@ -125,35 +127,35 @@ convert img10.jpg -monochrome -resize 50% -rotate 180
img10_mono.pdf"))
(should (equal (with-text-value "m\\n8|**** TODO Learning from Data Week %(+
x 2)\\nSCHEDULED: <%(date \"Oct 7\" (* x 7))> DEADLINE: <%(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>
+SCHEDULED: <2014-10-07 Tue> DEADLINE: <2014-10-14 Tue>
**** TODO Learning from Data Week 3
-SCHEDULED: <2013-10-14 Mon> DEADLINE: <2013-10-21 Mon>
+SCHEDULED: <2014-10-14 Tue> DEADLINE: <2014-10-21 Tue>
**** TODO Learning from Data Week 4
-SCHEDULED: <2013-10-21 Mon> DEADLINE: <2013-10-28 Mon>
+SCHEDULED: <2014-10-21 Tue> DEADLINE: <2014-10-28 Tue>
**** TODO Learning from Data Week 5
-SCHEDULED: <2013-10-28 Mon> DEADLINE: <2013-11-04 Mon>
+SCHEDULED: <2014-10-28 Tue> DEADLINE: <2014-11-04 Tue>
**** TODO Learning from Data Week 6
-SCHEDULED: <2013-11-04 Mon> DEADLINE: <2013-11-11 Mon>
+SCHEDULED: <2014-11-04 Tue> DEADLINE: <2014-11-11 Tue>
**** TODO Learning from Data Week 7
-SCHEDULED: <2013-11-11 Mon> DEADLINE: <2013-11-18 Mon>
+SCHEDULED: <2014-11-11 Tue> DEADLINE: <2014-11-18 Tue>
**** TODO Learning from Data Week 8
-SCHEDULED: <2013-11-18 Mon> DEADLINE: <2013-11-25 Mon>
+SCHEDULED: <2014-11-18 Tue> DEADLINE: <2014-11-25 Tue>
**** TODO Learning from Data Week 9
-SCHEDULED: <2013-11-25 Mon> DEADLINE: <2013-12-02 Mon>
+SCHEDULED: <2014-11-25 Tue> DEADLINE: <2014-12-02 Tue>
**** TODO Learning from Data Week 10
-SCHEDULED: <2013-12-02 Mon> DEADLINE: <2013-12-09 Mon>"))
+SCHEDULED: <2014-12-02 Tue> DEADLINE: <2014-12-09 Tue>"))
(should (string= (with-text-value "m\\n4|**** TODO Classical Mechanics Week
%(+ x 5)\\nSCHEDULED: <%(date \"Oct 15\" (* x 7))> DEADLINE: <%(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>
+SCHEDULED: <2014-10-15 Wed> DEADLINE: <2014-10-23 Thu>
**** TODO Classical Mechanics Week 6
-SCHEDULED: <2013-10-22 Tue> DEADLINE: <2013-10-30 Wed>
+SCHEDULED: <2014-10-22 Wed> DEADLINE: <2014-10-30 Thu>
**** TODO Classical Mechanics Week 7
-SCHEDULED: <2013-10-29 Tue> DEADLINE: <2013-11-06 Wed>
+SCHEDULED: <2014-10-29 Wed> DEADLINE: <2014-11-06 Thu>
**** TODO Classical Mechanics Week 8
-SCHEDULED: <2013-11-05 Tue> DEADLINE: <2013-11-13 Wed>
+SCHEDULED: <2014-11-05 Wed> DEADLINE: <2014-11-13 Thu>
**** TODO Classical Mechanics Week 9
-SCHEDULED: <2013-11-12 Tue> DEADLINE: <2013-11-20 Wed>")))
+SCHEDULED: <2014-11-12 Wed> DEADLINE: <2014-11-20 Thu>")))
(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 2d163c7..7213f79 100644
--- a/tiny.el
+++ b/tiny.el
@@ -58,6 +58,7 @@
;; m\n;; 10expx
;; m5\n;; 20expx%014.2f
;; m, 7|0x%02x
+;; m10|%0.2f
;; m1\n14|*** TODO http://emacsrocks.com/e%02d.html
;; m1\n10|convert img%s.jpg -monochrome -resize 50%% -rotate 180 img%s_mono.pdf
;; (setq foo-list '(m1 11+x96|?%c))
@@ -118,24 +119,31 @@ At the moment, only `tiny-mapconcat' is supported.
"Eval and replace the current sexp.
On error go up list and try again."
(interactive)
- (catch 'success
- (while t
- (ignore-errors
- (unless (looking-back ")")
- (error "bad location"))
- (let ((sexp (preceding-sexp)))
- (if (eq (car sexp) 'lambda)
- (error "lambda evaluates to itself")
- (let ((value (eval sexp)))
- (kill-sexp -1)
- (insert (format "%s" value))
- (throw 'success t)))))
- ;; if can't replace, go up list
- (condition-case nil
- (tiny-up-list)
- (error
- (message "reached the highest point, couldn't eval.")
- (throw 'success nil))))))
+ (if (region-active-p)
+ (let ((s (buffer-substring-no-properties
+ (region-beginning)
+ (region-end))))
+ (delete-region (region-beginning)
+ (region-end))
+ (insert (format "%s" (eval (read s)))))
+ (catch 'success
+ (while t
+ (ignore-errors
+ (unless (looking-back ")")
+ (error "bad location"))
+ (let ((sexp (preceding-sexp)))
+ (if (eq (car sexp) 'lambda)
+ (error "lambda evaluates to itself")
+ (let ((value (eval sexp)))
+ (kill-sexp -1)
+ (insert (format "%s" value))
+ (throw 'success t)))))
+ ;; if can't replace, go up list
+ (condition-case nil
+ (tiny-up-list)
+ (error
+ (message "reached the highest point, couldn't eval.")
+ (throw 'success nil)))))))
(defun tiny-up-list ()
"An `up-list' that can exit from string.
@@ -269,7 +277,7 @@ Return nil if nothing was matched, otherwise
;; or [expr][fmt]
;;
;; First, try to match [expr][fmt]
- (string-match "^\\(.*?\\)\\(%.*\\)?$" str)
+ (string-match "^\\(.*?\\)|?\\(%.*\\)?$" str)
(setq expr (match-string-no-properties 1 str))
(setq fmt (match-string-no-properties 2 str))
;; If it's a valid expression, we're done
@@ -293,14 +301,15 @@ Return nil if nothing was matched, otherwise
(setq expr (tiny-tokenize (match-string-no-properties 1
str)))
(setq fmt (match-string-no-properties 2 str)))
(error "couldn't match %s" str)))
- (when (equal expr "")
- (setq expr nil))
t)
+ (when (equal expr "")
+ (setq expr nil))
(list n1 s1 n2 expr fmt))))
;; TODO: check for arity: this doesn't work: exptxy
(defun tiny-tokenize (str)
- (unless (equal str "")
+ (if (equal str "")
+ ""
(ignore-errors
(let ((i 0) (j 1)
(len (length str))
- [elpa] master f1d1a2e 22/46: tiny-test.el: switched to ERT., (continued)
- [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, 2015/03/22
- [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 <=
- [elpa] master 4eef4e6 37/46: tiny.el: add a test case, Oleh Krehel, 2015/03/22
- [elpa] master 3a56283 38/46: tiny.el (tiny-mapconcat-parse): case-sensitive, Oleh Krehel, 2015/03/22
- [elpa] master dea7748 39/46: tiny.el (tiny-date): improve, Oleh Krehel, 2015/03/22
- [elpa] master ea7a184 42/46: tiny-test.el (tiny-mapconcat): Add test., Oleh Krehel, 2015/03/22
- [elpa] master d37646a 41/46: Add Travis CI testing and Coveralls.io reporting, Oleh Krehel, 2015/03/22
- [elpa] master fe0bade 43/46: tiny-test.el: Update, Oleh Krehel, 2015/03/22
- [elpa] master 5f25ce1 40/46: tiny.el: handle quotes in FMT part, Oleh Krehel, 2015/03/22
- [elpa] master fa90c2f 44/46: README.md: Add badges, Oleh Krehel, 2015/03/22
- [elpa] master 6719ab2 32/46: README.md: updated., Oleh Krehel, 2015/03/22
- [elpa] master 159c3f7 45/46: tiny.el: Update Copyright, Oleh Krehel, 2015/03/22