Skip to content

Commit fa7cb4d

Browse files
committed
`aw--doit' simply returns a window now
* ace-window.el (aw--doit): Only a single argument now. Don't do anything, except returning a selected window. (ace-select-window): Update. (ace-delete-window): Update. (ace-swap-window): Update. (ace-maximize-window): Simplify. (aw-switch-to-window): Simplify. (aw-delete-window): Simplify. (aw-swap-window): Simplify.
1 parent 4570578 commit fa7cb4d

File tree

1 file changed

+41
-60
lines changed

1 file changed

+41
-60
lines changed

ace-window.el

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -138,51 +138,33 @@ This hook is set to nil with each call to `ace-window'.")
138138
(ace-jump-delete-overlay-in-search-tree ace-jump-search-tree)
139139
(setq ace-jump-search-tree nil)))
140140

141-
(defun aw--doit (function mode-line)
142-
"Select a window and call FUNCTION for it.
143-
FUNCTION should accept a single `aj-position' structure.
144-
Set mode line to MODE-LINE during the selection process."
145-
(let* ((ace-jump-mode-scope aw-scope)
141+
(defun aw--doit (mode-line)
142+
"Return a selected other window.
143+
Amend MODE-LINE to the mode line for the duration of the selection."
144+
(let* ((start-window (selected-window))
145+
(ace-jump-mode-scope aw-scope)
146146
(next-window-scope
147147
(cl-case aw-scope
148148
('global 'visible)
149149
('frame 'frame)))
150150
(visual-area-list
151-
(sort (aw-list-visual-area) 'aw-visual-area<))
152-
(visual-area-list
153-
(if (<= (length visual-area-list) 2)
154-
visual-area-list
155-
(cl-remove-if
156-
(lambda (va)
157-
(let ((b (aj-visual-area-buffer va)))
158-
(with-current-buffer b
159-
(and buffer-read-only
160-
(= 0 (buffer-size b))))))
161-
visual-area-list))))
151+
(cl-remove-if
152+
(lambda (va)
153+
(let ((b (aj-visual-area-buffer va))
154+
(w (aj-visual-area-window va)))
155+
(or (with-current-buffer b
156+
(and buffer-read-only
157+
(= 0 (buffer-size b))))
158+
(aw-ignored-p w))))
159+
(sort (aw-list-visual-area) 'aw-visual-area<))))
162160
(cl-case (length visual-area-list)
163-
(0
164-
(error "Nowhere to switch to"))
161+
(0)
165162
(1
166-
(if (aw-ignored-p (selected-window))
167-
(other-window 1)
168-
;; don't get stuck in an empty read-only buffer
169-
(select-window (aj-visual-area-window (car visual-area-list)))))
163+
;; don't get stuck in an empty read-only buffer
164+
(select-window (aj-visual-area-window (car visual-area-list))))
170165
(2
171-
(if (aw-ignored-p (selected-window))
172-
(other-window 1)
173-
(let ((sw (selected-window))
174-
(w (next-window nil nil next-window-scope)))
175-
(while (aw-ignored-p w)
176-
(select-window w)
177-
(setq w (next-window nil nil next-window-scope)))
178-
(select-window sw)
179-
(funcall function
180-
(make-aj-position
181-
:offset 0
182-
:visual-area (make-aj-visual-area
183-
:buffer (window-buffer w)
184-
:window w
185-
:frame (window-frame w)))))))
166+
(select-window
167+
(next-window nil nil next-window-scope)))
186168
(t
187169
(let ((candidate-list
188170
(mapcar (lambda (va)
@@ -246,42 +228,44 @@ Set mode line to MODE-LINE during the selection process."
246228
(ace-jump-done)
247229
(ace-jump-push-mark)
248230
(run-hooks 'ace-jump-mode-before-jump-hook)
249-
(funcall function aj-data))
231+
(select-window (aj-position-window aj-data)))
250232
(throw 'done t))
251233

252234
(t
253235
(error "[AceJump] Internal error: tree node type is invalid"))))))
254-
(aw--done)))))))
236+
(aw--done)))))
237+
(prog1 (selected-window)
238+
(select-window start-window))))
255239

256240
;; ——— Interactive —————————————————————————————————————————————————————————————
257241
;;;###autoload
258242
(defun ace-select-window ()
259243
"Ace select window."
260244
(interactive)
261-
(aw--doit #'aw-switch-to-window " Ace - Window"))
245+
(aw-switch-to-window
246+
(aw--doit " Ace - Window")))
262247

263248
;;;###autoload
264249
(defun ace-delete-window ()
265250
"Ace delete window."
266251
(interactive)
267-
(aw--doit #'aw-delete-window " Ace - Delete Window"))
252+
(aw-delete-window
253+
(aw--doit " Ace - Delete Window")))
268254

269255
;;;###autoload
270256
(defun ace-swap-window ()
271257
"Ace swap window."
272258
(interactive)
273-
(aw--doit #'aw-swap-window " Ace - Swap Window"))
259+
(aw-swap-window
260+
(aw--doit " Ace - Swap Window")))
274261

275262
;;;###autoload
276263
(defun ace-maximize-window ()
277264
"Ace maximize window."
278265
(interactive)
279-
(aw--doit
280-
(lambda (aj)
281-
(let ((wnd (aj-position-window aj)))
282-
(select-window wnd)
283-
(delete-other-windows)))
284-
" Ace - Maximize Window"))
266+
(select-window
267+
(aw--doit " Ace - Maximize Window"))
268+
(delete-other-windows))
285269

286270
;;;###autoload
287271
(defun ace-window (arg)
@@ -326,21 +310,19 @@ Windows are numbered top down, left to right."
326310
((< (cadr e1) (cadr e2))
327311
t))))
328312

329-
(defun aw-switch-to-window (aj-data)
330-
"Switch to the window of `aj-position' structure AJ-DATA."
331-
(let ((frame (aj-position-frame aj-data))
332-
(window (aj-position-window aj-data)))
313+
(defun aw-switch-to-window (window)
314+
"Switch to the window WINDOW."
315+
(let ((frame (window-frame window)))
333316
(when (and (frame-live-p frame)
334317
(not (eq frame (selected-frame))))
335318
(select-frame-set-input-focus frame))
336319
(if (window-live-p window)
337320
(select-window window)
338321
(error "Bad aj-data, aw-delete-window: %S" aj-data))))
339322

340-
(defun aw-delete-window (aj-data)
341-
"Delete window of `aj-position' structure AJ-DATA."
342-
(let ((frame (aj-position-frame aj-data))
343-
(window (aj-position-window aj-data)))
323+
(defun aw-delete-window (window)
324+
"Delete window WINDOW."
325+
(let ((frame (window-frame window)))
344326
(when (and (frame-live-p frame)
345327
(not (eq frame (selected-frame))))
346328
(select-frame-set-input-focus (window-frame window)))
@@ -350,17 +332,16 @@ Windows are numbered top down, left to right."
350332
(delete-window window)
351333
(error "Bad aj-data, aw-delete-window: %S" aj-data)))))
352334

353-
(defun aw-swap-window (aj-data)
354-
"Swap buffers of current window and that of `aj-position' structure AJ-DATA."
335+
(defun aw-swap-window (window)
336+
"Swap buffers of current window and WINDOW."
355337
(cl-labels ((swap-windows (window1 window2)
356338
"Swap the buffers of WINDOW1 and WINDOW2."
357339
(let ((buffer1 (window-buffer window1))
358340
(buffer2 (window-buffer window2)))
359341
(set-window-buffer window1 buffer2)
360342
(set-window-buffer window2 buffer1)
361343
(select-window window2))))
362-
(let ((frame (aj-position-frame aj-data))
363-
(window (aj-position-window aj-data))
344+
(let ((frame (window-frame window))
364345
(this-window (selected-window)))
365346
(when (and (frame-live-p frame)
366347
(not (eq frame (selected-frame))))

0 commit comments

Comments
 (0)