@@ -377,7 +377,7 @@ This applies to the commands that use `lispy-pair'."
377
377
:type 'boolean)
378
378
379
379
(defcustom lispy-thread-last-macro 'thread-last
380
- "Threading macro to use by default in command `lispy-to-threaded -last'."
380
+ "Threading macro to use by default in command `lispy-thread -last'."
381
381
:type 'symbol)
382
382
383
383
(defun lispy-dir-string< (a b)
@@ -5334,43 +5334,40 @@ With ARG, use the contents of `lispy-store-region-and-buffer' instead."
5334
5334
(lispy-from-left
5335
5335
(indent-sexp)))
5336
5336
5337
- (defun lispy-threaded -last ()
5337
+ (defun lispy-toggle-thread -last ()
5338
5338
"Toggle current expression between last-threaded/unthreaded forms."
5339
5339
(interactive)
5340
5340
(lispy-from-left
5341
5341
(if (eq (car (read (current-buffer)))
5342
5342
lispy-thread-last-macro)
5343
- (call-interactively #' lispy-to -last-unthreaded )
5344
- (call-interactively #' lispy-to-threaded -last))))
5343
+ (lispy-unthread -last)
5344
+ (lispy-thread -last))))
5345
5345
5346
- (defun lispy-to-threaded -last ()
5346
+ (defun lispy-thread -last ()
5347
5347
"Transform current expression to equivalent threaded-last expression.
5348
5348
Macro used may be customized in `lispy-thread-last-macro', which see."
5349
- (interactive)
5350
- (lispy-from-left
5351
- (let* ((bnd (lispy--bounds-dwim))
5352
- (expr (lispy--read (lispy--string-dwim bnd)))
5353
- (new-expr (lispy--thread-lastify expr lispy-thread-last-macro)))
5354
- (delete-region (car bnd) (cdr bnd))
5355
- (lispy--fast-insert
5356
- (lispy--whitespace-trim
5357
- new-expr))))
5358
5349
(lispy-from-left
5359
- (indent-sexp)))
5360
-
5361
- (defun lispy-to-last-unthreaded ()
5350
+ (prin1 (list lispy-thread-last-macro) (current-buffer))
5351
+ (lispy-slurp 1)
5352
+ (lispy-flow 1)
5353
+ (while (and (lispy-right-p)
5354
+ (save-excursion (backward-char) (lispy-right-p)))
5355
+ (lispy-barf 1)
5356
+ (lispy-move-down 1)
5357
+ (lispy-up 1))
5358
+ (lispy-left 1)))
5359
+
5360
+ (defun lispy-unthread-last ()
5362
5361
"Transform current last-threaded expression to equivalent unthreaded expression."
5363
- (interactive)
5364
- (lispy-from-left
5365
- (let* ((bnd (lispy--bounds-dwim))
5366
- (expr (lispy--read (lispy--string-dwim bnd)))
5367
- (new-expr (lispy--unthread-lastify expr)))
5368
- (delete-region (car bnd) (cdr bnd))
5369
- (lispy--fast-insert
5370
- (lispy--whitespace-trim
5371
- new-expr))))
5372
5362
(lispy-from-left
5373
- (indent-sexp)))
5363
+ (lispy-flow 1)
5364
+ (lispy-different)
5365
+ (while (lispy-forward 1)
5366
+ (lispy-move-up 1)
5367
+ (lispy-slurp 1))
5368
+ (lispy-different)
5369
+ (lispy-flow 1)
5370
+ (lispy-raise 1)))
5374
5371
5375
5372
(defun lispy-unbind-variable ()
5376
5373
"Substitute let-bound variable."
@@ -5858,7 +5855,7 @@ An equivalent of `cl-destructuring-bind'."
5858
5855
("B" lispy-store-region-and-buffer "store list bounds")
5859
5856
("R" lispy-reverse "reverse")
5860
5857
("T" lispy-ert "ert")
5861
- (">" lispy-threaded -last "toggle last-threaded form")
5858
+ (">" lispy-toggle-thread -last "toggle last-threaded form")
5862
5859
("" lispy-x-more-verbosity :exit nil)
5863
5860
("?" lispy-x-more-verbosity "help" :exit nil))
5864
5861
@@ -7721,30 +7718,6 @@ Defaults to `error'."
7721
7718
(lispy--replace (car lst) from to)
7722
7719
(lispy--replace (cdr lst) from to)))))
7723
7720
7724
- (cl-defun lispy--thread-lastify (sexp &optional threading-macro)
7725
- "Return SEXP transformed into a threaded-last SEXP using THREADING-MACRO..
7726
- THREADING-MACRO symbol should be, e.g. `thread-last' or `->>'."
7727
- (cl-labels ((rec (form)
7728
- (if (and (consp form)
7729
- (car (last form)))
7730
- (if (consp (car (last form)))
7731
- `(,@(rec (car (last form))) ,(butlast form))
7732
- (list form))
7733
- form)))
7734
- `(,threading-macro ,@(rec sexp))))
7735
-
7736
- (defun lispy--unthread-lastify (sexp)
7737
- "Return last-threaded SEXP unthreaded."
7738
- (cl-labels ((rec (form)
7739
- (if (and (consp form)
7740
- (car form))
7741
- (if (and (consp (car form))
7742
- (cadr form))
7743
- `(,@(car (last form)) ,(rec (butlast form)))
7744
- (car form))
7745
- form)))
7746
- `(,@(rec (cdr sexp)))))
7747
-
7748
7721
;;* Utilities: error reporting
7749
7722
(defun lispy-complain (msg)
7750
7723
"Display MSG if `lispy-verbose' is t."
0 commit comments