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

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

[elpa] master b843226 26/46: tiny.el: removed `tiny-replace-sexp-despera


From: Oleh Krehel
Subject: [elpa] master b843226 26/46: tiny.el: removed `tiny-replace-sexp-desperately'
Date: Sun, 22 Mar 2015 17:42:33 +0000

branch: master
commit b8432269f5cfa32acd24df747306acf8c3c7a5a0
Author: oleh <address@hidden>
Commit: oleh <address@hidden>

    tiny.el: removed `tiny-replace-sexp-desperately'
---
 tiny.el |   54 +++++++++++++++++++++++++-----------------------------
 1 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/tiny.el b/tiny.el
index 071b842..a717e45 100644
--- a/tiny.el
+++ b/tiny.el
@@ -114,39 +114,35 @@ At the moment, only `tiny-mapconcat' is supported.
 (defun tiny-setup-default ()
   (global-set-key (kbd "C-;") 'tiny-expand))
 
-(defun tiny-replace-this-sexp ()
-  "Intelligently replace current sexp."
-  (interactive)
-  (or
-   (and (looking-back ")")
-        (ignore-errors
-          (let ((sexp (preceding-sexp)))
-            (unless (eq (car sexp) 'lambda)
-              (let ((value (eval sexp)))
-                (kill-sexp -1)
-                (insert (format "%s" value))
-                t)))))
-   (save-excursion (tiny-replace-sexp-desperately))))
+(defun tiny-replace-preceding-sexp ()
+  (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))))))
 
-(defun tiny-replace-sexp-desperately ()
+(defun tiny-replace-this-sexp ()
   "Eval and replace the current sexp.
-On error, go upwards and try again. Skip lambdas."
-  (condition-case nil
-      (tiny-up-list)
-    (error "can't go up this list"))
-  (let ((sexp (preceding-sexp)))
-    (cond
-      ;; since lambda evaluates to itself, skip it
-      ((eq (car sexp) 'lambda)
-       (tiny-replace-sexp-desperately))
-      (t
-       (condition-case nil
-           (let ((value (eval sexp)))
-             (kill-sexp -1)
-             (insert (format "%s" value)))
-         (error (tiny-replace-sexp-desperately)))))))
+On error go up list and try again."
+  (interactive)
+  (catch 'success
+    (while t
+      (ignore-errors
+        (tiny-replace-preceding-sexp)
+        (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.
+Must throw an error when can't go up further."
   (interactive)
   ;; check if inside string
   (let ((p (nth 8 (syntax-ppss))))



reply via email to

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