sideframe
sideframe copied to clipboard
Question: How can one force an existing frame-creating command to use a side-frame?
I would think a common use case would be to get an existing command, like speedbar, to display within a side frame. An example of how to do this would be very helpful. Maybe it requires an flet call to temporarily replace make-frame. It would be good to see your solution in any event as I'd like to try this out for this use. Thank you.
Since I wrote this package, I discovered side windows and it might be a better option. Below is the code for toggling a side popup containing a specific buffer with given width and the frame will be resized accordingly.
(defun nano-popup-frame-resize (&optional frame delta)
"Resize FRAME by the specified DELTA amount which is a list of cons
cells (SIDE . AMOUNT) where SIDE specifies the side to enlarge or
shrink (left, right, top, bottom) and AMOUNT specifies the number of
lines or columns. Positive number means to enlarge and negative number
means to shrink the frame.
;; Example usage
;; -------------
;;
;; Enlarge frame by 2 colums and 2 lines
;; (nano-popup-frame-resize nil '((right . 1) (left . 1) (top . 1) (bottom . 1)))
;;
;; Move frame one column to the left (side effect)
;; (nano-popup-frame-resize nil '((left . 1) (right . -1)))"
(let* ((frame (or frame (selected-frame)))
(cw (frame-char-width frame))
(ch (frame-char-height frame))
(x (car (frame-position frame)))
(y (cdr (frame-position frame)))
(border (frame-border-width frame))
(width (- (frame-pixel-width frame) (* 2 border)))
(height (- (frame-pixel-height frame) (* 2 border))))
(dolist (d delta)
(cond ((memq (car d) '(left right))
(let ((delta-width (* cw (cdr d))))
(setq width (+ width delta-width))
(when (eq (car d) 'left)
(setq x (- x delta-width)))))
((memq (car d) '(top bottom))
(let ((delta-height (* ch (cdr d))))
(setq height (+ height delta-height))
(when (eq (car d) 'top)
(setq y (- y delta-height)))))))
(set-frame-position frame x y)
(set-frame-size frame width height t)))
(defun nano-popup-side (buffer &optional width)
"Toggle a popup side window at the left of frame, displaying the given
BUFFER. The frame is enlarged on the left to accomodate the given WIDTH (in
columns). When the popup is hidden, the frame is shrunk accordingly."
(let* ((width (or width 32))
(side-window
(car (seq-filter
(lambda (window)
(eq 'left (window-parameter window 'window-side)))
(window-list))))
(side-buffer (when side-window (window-buffer side-window))))
(if (eq side-buffer buffer)
(progn
(delete-window side-window)
(nano-popup-frame-resize nil `((left . ,(- width)))))
(progn
(display-buffer-in-side-window buffer
`((side . left)
(dedicated . t)
(preserve-size . (t . nil))
(window-width . ,width)))
(unless side-window
(nano-popup-frame-resize nil `((left . ,width))))))))