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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 3f47a2a 10/10: Merge commit '3ae24d6b02b3b13a5468174599183


From: Oleh Krehel
Subject: [elpa] master 3f47a2a 10/10: Merge commit '3ae24d6b02b3b13a5468174599183102e1cb3c11' from tiny
Date: Wed, 30 Aug 2017 13:46:04 -0400 (EDT)

branch: master
commit 3f47a2a525bf6778b15de53be8f98207cff05770
Merge: 78af78e 3ae24d6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Merge commit '3ae24d6b02b3b13a5468174599183102e1cb3c11' from tiny
---
 packages/tiny/.travis.yml             |   7 +-
 packages/tiny/Cask                    |   5 -
 packages/tiny/Makefile                |   7 +-
 packages/tiny/targets/elpa.el         |   5 +
 packages/tiny/targets/install-deps.el |  28 +++++
 packages/tiny/tiny-test.el            |  11 +-
 packages/tiny/tiny.el                 | 224 +++++++++++++++++++++++++---------
 7 files changed, 219 insertions(+), 68 deletions(-)

diff --git a/packages/tiny/.travis.yml b/packages/tiny/.travis.yml
index fe3ab71..70a977d 100644
--- a/packages/tiny/.travis.yml
+++ b/packages/tiny/.travis.yml
@@ -7,14 +7,11 @@ before_install:
   # Update and install the Emacs for our environment
   - sudo apt-get update -qq
   - sudo apt-get install -qq -yy ${EMACS}-nox ${EMACS}-el
-  # Install cask dependencies
-  - curl -fsSLo /tmp/cask-master.zip 
https://github.com/cask/cask/archive/master.zip
-  - sudo unzip -qq -d /opt /tmp/cask-master.zip
-  - sudo ln -sf /opt/cask-master/bin/cask /usr/local/bin/cask
-  - cask
+
 env:
   - EMACS=emacs24
   - EMACS=emacs-snapshot
 script:
   - emacs --version
+  - make update
   - make test
diff --git a/packages/tiny/Cask b/packages/tiny/Cask
deleted file mode 100644
index 5336cec..0000000
--- a/packages/tiny/Cask
+++ /dev/null
@@ -1,5 +0,0 @@
-(source gnu)
-(source melpa)
-
-(development
- (depends-on "undercover"))
diff --git a/packages/tiny/Makefile b/packages/tiny/Makefile
index 708ea1a..a63f955 100644
--- a/packages/tiny/Makefile
+++ b/packages/tiny/Makefile
@@ -1,8 +1,13 @@
 emacs ?= emacs
+BEMACS = $(emacs) -batch -l targets/elpa.el
+
 all: test
 
+update:
+       $(emacs) -batch -l targets/install-deps.el
+
 test: clean
-       cask exec emacs -Q -batch -l tiny-test.el -l tiny.el -f 
ert-run-tests-batch-and-exit
+       $(BEMACS) -l tiny-test.el -l tiny.el -f ert-run-tests-batch-and-exit
 
 compile:
        $(emacs) -Q -batch -f batch-byte-compile tiny.el
