[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7cc4e00 07/46: tiny.el: x can be reused in format string.
From: |
Oleh Krehel |
Subject: |
[elpa] master 7cc4e00 07/46: tiny.el: x can be reused in format string. |
Date: |
Sun, 22 Mar 2015 17:42:26 +0000 |
branch: master
commit 7cc4e00db2bb6137527a098b7638a85823389dbc
Author: oleh <address@hidden>
Commit: oleh <address@hidden>
tiny.el: x can be reused in format string.
---
tiny.el | 29 +++++++++++++++++++++--------
1 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/tiny.el b/tiny.el
index 88e0b8b..e4f8c9c 100644
--- a/tiny.el
+++ b/tiny.el
@@ -58,6 +58,7 @@
;; m5\n;; 20expx&014.2f
;; m, 7&0x&02x
;; m1\n14&*** TODO http://emacsrocks.com/e&02d.html
+;; m1\n10&convert img&s.jpg -monochrome -resize 50% -rotate 180 img&s_mono.pdf
;;
;; As you might have guessed, the syntax is as follows:
;; m[<range start:=0>][<separator:= >]<range end>[lisp expr][&][format expr]
@@ -141,7 +142,7 @@ Skip lambdas."
"Take the output of `tiny-mapconcat-parse' and replace
the null values with defaults and return the formatted
expression."
- (destructuring-bind (n1 s1 n2 expr fmt) (tiny-mapconcat-parse)
+ (destructuring-bind (n1 s1 n2 expr fmt n-uses) (tiny-mapconcat-parse)
(when (zerop (length n1))
(setq n1 "0"))
(when (zerop (length s1))
@@ -152,9 +153,14 @@ expression."
(setq fmt "%s"))
(unless (>= (read n1) (read n2))
(format
- "(mapconcat (lambda(x) (format \"%s\" %s)) (number-sequence %s %s)
\"%s\")"
- fmt
+ (concat
+ "(mapconcat (lambda(x) (setq x %s)(format \"%s\" "
+ (if n-uses
+ (apply #'concat (make-list n-uses "x "))
+ "x")
+ ")) (number-sequence %s %s) \"%s\")")
expr
+ fmt
n1
n2
s1))))
@@ -172,7 +178,7 @@ m[START][SEPARATOR]END[EXPR][FORMAT]
and `(exp x)' can be shortened to expx.
A closing paren may be added to resolve ambiguity:
*2+x3"
- (let (n1 s1 n2 expr fmt str)
+ (let (n1 s1 n2 expr fmt str n-uses)
(and (catch 'done
(cond
;; either start with a number
@@ -202,8 +208,12 @@ m[START][SEPARATOR]END[EXPR][FORMAT]
;; If it's a valid expression, we're done
(when (setq expr (tiny-tokenize expr))
(when fmt
- (setq fmt (replace-regexp-in-string
- "&" "%" fmt)))
+ (setq n-uses (cl-count ?& fmt))
+ (setq fmt
+ (replace-regexp-in-string
+ "&" "%"
+ (replace-regexp-in-string
+ "%" "%%" fmt))))
(setq n2 n1
n1 nil)
(throw 'done t))
@@ -224,10 +234,13 @@ m[START][SEPARATOR]END[EXPR][FORMAT]
(error "couldn't match %s" str)))
(when (> (length fmt) 0)
(if (string-match "^&.*&.*$" fmt)
- (setq fmt (replace-regexp-in-string "&" "%" (substring fmt
1)))
+ (progn
+ (setq fmt (replace-regexp-in-string "%" "%%" (substring fmt
1)))
+ (setq n-uses (cl-count ?& fmt))
+ (setq fmt (replace-regexp-in-string "&" "%" fmt)))
(aset fmt 0 ?%)))
t)
- (list n1 s1 n2 expr fmt))))
+ (list n1 s1 n2 expr fmt n-uses))))
;; TODO: check for arity: this doesn't work: exptxy
(defun tiny-tokenize (str)
- [elpa] master updated (302a16a -> 3f035ad), Oleh Krehel, 2015/03/22
- [elpa] master ae0853e 03/46: tiny.el: fixed two snippets., Oleh Krehel, 2015/03/22
- [elpa] master 1273eae 04/46: tiny.el: added to the comments., Oleh Krehel, 2015/03/22
- [elpa] master 086708f 01/46: Initial import., Oleh Krehel, 2015/03/22
- [elpa] master 1baa50b 05/46: tiny.el: fixed some typos., Oleh Krehel, 2015/03/22
- [elpa] master 466e02c 06/46: tiny.el: added a use case for multiple TODO items in org-mode., Oleh Krehel, 2015/03/22
- [elpa] master cc8d243 02/46: tiny.el: Added new test snippets., Oleh Krehel, 2015/03/22
- [elpa] master 7cc4e00 07/46: tiny.el: x can be reused in format string.,
Oleh Krehel <=
- [elpa] master d053709 08/46: tiny.el: expr now can return a list., Oleh Krehel, 2015/03/22
- [elpa] master 03aef85 09/46: tiny.el: fixed a bug introduced by previous commit., Oleh Krehel, 2015/03/22
- [elpa] master 835c63e 12/46: tiny.el: fixed a small whitespace issue in `tiny-tokenize'., Oleh Krehel, 2015/03/22
- [elpa] master 36c8dc0 10/46: tiny.el: added missing functions., Oleh Krehel, 2015/03/22
- [elpa] master 067e820 11/46: tiny.el: improved `tiny-mapconcat` and `tiny-mapconcat-parse'., Oleh Krehel, 2015/03/22
- [elpa] master cad8e50 13/46: tiny.el: added the option to include %(sexps) into the format string., Oleh Krehel, 2015/03/22
- [elpa] master 78241c4 15/46: tiny.el: fixed a bug for expansion of m5%x., Oleh Krehel, 2015/03/22
- [elpa] master 29b5b76 16/46: Added README.md, Oleh Krehel, 2015/03/22
- [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