emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]