diff --git a/packages/tiny/targets/elpa.el b/packages/tiny/targets/elpa.el
new file mode 100644
index 0000000..931f67c
--- /dev/null
+++ b/packages/tiny/targets/elpa.el
@@ -0,0 +1,5 @@
+(setq package-user-dir
+      (expand-file-name (format ".cask/%s/elpa" emacs-version)))
+(package-initialize)
+(add-to-list 'load-path default-directory)
+
diff --git a/packages/tiny/targets/install-deps.el 
b/packages/tiny/targets/install-deps.el
new file mode 100644
index 0000000..572af4b
--- /dev/null
+++ b/packages/tiny/targets/install-deps.el
@@ -0,0 +1,28 @@
+(setq package-user-dir
+      (expand-file-name (format ".cask/%s/elpa" emacs-version)))
+(require 'dired)
+(dired-create-directory package-user-dir)
+(message "installing in %s ...\n" package-user-dir)
+(package-initialize)
+(setq package-archives
+      '(("melpa" . "http://melpa.org/packages/";)
+        ("gnu" . "http://elpa.gnu.org/packages/";)))
+(package-refresh-contents)
+
+(defconst tiny-dev-packages
+  '(undercover))
+
+(dolist (package tiny-dev-packages)
+  (unless (package-installed-p package)
+    (ignore-errors
+      (package-install package))))
+
+(save-window-excursion
+  (package-list-packages t)
+  (condition-case nil
+      (progn
+        (package-menu-mark-upgrades)
+        (package-menu-execute t))
+    (error
+     (message "All packages up to date"))))
+
diff --git a/packages/tiny/tiny-test.el b/packages/tiny/tiny-test.el
index 4503aa6..3a4af90 100644
--- a/packages/tiny/tiny-test.el
+++ b/packages/tiny/tiny-test.el
@@ -150,7 +150,7 @@ 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: <%(date \"Oct 7\" (* x 7))> DEADLINE: <%(date \"Oct 14\" (* x 
7))>"
+  (should (equal (with-text-value "m\\n8|**** TODO Learning from Data Week %(+ 
x 2)\\nSCHEDULED: <%(date \"Oct 7 2015\" (* x 7))> DEADLINE: <%(date \"Oct 14 
2015\" (* x 7))>"
                    (lambda()(eval (read (tiny-mapconcat)))))
                  "**** TODO Learning from Data Week 2
 SCHEDULED: <2015-10-07 Wed> DEADLINE: <2015-10-14 Wed>
@@ -170,7 +170,7 @@ SCHEDULED: <2015-11-18 Wed> DEADLINE: <2015-11-25 Wed>
 SCHEDULED: <2015-11-25 Wed> DEADLINE: <2015-12-02 Wed>
 **** TODO Learning from Data Week 10
 SCHEDULED: <2015-12-02 Wed> DEADLINE: <2015-12-09 Wed>"))
-  (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))>"
+  (should (string= (with-text-value "m\\n4|**** TODO Classical Mechanics Week 
%(+ x 5)\\nSCHEDULED: <%(date \"Oct 15 2015\" (* x 7))> DEADLINE: <%(date \"Oct 
23 2015\" (* x 7))>"
                      (lambda()(eval (read (tiny-mapconcat)))))
                    "**** TODO Classical Mechanics Week 5
 SCHEDULED: <2015-10-15 Thu> DEADLINE: <2015-10-23 Fri>
@@ -213,4 +213,11 @@ SCHEDULED: <2015-11-12 Thu> DEADLINE: <2015-11-20 Fri>"))
     (should (equal (tiny-tokenize "(string x (upcase x) x") "(string x (upcase 
x) x)"))
     (should (equal (tiny-tokenize "(string x (upcase x) x)") "(string x 
(upcase x) x)")))
 
+(ert-deftest tiny-decreasing-seq ()
+  (should (equal (with-text-value "m2 -2" (lambda () (eval (read 
(tiny-mapconcat)))))
+                 "2 1 0 -1 -2"))
+  (should (equal (with-text-value "m3 -1|%(+ x x)" (lambda ()
+                                                     (eval (read 
(tiny-mapconcat)))))
+                 "6 4 2 0 -2")))
+
 (provide 'tiny-test)
diff --git a/packages/tiny/tiny.el b/packages/tiny/tiny.el
index 5523e60..ce39dc8 100644
--- a/packages/tiny/tiny.el
+++ b/packages/tiny/tiny.el
@@ -4,7 +4,7 @@
 
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/tiny
-;; Version: 0.1.1
+;; Version: 0.2.0
 ;; Keywords: convenience
 
 ;; This file is part of GNU Emacs.
@@ -26,7 +26,7 @@
 ;;
 ;; To set it up, just bind e.g.:
 ;;
-;;     (global-set-key (kbd "C-;") 'tiny-expand)
+;;     (global-set-key (kbd "C-;") #'tiny-expand)
 ;;
 ;; Usage:
 ;; This extension's main command is `tiny-expand'.
@@ -39,54 +39,68 @@
 ;; You can still do the full thing, but +x2 would save you some
 ;; key strokes.
 ;;
-;; You can test out the following snippets
-;; by positioning the point at the end of the expression
-;; and calling `tiny-expand' (default shortcut is C-;):
+;; You can test out the following snippets by positioning the point at
+;; the end of the expression and calling `tiny-expand':
 ;;
-;; m10
-;; m5 10
-;; m5,10
-;; m5 10*xx
-;; m5 10*xx%x
-;; m5 10*xx|0x%x
-;; m25+x?a%c
-;; m25+x?A%c
-;; m97,122(string x)
-;; 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
-;; m7|%(expt 2 x)
-;; 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))
-;; m1\n10listx+x96|convert img%s.jpg -monochrome -resize 50%% -rotate 180 
img%c_mono.pdf
-;; m1\n10listxnthxfoo-list|convert img%s.jpg -monochrome -resize 50%% -rotate 
180 img%c_mono.pdf
-;; m\n;; 16list*xxx)*xx%s:%s:%s
-;; m\n8|**** TODO Learning from Data Week %(+ x 2) \nSCHEDULED: <%(date "Oct 
7" (* x 7))> DEADLINE: <%(date "Oct 14" (* x 7))>
+;;   m10
+;;   m5 10
+;;   m5,10
+;;   m5 10*xx
+;;   m5 10*xx%x
+;;   m5 10*xx|0x%x
+;;   m25+x?a%c
+;;   m25+x?A%c
+;;   m97,122(string x)
+;;   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
+;;   m7|%(expt 2 x)
+;;   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))
+;;   m1\n10listx+x96|convert img%s.jpg -monochrome -resize 50%% -rotate 180 
img%c_mono.pdf
+;;   m1\n10listxnthxfoo-list|convert img%s.jpg -monochrome -resize 50%% 
-rotate 180 img%c_mono.pdf
+;;   m\n;; 16list*xxx)*xx%s:%s:%s
+;;   m\n8|**** TODO Learning from Data Week %(+ x 2) \nSCHEDULED: <%(date "Oct 
7" (* x 7))> DEADLINE: <%(date "Oct 14" (* x 7))>
 ;;
 ;; As you might have guessed, the syntax is as follows:
-;; m[<range start:=0>][<separator:= >]<range end>[Lisp expr]|[format expr]
 ;;
-;; x is the default var in the elisp expression.  It will take one by one
-;; the value of all numbers in the range.
+;;   m[<range start:=0>][<separator:= >]<range end>[Lisp expr]|[format expr]
 ;;
-;; | means that elisp expr has ended and format expr has begun.
-;; It can be omitted if the format expr starts with %.
-;; The keys are the same as for format.
-;; In addition %(sexp) forms are allowed.  The sexp can depend on x.
+;;     x is the default var in the elisp expression.  It will take one by one
+;;     the value of all numbers in the range.
 ;;
-;; Note that multiple % can be used in the format expression.
-;; In that case:
-;; * if the Lisp expression returns a list, the members of this list
-;;   are used in the appropriate place.
-;; * otherwise, it's just the result of the expression repeated as
-;;   many times as necessary.
+;;     | means that elisp expr has ended and format expr has begun.
+;;     It can be omitted if the format expr starts with %.
+;;     The keys are the same as for format.
+;;     In addition %(sexp) forms are allowed.  The sexp can depend on x.
+;;
+;;   Note that multiple % can be used in the format expression.
+;;   In that case:
+;;   - if the Lisp expression returns a list, the members of this list
+;;     are used in the appropriate place.
+;;   - otherwise, it's just the result of the expression repeated as
+;;     many times as necessary.
+;;
+;; Alternatively, if user does not want to type in the "tiny
+;; expressions", they can call the `tiny-helper' command that helps
+;; construct the "tiny expression", and then expands that.
+;;
+;; For example, the below two are equivalent:
+;;
+;;  - Type "m2_9+1*x2"
+;;  - M-x tiny-expand
+;;
+;; OR
+;;
+;;  - M-x tiny-helper
+;;  - 9 RET 2 RET _ RET +1*x2 RET RET (user entry in the interactive prompts)
 
 ;;; Code:
 
@@ -194,6 +208,8 @@ Defaults are used in place of null values."
              (fmt (car tes))
              (n-need (cl-count nil (cdr tes)))
              (idx -1)
+             (seq (number-sequence (read n0) (read n2)
+                                   (if (>= (read n0) (read n2)) -1 1)))
              (format-expression
               (concat "(mapconcat (lambda(x) (let ((lst %s)) (format %S "
                       (mapconcat (lambda (x)
@@ -203,15 +219,13 @@ Defaults are used in place of null values."
                                          (format "(nth %d lst)" (incf idx)))))
                                  (cdr tes)
                                  " ")
-                      ")))(number-sequence %s %s) \"%s\")")))
-        (unless (>= (read n0) (read n2))
-          (format
-           format-expression
-           expr
-           (replace-regexp-in-string "\\\\n" "\n" fmt)
-           n0
-           n2
-           s1))))))
+                      ")))'%S \"%s\")")))
+        (format
+         format-expression
+         expr
+         (replace-regexp-in-string "\\\\n" "\n" fmt)
+         seq
+         s1)))))
 
 (defconst tiny-format-str
   (let ((flags "[+ #-0]\\{0,1\\}")
@@ -335,7 +349,8 @@ Return nil if nothing was matched, otherwise
   (if (equal str "")
       ""
     (ignore-errors
-      (let ((i 0) (j 1)
+      (let ((i 0)
+            (j 1)
             (len (length str))
             sym s out allow-spc
             (n-paren 0)
@@ -373,7 +388,8 @@ Return nil if nothing was matched, otherwise
                   ((progn (setq sym (intern-soft s))
                           (cond
                             ;; general functionp
-                            ((not (eq t (help-function-arglist sym)))
+                            ((and (not (eq t (help-function-arglist sym)))
+                                  (not (eq sym '\,)))
                              (setq expect-fun nil)
                              (setq allow-spc t)
                              ;; (when (zerop n-paren) (push "(" out))
@@ -421,5 +437,103 @@ Optional SHIFT argument is the integer amount of days to 
shift."
       (setq time (time-add time (days-to-time shift))))
     (format-time-string formatter time)))
 
+;;;###autoload
+(defun tiny-helper (&optional end-val begin-val sep op fmt)
+  "Helper function for `tiny-expand'.
+
+The arguments to this function construct a “tiny expression”
+\"mBSEO|F\" where
+  E is the end value (END-VAL)     - defaults to 0 internally if nil or \"\",
+                                      or 9 if BEGIN-VAL is nil or \"\" too.
+  B is the begin value (BEGIN-VAL) - defaults to 0 internally if nil or \"\".
+  S is the separator (SEP)         - defaults to \" \" if nil or \"\".
+  O is the elisp operation (OP)    - defaults to \"\" if nil.
+  F is the format (FMT)            - defaults to \"\" if nil.
+
+If `tiny' expansion is possible at point, do it.
+Otherwise activate the helper to generate a valid “tiny
+expression” and expand that.
+
+Usage: Call TINY-HELPER, ↵↵↵↵↵            -> 0 1 2 3 4 5 6 7 8 9
+       Call TINY-HELPER, 9↵2↵_↵+1*x2↵↵    -> 5_7_9_11_13_15_17_19
+       Call TINY-HELPER, 15↵1↵↵-30*2x↵%x↵ -> 1c 1a 18 16 14 12 10 e c a 8 6 4 
2 0"
+  (interactive
+   (when (and (null (barf-if-buffer-read-only)) ;Use the helper only if tiny 
expansion is not
+              (null (tiny-mapconcat))) ;possible at point and if the buffer is 
editable.
+     (let ((prompt (propertize "tiny-helper: " 'face 
'font-lock-function-name-face)))
+       (list (read-string (concat prompt
+                                  "END value "
+                                  "[Hit RET for default=0; "
+                                  "Auto-set to 9 if both begin and end values 
are 0]: "))
+             (read-string (concat prompt
+                                  "BEGIN value "
+                                  "[Hit RET for default=0; "
+                                  "Has to be *smaller* than the end value]: "))
+             (read-string (concat prompt
+                                  "Separator "
+                                  "[Hit RET for default=Space; "
+                                  "eg: \\n; No math operators like - or = 
allowed]: "))
+             (read-string (concat prompt
+                                  "Lisp Operation "
+                                  "[Hit RET for default=\"\" (no Lisp 
operation); "
+                                  "Parentheses are optional; eg: *xx | (+ x 
?A) | *2+3x]: "))
+             (read-string (concat prompt
+                                  "Format "
+                                  "[Hit RET for default=\"\" (%0d); "
+                                  "eg: %x | 0x%x | %c | %s | %(+ x x) | "
+                                  "%014.2f | %03d; Parentheses required here 
for sexps]: "))))))
+  (barf-if-buffer-read-only)  ;Proceed only if the buffer is editable.
+  ;; Use the helper to derive a "tiny expression" if tiny expansion is
+  ;; not possible at point.
+  (when (null (tiny-mapconcat))
+    (let* ((tiny-key-binding (or (substitute-command-keys "\\[tiny-helper]")
+                                 (substitute-command-keys "\\[tiny-expand]")))
+           (end-val (if (null end-val) "" end-val)) ;Initialize to empty 
strings for non-interactive use.
+           (begin-val (if (null begin-val) "" begin-val))
+           (sep (if (null sep) "" sep))
+           (op (if (null op) "" op))
+           (fmt (if (null fmt) "" fmt))
+           (end-val-num (string-to-number end-val)) ;Note that 
(string-to-number "") -> 0
+           (begin-val-num (string-to-number begin-val))
+           tiny-expr)
+      ;; BEGIN-VAL and END-VAL sanity check.
+      (cond
+        ((= end-val-num begin-val-num)
+         (if (zerop end-val-num)
+             ;; If both are zero, set the end value to 9 (arbitrarily chosen).
+             (setq end-val "9")
+           (user-error (format "Begin value (%s) and End value (%s) cannot be 
the same"
+                               begin-val end-val))))
+        ((< end-val-num begin-val-num)
+         (user-error (format "End value (%s) has to be greater than the begin 
value (%s)"
+                             begin-val end-val))))
+      ;; SEP cannot be an empty string if BEGIN-VAL is a non-empty string.
+      ;; It is OK to not specify BEGIN-VAL if it is 0.
+      (when (and (not (string= begin-val ""))
+                 (string= sep ""))
+        (setq sep " "))
+      ;; When non-empty, prefix FMT with the | char for reading clarity.
+      (when (not (string= fmt ""))
+        (setq fmt (concat "|" fmt)))
+      (setq tiny-expr (concat "m" begin-val sep end-val op fmt))
+      (message (format "This %s expansion can also be done by typing %s and 
then %s"
+                       (propertize "tiny"
+                                   'face 'font-lock-function-name-face)
+                       (propertize tiny-expr
+                                   'face 'font-lock-keyword-face)
+                       (if (stringp tiny-key-binding)
+                           (propertize tiny-key-binding
+                                       'face 'font-lock-keyword-face)
+                         (concat
+                          (propertize "M-x tiny-helper"
+                                      'face 'font-lock-keyword-face)
+                          " or "
+                          (propertize "M-x tiny-expand"
+                                      'face 'font-lock-keyword-face)))))
+      (insert tiny-expr)
+      (undo-boundary)))
+  (tiny-expand))
+
+
 (provide 'tiny)
 ;;; tiny.el ends here



reply via email to

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