[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master cad8e50 13/46: tiny.el: added the option to include %(sexp
From: |
Oleh Krehel |
Subject: |
[elpa] master cad8e50 13/46: tiny.el: added the option to include %(sexps) into the format string. |
Date: |
Sun, 22 Mar 2015 17:42:28 +0000 |
branch: master
commit cad8e50fbf9bfbd51d9008ccbc30fe8a2018d17e
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
tiny.el: added the option to include %(sexps) into the format string.
For instance:
m\n10 &%(+ x x) and %(* x x) and &s
---
tiny.el | 25 +++++++++++++++++++++----
1 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/tiny.el b/tiny.el
index 06d77ca..ec7de1b 100644
--- a/tiny.el
+++ b/tiny.el
@@ -46,17 +46,18 @@
;; m5,10
;; m5 10*xx
;; m5 10*xx&x
-;; m5 10*xx&0x&x
+;; m5 10*xx&&0x&x
;; m25+x?a&c
;; m25+x?A&c
;; m97,122stringx
;; m97,122stringxx
;; m97,120stringxupcasex
;; m97,120stringxupcasex)x
+;; m\n;; 10 &%(+ x x) and %(* x x) and &s
;; m10*2+3x
;; m\n;; 10expx
;; m5\n;; 20expx&014.2f
-;; m, 7&0x&02x
+;; 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
;; (setq foo-list '(m1 11+x96&?&c))
@@ -171,7 +172,7 @@ expression."
(s1 (or (nth 1 parsed) " "))
(n2 (nth 2 parsed))
(expr (or (nth 3 parsed) "x"))
- (fmt (or (nth 4 parsed) "%s"))
+ (fmt (tiny-extract-sexps (or (nth 4 parsed) "%s")))
(n-uses (or (nth 5 parsed) 1))
(lexpr (read expr))
(n-items (if (and (listp lexpr) (eq (car lexpr) 'list))
@@ -184,6 +185,7 @@ expression."
(loop for i from 0 to (1- n-items)
collecting (format "(nth %d lst)" i))
" ")
+ (mapconcat #'identity (cdr fmt) " ")
(if (or (equal expr "x") (> n-items 0)) "x " "y ")
(mapconcat #'identity
(loop for i from (1+ n-items) to (1- n-uses)
@@ -194,11 +196,26 @@ expression."
(format
format-expression
expr
- fmt
+ (car fmt)
n1
n2
s1))))
+(defun tiny-extract-sexps (str)
+ "Replace all %(...) forms in STR with %s.
+Return (STR forms)."
+ (let (forms beg)
+ (condition-case nil
+ (while (setq beg (string-match "%(" str))
+ (incf beg)
+ (destructuring-bind (sexp . end) (read-from-string str beg)
+ (push (substring str beg end) forms)
+ (setq str (concat (substring str 0 (1- beg))
+ "s"
+ (substring str end)))))
+ (error (message "Malformed sexp: %s" (substring str beg))))
+ (cons str (nreverse forms))))
+
(defun tiny-mapconcat-parse ()
"Try to match a snippet of this form:
m[START][SEPARATOR]END[EXPR][FORMAT]
- [elpa] master 086708f 01/46: Initial import., (continued)
- [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, 2015/03/22
- [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 <=
- [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
- [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