Skip to content

Commit c381a4b

Browse files
committed
Overlay other windows
Refresh overlays after window split. Update: - readme.md
1 parent 5e2aee7 commit c381a4b

File tree

2 files changed

+59
-55
lines changed

2 files changed

+59
-55
lines changed

readme.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,13 @@ resize these buffers.
127127
![usage gif](images/navigate.gif)
128128

129129
## Bugs ##
130-
- When in resize mode, there's a visual overlay over the current
131-
buffer to give some visual indication what's going on. However, if
132-
you have two copies of the same buffer open, both are
133-
overlayed. Would like to reduce this so that only the buffer you're
134-
working in is overlaid, regardless of how many copies are open
130+
Working to spot one to fix...!
135131

136132
## Hopeful upcoming features ##
137133
I can't promise any of these but these are the things I'm hoping to
138134
do:
139135

140-
- put overlays over *other* buffers rather than current one. This
136+
- DONE: put overlays over *other* buffers rather than current one. This
141137
greys out other workspaces and leaves yours with full color,
142138
bringing your eye there. Just seems like a nice ergonomic touch.
143139
- DONE: allow customization to invert capital/non-capital behavior. Right

resize-window.el

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ This is also valuable to see that you are in resize mode."
9292
:type 'boolean
9393
:group 'resize-window)
9494

95-
(defvar resize-window--background-overlay ()
96-
"Holder for background overlay.")
95+
(defvar resize-window--background-overlays ()
96+
"List of background overlays.")
9797

9898
(defvar resize-window--window-stack ()
9999
"Stack for holding window configurations.")
@@ -128,8 +128,8 @@ should return the fine adjustment (default 1)."
128128
(?r resize-window--reset-windows " Resize - reset window layout" nil)
129129
(?w resize-window--cycle-window-positive " Resize - cycle window" nil)
130130
(?W resize-window--cycle-window-negative " Resize - cycle window" nil)
131-
(?2 split-window-below " Split window horizontally" nil)
132-
(?3 split-window-right " Slit window vertically" nil)
131+
(?2 resize-window--split-window-below " Split window horizontally" nil)
132+
(?3 resize-window--split-window-right " Slit window vertically" nil)
133133
(?0 resize-window--delete-window " Delete window" nil)
134134
(?k resize-window--kill-other-windows " Kill other windows (save state)" nil)
135135
(?y resize-window--restore-windows " (when state) Restore window configuration" nil)
@@ -198,15 +198,25 @@ CHOICE is a \(key function documentation allows-capitals\)."
198198
resize-window-dispatch-alist)
199199
"\n"))
200200

