Allow specifying a buffer to add when called from a program

This commit is contained in:
Milan Zamazal 2022-05-16 07:21:41 +02:00
parent 5c89fb4fd6
commit 31636a8ccf

View File

@ -70,7 +70,7 @@ custom option but it can be overriden here."
(unless no-error (unless no-error
(error "No PIP frame"))))) (error "No PIP frame")))))
(defun pip-frame--make-frame () (defun pip-frame--make-frame (buffer)
(let ((frame (make-frame `((name . ,pip-frame--name) (let ((frame (make-frame `((name . ,pip-frame--name)
(unsplittable . t) (unsplittable . t)
,@pip-frame-parameters ,@pip-frame-parameters
@ -81,6 +81,7 @@ custom option but it can be overriden here."
(set-face-attribute 'default frame :height face-height) (set-face-attribute 'default frame :height face-height)
(mapc #'(lambda (p) (set-face-attribute 'default frame (car p) (cdr p))) (mapc #'(lambda (p) (set-face-attribute 'default frame (car p) (cdr p)))
pip-frame-face-attributes) pip-frame-face-attributes)
(set-window-buffer (car (window-list frame)) buffer)
frame)) frame))
(defun pip-frame-delete-frame () (defun pip-frame-delete-frame ()
@ -91,7 +92,7 @@ custom option but it can be overriden here."
(defun pip-frame--buffers () (defun pip-frame--buffers ()
(mapcar #'window-buffer (window-list (pip-frame--get-frame)))) (mapcar #'window-buffer (window-list (pip-frame--get-frame))))
(defun pip-frame--add-additional-buffer () (defun pip-frame--add-additional-buffer (buffer)
(let* ((windows (window-list (pip-frame--get-frame))) (let* ((windows (window-list (pip-frame--get-frame)))
(sizes (mapcar #'(lambda (w) (sizes (mapcar #'(lambda (w)
(let ((width (window-body-width w t)) (let ((width (window-body-width w t))
@ -104,18 +105,21 @@ custom option but it can be overriden here."
'right 'right
'below)) 'below))
(new-window (split-window largest nil side))) (new-window (split-window largest nil side)))
(set-window-buffer new-window (current-buffer)))) (set-window-buffer new-window buffer)))
;;;###autoload ;;;###autoload
(defun pip-frame-add-buffer () (defun pip-frame-add-buffer (&optional buffer-or-name)
"Add the current buffer to the PIP frame. "Add a buffer to the PIP frame.
If there is no PIP frame then create one. If there is no PIP frame then create one.
If BUFFER-OR-NAME is specified, add the given buffer to the frame,
otherwise add the current buffer.
A buffer can be added and displayed multiple times in the frame." A buffer can be added and displayed multiple times in the frame."
(interactive) (interactive)
(let ((frame (pip-frame--get-frame t))) (let ((frame (pip-frame--get-frame t))
(buffer (get-buffer (or buffer-or-name (current-buffer)))))
(if frame (if frame
(pip-frame--add-additional-buffer) (pip-frame--add-additional-buffer buffer)
(pip-frame--make-frame)))) (pip-frame--make-frame buffer))))
(defun pip-frame-remove-buffer (buffer-name) (defun pip-frame-remove-buffer (buffer-name)
"Remove buffer named BUFFER-NAME from the PIP frame. "Remove buffer named BUFFER-NAME from the PIP frame.