Skip to content

Commit 2083ee3

Browse files
committed
Display the help menu in a side window
Exclude the help menu when saving a configuration. When restoring a configuration display the help menu only if it was currently open.
1 parent c381a4b commit 2083ee3

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

resize-window.el

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ should return the fine adjustment (default 1)."
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)
136-
(?? resize-window--display-menu " Resize - display menu" nil))
136+
(?? resize-window--display-menu " Resize - toggle help menu" nil))
137137
"List of resize mode bindings.
138138
Main data structure of the dispatcher with the form:
139139
\(key function documentation allows-capitals\)")
@@ -260,9 +260,12 @@ to resize right."
260260
;; with t and that method can worry about how to get that
261261
;; action
262262
(resize-window--execute-action capital t))
263-
(t (setq reading-characters nil)
264-
(resize-window--remove-backgrounds))))))
263+
(t
264+
(setq reading-characters nil)
265+
(resize-window--display-menu 'kill)
266+
(resize-window--remove-backgrounds))))))
265267
(quit
268+
(resize-window--display-menu 'kill)
266269
(resize-window--remove-backgrounds))))
267270

268271
;;; Function Handlers
@@ -312,9 +315,33 @@ If no SIZE is given, modify by `resize-window-default-argument'"
312315
(other-window -1)
313316
(resize-window--add-backgrounds))
314317

315-
(defun resize-window--display-menu ()
316-
"Display menu in minibuffer."
317-
(resize-window--notify "%s" (resize-window--get-documentation-strings)))
318+
(defun resize-window--display-menu (&optional action)
319+
"Toggle help menu side window or perform ACTION if non-nil.
320+
ACTION is a symbol of value 'kill or 'open."
321+
(let* ((buffer (get-buffer-create "*Resize-Window-Help*"))
322+
(window (get-buffer-window buffer))
323+
(add-backgrounds nil))
324+
(cond
325+
((and window (or (not action) (eq action 'kill)))
326+
(quit-window t window)
327+
(setq add-backgrounds t))
328+
((and (not window) (or (not action) (eq action 'open)))
329+
(setq window (display-buffer-in-side-window buffer nil))
330+
(set-window-parameter window 'no-other-window t)
331+
(set-window-parameter window 'no-delete-other-windows t)
332+
(with-current-buffer buffer
333+
(setq buffer-read-only t)
334+
(setq window-size-fixed t)
335+
(let ((inhibit-read-only t)
336+
(window-size-fixed nil))
337+
(erase-buffer)
338+
(insert (resize-window--get-documentation-strings))
339+
(fit-window-to-buffer window)))
340+
(setq add-backgrounds t)))
341+
;; NOTE: Just in case the help menu was selected (it shouldn't)
342+
;; refresh the backgrounds even when the help menu is killed.
343+
(when add-backgrounds
344+
(resize-window--add-backgrounds))))
318345

319346
(defun resize-window--split-window-below ()
320347
"Split the window vertically."
@@ -332,9 +359,33 @@ If no SIZE is given, modify by `resize-window-default-argument'"
332359
(delete-window)
333360
(resize-window--add-backgrounds)))
334361

362+
(defun resize-window--window-config ()
363+
"Return the current window configuration.
364+
Exclude the help menu from the configuration."
365+
(let ((display-menu (get-buffer-window "*Resize-Window-Help*")))
366+
(prog2
367+
(resize-window--display-menu 'kill)
368+
(current-window-configuration)
369+
(when display-menu
370+
(resize-window--display-menu 'open)))))
371+
372+
(defun resize-window--restore-config (config)
373+
"Restore the window configuration CONFIG then return it.
374+
Restore the help menu only if it is currently open."
375+
(let ((display-menu (get-buffer-window "*Resize-Window-Help*")))
376+
(set-window-configuration config)
377+
;; NOTE: If `resize-window--window-config' was used to save the
378+
;; CONFIG there is no help menu to kill. Keep this just in case.
379+
(resize-window--display-menu 'kill)
380+
(prog1
381+
(current-window-configuration)
382+
(if display-menu
383+
(resize-window--display-menu 'open)
384+
(resize-window--add-backgrounds)))))
385+
335386
(defun resize-window--window-push ()
336387
"Save the current state in the stack."
337-
(push (current-window-configuration) resize-window--window-stack))
388+
(push (resize-window--window-config) resize-window--window-stack))
338389

339390
(defun resize-window--window-pop ()
340391
"Return the first element and remove it from the stack."
@@ -350,8 +401,7 @@ If no SIZE is given, modify by `resize-window-default-argument'"
350401
"Restore the previous state."
351402
(let ((config (resize-window--window-pop)))
352403
(when config
353-
(set-window-configuration config)
354-
(resize-window--add-backgrounds))))
404+
(resize-window--restore-config config))))
355405

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

0 commit comments

Comments
 (0)