201-
(defun resize-window--make-background ()
202-
"Place a background over the current window."
201+
(defun resize-window--add-backgrounds ()
202+
"Place an overlay background over other windows."
203+
(resize-window--remove-backgrounds)
203204
(when resize-window-allow-backgrounds
204-
(let ((ol (make-overlay
205-
(point-min)
206-
(point-max)
207-
(window-buffer))))
208-
(overlay-put ol 'face 'resize-window-background)
209-
ol)))
205+
(let ((windows (remq (get-buffer-window) (window-list nil -1))))
206+
(dolist (window windows)
207+
(with-current-buffer (window-buffer window)
208+
(let ((ol (make-overlay
209+
(point-min)
210+
(point-max)
211+
(current-buffer))))
212+
(overlay-put ol 'face 'resize-window-background)
213+
(overlay-put ol 'window window)
214+
(push ol resize-window--background-overlays)))))))
215+
216+
(defun resize-window--remove-backgrounds ()
217+
"Remove the overlay backgrounds."
218+
(mapc 'delete-overlay resize-window--background-overlays)
219+
(setq resize-window--background-overlays nil))
210220

211221
(defun resize-window--execute-action (choice &optional scaled)
212222
"Given a CHOICE, grab values out of the alist.
@@ -232,27 +242,28 @@ If SCALED, then call action with the `resize-window-uppercase-argument'."
232242
Press n to resize down, p to resize up, b to resize left and f
233243
to resize right."
234244
(interactive)
235-
(setq resize-window--background-overlay (resize-window--make-background))
245+
(resize-window--add-backgrounds)
236246
(resize-window--notify "Resize mode: enter character, ? for help")
237247
(condition-case nil
238-
(let ((reading-characters t)
239-
;; allow mini-buffer to collapse after displaying menu
240-
(resize-mini-windows t))
241-
(while reading-characters
242-
(let* ((char (resize-window--match-alias (read-key)))
243-
(choice (assoc char resize-window-dispatch-alist))
244-
(capital (when (numberp char)
245-
(assoc (+ char 32) resize-window-dispatch-alist))))
246-
(cond
247-
(choice (resize-window--execute-action choice))
248-
((and capital (resize-window--allows-capitals capital))
249-
;; rather than pass an argument, we tell it to "scale" it
250-
;; with t and that method can worry about how to get that
251-
;; action
252-
(resize-window--execute-action capital t))
253-
(t (setq reading-characters nil)
254-
(delete-overlay resize-window--background-overlay))))))
255-
(quit (resize-window--delete-overlays))))
248+
(let ((reading-characters t)
249+
;; allow mini-buffer to collapse after displaying menu
250+
(resize-mini-windows t))
251+
(while reading-characters
252+
(let* ((char (resize-window--match-alias (read-key)))
253+
(choice (assoc char resize-window-dispatch-alist))
254+
(capital (when (numberp char)
255+
(assoc (+ char 32) resize-window-dispatch-alist))))
256+
(cond
257+
(choice (resize-window--execute-action choice))
258+
((and capital (resize-window--allows-capitals capital))
259+
;; rather than pass an argument, we tell it to "scale" it
260+
;; with t and that method can worry about how to get that
261+
;; action
262+
(resize-window--execute-action capital t))
263+
(t (setq reading-characters nil)
264+
(resize-window--remove-backgrounds))))))
265+
(quit
266+
(resize-window--remove-backgrounds))))
256267

257268
;;; Function Handlers
258269
(defun resize-window--resize-downward (&optional size)
@@ -291,36 +302,35 @@ If no SIZE is given, modify by `resize-window-default-argument'"
291302
"Reset window layout to even spread."
292303
(balance-windows))
293304

294-
(defun resize-window--delete-overlays ()
295-
"Remove overlays."
296-
(delete-overlay resize-window--background-overlay))
297-
298-
(defun resize-window--create-overlay ()
299-
"Add overlay."
300-
(setq resize-window--background-overlay (resize-window--make-background)))
301-
302305
(defun resize-window--cycle-window-positive ()
303306
"Cycle windows."
304-
(delete-overlay resize-window--background-overlay)
305307
(other-window 1)
306-
(setq resize-window--background-overlay (resize-window--make-background)))
308+
(resize-window--add-backgrounds))
307309

308310
(defun resize-window--cycle-window-negative ()
309311
"Cycle windows negative."
310-
(delete-overlay resize-window--background-overlay)
311312
(other-window -1)
312-
(setq resize-window--background-overlay (resize-window--make-background)))
313+
(resize-window--add-backgrounds))
313314

314315
(defun resize-window--display-menu ()
315316
"Display menu in minibuffer."
316317
(resize-window--notify "%s" (resize-window--get-documentation-strings)))
317318

319+
(defun resize-window--split-window-below ()
320+
"Split the window vertically."
321+
(split-window-below)
322+
(resize-window--add-backgrounds))
323+
324+
(defun resize-window--split-window-right ()
325+
"Split the window horizontally."
326+
(split-window-right)
327+
(resize-window--add-backgrounds))
328+
318329
(defun resize-window--delete-window ()
319330
"Delete the current window."
320331
(unless (eq (get-buffer-window) (window-main-window))
321-
(delete-overlay resize-window--background-overlay)
322332
(delete-window)
323-
(setq resize-window--background-overlay (resize-window--make-background))))
333+
(resize-window--add-backgrounds)))
324334

325335
(defun resize-window--window-push ()
326336
"Save the current state in the stack."
@@ -332,18 +342,16 @@ If no SIZE is given, modify by `resize-window-default-argument'"
332342

333343
(defun resize-window--kill-other-windows ()
334344
"Delete other windows."
335-
(resize-window--delete-overlays)
336345
(resize-window--window-push)
337346
(delete-other-windows)
338-
(resize-window--create-overlay))
347+
(resize-window--add-backgrounds))
339348

340349
(defun resize-window--restore-windows ()
341350
"Restore the previous state."
342351
(let ((config (resize-window--window-pop)))
343352
(when config
344-
(resize-window--delete-overlays)
345353
(set-window-configuration config)
346-
(resize-window--create-overlay))))
354+
(resize-window--add-backgrounds))))
347355

348356
(defvar resize-window--capital-letters (number-sequence ?A ?Z)
349357
"List of uppercase letters as characters.")

0 commit comments

Comments
 (0)