help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using windmove with side windows


From: pillule
Subject: using windmove with side windows
Date: Wed, 16 Jun 2021 03:09:49 +0200

Hi,

with commits db106ea88b and 0367d17482, windmove will now be able to
   1. select windows with the no-other-window window-parameter (if you
never set it yourself you should not see much difference) with
'windmove-allow-all-windows'
   2. specify you own function to creates window when you hit a frame edge
(previously that was customizable to only call split-window) with
'windmove-create-window'

That may make not much sense said as it so I wrote something to explain,
before I just forget about it, let's post it here :)


Configuring windmove to display side windows :

Assuming you have customized your 'display-buffer-alist' to
uses side-windows, see (info "(elisp) Choosing Window")

Or refer to this basic example :

(customize-set-variable 'display-buffer-alist
                        '(("\\*Ibuffer\\*"
                           (display-buffer-in-side-window)
                           (side . left) (window-width . 42))
                          ("\\*Info.*"
                           (display-buffer-in-side-window)
                           (side . right) (window-width . 80))
                          ("\\*e?shell.*"
                           (display-buffer-in-side-window)
                           (side . top))
                          ("\\*Messages.*"
                           (display-buffer-in-side-window)
                           (side . bottom))))

You can create a function that will dispatch the calls by direction :

(defun windmove-create-side-window (dir arg window)
  "Intermedary function choosing what to call on direction DIR.
If the selected-window is a side-window, delete it, otherwise,
select the relevant function from `windmove-dispatch-sides-functions'.
Only pass ARG and WINDOW to the childs functions."
  ;; normalise the direction
  (let ((dir (pcase dir (`up 'top) (`down 'bottom) (_ dir))))
    (funcall (if (eq dir (window-parameter window 'window-side))
                 (lambda (_dir _arg window)
                   (prog1 (get-mru-window) (delete-window window)))
               (alist-get dir windmove-dispatch-sides-functions))
             dir arg window)))

Then assign it to 'windmove-create-window'

(customize-set-variable 'windmove-create-window
                        #'windmove-create-side-window)

You can then specify an alist to actually hold the functions
to be called with their directions :

(defvar windmove-dispatch-sides-functions
  '((left . (lambda (_dir _arg _window)
              (ibuffer 'other-window)
              (get-buffer-window "*Ibuffer*")))
    (right . (lambda (_dir _arg _window)
               (let ((buffer (get-buffer "*info*")))
                 (if buffer
                     (display-buffer buffer)
                   (info))
                 (get-buffer-window "*info*"))))
    (top . (lambda (_dir _arg _window)
             (shell)
             (get-buffer-window "*shell*")))
    (bottom . (lambda (_arg _dir _window)
                (view-echo-area-messages)
                'no-select)))
  "Alist to dispatch by direction the calls of `windmove-create-side-window'")

And also activate this recommended setting :

(customize-set-variable 'windmove-allow-all-windows t)



I hope the snippets helps.

--



reply via email to

[Prev in Thread] Current Thread [Next in Thread]