Skip to content

Commit 611f2f1

Browse files
committed
Improve "p" when there are more than 2 windows
* lispy.el (lispy-eval--active-window): Remove. (lispy-eval--eval-window): Remove. (lispy-eval-other--window): Add. (lispy-eval--eval-buffer): Remove. (lispy-eval-other--buffer): Add. (lispy-eval--expr): Remove. (lispy--eval-in-window): Remove. (lispy-eval--last-live-p): Add. (lispy-eval-other-window): Eval in `lispy-eval-other--window' when it's live, otherwise select it with `ace-window'. * lispy-pkg.el: Depend on `ace-window'. * Cask: Depend on `ace-window'.
1 parent d999f19 commit 611f2f1

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

Cask

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
(depends-on "projectile")
1717
(depends-on "s")
1818
(depends-on "highlight")
19-
(depends-on "hydra"))
19+
(depends-on "hydra")
20+
(depends-on "ace-window"))

lispy-pkg.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
(define-package "lispy" "0.22.0"
1+
(define-package "lispy" "0.23.0"
22
"vi-like Paredit"
33
'((helm "1.5.3")
44
(ace-jump-mode "2.0")
55
(s "1.4.0")
66
(multiple-cursors "1.3.0")
77
(iedit "0.97")
88
(highlight "0")
9-
(hydra "0.4.1")))
9+
(hydra "0.4.1")
10+
(ace-window "0.7.0")))

lispy.el

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; Author: Oleh Krehel <[email protected]>
66
;; URL: https://github.com/abo-abo/lispy
7-
;; Version: 0.22.0
7+
;; Version: 0.23.0
88
;; Keywords: lisp
99

1010
;; This file is not part of GNU Emacs
@@ -2682,33 +2682,18 @@ When ARG isn't nil, try to pretty print the sexp."
26822682
(format "%s: nil" (propertize "cond" 'face 'font-lock-keyword-face))
26832683
"Message to echo when the current `cond' branch is nil.")
26842684

2685-
(defvar lispy-eval--active-window nil
2686-
"Source window for `lispy-eval-other-window'.")
2687-
(defvar lispy-eval--eval-window nil
2685+
(defvar lispy-eval-other--window nil
26882686
"Target window for `lispy-eval-other-window'.")
2689-
(defvar lispy-eval--eval-buffer nil
2687+
2688+
(defvar lispy-eval-other--buffer nil
26902689
"Target buffer for `lispy-eval-other-window'.")
2691-
(defvar lispy-eval--expr nil
2692-
"The expression for`lispy-eval-other-window'.")
2693-
2694-
(defun lispy--eval-in-window (aj-data)
2695-
"Eval in the context of AJ-DATA."
2696-
(let ((frame (aj-position-frame aj-data))
2697-
(window (aj-position-window aj-data)))
2698-
(when (and (frame-live-p frame)
2699-
(not (eq frame (selected-frame))))
2700-
(select-frame-set-input-focus frame))
2701-
(select-window window)
2702-
(setq lispy-eval--eval-window window)
2703-
(setq lispy-eval--eval-buffer (current-buffer))
2704-
(let ((res (condition-case e
2705-
(eval lispy-eval--expr lexical-binding)
2706-
(error
2707-
(message "error: %s" (error-message-string e))))))
2708-
(if (equal res lispy--eval-cond-msg)
2709-
(message res)
2710-
(message "%S" res))
2711-
(select-window lispy-eval--active-window))))
2690+
2691+
(defun lispy-eval--last-live-p ()
2692+
(and (window-live-p
2693+
lispy-eval-other--window)
2694+
(equal (window-buffer
2695+
lispy-eval-other--window)
2696+
lispy-eval-other--buffer)))
27122697

27132698
(defun lispy-eval-other-window ()
27142699
"Eval current expression in the context of other window.
@@ -2749,9 +2734,21 @@ In case the point is on a let-bound variable, add a `setq'."
27492734
(t (read str)))))
27502735
res)
27512736
(goto-char pt)
2752-
(other-window 1)
2753-
(setq res (eval expr lexical-binding))
2754-
(other-window -1)
2737+
(let* ((source-window (selected-window))
2738+
(target-window
2739+
(if (lispy-eval--last-live-p)
2740+
lispy-eval-other--window
2741+
(if (setq lispy-eval-other--window
2742+
(aw-select " Ace - Eval in Window"))
2743+
(progn
2744+
(setq lispy-eval-other--buffer
2745+
(window-buffer lispy-eval-other--window))
2746+
lispy-eval-other--window)
2747+
(setq lispy-eval-other--buffer nil)
2748+
source-window))))
2749+
(select-window target-window)
2750+
(setq res (eval expr lexical-binding))
2751+
(select-window source-window))
27552752
(if (equal res lispy--eval-cond-msg)
27562753
(message res)
27572754
(message "%S" res))))

0 commit comments

Comments
 (0)